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

/* pngget.c - retrieval of values from info struct
3
 *
4
 * Last changed in libpng 1.40. [July 30, 2008]
5
 * For conditions of distribution and use, see copyright notice in png.h
6
 * Copyright (c) 1998-2008 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 20 21 22 23
      return(info_ptr->valid & flag);
   else
      return(0);
}

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

33
#if defined(PNG_INFO_IMAGE_SUPPORTED)
34
png_bytepp PNGAPI
35 36 37 38 39 40 41 42 43
png_get_rows(png_structp png_ptr, png_infop info_ptr)
{
   if (png_ptr != NULL && info_ptr != NULL)
      return(info_ptr->row_pointers);
   else
      return(0);
}
#endif

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

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

66
png_byte PNGAPI
67 68
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
69
   if (png_ptr != NULL && info_ptr != NULL)
70 71 72 73 74 75
   {
      return info_ptr->bit_depth;
   }
   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 81 82 83 84 85
   {
      return info_ptr->color_type;
   }
   return (0);
}

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

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

106
png_byte PNGAPI
107 108
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
109
   if (png_ptr != NULL && info_ptr != NULL)
110 111 112 113 114 115
   {
      return info_ptr->compression_type;
   }
   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\n", "png_get_x_pixels_per_meter");
124
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
125 126 127
          return (0);
      else return (info_ptr->x_pixels_per_unit);
   }
128 129
#else
   return (0);
130 131 132 133
#endif
   return (0);
}

134
png_uint_32 PNGAPI
135 136
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
137
   if (png_ptr != NULL && info_ptr != NULL)
138
#if defined(PNG_pHYs_SUPPORTED)
139
   if (info_ptr->valid & PNG_INFO_pHYs)
140
   {
141
      png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
142
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
143 144 145
          return (0);
      else return (info_ptr->y_pixels_per_unit);
   }
146 147
#else
   return (0);
148 149 150 151
#endif
   return (0);
}

152
png_uint_32 PNGAPI
153 154
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
155
   if (png_ptr != NULL && info_ptr != NULL)
156
#if defined(PNG_pHYs_SUPPORTED)
157
   if (info_ptr->valid & PNG_INFO_pHYs)
158 159
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
160
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
161
         info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
162 163 164
          return (0);
      else return (info_ptr->x_pixels_per_unit);
   }
165 166
#else
   return (0);
167 168 169 170
#endif
   return (0);
}

171
#ifdef PNG_FLOATING_POINT_SUPPORTED
172
float PNGAPI
173 174
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
   {
175
   if (png_ptr != NULL && info_ptr != NULL)
176
#if defined(PNG_pHYs_SUPPORTED)
177
   if (info_ptr->valid & PNG_INFO_pHYs)
178 179 180
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
      if (info_ptr->x_pixels_per_unit == 0)
181
         return ((float)0.0);
182
      else
183 184
         return ((float)((float)info_ptr->y_pixels_per_unit
            /(float)info_ptr->x_pixels_per_unit));
185
   }
186 187
#else
   return (0.0);
188
#endif
189
   return ((float)0.0);
190
}
191
#endif
192

193
png_int_32 PNGAPI
194 195
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
196
   if (png_ptr != NULL && info_ptr != NULL)
197
#if defined(PNG_oFFs_SUPPORTED)
198
   if (info_ptr->valid & PNG_INFO_oFFs)
199 200
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
201
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
202 203 204
          return (0);
      else return (info_ptr->x_offset);
   }
205 206
#else
   return (0);
207 208 209 210
#endif
   return (0);
}

211
png_int_32 PNGAPI
212 213
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
214
   if (png_ptr != NULL && info_ptr != NULL)
215
#if defined(PNG_oFFs_SUPPORTED)
216
   if (info_ptr->valid & PNG_INFO_oFFs)
217 218
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
219
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
220 221 222
          return (0);
      else return (info_ptr->y_offset);
   }
223 224
#else
   return (0);
225 226 227 228
#endif
   return (0);
}

229
png_int_32 PNGAPI
230 231
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
232
   if (png_ptr != NULL && info_ptr != NULL)
233
#if defined(PNG_oFFs_SUPPORTED)
234
   if (info_ptr->valid & PNG_INFO_oFFs)
235 236
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
237
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
238 239 240
          return (0);
      else return (info_ptr->x_offset);
   }
241 242
#else
   return (0);
243 244 245 246
#endif
   return (0);
}

247
png_int_32 PNGAPI
248 249
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
250
   if (png_ptr != NULL && info_ptr != NULL)
251
#if defined(PNG_oFFs_SUPPORTED)
252
   if (info_ptr->valid & PNG_INFO_oFFs)
253 254
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
255
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
256 257 258
          return (0);
      else return (info_ptr->y_offset);
   }
259 260
#else
   return (0);
261 262 263 264
#endif
   return (0);
}

265
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
266
png_uint_32 PNGAPI
267 268 269
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)
270
     *.0254 +.5));
271 272
}

273
png_uint_32 PNGAPI
274 275 276
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)
277
     *.0254 +.5));
278 279
}

280
png_uint_32 PNGAPI
281 282 283
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)
284
     *.0254 +.5));
285 286
}

287
float PNGAPI
288 289 290
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
291
     *.00003937);
292 293
}

294
float PNGAPI
295 296 297
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
298
     *.00003937);
299 300
}

301
#if defined(PNG_pHYs_SUPPORTED)
302
png_uint_32 PNGAPI
303 304 305 306 307
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;

308
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
   {
      png_debug1(1, "in %s retrieval function\n", "pHYs");
      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;
325
         if (*unit_type == 1)
326
         {
327 328
            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);
329 330 331 332 333
         }
      }
   }
   return (retval);
}
334
#endif /* PNG_pHYs_SUPPORTED */
335
#endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
336 337

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

339 340
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

341
png_byte PNGAPI
A
Andreas Dilger 已提交
342 343
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
344
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
345 346
      return(info_ptr->channels);
   else
347
      return (0);
A
Andreas Dilger 已提交
348 349
}

350
png_bytep PNGAPI
A
Andreas Dilger 已提交
351 352
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
353
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
354 355
      return(info_ptr->signature);
   else
356
      return (NULL);
A
Andreas Dilger 已提交
357 358
}

359
#if defined(PNG_bKGD_SUPPORTED)
360
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
361 362 363
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
   png_color_16p *background)
{
364 365
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
      && background != NULL)
A
Andreas Dilger 已提交
366 367 368 369 370 371 372 373 374
   {
      png_debug1(1, "in %s retrieval function\n", "bKGD");
      *background = &(info_ptr->background);
      return (PNG_INFO_bKGD);
   }
   return (0);
}
#endif

375
#if defined(PNG_cHRM_SUPPORTED)
376
#ifdef PNG_FLOATING_POINT_SUPPORTED
377
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
378 379 380 381
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)
{
382
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
A
Andreas Dilger 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
   {
      png_debug1(1, "in %s retrieval function\n", "cHRM");
      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
406
#ifdef PNG_FIXED_POINT_SUPPORTED
407
png_uint_32 PNGAPI
408
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
409 410 411
   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)
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
   {
      png_debug1(1, "in %s retrieval function\n", "cHRM");
      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 已提交
438

439
#if defined(PNG_gAMA_SUPPORTED)
440
#ifdef PNG_FLOATING_POINT_SUPPORTED
441
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
442 443
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
444 445
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
      && file_gamma != NULL)
A
Andreas Dilger 已提交
446 447 448 449 450 451 452 453
   {
      png_debug1(1, "in %s retrieval function\n", "gAMA");
      *file_gamma = (double)info_ptr->gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
454
#ifdef PNG_FIXED_POINT_SUPPORTED
455
png_uint_32 PNGAPI
456
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
457
    png_fixed_point *int_file_gamma)
458 459 460 461 462 463 464 465 466 467 468
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
      && int_file_gamma != NULL)
   {
      png_debug1(1, "in %s retrieval function\n", "gAMA");
      *int_file_gamma = info_ptr->int_gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
469
#endif
A
Andreas Dilger 已提交
470

471
#if defined(PNG_sRGB_SUPPORTED)
472
png_uint_32 PNGAPI
473
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
474
{
475 476
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
      && file_srgb_intent != NULL)
477 478
   {
      png_debug1(1, "in %s retrieval function\n", "sRGB");
479
      *file_srgb_intent = (int)info_ptr->srgb_intent;
480 481 482 483 484 485
      return (PNG_INFO_sRGB);
   }
   return (0);
}
#endif

486
#if defined(PNG_iCCP_SUPPORTED)
487
png_uint_32 PNGAPI
488 489
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
             png_charpp name, int *compression_type,
490
             png_charpp profile, png_uint_32 *proflen)
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
{
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
      && name != NULL && profile != NULL && proflen != NULL)
   {
      png_debug1(1, "in %s retrieval function\n", "iCCP");
      *name = info_ptr->iccp_name;
      *profile = info_ptr->iccp_profile;
      /* compression_type is a dummy so the API won't have to change
         if we introduce multiple compression types later. */
      *proflen = (int)info_ptr->iccp_proflen;
      *compression_type = (int)info_ptr->iccp_compression;
      return (PNG_INFO_iCCP);
   }
   return (0);
}
#endif

508
#if defined(PNG_sPLT_SUPPORTED)
509
png_uint_32 PNGAPI
510
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
511
             png_sPLT_tpp spalettes)
512 513
{
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
514
   {
515
     *spalettes = info_ptr->splt_palettes;
516 517 518
     return ((png_uint_32)info_ptr->splt_palettes_num);
   }
   return (0);
519 520 521
}
#endif

522
#if defined(PNG_hIST_SUPPORTED)
523
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
524 525
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
526 527
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
      && hist != NULL)
A
Andreas Dilger 已提交
528 529 530 531 532 533 534 535 536
   {
      png_debug1(1, "in %s retrieval function\n", "hIST");
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
   return (0);
}
#endif

537
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
538 539 540 541
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)
542

A
Andreas Dilger 已提交
543
{
544
   if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
A
Andreas Dilger 已提交
545 546 547 548 549 550
      bit_depth != NULL && color_type != NULL)
   {
      png_debug1(1, "in %s retrieval function\n", "IHDR");
      *width = info_ptr->width;
      *height = info_ptr->height;
      *bit_depth = info_ptr->bit_depth;
551 552
      if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
        png_error(png_ptr, "Invalid bit depth");
A
Andreas Dilger 已提交
553
      *color_type = info_ptr->color_type;
554 555
      if (info_ptr->color_type > 6)
        png_error(png_ptr, "Invalid color type");
A
Andreas Dilger 已提交
556 557 558 559 560 561
      if (compression_type != NULL)
         *compression_type = info_ptr->compression_type;
      if (filter_type != NULL)
         *filter_type = info_ptr->filter_type;
      if (interlace_type != NULL)
         *interlace_type = info_ptr->interlace_type;
562 563

      /* check for potential overflow of rowbytes */
564
      if (*width == 0 || *width > PNG_UINT_31_MAX)
565
        png_error(png_ptr, "Invalid image width");
566
      if (*height == 0 || *height > PNG_UINT_31_MAX)
567
        png_error(png_ptr, "Invalid image height");
568 569 570 571 572 573
      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 */
574
      {
575
         png_warning(png_ptr,
576
            "Width too large for libpng to process image data");
577
      }
A
Andreas Dilger 已提交
578 579 580 581 582
      return (1);
   }
   return (0);
}

583
#if defined(PNG_oFFs_SUPPORTED)
584
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
585
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
586
   png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
587
{
588 589
   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 已提交
590 591 592 593 594 595 596 597 598 599 600
   {
      png_debug1(1, "in %s retrieval function\n", "oFFs");
      *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

601
#if defined(PNG_pCAL_SUPPORTED)
602
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
603 604 605 606
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)
{
607 608
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
      && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
A
Andreas Dilger 已提交
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
      nparams != NULL && units != NULL && params != NULL)
   {
      png_debug1(1, "in %s retrieval function\n", "pCAL");
      *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

625
#if defined(PNG_sCAL_SUPPORTED)
626
#ifdef PNG_FLOATING_POINT_SUPPORTED
627
png_uint_32 PNGAPI
628
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
629
             int *unit, double *width, double *height)
630
{
631 632
    if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
633 634 635 636 637 638 639 640
    {
        *unit = info_ptr->scal_unit;
        *width = info_ptr->scal_pixel_width;
        *height = info_ptr->scal_pixel_height;
        return (PNG_INFO_sCAL);
    }
    return(0);
}
641 642
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
643
png_uint_32 PNGAPI
644
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
645
             int *unit, png_charpp width, png_charpp height)
646
{
647 648
    if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
649 650 651 652 653 654 655 656 657
    {
        *unit = info_ptr->scal_unit;
        *width = info_ptr->scal_s_width;
        *height = info_ptr->scal_s_height;
        return (PNG_INFO_sCAL);
    }
    return(0);
}
#endif
658 659
#endif
#endif
660

661
#if defined(PNG_pHYs_SUPPORTED)
662
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
663 664 665
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
666 667
   png_uint_32 retval = 0;

668 669
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->valid & PNG_INFO_pHYs))
A
Andreas Dilger 已提交
670 671
   {
      png_debug1(1, "in %s retrieval function\n", "pHYs");
672
      if (res_x != NULL)
673 674
      {
         *res_x = info_ptr->x_pixels_per_unit;
675 676 677 678
         retval |= PNG_INFO_pHYs;
      }
      if (res_y != NULL)
      {
679 680 681 682 683 684 685 686
         *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;
      }
A
Andreas Dilger 已提交
687
   }
688
   return (retval);
A
Andreas Dilger 已提交
689 690 691
}
#endif

692
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
693 694 695
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
   int *num_palette)
{
696 697
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
698 699 700 701 702 703 704 705 706 707
   {
      png_debug1(1, "in %s retrieval function\n", "PLTE");
      *palette = info_ptr->palette;
      *num_palette = info_ptr->num_palette;
      png_debug1(3, "num_palette = %d\n", *num_palette);
      return (PNG_INFO_PLTE);
   }
   return (0);
}

708
#if defined(PNG_sBIT_SUPPORTED)
709
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
710 711
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
712 713
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
      && sig_bit != NULL)
A
Andreas Dilger 已提交
714 715 716 717 718 719 720 721 722
   {
      png_debug1(1, "in %s retrieval function\n", "sBIT");
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
   return (0);
}
#endif

723
#if defined(PNG_TEXT_SUPPORTED)
724
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
725 726 727
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
   int *num_text)
{
728
   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
A
Andreas Dilger 已提交
729 730
   {
      png_debug1(1, "in %s retrieval function\n",
731 732
         (png_ptr->chunk_name[0] == '\0' ? "text"
             : (png_const_charp)png_ptr->chunk_name));
A
Andreas Dilger 已提交
733 734 735 736
      if (text_ptr != NULL)
         *text_ptr = info_ptr->text;
      if (num_text != NULL)
         *num_text = info_ptr->num_text;
737
      return ((png_uint_32)info_ptr->num_text);
A
Andreas Dilger 已提交
738
   }
739 740
   if (num_text != NULL)
     *num_text = 0;
A
Andreas Dilger 已提交
741 742 743 744
   return(0);
}
#endif

745
#if defined(PNG_tIME_SUPPORTED)
746
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
747 748
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
749 750
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
751 752 753 754 755 756 757 758 759
   {
      png_debug1(1, "in %s retrieval function\n", "tIME");
      *mod_time = &(info_ptr->mod_time);
      return (PNG_INFO_tIME);
   }
   return (0);
}
#endif

760
#if defined(PNG_tRNS_SUPPORTED)
761
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
762 763 764
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
   png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{
765
   png_uint_32 retval = 0;
766
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
767 768
   {
      png_debug1(1, "in %s retrieval function\n", "tRNS");
769
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
A
Andreas Dilger 已提交
770
      {
771 772 773 774 775 776 777
          if (trans != NULL)
          {
             *trans = info_ptr->trans;
             retval |= PNG_INFO_tRNS;
          }
          if (trans_values != NULL)
             *trans_values = &(info_ptr->trans_values);
A
Andreas Dilger 已提交
778
      }
779
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
780
      {
781 782 783 784 785
          if (trans_values != NULL)
          {
             *trans_values = &(info_ptr->trans_values);
             retval |= PNG_INFO_tRNS;
          }
786
          if (trans != NULL)
787
             *trans = NULL;
A
Andreas Dilger 已提交
788
      }
789
      if (num_trans != NULL)
A
Andreas Dilger 已提交
790
      {
791 792
         *num_trans = info_ptr->num_trans;
         retval |= PNG_INFO_tRNS;
A
Andreas Dilger 已提交
793 794
      }
   }
795
   return (retval);
A
Andreas Dilger 已提交
796 797 798
}
#endif

799
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
800
png_uint_32 PNGAPI
801 802 803 804
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)
805
   {
806
     *unknowns = info_ptr->unknown_chunks;
807 808 809
     return ((png_uint_32)info_ptr->unknown_chunks_num);
   }
   return (0);
810 811 812
}
#endif

813
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
814
png_byte PNGAPI
815 816
png_get_rgb_to_gray_status (png_structp png_ptr)
{
817
   return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
818 819
}
#endif
820

821
#if defined(PNG_USER_CHUNKS_SUPPORTED)
822
png_voidp PNGAPI
823 824
png_get_user_chunk_ptr(png_structp png_ptr)
{
825
   return (png_ptr? png_ptr->user_chunk_ptr : NULL);
826 827 828
}
#endif

829
#ifdef PNG_WRITE_SUPPORTED
830
png_size_t PNGAPI
831 832
png_get_compression_buffer_size(png_structp png_ptr)
{
833
   return (png_ptr ? png_ptr->zbuf_size : 0L);
834
}
835
#endif
836

837 838 839 840 841 842 843 844 845 846 847 848 849 850

#ifdef PNG_SET_USER_LIMITS_SUPPORTED
/* these functions were added to libpng 1.2.6 */
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);
}
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
851
 
852 853 854 855 856 857 858 859 860 861 862 863 864 865
#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 */

866
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */