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

/* pngget.c - retrieval of values from info struct
3
 *
4
 * Last changed in libpng 1.4.1 [March 8, 2010]
5
 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 7
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8
 *
9
 * This code is released under the libpng license.
10
 * For conditions of distribution and use, see the disclaimer
11
 * and license in png.h
12
 *
13
 */
A
Andreas Dilger 已提交
14

15
#define PNG_EXPOSE_INTERNAL_STRUCTURES
16
#define PNG_NO_PEDANTIC_WARNINGS
A
Andreas Dilger 已提交
17
#include "png.h"
18
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
19
#include "pngpriv.h"
20

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

A
Andreas Dilger 已提交
27 28 29 30
   else
      return(0);
}

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

A
Andreas Dilger 已提交
37 38 39 40
   else
      return(0);
}

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

48 49 50 51 52
   else
      return(0);
}
#endif

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

61 62 63
   return (0);
}

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

70 71 72
   return (0);
}

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

79 80 81
   return (0);
}

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

88 89 90
   return (0);
}

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

97 98 99
   return (0);
}

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

106 107 108
   return (0);
}

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

115 116 117
   return (0);
}

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

127
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
128
         return (0);
129

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

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

148
      if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
149
         return (0);
150

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

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

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

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

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

189
   if (info_ptr->valid & PNG_INFO_pHYs)
190
   {
191
      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
192

193
      if (info_ptr->x_pixels_per_unit == 0)
194
         return ((float)0.0);
195

196
      else
197
         return ((float)((float)info_ptr->y_pixels_per_unit
198
             /(float)info_ptr->x_pixels_per_unit));
199
   }
200
#else
201
      return (0.0);
202
#endif
203
   return ((float)0.0);
204
}
205
#endif
206

207
png_int_32 PNGAPI
208 209
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
210
   if (png_ptr != NULL && info_ptr != NULL)
211
#ifdef PNG_oFFs_SUPPORTED
212

213
   if (info_ptr->valid & PNG_INFO_oFFs)
214
   {
215
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
216

217
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
218
         return (0);
219

220
      else
221
         return (info_ptr->x_offset);
222
   }
223
#else
224
      return (0);
225 226 227 228
#endif
   return (0);
}

229
png_int_32 PNGAPI
230 231
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
232
   if (png_ptr != NULL && info_ptr != NULL)
233

234
#ifdef PNG_oFFs_SUPPORTED
235
   if (info_ptr->valid & PNG_INFO_oFFs)
236
   {
237
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
238

239
      if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
240
         return (0);
241

242
      else
243
         return (info_ptr->y_offset);
244
   }
245 246
#else
   return (0);
247 248 249 250
#endif
   return (0);
}

251
png_int_32 PNGAPI
252 253
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
254
   if (png_ptr != NULL && info_ptr != NULL)
255

256
#ifdef PNG_oFFs_SUPPORTED
257
   if (info_ptr->valid & PNG_INFO_oFFs)
258
   {
259
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
260

261
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
262
         return (0);
263

264
      else
265
         return (info_ptr->x_offset);
266
   }
267 268
#else
   return (0);
269 270 271 272
#endif
   return (0);
}

273
png_int_32 PNGAPI
274 275
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
276
   if (png_ptr != NULL && info_ptr != NULL)
277

278
#ifdef PNG_oFFs_SUPPORTED
279
   if (info_ptr->valid & PNG_INFO_oFFs)
280
   {
281
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
282

283
      if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
284
         return (0);
285

286
      else
287
         return (info_ptr->y_offset);
288
   }
289 290
#else
   return (0);
291 292 293 294
#endif
   return (0);
}

295
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
296
png_uint_32 PNGAPI
297 298 299
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)
300
       *.0254 +.5));
301 302
}

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

310
png_uint_32 PNGAPI
311 312 313
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)
314
       *.0254 +.5));
315 316
}

317
float PNGAPI
318 319 320
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
321
       *.00003937);
322 323
}

324
float PNGAPI
325 326 327
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
   return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
328
       *.00003937);
329 330
}

331
#ifdef PNG_pHYs_SUPPORTED
332
png_uint_32 PNGAPI
333
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
334
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
335 336 337
{
   png_uint_32 retval = 0;

338
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
339
   {
340
      png_debug1(1, "in %s retrieval function", "pHYs");
341

342 343 344 345 346 347 348 349 350 351 352 353 354 355
      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;
356
         if (*unit_type == 1)
357
         {
358 359
            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);
360 361 362 363 364
         }
      }
   }
   return (retval);
}
365
#endif /* PNG_pHYs_SUPPORTED */
366
#endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
367 368

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

370 371
#endif  /* PNG_EASY_ACCESS_SUPPORTED */

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

381
png_bytep PNGAPI
A
Andreas Dilger 已提交
382 383
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
384
   if (png_ptr != NULL && info_ptr != NULL)
A
Andreas Dilger 已提交
385 386
      return(info_ptr->signature);
   else
387
      return (NULL);
A
Andreas Dilger 已提交
388 389
}

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

A
Andreas Dilger 已提交
400 401 402 403 404 405 406
      *background = &(info_ptr->background);
      return (PNG_INFO_bKGD);
   }
   return (0);
}
#endif

407
#ifdef PNG_cHRM_SUPPORTED
408
#ifdef PNG_FLOATING_POINT_SUPPORTED
409
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
410
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
411 412
    double *white_x, double *white_y, double *red_x, double *red_y,
    double *green_x, double *green_y, double *blue_x, double *blue_y)
A
Andreas Dilger 已提交
413
{
414
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
A
Andreas Dilger 已提交
415
   {
416
      png_debug1(1, "in %s retrieval function", "cHRM");
417

A
Andreas Dilger 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
      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
439
#ifdef PNG_FIXED_POINT_SUPPORTED
440
png_uint_32 PNGAPI
441
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
442 443 444
    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)
445
{
446 447
   png_debug1(1, "in %s retrieval function", "cHRM");

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_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 已提交
472

473
#ifdef PNG_gAMA_SUPPORTED
474
#ifdef PNG_FLOATING_POINT_SUPPORTED
475
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
476 477
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
478 479
   png_debug1(1, "in %s retrieval function", "gAMA");

480
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
481
       && file_gamma != NULL)
A
Andreas Dilger 已提交
482 483 484 485 486 487 488
   {
      *file_gamma = (double)info_ptr->gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
489
#ifdef PNG_FIXED_POINT_SUPPORTED
490
png_uint_32 PNGAPI
491
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
492
    png_fixed_point *int_file_gamma)
493
{
494 495
   png_debug1(1, "in %s retrieval function", "gAMA");

496
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
497
       && int_file_gamma != NULL)
498 499 500 501 502 503 504
   {
      *int_file_gamma = info_ptr->int_gamma;
      return (PNG_INFO_gAMA);
   }
   return (0);
}
#endif
505
#endif
A
Andreas Dilger 已提交
506

507
#ifdef PNG_sRGB_SUPPORTED
508
png_uint_32 PNGAPI
509
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
510
{
511 512
   png_debug1(1, "in %s retrieval function", "sRGB");

513
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
514
       && file_srgb_intent != NULL)
515
   {
516
      *file_srgb_intent = (int)info_ptr->srgb_intent;
517 518 519 520 521 522
      return (PNG_INFO_sRGB);
   }
   return (0);
}
#endif

523
#ifdef PNG_iCCP_SUPPORTED
524
png_uint_32 PNGAPI
525
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
526 527
    png_charpp name, int *compression_type,
    png_charpp profile, png_uint_32 *proflen)
528
{
529 530
   png_debug1(1, "in %s retrieval function", "iCCP");

531
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
532
       && name != NULL && profile != NULL && proflen != NULL)
533 534 535
   {
      *name = info_ptr->iccp_name;
      *profile = info_ptr->iccp_profile;
536 537 538
      /* Compression_type is a dummy so the API won't have to change
       * if we introduce multiple compression types later.
       */
539 540 541 542 543 544 545 546
      *proflen = (int)info_ptr->iccp_proflen;
      *compression_type = (int)info_ptr->iccp_compression;
      return (PNG_INFO_iCCP);
   }
   return (0);
}
#endif

547
#ifdef PNG_sPLT_SUPPORTED
548
png_uint_32 PNGAPI
549
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
550
    png_sPLT_tpp spalettes)
551 552
{
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
553
   {
554 555
      *spalettes = info_ptr->splt_palettes;
      return ((png_uint_32)info_ptr->splt_palettes_num);
556 557
   }
   return (0);
558 559 560
}
#endif

561
#ifdef PNG_hIST_SUPPORTED
562
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
563 564
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
565 566
   png_debug1(1, "in %s retrieval function", "hIST");

567
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
568
       && hist != NULL)
A
Andreas Dilger 已提交
569 570 571 572 573 574 575 576
   {
      *hist = info_ptr->hist;
      return (PNG_INFO_hIST);
   }
   return (0);
}
#endif

577
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
578
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
579 580 581
    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
    int *color_type, int *interlace_type, int *compression_type,
    int *filter_type)
582

A
Andreas Dilger 已提交
583
{
584
   png_debug1(1, "in %s retrieval function", "IHDR");
585

586 587 588
   if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
       height == NULL || bit_depth == NULL || color_type == NULL)
      return (0);
589

590 591 592 593
   *width = info_ptr->width;
   *height = info_ptr->height;
   *bit_depth = info_ptr->bit_depth;
   *color_type = info_ptr->color_type;
594

595 596
   if (compression_type != NULL)
      *compression_type = info_ptr->compression_type;
597

598 599
   if (filter_type != NULL)
      *filter_type = info_ptr->filter_type;
600

601 602
   if (interlace_type != NULL)
      *interlace_type = info_ptr->interlace_type;
603

604 605 606 607 608 609 610 611
   /* This is redundant if we can be sure that the info_ptr values were all
    * assigned in png_set_IHDR().  We do the check anyhow in case an
    * application has ignored our advice not to mess with the members
    * of info_ptr directly.
    */
   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
       info_ptr->compression_type, info_ptr->filter_type);
612

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

616
#ifdef PNG_oFFs_SUPPORTED
617
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
618
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
619
    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
A
Andreas Dilger 已提交
620
{
621 622
   png_debug1(1, "in %s retrieval function", "oFFs");

623
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
624
       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
A
Andreas Dilger 已提交
625 626 627 628 629 630 631 632 633 634
   {
      *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

635
#ifdef PNG_pCAL_SUPPORTED
636
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
637
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
638 639
    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
    png_charp *units, png_charpp *params)
A
Andreas Dilger 已提交
640
{
641 642
   png_debug1(1, "in %s retrieval function", "pCAL");

643
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
644 645
       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
       nparams != NULL && units != NULL && params != NULL)
A
Andreas Dilger 已提交
646 647 648 649 650 651 652 653 654 655 656 657 658 659
   {
      *purpose = info_ptr->pcal_purpose;
      *X0 = info_ptr->pcal_X0;
      *X1 = info_ptr->pcal_X1;
      *type = (int)info_ptr->pcal_type;
      *nparams = (int)info_ptr->pcal_nparams;
      *units = info_ptr->pcal_units;
      *params = info_ptr->pcal_params;
      return (PNG_INFO_pCAL);
   }
   return (0);
}
#endif

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

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

703 704
   png_debug1(1, "in %s retrieval function", "pHYs");

705
   if (png_ptr != NULL && info_ptr != NULL &&
706
       (info_ptr->valid & PNG_INFO_pHYs))
A
Andreas Dilger 已提交
707
   {
708
      if (res_x != NULL)
709 710
      {
         *res_x = info_ptr->x_pixels_per_unit;
711 712
         retval |= PNG_INFO_pHYs;
      }
713

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

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

730
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
731
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
732
    int *num_palette)
A
Andreas Dilger 已提交
733
{
734 735
   png_debug1(1, "in %s retrieval function", "PLTE");

736 737
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       && palette != NULL)
A
Andreas Dilger 已提交
738 739 740
   {
      *palette = info_ptr->palette;
      *num_palette = info_ptr->num_palette;
741
      png_debug1(3, "num_palette = %d", *num_palette);
A
Andreas Dilger 已提交
742 743 744 745 746
      return (PNG_INFO_PLTE);
   }
   return (0);
}

747
#ifdef PNG_sBIT_SUPPORTED
748
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
749 750
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
751 752
   png_debug1(1, "in %s retrieval function", "sBIT");

753
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
754
       && sig_bit != NULL)
A
Andreas Dilger 已提交
755 756 757 758 759 760 761 762
   {
      *sig_bit = &(info_ptr->sig_bit);
      return (PNG_INFO_sBIT);
   }
   return (0);
}
#endif

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

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

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

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

788
#ifdef PNG_tIME_SUPPORTED
789
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
790 791
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
792 793
   png_debug1(1, "in %s retrieval function", "tIME");

794 795
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       && mod_time != NULL)
A
Andreas Dilger 已提交
796 797 798 799 800 801 802 803
   {
      *mod_time = &(info_ptr->mod_time);
      return (PNG_INFO_tIME);
   }
   return (0);
}
#endif

804
#ifdef PNG_tRNS_SUPPORTED
805
png_uint_32 PNGAPI
A
Andreas Dilger 已提交
806
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
807
    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
A
Andreas Dilger 已提交
808
{
809
   png_uint_32 retval = 0;
810
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
A
Andreas Dilger 已提交
811
   {
812
      png_debug1(1, "in %s retrieval function", "tRNS");
813

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

         if (trans_color != NULL)
            *trans_color = &(info_ptr->trans_color);
A
Andreas Dilger 已提交
824
      }
825
      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
A
Andreas Dilger 已提交
826
      {
827 828 829 830 831 832 833 834
         if (trans_color != NULL)
         {
            *trans_color = &(info_ptr->trans_color);
            retval |= PNG_INFO_tRNS;
         }

         if (trans_alpha != NULL)
            *trans_alpha = NULL;
A
Andreas Dilger 已提交
835
      }
836
      if (num_trans != NULL)
A
Andreas Dilger 已提交
837
      {
838 839
         *num_trans = info_ptr->num_trans;
         retval |= PNG_INFO_tRNS;
A
Andreas Dilger 已提交
840 841
      }
   }
842
   return (retval);
A
Andreas Dilger 已提交
843 844 845
}
#endif

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

860
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
861
png_byte PNGAPI
862 863
png_get_rgb_to_gray_status (png_structp png_ptr)
{
864
   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
865 866
}
#endif
867

868
#ifdef PNG_USER_CHUNKS_SUPPORTED
869
png_voidp PNGAPI
870 871
png_get_user_chunk_ptr(png_structp png_ptr)
{
872
   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
873 874 875
}
#endif

876
png_size_t PNGAPI
877 878
png_get_compression_buffer_size(png_structp png_ptr)
{
879
   return (png_ptr ? png_ptr->zbuf_size : 0L);
880 881
}

882 883

#ifdef PNG_SET_USER_LIMITS_SUPPORTED
884 885
/* These functions were added to libpng 1.2.6 and were enabled
 * by default in libpng-1.4.0 */
886 887 888
png_uint_32 PNGAPI
png_get_user_width_max (png_structp png_ptr)
{
889
   return (png_ptr ? png_ptr->user_width_max : 0);
890 891 892 893
}
png_uint_32 PNGAPI
png_get_user_height_max (png_structp png_ptr)
{
894
   return (png_ptr ? png_ptr->user_height_max : 0);
895
}
896
/* This function was added to libpng 1.4.0 */
897 898 899
png_uint_32 PNGAPI
png_get_chunk_cache_max (png_structp png_ptr)
{
900
   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
901 902
}
/* This function was added to libpng 1.4.1 */
903
png_alloc_size_t PNGAPI
904 905
png_get_chunk_malloc_max (png_structp png_ptr)
{
906
   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
907
}
908
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
909

910
/* These functions were added to libpng 1.4.0 */
911 912 913 914
#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 PNGAPI
png_get_io_state (png_structp png_ptr)
{
915
   return png_ptr->io_state;
916 917 918 919 920 921 922 923 924
}

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

925
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */