1 2/* pngget.c - retrieval of values from info struct 3 * 4 * Last changed in libpng 1.2.15 January 5, 2007 5 * For conditions of distribution and use, see copyright notice in png.h 6 * Copyright (c) 1998-2007 Glenn Randers-Pehrson 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 */ 10 11#define PNG_INTERNAL 12#include "png.h" 13 14#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 15 16png_uint_32 PNGAPI 17png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) 18{ 19 if (png_ptr != NULL && info_ptr != NULL) 20 return(info_ptr->valid & flag); 21 else 22 return(0); 23} 24 25png_uint_32 PNGAPI 26png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) 27{ 28 if (png_ptr != NULL && info_ptr != NULL) 29 return(info_ptr->rowbytes); 30 else 31 return(0); 32} 33 34#if defined(PNG_INFO_IMAGE_SUPPORTED) 35png_bytepp PNGAPI 36png_get_rows(png_structp png_ptr, png_infop info_ptr) 37{ 38 if (png_ptr != NULL && info_ptr != NULL) 39 return(info_ptr->row_pointers); 40 else 41 return(0); 42} 43#endif 44 45#ifdef PNG_EASY_ACCESS_SUPPORTED 46/* easy access to info, added in libpng-0.99 */ 47png_uint_32 PNGAPI 48png_get_image_width(png_structp png_ptr, png_infop info_ptr) 49{ 50 if (png_ptr != NULL && info_ptr != NULL) 51 { 52 return info_ptr->width; 53 } 54 return (0); 55} 56 57png_uint_32 PNGAPI 58png_get_image_height(png_structp png_ptr, png_infop info_ptr) 59{ 60 if (png_ptr != NULL && info_ptr != NULL) 61 { 62 return info_ptr->height; 63 } 64 return (0); 65} 66 67png_byte PNGAPI 68png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) 69{ 70 if (png_ptr != NULL && info_ptr != NULL) 71 { 72 return info_ptr->bit_depth; 73 } 74 return (0); 75} 76 77png_byte PNGAPI 78png_get_color_type(png_structp png_ptr, png_infop info_ptr) 79{ 80 if (png_ptr != NULL && info_ptr != NULL) 81 { 82 return info_ptr->color_type; 83 } 84 return (0); 85} 86 87png_byte PNGAPI 88png_get_filter_type(png_structp png_ptr, png_infop info_ptr) 89{ 90 if (png_ptr != NULL && info_ptr != NULL) 91 { 92 return info_ptr->filter_type; 93 } 94 return (0); 95} 96 97png_byte PNGAPI 98png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) 99{ 100 if (png_ptr != NULL && info_ptr != NULL) 101 { 102 return info_ptr->interlace_type; 103 } 104 return (0); 105} 106 107png_byte PNGAPI 108png_get_compression_type(png_structp png_ptr, png_infop info_ptr) 109{ 110 if (png_ptr != NULL && info_ptr != NULL) 111 { 112 return info_ptr->compression_type; 113 } 114 return (0); 115} 116 117png_uint_32 PNGAPI 118png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) 119{ 120 if (png_ptr != NULL && info_ptr != NULL) 121#if defined(PNG_pHYs_SUPPORTED) 122 if (info_ptr->valid & PNG_INFO_pHYs) 123 { 124 png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter"); 125 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) 126 return (0); 127 else return (info_ptr->x_pixels_per_unit); 128 } 129#else 130 return (0); 131#endif 132 return (0); 133} 134 135png_uint_32 PNGAPI 136png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) 137{ 138 if (png_ptr != NULL && info_ptr != NULL) 139#if defined(PNG_pHYs_SUPPORTED) 140 if (info_ptr->valid & PNG_INFO_pHYs) 141 { 142 png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); 143 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) 144 return (0); 145 else return (info_ptr->y_pixels_per_unit); 146 } 147#else 148 return (0); 149#endif 150 return (0); 151} 152 153png_uint_32 PNGAPI 154png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) 155{ 156 if (png_ptr != NULL && info_ptr != NULL) 157#if defined(PNG_pHYs_SUPPORTED) 158 if (info_ptr->valid & PNG_INFO_pHYs) 159 { 160 png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); 161 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER || 162 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) 163 return (0); 164 else return (info_ptr->x_pixels_per_unit); 165 } 166#else 167 return (0); 168#endif 169 return (0); 170} 171 172#ifdef PNG_FLOATING_POINT_SUPPORTED 173float PNGAPI 174png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) 175 { 176 if (png_ptr != NULL && info_ptr != NULL) 177#if defined(PNG_pHYs_SUPPORTED) 178 if (info_ptr->valid & PNG_INFO_pHYs) 179 { 180 png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); 181 if (info_ptr->x_pixels_per_unit == 0) 182 return ((float)0.0); 183 else 184 return ((float)((float)info_ptr->y_pixels_per_unit 185 /(float)info_ptr->x_pixels_per_unit)); 186 } 187#else 188 return (0.0); 189#endif 190 return ((float)0.0); 191} 192#endif 193 194png_int_32 PNGAPI 195png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) 196{ 197 if (png_ptr != NULL && info_ptr != NULL) 198#if defined(PNG_oFFs_SUPPORTED) 199 if (info_ptr->valid & PNG_INFO_oFFs) 200 { 201 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); 202 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) 203 return (0); 204 else return (info_ptr->x_offset); 205 } 206#else 207 return (0); 208#endif 209 return (0); 210} 211 212png_int_32 PNGAPI 213png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) 214{ 215 if (png_ptr != NULL && info_ptr != NULL) 216#if defined(PNG_oFFs_SUPPORTED) 217 if (info_ptr->valid & PNG_INFO_oFFs) 218 { 219 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); 220 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) 221 return (0); 222 else return (info_ptr->y_offset); 223 } 224#else 225 return (0); 226#endif 227 return (0); 228} 229 230png_int_32 PNGAPI 231png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) 232{ 233 if (png_ptr != NULL && info_ptr != NULL) 234#if defined(PNG_oFFs_SUPPORTED) 235 if (info_ptr->valid & PNG_INFO_oFFs) 236 { 237 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); 238 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) 239 return (0); 240 else return (info_ptr->x_offset); 241 } 242#else 243 return (0); 244#endif 245 return (0); 246} 247 248png_int_32 PNGAPI 249png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) 250{ 251 if (png_ptr != NULL && info_ptr != NULL) 252#if defined(PNG_oFFs_SUPPORTED) 253 if (info_ptr->valid & PNG_INFO_oFFs) 254 { 255 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); 256 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) 257 return (0); 258 else return (info_ptr->y_offset); 259 } 260#else 261 return (0); 262#endif 263 return (0); 264} 265 266#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) 267png_uint_32 PNGAPI 268png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) 269{ 270 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) 271 *.0254 +.5)); 272} 273 274png_uint_32 PNGAPI 275png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) 276{ 277 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) 278 *.0254 +.5)); 279} 280 281png_uint_32 PNGAPI 282png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) 283{ 284 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) 285 *.0254 +.5)); 286} 287 288float PNGAPI 289png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) 290{ 291 return ((float)png_get_x_offset_microns(png_ptr, info_ptr) 292 *.00003937); 293} 294 295float PNGAPI 296png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) 297{ 298 return ((float)png_get_y_offset_microns(png_ptr, info_ptr) 299 *.00003937); 300} 301 302#if defined(PNG_pHYs_SUPPORTED) 303png_uint_32 PNGAPI 304png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, 305 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) 306{ 307 png_uint_32 retval = 0; 308 309 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) 310 { 311 png_debug1(1, "in %s retrieval function\n", "pHYs"); 312 if (res_x != NULL) 313 { 314 *res_x = info_ptr->x_pixels_per_unit; 315 retval |= PNG_INFO_pHYs; 316 } 317 if (res_y != NULL) 318 { 319 *res_y = info_ptr->y_pixels_per_unit; 320 retval |= PNG_INFO_pHYs; 321 } 322 if (unit_type != NULL) 323 { 324 *unit_type = (int)info_ptr->phys_unit_type; 325 retval |= PNG_INFO_pHYs; 326 if(*unit_type == 1) 327 { 328 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); 329 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); 330 } 331 } 332 } 333 return (retval); 334} 335#endif /* PNG_pHYs_SUPPORTED */ 336#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ 337 338/* png_get_channels really belongs in here, too, but it's been around longer */ 339 340#endif /* PNG_EASY_ACCESS_SUPPORTED */ 341 342png_byte PNGAPI 343png_get_channels(png_structp png_ptr, png_infop info_ptr) 344{ 345 if (png_ptr != NULL && info_ptr != NULL) 346 return(info_ptr->channels); 347 else 348 return (0); 349} 350 351png_bytep PNGAPI 352png_get_signature(png_structp png_ptr, png_infop info_ptr) 353{ 354 if (png_ptr != NULL && info_ptr != NULL) 355 return(info_ptr->signature); 356 else 357 return (NULL); 358} 359 360#if defined(PNG_bKGD_SUPPORTED) 361png_uint_32 PNGAPI 362png_get_bKGD(png_structp png_ptr, png_infop info_ptr, 363 png_color_16p *background) 364{ 365 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) 366 && background != NULL) 367 { 368 png_debug1(1, "in %s retrieval function\n", "bKGD"); 369 *background = &(info_ptr->background); 370 return (PNG_INFO_bKGD); 371 } 372 return (0); 373} 374#endif 375 376#if defined(PNG_cHRM_SUPPORTED) 377#ifdef PNG_FLOATING_POINT_SUPPORTED 378png_uint_32 PNGAPI 379png_get_cHRM(png_structp png_ptr, png_infop info_ptr, 380 double *white_x, double *white_y, double *red_x, double *red_y, 381 double *green_x, double *green_y, double *blue_x, double *blue_y) 382{ 383 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) 384 { 385 png_debug1(1, "in %s retrieval function\n", "cHRM"); 386 if (white_x != NULL) 387 *white_x = (double)info_ptr->x_white; 388 if (white_y != NULL) 389 *white_y = (double)info_ptr->y_white; 390 if (red_x != NULL) 391 *red_x = (double)info_ptr->x_red; 392 if (red_y != NULL) 393 *red_y = (double)info_ptr->y_red; 394 if (green_x != NULL) 395 *green_x = (double)info_ptr->x_green; 396 if (green_y != NULL) 397 *green_y = (double)info_ptr->y_green; 398 if (blue_x != NULL) 399 *blue_x = (double)info_ptr->x_blue; 400 if (blue_y != NULL) 401 *blue_y = (double)info_ptr->y_blue; 402 return (PNG_INFO_cHRM); 403 } 404 return (0); 405} 406#endif 407#ifdef PNG_FIXED_POINT_SUPPORTED 408png_uint_32 PNGAPI 409png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, 410 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, 411 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, 412 png_fixed_point *blue_x, png_fixed_point *blue_y) 413{ 414 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) 415 { 416 png_debug1(1, "in %s retrieval function\n", "cHRM"); 417 if (white_x != NULL) 418 *white_x = info_ptr->int_x_white; 419 if (white_y != NULL) 420 *white_y = info_ptr->int_y_white; 421 if (red_x != NULL) 422 *red_x = info_ptr->int_x_red; 423 if (red_y != NULL) 424 *red_y = info_ptr->int_y_red; 425 if (green_x != NULL) 426 *green_x = info_ptr->int_x_green; 427 if (green_y != NULL) 428 *green_y = info_ptr->int_y_green; 429 if (blue_x != NULL) 430 *blue_x = info_ptr->int_x_blue; 431 if (blue_y != NULL) 432 *blue_y = info_ptr->int_y_blue; 433 return (PNG_INFO_cHRM); 434 } 435 return (0); 436} 437#endif 438#endif 439 440#if defined(PNG_gAMA_SUPPORTED) 441#ifdef PNG_FLOATING_POINT_SUPPORTED 442png_uint_32 PNGAPI 443png_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) 446 && file_gamma != NULL) 447 { 448 png_debug1(1, "in %s retrieval function\n", "gAMA"); 449 *file_gamma = (double)info_ptr->gamma; 450 return (PNG_INFO_gAMA); 451 } 452 return (0); 453} 454#endif 455#ifdef PNG_FIXED_POINT_SUPPORTED 456png_uint_32 PNGAPI 457png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, 458 png_fixed_point *int_file_gamma) 459{ 460 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) 461 && int_file_gamma != NULL) 462 { 463 png_debug1(1, "in %s retrieval function\n", "gAMA"); 464 *int_file_gamma = info_ptr->int_gamma; 465 return (PNG_INFO_gAMA); 466 } 467 return (0); 468} 469#endif 470#endif 471 472#if defined(PNG_sRGB_SUPPORTED) 473png_uint_32 PNGAPI 474png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) 475{ 476 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) 477 && file_srgb_intent != NULL) 478 { 479 png_debug1(1, "in %s retrieval function\n", "sRGB"); 480 *file_srgb_intent = (int)info_ptr->srgb_intent; 481 return (PNG_INFO_sRGB); 482 } 483 return (0); 484} 485#endif 486 487#if defined(PNG_iCCP_SUPPORTED) 488png_uint_32 PNGAPI 489png_get_iCCP(png_structp png_ptr, png_infop info_ptr, 490 png_charpp name, int *compression_type, 491 png_charpp profile, png_uint_32 *proflen) 492{ 493 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) 494 && name != NULL && profile != NULL && proflen != NULL) 495 { 496 png_debug1(1, "in %s retrieval function\n", "iCCP"); 497 *name = info_ptr->iccp_name; 498 *profile = info_ptr->iccp_profile; 499 /* compression_type is a dummy so the API won't have to change 500 if we introduce multiple compression types later. */ 501 *proflen = (int)info_ptr->iccp_proflen; 502 *compression_type = (int)info_ptr->iccp_compression; 503 return (PNG_INFO_iCCP); 504 } 505 return (0); 506} 507#endif 508 509#if defined(PNG_sPLT_SUPPORTED) 510png_uint_32 PNGAPI 511png_get_sPLT(png_structp png_ptr, png_infop info_ptr, 512 png_sPLT_tpp spalettes) 513{ 514 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) 515 { 516 *spalettes = info_ptr->splt_palettes; 517 return ((png_uint_32)info_ptr->splt_palettes_num); 518 } 519 return (0); 520} 521#endif 522 523#if defined(PNG_hIST_SUPPORTED) 524png_uint_32 PNGAPI 525png_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) 528 && hist != NULL) 529 { 530 png_debug1(1, "in %s retrieval function\n", "hIST"); 531 *hist = info_ptr->hist; 532 return (PNG_INFO_hIST); 533 } 534 return (0); 535} 536#endif 537 538png_uint_32 PNGAPI 539png_get_IHDR(png_structp png_ptr, png_infop info_ptr, 540 png_uint_32 *width, png_uint_32 *height, int *bit_depth, 541 int *color_type, int *interlace_type, int *compression_type, 542 int *filter_type) 543 544{ 545 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && 546 bit_depth != NULL && color_type != NULL) 547 { 548 png_debug1(1, "in %s retrieval function\n", "IHDR"); 549 *width = info_ptr->width; 550 *height = info_ptr->height; 551 *bit_depth = info_ptr->bit_depth; 552 if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16) 553 png_error(png_ptr, "Invalid bit depth"); 554 *color_type = info_ptr->color_type; 555 if (info_ptr->color_type > 6) 556 png_error(png_ptr, "Invalid color type"); 557 if (compression_type != NULL) 558 *compression_type = info_ptr->compression_type; 559 if (filter_type != NULL) 560 *filter_type = info_ptr->filter_type; 561 if (interlace_type != NULL) 562 *interlace_type = info_ptr->interlace_type; 563 564 /* check for potential overflow of rowbytes */ 565 if (*width == 0 || *width > PNG_UINT_31_MAX) 566 png_error(png_ptr, "Invalid image width"); 567 if (*height == 0 || *height > PNG_UINT_31_MAX) 568 png_error(png_ptr, "Invalid image height"); 569 if (info_ptr->width > (PNG_UINT_32_MAX 570 >> 3) /* 8-byte RGBA pixels */ 571 - 64 /* bigrowbuf hack */ 572 - 1 /* filter byte */ 573 - 7*8 /* rounding of width to multiple of 8 pixels */ 574 - 8) /* extra max_pixel_depth pad */ 575 { 576 png_warning(png_ptr, 577 "Width too large for libpng to process image data."); 578 } 579 return (1); 580 } 581 return (0); 582} 583 584#if defined(PNG_oFFs_SUPPORTED) 585png_uint_32 PNGAPI 586png_get_oFFs(png_structp png_ptr, png_infop info_ptr, 587 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) 588{ 589 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) 590 && offset_x != NULL && offset_y != NULL && unit_type != NULL) 591 { 592 png_debug1(1, "in %s retrieval function\n", "oFFs"); 593 *offset_x = info_ptr->x_offset; 594 *offset_y = info_ptr->y_offset; 595 *unit_type = (int)info_ptr->offset_unit_type; 596 return (PNG_INFO_oFFs); 597 } 598 return (0); 599} 600#endif 601 602#if defined(PNG_pCAL_SUPPORTED) 603png_uint_32 PNGAPI 604png_get_pCAL(png_structp png_ptr, png_infop info_ptr, 605 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, 606 png_charp *units, png_charpp *params) 607{ 608 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) 609 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && 610 nparams != NULL && units != NULL && params != NULL) 611 { 612 png_debug1(1, "in %s retrieval function\n", "pCAL"); 613 *purpose = info_ptr->pcal_purpose; 614 *X0 = info_ptr->pcal_X0; 615 *X1 = info_ptr->pcal_X1; 616 *type = (int)info_ptr->pcal_type; 617 *nparams = (int)info_ptr->pcal_nparams; 618 *units = info_ptr->pcal_units; 619 *params = info_ptr->pcal_params; 620 return (PNG_INFO_pCAL); 621 } 622 return (0); 623} 624#endif 625 626#if defined(PNG_sCAL_SUPPORTED) 627#ifdef PNG_FLOATING_POINT_SUPPORTED 628png_uint_32 PNGAPI 629png_get_sCAL(png_structp png_ptr, png_infop info_ptr, 630 int *unit, double *width, double *height) 631{ 632 if (png_ptr != NULL && info_ptr != NULL && 633 (info_ptr->valid & PNG_INFO_sCAL)) 634 { 635 *unit = info_ptr->scal_unit; 636 *width = info_ptr->scal_pixel_width; 637 *height = info_ptr->scal_pixel_height; 638 return (PNG_INFO_sCAL); 639 } 640 return(0); 641} 642#else 643#ifdef PNG_FIXED_POINT_SUPPORTED 644png_uint_32 PNGAPI 645png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, 646 int *unit, png_charpp width, png_charpp height) 647{ 648 if (png_ptr != NULL && info_ptr != NULL && 649 (info_ptr->valid & PNG_INFO_sCAL)) 650 { 651 *unit = info_ptr->scal_unit; 652 *width = info_ptr->scal_s_width; 653 *height = info_ptr->scal_s_height; 654 return (PNG_INFO_sCAL); 655 } 656 return(0); 657} 658#endif 659#endif 660#endif 661 662#if defined(PNG_pHYs_SUPPORTED) 663png_uint_32 PNGAPI 664png_get_pHYs(png_structp png_ptr, png_infop info_ptr, 665 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 && 670 (info_ptr->valid & PNG_INFO_pHYs)) 671 { 672 png_debug1(1, "in %s retrieval function\n", "pHYs"); 673 if (res_x != NULL) 674 { 675 *res_x = info_ptr->x_pixels_per_unit; 676 retval |= PNG_INFO_pHYs; 677 } 678 if (res_y != NULL) 679 { 680 *res_y = info_ptr->y_pixels_per_unit; 681 retval |= PNG_INFO_pHYs; 682 } 683 if (unit_type != NULL) 684 { 685 *unit_type = (int)info_ptr->phys_unit_type; 686 retval |= PNG_INFO_pHYs; 687 } 688 } 689 return (retval); 690} 691#endif 692 693png_uint_32 PNGAPI 694png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, 695 int *num_palette) 696{ 697 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) 698 && palette != NULL) 699 { 700 png_debug1(1, "in %s retrieval function\n", "PLTE"); 701 *palette = info_ptr->palette; 702 *num_palette = info_ptr->num_palette; 703 png_debug1(3, "num_palette = %d\n", *num_palette); 704 return (PNG_INFO_PLTE); 705 } 706 return (0); 707} 708 709#if defined(PNG_sBIT_SUPPORTED) 710png_uint_32 PNGAPI 711png_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) 714 && sig_bit != NULL) 715 { 716 png_debug1(1, "in %s retrieval function\n", "sBIT"); 717 *sig_bit = &(info_ptr->sig_bit); 718 return (PNG_INFO_sBIT); 719 } 720 return (0); 721} 722#endif 723 724#if defined(PNG_TEXT_SUPPORTED) 725png_uint_32 PNGAPI 726png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, 727 int *num_text) 728{ 729 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) 730 { 731 png_debug1(1, "in %s retrieval function\n", 732 (png_ptr->chunk_name[0] == '\0' ? "text" 733 : (png_const_charp)png_ptr->chunk_name)); 734 if (text_ptr != NULL) 735 *text_ptr = info_ptr->text; 736 if (num_text != NULL) 737 *num_text = info_ptr->num_text; 738 return ((png_uint_32)info_ptr->num_text); 739 } 740 if (num_text != NULL) 741 *num_text = 0; 742 return(0); 743} 744#endif 745 746#if defined(PNG_tIME_SUPPORTED) 747png_uint_32 PNGAPI 748png_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) 751 && mod_time != NULL) 752 { 753 png_debug1(1, "in %s retrieval function\n", "tIME"); 754 *mod_time = &(info_ptr->mod_time); 755 return (PNG_INFO_tIME); 756 } 757 return (0); 758} 759#endif 760 761#if defined(PNG_tRNS_SUPPORTED) 762png_uint_32 PNGAPI 763png_get_tRNS(png_structp png_ptr, png_infop info_ptr, 764 png_bytep *trans, int *num_trans, png_color_16p *trans_values) 765{ 766 png_uint_32 retval = 0; 767 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) 768 { 769 png_debug1(1, "in %s retrieval function\n", "tRNS"); 770 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 771 { 772 if (trans != NULL) 773 { 774 *trans = info_ptr->trans; 775 retval |= PNG_INFO_tRNS; 776 } 777 if (trans_values != NULL) 778 *trans_values = &(info_ptr->trans_values); 779 } 780 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ 781 { 782 if (trans_values != NULL) 783 { 784 *trans_values = &(info_ptr->trans_values); 785 retval |= PNG_INFO_tRNS; 786 } 787 if(trans != NULL) 788 *trans = NULL; 789 } 790 if(num_trans != NULL) 791 { 792 *num_trans = info_ptr->num_trans; 793 retval |= PNG_INFO_tRNS; 794 } 795 } 796 return (retval); 797} 798#endif 799 800#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 801png_uint_32 PNGAPI 802png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, 803 png_unknown_chunkpp unknowns) 804{ 805 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) 806 { 807 *unknowns = info_ptr->unknown_chunks; 808 return ((png_uint_32)info_ptr->unknown_chunks_num); 809 } 810 return (0); 811} 812#endif 813 814#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 815png_byte PNGAPI 816png_get_rgb_to_gray_status (png_structp png_ptr) 817{ 818 return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); 819} 820#endif 821 822#if defined(PNG_USER_CHUNKS_SUPPORTED) 823png_voidp PNGAPI 824png_get_user_chunk_ptr(png_structp png_ptr) 825{ 826 return (png_ptr? png_ptr->user_chunk_ptr : NULL); 827} 828#endif 829 830#ifdef PNG_WRITE_SUPPORTED 831png_uint_32 PNGAPI 832png_get_compression_buffer_size(png_structp png_ptr) 833{ 834 return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); 835} 836#endif 837 838#ifdef PNG_ASSEMBLER_CODE_SUPPORTED 839#ifndef PNG_1_0_X 840/* this function was added to libpng 1.2.0 and should exist by default */ 841png_uint_32 PNGAPI 842png_get_asm_flags (png_structp png_ptr) 843{ 844#ifdef PNG_MMX_CODE_SUPPORTED 845 return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L); 846#else 847 return (png_ptr? 0L: 0L); 848#endif 849} 850 851/* this function was added to libpng 1.2.0 and should exist by default */ 852png_uint_32 PNGAPI 853png_get_asm_flagmask (int flag_select) 854{ 855#ifdef PNG_MMX_CODE_SUPPORTED 856 png_uint_32 settable_asm_flags = 0; 857 858 if (flag_select & PNG_SELECT_READ) 859 settable_asm_flags |= 860 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW | 861 PNG_ASM_FLAG_MMX_READ_INTERLACE | 862 PNG_ASM_FLAG_MMX_READ_FILTER_SUB | 863 PNG_ASM_FLAG_MMX_READ_FILTER_UP | 864 PNG_ASM_FLAG_MMX_READ_FILTER_AVG | 865 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ; 866 /* no non-MMX flags yet */ 867 868#if 0 869 /* GRR: no write-flags yet, either, but someday... */ 870 if (flag_select & PNG_SELECT_WRITE) 871 settable_asm_flags |= 872 PNG_ASM_FLAG_MMX_WRITE_ [whatever] ; 873#endif /* 0 */ 874 875 return settable_asm_flags; /* _theoretically_ settable capabilities only */ 876#else 877 return (0L); 878#endif /* PNG_MMX_CODE_SUPPORTED */ 879} 880 881 882 /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ 883/* this function was added to libpng 1.2.0 */ 884png_uint_32 PNGAPI 885png_get_mmx_flagmask (int flag_select, int *compilerID) 886{ 887#if defined(PNG_MMX_CODE_SUPPORTED) 888 png_uint_32 settable_mmx_flags = 0; 889 890 if (flag_select & PNG_SELECT_READ) 891 settable_mmx_flags |= 892 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW | 893 PNG_ASM_FLAG_MMX_READ_INTERLACE | 894 PNG_ASM_FLAG_MMX_READ_FILTER_SUB | 895 PNG_ASM_FLAG_MMX_READ_FILTER_UP | 896 PNG_ASM_FLAG_MMX_READ_FILTER_AVG | 897 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ; 898#if 0 899 /* GRR: no MMX write support yet, but someday... */ 900 if (flag_select & PNG_SELECT_WRITE) 901 settable_mmx_flags |= 902 PNG_ASM_FLAG_MMX_WRITE_ [whatever] ; 903#endif /* 0 */ 904 905 if (compilerID != NULL) { 906#ifdef PNG_USE_PNGVCRD 907 *compilerID = 1; /* MSVC */ 908#else 909#ifdef PNG_USE_PNGGCCRD 910 *compilerID = 2; /* gcc/gas */ 911#else 912 *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */ 913#endif 914#endif 915 } 916 917 return settable_mmx_flags; /* _theoretically_ settable capabilities only */ 918#else 919 return (0L); 920#endif /* ?PNG_MMX_CODE_SUPPORTED */ 921} 922 923/* this function was added to libpng 1.2.0 */ 924png_byte PNGAPI 925png_get_mmx_bitdepth_threshold (png_structp png_ptr) 926{ 927#if defined(PNG_MMX_CODE_SUPPORTED) 928 return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0); 929#else 930 return (png_ptr? 0: 0); 931#endif /* ?PNG_MMX_CODE_SUPPORTED */ 932} 933 934/* this function was added to libpng 1.2.0 */ 935png_uint_32 PNGAPI 936png_get_mmx_rowbytes_threshold (png_structp png_ptr) 937{ 938#if defined(PNG_MMX_CODE_SUPPORTED) 939 return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L); 940#else 941 return (png_ptr? 0L: 0L); 942#endif /* ?PNG_MMX_CODE_SUPPORTED */ 943} 944#endif /* ?PNG_1_0_X */ 945#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ 946 947#ifdef PNG_SET_USER_LIMITS_SUPPORTED 948/* these functions were added to libpng 1.2.6 */ 949png_uint_32 PNGAPI 950png_get_user_width_max (png_structp png_ptr) 951{ 952 return (png_ptr? png_ptr->user_width_max : 0); 953} 954png_uint_32 PNGAPI 955png_get_user_height_max (png_structp png_ptr) 956{ 957 return (png_ptr? png_ptr->user_height_max : 0); 958} 959#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 960 961 962#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ 963