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

/* pngget.c - retrieval of values from info struct
3
 *
4
 * libpng 1.0.9beta7 - December 28, 2000
5
 * For conditions of distribution and use, see copyright notice in png.h
6
 * Copyright (c) 1998, 1999, 2000 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 12 13

#define PNG_INTERNAL
#include "png.h"

14
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
15 16
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
      return(info_ptr->valid & flag);
   else
      return(0);
}

23
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
24 25
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
#if defined(PNG_INFO_IMAGE_SUPPORTED)
33
png_bytepp PNGAPI
34 35 36 37 38 39 40 41 42
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
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */
45
png_uint_32 PNGAPI
46 47
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
   {
      return info_ptr->width;
   }
   return (0);
}

55
png_uint_32 PNGAPI
56 57
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
   {
      return info_ptr->height;
   }
   return (0);
}

65
png_byte PNGAPI
66 67
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
   {
      return info_ptr->bit_depth;
   }
   return (0);
}

75
png_byte PNGAPI
76 77
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
   {
      return info_ptr->color_type;
   }
   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 90 91 92 93 94
   {
      return info_ptr->filter_type;
   }
   return (0);
}

95
png_byte PNGAPI
96 97
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
   {
      return info_ptr->interlace_type;
   }
   return (0);
}

105
png_byte PNGAPI
106 107
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
png_uint_32 PNGAPI
116 117
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
118
   if (png_ptr != NULL && info_ptr != NULL)
119
#if defined(PNG_pHYs_SUPPORTED)
120
   if (info_ptr->valid & PNG_INFO_pHYs)
121 122 123 124 125 126
   {
      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);
   }
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\n", "png_get_y_pixels_per_meter");
141 142 143 144
      if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
          return (0);
      else return (info_ptr->y_pixels_per_unit);
   }
145 146
#else
   return (0);
147 148 149 150
#endif
   return (0);
}

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

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

192
png_int_32 PNGAPI
193 194
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
195
   if (png_ptr != NULL && info_ptr != NULL)
196
#if defined(PNG_oFFs_SUPPORTED)
197
   if (info_ptr->valid & PNG_INFO_oFFs)
198 199 200 201 202 203
   {
      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);
   }
204 205
#else
   return (0);
206 207 208 209
#endif
   return (0);
}

210
png_int_32 PNGAPI
211 212
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
213
   if (png_ptr != NULL && info_ptr != NULL)
214
#if defined(PNG_oFFs_SUPPORTED)
215
   if (info_ptr->valid & PNG_INFO_oFFs)
216 217 218 219 220 221
   {
      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);
   }
222 223
#else
   return (0);
224 225 226 227
#endif
   return (0);
}

228
png_int_32 PNGAPI
229 230
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
231
   if (png_ptr != NULL && info_ptr != NULL)
232
#if defined(PNG_oFFs_SUPPORTED)
233
   if (info_ptr->valid & PNG_INFO_oFFs)
234 235 236 237 238 239
   {
      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);
   }
240 241
#else
   return (0);
242 243 244 245
#endif
   return (0);
}

246
png_int_32 PNGAPI
247 248
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
249
   if (png_ptr != NULL && info_ptr != NULL)
250
#if defined(PNG_oFFs_SUPPORTED)
251
   if (info_ptr->valid & PNG_INFO_oFFs)
252 253 254 255 256 257
   {
      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);
   }
258 259
#else
   return (0);
260 261 262 263
#endif
   return (0);
}

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

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

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

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

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

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

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

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

338 339
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

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

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

#if defined(PNG_READ_bKGD_SUPPORTED)
359
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
360 361 362
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
   png_color_16p *background)
{
363 364
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
      && background != NULL)
A
Andreas Dilger 已提交
365 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

#if defined(PNG_READ_cHRM_SUPPORTED)
375
#ifdef PNG_FLOATING_POINT_SUPPORTED
376
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
377 378 379 380
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)
{
381
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
A
Andreas Dilger 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
   {
      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
405
#ifdef PNG_FIXED_POINT_SUPPORTED
406
png_uint_32 PNGAPI
407
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
408 409 410
   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)
411 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
{
   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 已提交
437 438

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

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

485
#if defined(PNG_READ_iCCP_SUPPORTED)
486
png_uint_32 PNGAPI
487 488
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
             png_charpp name, int *compression_type,
489
             png_charpp profile, png_uint_32 *proflen)
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
{
   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

507
#if defined(PNG_READ_sPLT_SUPPORTED)
508
png_uint_32 PNGAPI
509
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
510
             png_sPLT_tpp spalettes)
511 512 513 514 515 516 517
{
   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 已提交
518
#if defined(PNG_READ_hIST_SUPPORTED)
519
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
520 521
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
522 523
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
      && hist != NULL)
A
Andreas Dilger 已提交
524 525 526 527 528 529 530 531 532
   {
      png_debug1(1, "in %s retrieval function\n", "hIST");
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
   return (0);
}
#endif

533
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
534 535 536 537
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)
538

A
Andreas Dilger 已提交
539
{
540
   if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
A
Andreas Dilger 已提交
541 542
      bit_depth != NULL && color_type != NULL)
   {
543 544 545
      int pixel_depth, channels;
      png_uint_32 rowbytes_per_pixel;

A
Andreas Dilger 已提交
546 547 548 549 550 551 552 553 554 555 556
      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;
557 558 559 560 561 562 563 564 565 566 567 568

      /* 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;
569
      if ((*width > PNG_MAX_UINT/rowbytes_per_pixel))
570 571 572 573
      {
         png_warning(png_ptr,
            "Width too large for libpng to process image data.");
      }
A
Andreas Dilger 已提交
574 575 576 577 578 579
      return (1);
   }
   return (0);
}

#if defined(PNG_READ_oFFs_SUPPORTED)
580
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
581
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
582
   png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
583
{
584 585
   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 已提交
586 587 588 589 590 591 592 593 594 595 596 597
   {
      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)
598
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
599 600 601 602
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)
{
603 604
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
      && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
A
Andreas Dilger 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
      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

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

A
Andreas Dilger 已提交
657
#if defined(PNG_READ_pHYs_SUPPORTED)
658
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
659 660 661
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
662 663
   png_uint_32 retval = 0;

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

688
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
689 690 691
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
   int *num_palette)
{
692 693
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
694 695 696 697 698 699 700 701 702 703 704
   {
      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)
705
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
706 707
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
708 709
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
      && sig_bit != NULL)
A
Andreas Dilger 已提交
710 711 712 713 714 715 716 717 718
   {
      png_debug1(1, "in %s retrieval function\n", "sBIT");
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
   return (0);
}
#endif

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

#if defined(PNG_READ_tIME_SUPPORTED)
742
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
743 744
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
745 746
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
747 748 749 750 751 752 753 754 755 756
   {
      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)
757
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
758 759 760
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
   png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{
761
   png_uint_32 retval = 0;
762
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
763 764
   {
      png_debug1(1, "in %s retrieval function\n", "tRNS");
765
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
A
Andreas Dilger 已提交
766
      {
767 768 769 770 771 772 773
          if (trans != NULL)
          {
             *trans = info_ptr->trans;
             retval |= PNG_INFO_tRNS;
          }
          if (trans_values != NULL)
             *trans_values = &(info_ptr->trans_values);
A
Andreas Dilger 已提交
774
      }
775
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
776
      {
777 778 779 780 781 782 783
          if (trans_values != NULL)
          {
             *trans_values = &(info_ptr->trans_values);
             retval |= PNG_INFO_tRNS;
          }
          if(trans != NULL)
             *trans = NULL;
A
Andreas Dilger 已提交
784
      }
785
      if(num_trans != NULL)
A
Andreas Dilger 已提交
786
      {
787 788
         *num_trans = info_ptr->num_trans;
         retval |= PNG_INFO_tRNS;
A
Andreas Dilger 已提交
789 790
      }
   }
791
   return (retval);
A
Andreas Dilger 已提交
792 793 794
}
#endif

795
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
796
png_uint_32 PNGAPI
797 798 799 800 801 802 803 804 805
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

806
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
807
png_byte PNGAPI
808 809
png_get_rgb_to_gray_status (png_structp png_ptr)
{
810
   return png_ptr->rgb_to_gray_status;
811 812
}
#endif
813 814

#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
815
png_voidp PNGAPI
816 817
png_get_user_chunk_ptr(png_structp png_ptr)
{
818
   return (png_ptr->user_chunk_ptr);
819 820 821
}
#endif

822

823
png_uint_32 PNGAPI
824 825
png_get_compression_buffer_size(png_structp png_ptr)
{
826
   return(png_ptr->zbuf_size);
827
}