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

/* pngget.c - retrieval of values from info struct
3
 *
4
 * libpng 1.0.6h - April 24, 2000
5 6 7
 * For conditions of distribution and use, see copyright notice in png.h
 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
 * Copyright (c) 1996, 1997 Andreas Dilger
8
 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
9
 */
A
Andreas Dilger 已提交
10 11 12 13 14 15 16

#define PNG_INTERNAL
#include "png.h"

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

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

32 33 34 35 36 37 38 39 40 41 42
#if defined(PNG_INFO_IMAGE_SUPPORTED)
png_bytepp
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

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

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

png_byte
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
68
   if (png_ptr != NULL && info_ptr != NULL)
69 70 71 72 73 74 75 76 77
   {
      return info_ptr->bit_depth;
   }
   return (0);
}

png_byte
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
78
   if (png_ptr != NULL && info_ptr != NULL)
79 80 81 82 83 84 85 86 87
   {
      return info_ptr->color_type;
   }
   return (0);
}

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

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

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

115 116 117
png_uint_32
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
118
#if defined(PNG_pHYs_SUPPORTED)
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
      if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
          return (0);
      else return (info_ptr->x_pixels_per_unit);
   }
   else
#endif
   return (0);
}

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

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

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

png_uint_32
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
187
#if defined(PNG_oFFs_SUPPORTED)
188
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
189 190 191 192 193 194 195 196 197 198 199 200 201 202
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
      if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
          return (0);
      else return (info_ptr->x_offset);
   }
   else
#endif
   return (0);
}

png_uint_32
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
203
#if defined(PNG_oFFs_SUPPORTED)
204
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
205 206 207 208 209 210 211 212 213 214 215 216 217 218
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
      if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
          return (0);
      else return (info_ptr->y_offset);
   }
   else
#endif
   return (0);
}

png_uint_32
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
219
#if defined(PNG_oFFs_SUPPORTED)
220
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
221 222 223 224 225 226 227 228 229 230 231 232 233 234
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
      if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
          return (0);
      else return (info_ptr->x_offset);
   }
   else
#endif
   return (0);
}

png_uint_32
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
235
#if defined(PNG_oFFs_SUPPORTED)
236
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
237 238 239 240 241 242 243 244 245 246 247
   {
      png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
      if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
          return (0);
      else return (info_ptr->y_offset);
   }
   else
#endif
   return (0);
}

248
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
249 250 251 252
png_uint_32
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)
253
     *.0254 +.5);
254 255 256 257 258 259
}

png_uint_32
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)
260
     *.0254 +.5);
261 262 263 264 265 266
}

png_uint_32
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)
267
     *.0254 +.5);
268 269 270 271 272 273
}

float
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
274
     *.00003937);
275 276 277 278 279 280
}

float
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
281
     *.00003937)
282 283 284 285 286 287 288 289 290
}

#if defined(PNG_READ_pHYs_SUPPORTED)
png_uint_32
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;

291
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
   {
      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;
         if(unit_type == 1)
         {
310 311
            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);
312 313 314 315 316
         }
      }
   }
   return (retval);
}
317
#endif /* PNG_READ_pHYs_SUPPORTED */
318
#endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
319 320

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

322 323
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

A
Andreas Dilger 已提交
324 325 326
png_byte
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
327
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
328 329
      return(info_ptr->channels);
   else
330
      return (0);
A
Andreas Dilger 已提交
331 332 333 334 335
}

png_bytep
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
336
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
337 338
      return(info_ptr->signature);
   else
339
      return (NULL);
A
Andreas Dilger 已提交
340 341 342 343 344 345 346
}

#if defined(PNG_READ_bKGD_SUPPORTED)
png_uint_32
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
   png_color_16p *background)
{
347 348
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
      && background != NULL)
A
Andreas Dilger 已提交
349 350 351 352 353 354 355 356 357 358
   {
      png_debug1(1, "in %s retrieval function\n", "bKGD");
      *background = &(info_ptr->background);
      return (PNG_INFO_bKGD);
   }
   return (0);
}
#endif

#if defined(PNG_READ_cHRM_SUPPORTED)
359
#ifdef PNG_FLOATING_POINT_SUPPORTED
A
Andreas Dilger 已提交
360 361 362 363 364
png_uint_32
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)
{
365
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
A
Andreas Dilger 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
   {
      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
389 390 391
#ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
392 393 394
   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)
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
{
   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 已提交
421 422

#if defined(PNG_READ_gAMA_SUPPORTED)
423
#ifdef PNG_FLOATING_POINT_SUPPORTED
A
Andreas Dilger 已提交
424 425 426
png_uint_32
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
427 428
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
      && file_gamma != NULL)
A
Andreas Dilger 已提交
429 430 431 432 433 434 435 436
   {
      png_debug1(1, "in %s retrieval function\n", "gAMA");
      *file_gamma = (double)info_ptr->gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
437 438
png_uint_32
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
439
    png_fixed_point *int_file_gamma)
440 441 442 443 444 445 446 447 448 449 450
{
   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
A
Andreas Dilger 已提交
451

452 453
#if defined(PNG_READ_sRGB_SUPPORTED)
png_uint_32
454
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
455
{
456 457
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
      && file_srgb_intent != NULL)
458 459
   {
      png_debug1(1, "in %s retrieval function\n", "sRGB");
460
      *file_srgb_intent = (int)info_ptr->srgb_intent;
461 462 463 464 465 466
      return (PNG_INFO_sRGB);
   }
   return (0);
}
#endif

467 468 469 470
#if defined(PNG_READ_iCCP_SUPPORTED)
png_uint_32
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
             png_charpp name, int *compression_type,
471
             png_charpp profile, png_uint_32 *proflen)
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
{
   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

489
#if defined(PNG_READ_sPLT_SUPPORTED)
490
png_uint_32
491
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
492
             png_sPLT_tpp spalettes)
493 494 495 496 497 498 499
{
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
     *spalettes = info_ptr->splt_palettes;
   return ((png_uint_32)info_ptr->splt_palettes_num);
}
#endif

A
Andreas Dilger 已提交
500 501 502 503
#if defined(PNG_READ_hIST_SUPPORTED)
png_uint_32
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
504 505
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
      && hist != NULL)
A
Andreas Dilger 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519
   {
      png_debug1(1, "in %s retrieval function\n", "hIST");
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
   return (0);
}
#endif

png_uint_32
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)
520

A
Andreas Dilger 已提交
521
{
522
   if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
A
Andreas Dilger 已提交
523 524
      bit_depth != NULL && color_type != NULL)
   {
525 526 527
      int pixel_depth, channels;
      png_uint_32 rowbytes_per_pixel;

A
Andreas Dilger 已提交
528 529 530 531 532 533 534 535 536 537 538
      png_debug1(1, "in %s retrieval function\n", "IHDR");
      *width = info_ptr->width;
      *height = info_ptr->height;
      *bit_depth = info_ptr->bit_depth;
      *color_type = info_ptr->color_type;
      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;
539 540 541 542 543 544 545 546 547 548 549 550

      /* check for potential overflow of rowbytes */
      if (*color_type == PNG_COLOR_TYPE_PALETTE)
         channels = 1;
      else if (*color_type & PNG_COLOR_MASK_COLOR)
         channels = 3;
      else
         channels = 1;
      if (*color_type & PNG_COLOR_MASK_ALPHA)
         channels++;
      pixel_depth = *bit_depth * channels;
      rowbytes_per_pixel = (pixel_depth + 7) >> 3;
551
      if ((*width > PNG_MAX_UINT/rowbytes_per_pixel))
552 553 554 555
      {
         png_warning(png_ptr,
            "Width too large for libpng to process image data.");
      }
A
Andreas Dilger 已提交
556 557 558 559 560 561 562 563
      return (1);
   }
   return (0);
}

#if defined(PNG_READ_oFFs_SUPPORTED)
png_uint_32
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
564
   png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
565
{
566 567
   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 已提交
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
   {
      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

#if defined(PNG_READ_pCAL_SUPPORTED)
png_uint_32
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)
{
585 586
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
      && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
A
Andreas Dilger 已提交
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
      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

603 604 605 606
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
607
             int *unit, double *width, double *height)
608
{
609 610
    if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
611 612 613 614 615 616 617 618
    {
        *unit = info_ptr->scal_unit;
        *width = info_ptr->scal_pixel_width;
        *height = info_ptr->scal_pixel_height;
        return (PNG_INFO_sCAL);
    }
    return(0);
}
619 620
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
621 622
png_uint_32
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
623
             int *unit, png_charpp width, png_charpp height)
624
{
625 626
    if (png_ptr != NULL && info_ptr != NULL &&
       (info_ptr->valid & PNG_INFO_sCAL))
627 628 629 630 631 632 633 634 635
    {
        *unit = info_ptr->scal_unit;
        *width = info_ptr->scal_s_width;
        *height = info_ptr->scal_s_height;
        return (PNG_INFO_sCAL);
    }
    return(0);
}
#endif
636 637
#endif
#endif
638

A
Andreas Dilger 已提交
639 640 641 642 643
#if defined(PNG_READ_pHYs_SUPPORTED)
png_uint_32
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
644 645
   png_uint_32 retval = 0;

646 647
   if (png_ptr != NULL && info_ptr != NULL &&
      (info_ptr->valid & PNG_INFO_pHYs))
A
Andreas Dilger 已提交
648 649
   {
      png_debug1(1, "in %s retrieval function\n", "pHYs");
650
      if (res_x != NULL)
651 652
      {
         *res_x = info_ptr->x_pixels_per_unit;
653 654 655 656
         retval |= PNG_INFO_pHYs;
      }
      if (res_y != NULL)
      {
657 658 659 660 661 662 663 664
         *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 已提交
665
   }
666
   return (retval);
A
Andreas Dilger 已提交
667 668 669 670 671 672 673
}
#endif

png_uint_32
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
   int *num_palette)
{
674 675
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
676 677 678 679 680 681 682 683 684 685 686 687 688 689
   {
      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);
}

#if defined(PNG_READ_sBIT_SUPPORTED)
png_uint_32
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
690 691
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
      && sig_bit != NULL)
A
Andreas Dilger 已提交
692 693 694 695 696 697 698 699 700
   {
      png_debug1(1, "in %s retrieval function\n", "sBIT");
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
   return (0);
}
#endif

701
#if defined(PNG_READ_TEXT_SUPPORTED)
A
Andreas Dilger 已提交
702 703 704 705
png_uint_32
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
   int *num_text)
{
706
   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
A
Andreas Dilger 已提交
707 708
   {
      png_debug1(1, "in %s retrieval function\n",
709 710
         (png_ptr->chunk_name[0] == '\0' ? "text"
             : (png_const_charp)png_ptr->chunk_name));
A
Andreas Dilger 已提交
711 712 713 714
      if (text_ptr != NULL)
         *text_ptr = info_ptr->text;
      if (num_text != NULL)
         *num_text = info_ptr->num_text;
715
      return ((png_uint_32)info_ptr->num_text);
A
Andreas Dilger 已提交
716
   }
717 718
   if (num_text != NULL)
     *num_text = 0;
A
Andreas Dilger 已提交
719 720 721 722 723 724 725 726
   return(0);
}
#endif

#if defined(PNG_READ_tIME_SUPPORTED)
png_uint_32
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
727 728
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
729 730 731 732 733 734 735 736 737 738 739 740 741 742
   {
      png_debug1(1, "in %s retrieval function\n", "tIME");
      *mod_time = &(info_ptr->mod_time);
      return (PNG_INFO_tIME);
   }
   return (0);
}
#endif

#if defined(PNG_READ_tRNS_SUPPORTED)
png_uint_32
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
   png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{
743
   png_uint_32 retval = 0;
744
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
745 746
   {
      png_debug1(1, "in %s retrieval function\n", "tRNS");
747
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
A
Andreas Dilger 已提交
748
      {
749 750 751 752 753 754 755
          if (trans != NULL)
          {
             *trans = info_ptr->trans;
             retval |= PNG_INFO_tRNS;
          }
          if (trans_values != NULL)
             *trans_values = &(info_ptr->trans_values);
A
Andreas Dilger 已提交
756
      }
757
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
758
      {
759 760 761 762 763 764 765
          if (trans_values != NULL)
          {
             *trans_values = &(info_ptr->trans_values);
             retval |= PNG_INFO_tRNS;
          }
          if(trans != NULL)
             *trans = NULL;
A
Andreas Dilger 已提交
766
      }
767
      if(num_trans != NULL)
A
Andreas Dilger 已提交
768
      {
769 770
         *num_trans = info_ptr->num_trans;
         retval |= PNG_INFO_tRNS;
A
Andreas Dilger 已提交
771 772
      }
   }
773
   return (retval);
A
Andreas Dilger 已提交
774 775 776
}
#endif

777 778 779 780 781 782 783 784 785 786 787
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
png_uint_32
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)
     *unknowns = info_ptr->unknown_chunks;
   return ((png_uint_32)info_ptr->unknown_chunks_num);
}
#endif

788 789 790 791 792 793 794
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
png_byte
png_get_rgb_to_gray_status (png_structp png_ptr)
{
   return png_ptr->rgb_to_gray_status;
}
#endif
795 796 797 798 799 800 801 802 803

#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
png_voidp
png_get_user_chunk_ptr(png_structp png_ptr)
{
   return (png_ptr->user_chunk_ptr);
}
#endif

804 805 806 807 808 809

png_uint_32
png_get_compression_buffer_size(png_structp png_ptr)
{
   return(png_ptr->zbuf_size);
}