| 1 | |
| 2 | /* pngget.c - retrieval of values from info struct |
| 3 | * |
| 4 | * Copyright (c) 2018-2023 Cosmin Truta |
| 5 | * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson |
| 6 | * Copyright (c) 1996-1997 Andreas Dilger |
| 7 | * 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 | */ |
| 14 | |
| 15 | #include "pngpriv.h" |
| 16 | |
| 17 | #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 18 | |
| 19 | png_uint_32 PNGAPI |
| 20 | png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 21 | png_uint_32 flag) |
| 22 | { |
| 23 | if (png_ptr != NULL && info_ptr != NULL) |
| 24 | { |
| 25 | #ifdef PNG_READ_tRNS_SUPPORTED |
| 26 | /* png_handle_PLTE() may have canceled a valid tRNS chunk but left the |
| 27 | * 'valid' flag for the detection of duplicate chunks. Do not report a |
| 28 | * valid tRNS chunk in this case. |
| 29 | */ |
| 30 | if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0) |
| 31 | return(0); |
| 32 | #endif |
| 33 | |
| 34 | return(info_ptr->valid & flag); |
| 35 | } |
| 36 | |
| 37 | return(0); |
| 38 | } |
| 39 | |
| 40 | size_t PNGAPI |
| 41 | png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 42 | { |
| 43 | if (png_ptr != NULL && info_ptr != NULL) |
| 44 | return(info_ptr->rowbytes); |
| 45 | |
| 46 | return(0); |
| 47 | } |
| 48 | |
| 49 | #ifdef PNG_INFO_IMAGE_SUPPORTED |
| 50 | png_bytepp PNGAPI |
| 51 | png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 52 | { |
| 53 | if (png_ptr != NULL && info_ptr != NULL) |
| 54 | return(info_ptr->row_pointers); |
| 55 | |
| 56 | return(0); |
| 57 | } |
| 58 | #endif |
| 59 | |
| 60 | #ifdef PNG_EASY_ACCESS_SUPPORTED |
| 61 | /* Easy access to info, added in libpng-0.99 */ |
| 62 | png_uint_32 PNGAPI |
| 63 | png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 64 | { |
| 65 | if (png_ptr != NULL && info_ptr != NULL) |
| 66 | return info_ptr->width; |
| 67 | |
| 68 | return (0); |
| 69 | } |
| 70 | |
| 71 | png_uint_32 PNGAPI |
| 72 | png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 73 | { |
| 74 | if (png_ptr != NULL && info_ptr != NULL) |
| 75 | return info_ptr->height; |
| 76 | |
| 77 | return (0); |
| 78 | } |
| 79 | |
| 80 | png_byte PNGAPI |
| 81 | png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 82 | { |
| 83 | if (png_ptr != NULL && info_ptr != NULL) |
| 84 | return info_ptr->bit_depth; |
| 85 | |
| 86 | return (0); |
| 87 | } |
| 88 | |
| 89 | png_byte PNGAPI |
| 90 | png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 91 | { |
| 92 | if (png_ptr != NULL && info_ptr != NULL) |
| 93 | return info_ptr->color_type; |
| 94 | |
| 95 | return (0); |
| 96 | } |
| 97 | |
| 98 | png_byte PNGAPI |
| 99 | png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 100 | { |
| 101 | if (png_ptr != NULL && info_ptr != NULL) |
| 102 | return info_ptr->filter_type; |
| 103 | |
| 104 | return (0); |
| 105 | } |
| 106 | |
| 107 | png_byte PNGAPI |
| 108 | png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 109 | { |
| 110 | if (png_ptr != NULL && info_ptr != NULL) |
| 111 | return info_ptr->interlace_type; |
| 112 | |
| 113 | return (0); |
| 114 | } |
| 115 | |
| 116 | png_byte PNGAPI |
| 117 | png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 118 | { |
| 119 | if (png_ptr != NULL && info_ptr != NULL) |
| 120 | return info_ptr->compression_type; |
| 121 | |
| 122 | return (0); |
| 123 | } |
| 124 | |
| 125 | png_uint_32 PNGAPI |
| 126 | png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp |
| 127 | info_ptr) |
| 128 | { |
| 129 | #ifdef PNG_pHYs_SUPPORTED |
| 130 | if (png_ptr != NULL && info_ptr != NULL && |
| 131 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
| 132 | { |
| 133 | png_debug1(1, "in %s retrieval function" , |
| 134 | "png_get_x_pixels_per_meter" ); |
| 135 | |
| 136 | if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) |
| 137 | return (info_ptr->x_pixels_per_unit); |
| 138 | } |
| 139 | #else |
| 140 | PNG_UNUSED(png_ptr) |
| 141 | PNG_UNUSED(info_ptr) |
| 142 | #endif |
| 143 | |
| 144 | return (0); |
| 145 | } |
| 146 | |
| 147 | png_uint_32 PNGAPI |
| 148 | png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp |
| 149 | info_ptr) |
| 150 | { |
| 151 | #ifdef PNG_pHYs_SUPPORTED |
| 152 | if (png_ptr != NULL && info_ptr != NULL && |
| 153 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
| 154 | { |
| 155 | png_debug1(1, "in %s retrieval function" , |
| 156 | "png_get_y_pixels_per_meter" ); |
| 157 | |
| 158 | if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) |
| 159 | return (info_ptr->y_pixels_per_unit); |
| 160 | } |
| 161 | #else |
| 162 | PNG_UNUSED(png_ptr) |
| 163 | PNG_UNUSED(info_ptr) |
| 164 | #endif |
| 165 | |
| 166 | return (0); |
| 167 | } |
| 168 | |
| 169 | png_uint_32 PNGAPI |
| 170 | png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 171 | { |
| 172 | #ifdef PNG_pHYs_SUPPORTED |
| 173 | if (png_ptr != NULL && info_ptr != NULL && |
| 174 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
| 175 | { |
| 176 | png_debug1(1, "in %s retrieval function" , "png_get_pixels_per_meter" ); |
| 177 | |
| 178 | if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && |
| 179 | info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) |
| 180 | return (info_ptr->x_pixels_per_unit); |
| 181 | } |
| 182 | #else |
| 183 | PNG_UNUSED(png_ptr) |
| 184 | PNG_UNUSED(info_ptr) |
| 185 | #endif |
| 186 | |
| 187 | return (0); |
| 188 | } |
| 189 | |
| 190 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 191 | float PNGAPI |
| 192 | png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp |
| 193 | info_ptr) |
| 194 | { |
| 195 | #ifdef PNG_READ_pHYs_SUPPORTED |
| 196 | if (png_ptr != NULL && info_ptr != NULL && |
| 197 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
| 198 | { |
| 199 | png_debug1(1, "in %s retrieval function" , "png_get_aspect_ratio" ); |
| 200 | |
| 201 | if (info_ptr->x_pixels_per_unit != 0) |
| 202 | return ((float)((float)info_ptr->y_pixels_per_unit |
| 203 | /(float)info_ptr->x_pixels_per_unit)); |
| 204 | } |
| 205 | #else |
| 206 | PNG_UNUSED(png_ptr) |
| 207 | PNG_UNUSED(info_ptr) |
| 208 | #endif |
| 209 | |
| 210 | return ((float)0.0); |
| 211 | } |
| 212 | #endif |
| 213 | |
| 214 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 215 | png_fixed_point PNGAPI |
| 216 | png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr, |
| 217 | png_const_inforp info_ptr) |
| 218 | { |
| 219 | #ifdef PNG_READ_pHYs_SUPPORTED |
| 220 | if (png_ptr != NULL && info_ptr != NULL && |
| 221 | (info_ptr->valid & PNG_INFO_pHYs) != 0 && |
| 222 | info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 && |
| 223 | info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX && |
| 224 | info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) |
| 225 | { |
| 226 | png_fixed_point res; |
| 227 | |
| 228 | png_debug1(1, "in %s retrieval function" , "png_get_aspect_ratio_fixed" ); |
| 229 | |
| 230 | /* The following casts work because a PNG 4 byte integer only has a valid |
| 231 | * range of 0..2^31-1; otherwise the cast might overflow. |
| 232 | */ |
| 233 | if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, |
| 234 | (png_int_32)info_ptr->x_pixels_per_unit) != 0) |
| 235 | return res; |
| 236 | } |
| 237 | #else |
| 238 | PNG_UNUSED(png_ptr) |
| 239 | PNG_UNUSED(info_ptr) |
| 240 | #endif |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | #endif |
| 245 | |
| 246 | png_int_32 PNGAPI |
| 247 | png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 248 | { |
| 249 | #ifdef PNG_oFFs_SUPPORTED |
| 250 | if (png_ptr != NULL && info_ptr != NULL && |
| 251 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
| 252 | { |
| 253 | png_debug1(1, "in %s retrieval function" , "png_get_x_offset_microns" ); |
| 254 | |
| 255 | if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) |
| 256 | return (info_ptr->x_offset); |
| 257 | } |
| 258 | #else |
| 259 | PNG_UNUSED(png_ptr) |
| 260 | PNG_UNUSED(info_ptr) |
| 261 | #endif |
| 262 | |
| 263 | return (0); |
| 264 | } |
| 265 | |
| 266 | png_int_32 PNGAPI |
| 267 | png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 268 | { |
| 269 | #ifdef PNG_oFFs_SUPPORTED |
| 270 | if (png_ptr != NULL && info_ptr != NULL && |
| 271 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
| 272 | { |
| 273 | png_debug1(1, "in %s retrieval function" , "png_get_y_offset_microns" ); |
| 274 | |
| 275 | if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) |
| 276 | return (info_ptr->y_offset); |
| 277 | } |
| 278 | #else |
| 279 | PNG_UNUSED(png_ptr) |
| 280 | PNG_UNUSED(info_ptr) |
| 281 | #endif |
| 282 | |
| 283 | return (0); |
| 284 | } |
| 285 | |
| 286 | png_int_32 PNGAPI |
| 287 | png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 288 | { |
| 289 | #ifdef PNG_oFFs_SUPPORTED |
| 290 | if (png_ptr != NULL && info_ptr != NULL && |
| 291 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
| 292 | { |
| 293 | png_debug1(1, "in %s retrieval function" , "png_get_x_offset_pixels" ); |
| 294 | |
| 295 | if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) |
| 296 | return (info_ptr->x_offset); |
| 297 | } |
| 298 | #else |
| 299 | PNG_UNUSED(png_ptr) |
| 300 | PNG_UNUSED(info_ptr) |
| 301 | #endif |
| 302 | |
| 303 | return (0); |
| 304 | } |
| 305 | |
| 306 | png_int_32 PNGAPI |
| 307 | png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 308 | { |
| 309 | #ifdef PNG_oFFs_SUPPORTED |
| 310 | if (png_ptr != NULL && info_ptr != NULL && |
| 311 | (info_ptr->valid & PNG_INFO_oFFs) != 0) |
| 312 | { |
| 313 | png_debug1(1, "in %s retrieval function" , "png_get_y_offset_pixels" ); |
| 314 | |
| 315 | if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) |
| 316 | return (info_ptr->y_offset); |
| 317 | } |
| 318 | #else |
| 319 | PNG_UNUSED(png_ptr) |
| 320 | PNG_UNUSED(info_ptr) |
| 321 | #endif |
| 322 | |
| 323 | return (0); |
| 324 | } |
| 325 | |
| 326 | #ifdef PNG_INCH_CONVERSIONS_SUPPORTED |
| 327 | static png_uint_32 |
| 328 | ppi_from_ppm(png_uint_32 ppm) |
| 329 | { |
| 330 | #if 0 |
| 331 | /* The conversion is *(2.54/100), in binary (32 digits): |
| 332 | * .00000110100000001001110101001001 |
| 333 | */ |
| 334 | png_uint_32 t1001, t1101; |
| 335 | ppm >>= 1; /* .1 */ |
| 336 | t1001 = ppm + (ppm >> 3); /* .1001 */ |
| 337 | t1101 = t1001 + (ppm >> 1); /* .1101 */ |
| 338 | ppm >>= 20; /* .000000000000000000001 */ |
| 339 | t1101 += t1101 >> 15; /* .1101000000000001101 */ |
| 340 | t1001 >>= 11; /* .000000000001001 */ |
| 341 | t1001 += t1001 >> 12; /* .000000000001001000000001001 */ |
| 342 | ppm += t1001; /* .000000000001001000001001001 */ |
| 343 | ppm += t1101; /* .110100000001001110101001001 */ |
| 344 | return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */ |
| 345 | #else |
| 346 | /* The argument is a PNG unsigned integer, so it is not permitted |
| 347 | * to be bigger than 2^31. |
| 348 | */ |
| 349 | png_fixed_point result; |
| 350 | if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, |
| 351 | 5000) != 0) |
| 352 | return (png_uint_32)result; |
| 353 | |
| 354 | /* Overflow. */ |
| 355 | return 0; |
| 356 | #endif |
| 357 | } |
| 358 | |
| 359 | png_uint_32 PNGAPI |
| 360 | png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 361 | { |
| 362 | return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); |
| 363 | } |
| 364 | |
| 365 | png_uint_32 PNGAPI |
| 366 | png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 367 | { |
| 368 | return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); |
| 369 | } |
| 370 | |
| 371 | png_uint_32 PNGAPI |
| 372 | png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 373 | { |
| 374 | return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); |
| 375 | } |
| 376 | |
| 377 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 378 | static png_fixed_point |
| 379 | png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns) |
| 380 | { |
| 381 | /* Convert from meters * 1,000,000 to inches * 100,000, meters to |
| 382 | * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. |
| 383 | * Notice that this can overflow - a warning is output and 0 is |
| 384 | * returned. |
| 385 | */ |
| 386 | return png_muldiv_warn(png_ptr, microns, 500, 127); |
| 387 | } |
| 388 | |
| 389 | png_fixed_point PNGAPI |
| 390 | png_get_x_offset_inches_fixed(png_const_structrp png_ptr, |
| 391 | png_const_inforp info_ptr) |
| 392 | { |
| 393 | return png_fixed_inches_from_microns(png_ptr, |
| 394 | png_get_x_offset_microns(png_ptr, info_ptr)); |
| 395 | } |
| 396 | #endif |
| 397 | |
| 398 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 399 | png_fixed_point PNGAPI |
| 400 | png_get_y_offset_inches_fixed(png_const_structrp png_ptr, |
| 401 | png_const_inforp info_ptr) |
| 402 | { |
| 403 | return png_fixed_inches_from_microns(png_ptr, |
| 404 | png_get_y_offset_microns(png_ptr, info_ptr)); |
| 405 | } |
| 406 | #endif |
| 407 | |
| 408 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 409 | float PNGAPI |
| 410 | png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 411 | { |
| 412 | /* To avoid the overflow do the conversion directly in floating |
| 413 | * point. |
| 414 | */ |
| 415 | return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); |
| 416 | } |
| 417 | #endif |
| 418 | |
| 419 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 420 | float PNGAPI |
| 421 | png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 422 | { |
| 423 | /* To avoid the overflow do the conversion directly in floating |
| 424 | * point. |
| 425 | */ |
| 426 | return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); |
| 427 | } |
| 428 | #endif |
| 429 | |
| 430 | #ifdef PNG_pHYs_SUPPORTED |
| 431 | png_uint_32 PNGAPI |
| 432 | png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 433 | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
| 434 | { |
| 435 | png_uint_32 retval = 0; |
| 436 | |
| 437 | if (png_ptr != NULL && info_ptr != NULL && |
| 438 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
| 439 | { |
| 440 | png_debug1(1, "in %s retrieval function" , "pHYs" ); |
| 441 | |
| 442 | if (res_x != NULL) |
| 443 | { |
| 444 | *res_x = info_ptr->x_pixels_per_unit; |
| 445 | retval |= PNG_INFO_pHYs; |
| 446 | } |
| 447 | |
| 448 | if (res_y != NULL) |
| 449 | { |
| 450 | *res_y = info_ptr->y_pixels_per_unit; |
| 451 | retval |= PNG_INFO_pHYs; |
| 452 | } |
| 453 | |
| 454 | if (unit_type != NULL) |
| 455 | { |
| 456 | *unit_type = (int)info_ptr->phys_unit_type; |
| 457 | retval |= PNG_INFO_pHYs; |
| 458 | |
| 459 | if (*unit_type == 1) |
| 460 | { |
| 461 | if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); |
| 462 | if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | return (retval); |
| 468 | } |
| 469 | #endif /* pHYs */ |
| 470 | #endif /* INCH_CONVERSIONS */ |
| 471 | |
| 472 | /* png_get_channels really belongs in here, too, but it's been around longer */ |
| 473 | |
| 474 | #endif /* EASY_ACCESS */ |
| 475 | |
| 476 | |
| 477 | png_byte PNGAPI |
| 478 | png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 479 | { |
| 480 | if (png_ptr != NULL && info_ptr != NULL) |
| 481 | return(info_ptr->channels); |
| 482 | |
| 483 | return (0); |
| 484 | } |
| 485 | |
| 486 | #ifdef PNG_READ_SUPPORTED |
| 487 | png_const_bytep PNGAPI |
| 488 | png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 489 | { |
| 490 | if (png_ptr != NULL && info_ptr != NULL) |
| 491 | return(info_ptr->signature); |
| 492 | |
| 493 | return (NULL); |
| 494 | } |
| 495 | #endif |
| 496 | |
| 497 | #ifdef PNG_bKGD_SUPPORTED |
| 498 | png_uint_32 PNGAPI |
| 499 | png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, |
| 500 | png_color_16p *background) |
| 501 | { |
| 502 | if (png_ptr != NULL && info_ptr != NULL && |
| 503 | (info_ptr->valid & PNG_INFO_bKGD) != 0 && |
| 504 | background != NULL) |
| 505 | { |
| 506 | png_debug1(1, "in %s retrieval function" , "bKGD" ); |
| 507 | |
| 508 | *background = &(info_ptr->background); |
| 509 | return (PNG_INFO_bKGD); |
| 510 | } |
| 511 | |
| 512 | return (0); |
| 513 | } |
| 514 | #endif |
| 515 | |
| 516 | #ifdef PNG_cHRM_SUPPORTED |
| 517 | /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the |
| 518 | * same time to correct the rgb grayscale coefficient defaults obtained from the |
| 519 | * cHRM chunk in 1.5.4 |
| 520 | */ |
| 521 | # ifdef PNG_FLOATING_POINT_SUPPORTED |
| 522 | png_uint_32 PNGAPI |
| 523 | png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 524 | double *white_x, double *white_y, double *red_x, double *red_y, |
| 525 | double *green_x, double *green_y, double *blue_x, double *blue_y) |
| 526 | { |
| 527 | /* Quiet API change: this code used to only return the end points if a cHRM |
| 528 | * chunk was present, but the end points can also come from iCCP or sRGB |
| 529 | * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and |
| 530 | * the png_set_ APIs merely check that set end points are mutually |
| 531 | * consistent. |
| 532 | */ |
| 533 | if (png_ptr != NULL && info_ptr != NULL && |
| 534 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
| 535 | { |
| 536 | png_debug1(1, "in %s retrieval function" , "cHRM" ); |
| 537 | |
| 538 | if (white_x != NULL) |
| 539 | *white_x = png_float(png_ptr, |
| 540 | info_ptr->colorspace.end_points_xy.whitex, "cHRM white X" ); |
| 541 | if (white_y != NULL) |
| 542 | *white_y = png_float(png_ptr, |
| 543 | info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y" ); |
| 544 | if (red_x != NULL) |
| 545 | *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx, |
| 546 | "cHRM red X" ); |
| 547 | if (red_y != NULL) |
| 548 | *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy, |
| 549 | "cHRM red Y" ); |
| 550 | if (green_x != NULL) |
| 551 | *green_x = png_float(png_ptr, |
| 552 | info_ptr->colorspace.end_points_xy.greenx, "cHRM green X" ); |
| 553 | if (green_y != NULL) |
| 554 | *green_y = png_float(png_ptr, |
| 555 | info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y" ); |
| 556 | if (blue_x != NULL) |
| 557 | *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex, |
| 558 | "cHRM blue X" ); |
| 559 | if (blue_y != NULL) |
| 560 | *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey, |
| 561 | "cHRM blue Y" ); |
| 562 | return (PNG_INFO_cHRM); |
| 563 | } |
| 564 | |
| 565 | return (0); |
| 566 | } |
| 567 | |
| 568 | png_uint_32 PNGAPI |
| 569 | png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 570 | double *red_X, double *red_Y, double *red_Z, double *green_X, |
| 571 | double *green_Y, double *green_Z, double *blue_X, double *blue_Y, |
| 572 | double *blue_Z) |
| 573 | { |
| 574 | if (png_ptr != NULL && info_ptr != NULL && |
| 575 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
| 576 | { |
| 577 | png_debug1(1, "in %s retrieval function" , "cHRM_XYZ(float)" ); |
| 578 | |
| 579 | if (red_X != NULL) |
| 580 | *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X, |
| 581 | "cHRM red X" ); |
| 582 | if (red_Y != NULL) |
| 583 | *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y, |
| 584 | "cHRM red Y" ); |
| 585 | if (red_Z != NULL) |
| 586 | *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z, |
| 587 | "cHRM red Z" ); |
| 588 | if (green_X != NULL) |
| 589 | *green_X = png_float(png_ptr, |
| 590 | info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X" ); |
| 591 | if (green_Y != NULL) |
| 592 | *green_Y = png_float(png_ptr, |
| 593 | info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y" ); |
| 594 | if (green_Z != NULL) |
| 595 | *green_Z = png_float(png_ptr, |
| 596 | info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z" ); |
| 597 | if (blue_X != NULL) |
| 598 | *blue_X = png_float(png_ptr, |
| 599 | info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X" ); |
| 600 | if (blue_Y != NULL) |
| 601 | *blue_Y = png_float(png_ptr, |
| 602 | info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y" ); |
| 603 | if (blue_Z != NULL) |
| 604 | *blue_Z = png_float(png_ptr, |
| 605 | info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z" ); |
| 606 | return (PNG_INFO_cHRM); |
| 607 | } |
| 608 | |
| 609 | return (0); |
| 610 | } |
| 611 | # endif |
| 612 | |
| 613 | # ifdef PNG_FIXED_POINT_SUPPORTED |
| 614 | png_uint_32 PNGAPI |
| 615 | png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 616 | png_fixed_point *int_red_X, png_fixed_point *int_red_Y, |
| 617 | png_fixed_point *int_red_Z, png_fixed_point *int_green_X, |
| 618 | png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, |
| 619 | png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, |
| 620 | png_fixed_point *int_blue_Z) |
| 621 | { |
| 622 | if (png_ptr != NULL && info_ptr != NULL && |
| 623 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
| 624 | { |
| 625 | png_debug1(1, "in %s retrieval function" , "cHRM_XYZ" ); |
| 626 | |
| 627 | if (int_red_X != NULL) |
| 628 | *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X; |
| 629 | if (int_red_Y != NULL) |
| 630 | *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y; |
| 631 | if (int_red_Z != NULL) |
| 632 | *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z; |
| 633 | if (int_green_X != NULL) |
| 634 | *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X; |
| 635 | if (int_green_Y != NULL) |
| 636 | *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y; |
| 637 | if (int_green_Z != NULL) |
| 638 | *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z; |
| 639 | if (int_blue_X != NULL) |
| 640 | *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X; |
| 641 | if (int_blue_Y != NULL) |
| 642 | *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y; |
| 643 | if (int_blue_Z != NULL) |
| 644 | *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z; |
| 645 | return (PNG_INFO_cHRM); |
| 646 | } |
| 647 | |
| 648 | return (0); |
| 649 | } |
| 650 | |
| 651 | png_uint_32 PNGAPI |
| 652 | png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 653 | png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, |
| 654 | png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, |
| 655 | png_fixed_point *blue_x, png_fixed_point *blue_y) |
| 656 | { |
| 657 | png_debug1(1, "in %s retrieval function" , "cHRM" ); |
| 658 | |
| 659 | if (png_ptr != NULL && info_ptr != NULL && |
| 660 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) |
| 661 | { |
| 662 | if (white_x != NULL) |
| 663 | *white_x = info_ptr->colorspace.end_points_xy.whitex; |
| 664 | if (white_y != NULL) |
| 665 | *white_y = info_ptr->colorspace.end_points_xy.whitey; |
| 666 | if (red_x != NULL) |
| 667 | *red_x = info_ptr->colorspace.end_points_xy.redx; |
| 668 | if (red_y != NULL) |
| 669 | *red_y = info_ptr->colorspace.end_points_xy.redy; |
| 670 | if (green_x != NULL) |
| 671 | *green_x = info_ptr->colorspace.end_points_xy.greenx; |
| 672 | if (green_y != NULL) |
| 673 | *green_y = info_ptr->colorspace.end_points_xy.greeny; |
| 674 | if (blue_x != NULL) |
| 675 | *blue_x = info_ptr->colorspace.end_points_xy.bluex; |
| 676 | if (blue_y != NULL) |
| 677 | *blue_y = info_ptr->colorspace.end_points_xy.bluey; |
| 678 | return (PNG_INFO_cHRM); |
| 679 | } |
| 680 | |
| 681 | return (0); |
| 682 | } |
| 683 | # endif |
| 684 | #endif |
| 685 | |
| 686 | #ifdef PNG_gAMA_SUPPORTED |
| 687 | # ifdef PNG_FIXED_POINT_SUPPORTED |
| 688 | png_uint_32 PNGAPI |
| 689 | png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 690 | png_fixed_point *file_gamma) |
| 691 | { |
| 692 | png_debug1(1, "in %s retrieval function" , "gAMA" ); |
| 693 | |
| 694 | if (png_ptr != NULL && info_ptr != NULL && |
| 695 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && |
| 696 | file_gamma != NULL) |
| 697 | { |
| 698 | *file_gamma = info_ptr->colorspace.gamma; |
| 699 | return (PNG_INFO_gAMA); |
| 700 | } |
| 701 | |
| 702 | return (0); |
| 703 | } |
| 704 | # endif |
| 705 | |
| 706 | # ifdef PNG_FLOATING_POINT_SUPPORTED |
| 707 | png_uint_32 PNGAPI |
| 708 | png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 709 | double *file_gamma) |
| 710 | { |
| 711 | png_debug1(1, "in %s retrieval function" , "gAMA(float)" ); |
| 712 | |
| 713 | if (png_ptr != NULL && info_ptr != NULL && |
| 714 | (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 && |
| 715 | file_gamma != NULL) |
| 716 | { |
| 717 | *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma, |
| 718 | "png_get_gAMA" ); |
| 719 | return (PNG_INFO_gAMA); |
| 720 | } |
| 721 | |
| 722 | return (0); |
| 723 | } |
| 724 | # endif |
| 725 | #endif |
| 726 | |
| 727 | #ifdef PNG_sRGB_SUPPORTED |
| 728 | png_uint_32 PNGAPI |
| 729 | png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 730 | int *file_srgb_intent) |
| 731 | { |
| 732 | png_debug1(1, "in %s retrieval function" , "sRGB" ); |
| 733 | |
| 734 | if (png_ptr != NULL && info_ptr != NULL && |
| 735 | (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL) |
| 736 | { |
| 737 | *file_srgb_intent = info_ptr->colorspace.rendering_intent; |
| 738 | return (PNG_INFO_sRGB); |
| 739 | } |
| 740 | |
| 741 | return (0); |
| 742 | } |
| 743 | #endif |
| 744 | |
| 745 | #ifdef PNG_iCCP_SUPPORTED |
| 746 | png_uint_32 PNGAPI |
| 747 | png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, |
| 748 | png_charpp name, int *compression_type, |
| 749 | png_bytepp profile, png_uint_32 *proflen) |
| 750 | { |
| 751 | png_debug1(1, "in %s retrieval function" , "iCCP" ); |
| 752 | |
| 753 | if (png_ptr != NULL && info_ptr != NULL && |
| 754 | (info_ptr->valid & PNG_INFO_iCCP) != 0 && |
| 755 | name != NULL && profile != NULL && proflen != NULL) |
| 756 | { |
| 757 | *name = info_ptr->iccp_name; |
| 758 | *profile = info_ptr->iccp_profile; |
| 759 | *proflen = png_get_uint_32(info_ptr->iccp_profile); |
| 760 | /* This is somewhat irrelevant since the profile data returned has |
| 761 | * actually been uncompressed. |
| 762 | */ |
| 763 | if (compression_type != NULL) |
| 764 | *compression_type = PNG_COMPRESSION_TYPE_BASE; |
| 765 | return (PNG_INFO_iCCP); |
| 766 | } |
| 767 | |
| 768 | return (0); |
| 769 | |
| 770 | } |
| 771 | #endif |
| 772 | |
| 773 | #ifdef PNG_sPLT_SUPPORTED |
| 774 | int PNGAPI |
| 775 | png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr, |
| 776 | png_sPLT_tpp spalettes) |
| 777 | { |
| 778 | if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) |
| 779 | { |
| 780 | *spalettes = info_ptr->splt_palettes; |
| 781 | return info_ptr->splt_palettes_num; |
| 782 | } |
| 783 | |
| 784 | return (0); |
| 785 | } |
| 786 | #endif |
| 787 | |
| 788 | #ifdef PNG_eXIf_SUPPORTED |
| 789 | png_uint_32 PNGAPI |
| 790 | png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr, |
| 791 | png_bytep *exif) |
| 792 | { |
| 793 | png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1" ); |
| 794 | PNG_UNUSED(info_ptr) |
| 795 | PNG_UNUSED(exif) |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | png_uint_32 PNGAPI |
| 800 | png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 801 | png_uint_32 *num_exif, png_bytep *exif) |
| 802 | { |
| 803 | png_debug1(1, "in %s retrieval function" , "eXIf" ); |
| 804 | |
| 805 | if (png_ptr != NULL && info_ptr != NULL && |
| 806 | (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL) |
| 807 | { |
| 808 | *num_exif = info_ptr->num_exif; |
| 809 | *exif = info_ptr->exif; |
| 810 | return (PNG_INFO_eXIf); |
| 811 | } |
| 812 | |
| 813 | return (0); |
| 814 | } |
| 815 | #endif |
| 816 | |
| 817 | #ifdef PNG_hIST_SUPPORTED |
| 818 | png_uint_32 PNGAPI |
| 819 | png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, |
| 820 | png_uint_16p *hist) |
| 821 | { |
| 822 | png_debug1(1, "in %s retrieval function" , "hIST" ); |
| 823 | |
| 824 | if (png_ptr != NULL && info_ptr != NULL && |
| 825 | (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL) |
| 826 | { |
| 827 | *hist = info_ptr->hist; |
| 828 | return (PNG_INFO_hIST); |
| 829 | } |
| 830 | |
| 831 | return (0); |
| 832 | } |
| 833 | #endif |
| 834 | |
| 835 | png_uint_32 PNGAPI |
| 836 | png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 837 | png_uint_32 *width, png_uint_32 *height, int *bit_depth, |
| 838 | int *color_type, int *interlace_type, int *compression_type, |
| 839 | int *filter_type) |
| 840 | { |
| 841 | png_debug1(1, "in %s retrieval function" , "IHDR" ); |
| 842 | |
| 843 | if (png_ptr == NULL || info_ptr == NULL) |
| 844 | return (0); |
| 845 | |
| 846 | if (width != NULL) |
| 847 | *width = info_ptr->width; |
| 848 | |
| 849 | if (height != NULL) |
| 850 | *height = info_ptr->height; |
| 851 | |
| 852 | if (bit_depth != NULL) |
| 853 | *bit_depth = info_ptr->bit_depth; |
| 854 | |
| 855 | if (color_type != NULL) |
| 856 | *color_type = info_ptr->color_type; |
| 857 | |
| 858 | if (compression_type != NULL) |
| 859 | *compression_type = info_ptr->compression_type; |
| 860 | |
| 861 | if (filter_type != NULL) |
| 862 | *filter_type = info_ptr->filter_type; |
| 863 | |
| 864 | if (interlace_type != NULL) |
| 865 | *interlace_type = info_ptr->interlace_type; |
| 866 | |
| 867 | /* This is redundant if we can be sure that the info_ptr values were all |
| 868 | * assigned in png_set_IHDR(). We do the check anyhow in case an |
| 869 | * application has ignored our advice not to mess with the members |
| 870 | * of info_ptr directly. |
| 871 | */ |
| 872 | png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
| 873 | info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, |
| 874 | info_ptr->compression_type, info_ptr->filter_type); |
| 875 | |
| 876 | return (1); |
| 877 | } |
| 878 | |
| 879 | #ifdef PNG_oFFs_SUPPORTED |
| 880 | png_uint_32 PNGAPI |
| 881 | png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 882 | png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) |
| 883 | { |
| 884 | png_debug1(1, "in %s retrieval function" , "oFFs" ); |
| 885 | |
| 886 | if (png_ptr != NULL && info_ptr != NULL && |
| 887 | (info_ptr->valid & PNG_INFO_oFFs) != 0 && |
| 888 | offset_x != NULL && offset_y != NULL && unit_type != NULL) |
| 889 | { |
| 890 | *offset_x = info_ptr->x_offset; |
| 891 | *offset_y = info_ptr->y_offset; |
| 892 | *unit_type = (int)info_ptr->offset_unit_type; |
| 893 | return (PNG_INFO_oFFs); |
| 894 | } |
| 895 | |
| 896 | return (0); |
| 897 | } |
| 898 | #endif |
| 899 | |
| 900 | #ifdef PNG_pCAL_SUPPORTED |
| 901 | png_uint_32 PNGAPI |
| 902 | png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, |
| 903 | png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, |
| 904 | png_charp *units, png_charpp *params) |
| 905 | { |
| 906 | png_debug1(1, "in %s retrieval function" , "pCAL" ); |
| 907 | |
| 908 | if (png_ptr != NULL && info_ptr != NULL && |
| 909 | (info_ptr->valid & PNG_INFO_pCAL) != 0 && |
| 910 | purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && |
| 911 | nparams != NULL && units != NULL && params != NULL) |
| 912 | { |
| 913 | *purpose = info_ptr->pcal_purpose; |
| 914 | *X0 = info_ptr->pcal_X0; |
| 915 | *X1 = info_ptr->pcal_X1; |
| 916 | *type = (int)info_ptr->pcal_type; |
| 917 | *nparams = (int)info_ptr->pcal_nparams; |
| 918 | *units = info_ptr->pcal_units; |
| 919 | *params = info_ptr->pcal_params; |
| 920 | return (PNG_INFO_pCAL); |
| 921 | } |
| 922 | |
| 923 | return (0); |
| 924 | } |
| 925 | #endif |
| 926 | |
| 927 | #ifdef PNG_sCAL_SUPPORTED |
| 928 | # ifdef PNG_FIXED_POINT_SUPPORTED |
| 929 | # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ |
| 930 | defined(PNG_FLOATING_POINT_SUPPORTED) |
| 931 | png_uint_32 PNGAPI |
| 932 | png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 933 | int *unit, png_fixed_point *width, png_fixed_point *height) |
| 934 | { |
| 935 | if (png_ptr != NULL && info_ptr != NULL && |
| 936 | (info_ptr->valid & PNG_INFO_sCAL) != 0) |
| 937 | { |
| 938 | *unit = info_ptr->scal_unit; |
| 939 | /*TODO: make this work without FP support; the API is currently eliminated |
| 940 | * if neither floating point APIs nor internal floating point arithmetic |
| 941 | * are enabled. |
| 942 | */ |
| 943 | *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width" ); |
| 944 | *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), |
| 945 | "sCAL height" ); |
| 946 | return (PNG_INFO_sCAL); |
| 947 | } |
| 948 | |
| 949 | return(0); |
| 950 | } |
| 951 | # endif /* FLOATING_ARITHMETIC */ |
| 952 | # endif /* FIXED_POINT */ |
| 953 | # ifdef PNG_FLOATING_POINT_SUPPORTED |
| 954 | png_uint_32 PNGAPI |
| 955 | png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 956 | int *unit, double *width, double *height) |
| 957 | { |
| 958 | if (png_ptr != NULL && info_ptr != NULL && |
| 959 | (info_ptr->valid & PNG_INFO_sCAL) != 0) |
| 960 | { |
| 961 | *unit = info_ptr->scal_unit; |
| 962 | *width = atof(info_ptr->scal_s_width); |
| 963 | *height = atof(info_ptr->scal_s_height); |
| 964 | return (PNG_INFO_sCAL); |
| 965 | } |
| 966 | |
| 967 | return(0); |
| 968 | } |
| 969 | # endif /* FLOATING POINT */ |
| 970 | png_uint_32 PNGAPI |
| 971 | png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 972 | int *unit, png_charpp width, png_charpp height) |
| 973 | { |
| 974 | if (png_ptr != NULL && info_ptr != NULL && |
| 975 | (info_ptr->valid & PNG_INFO_sCAL) != 0) |
| 976 | { |
| 977 | *unit = info_ptr->scal_unit; |
| 978 | *width = info_ptr->scal_s_width; |
| 979 | *height = info_ptr->scal_s_height; |
| 980 | return (PNG_INFO_sCAL); |
| 981 | } |
| 982 | |
| 983 | return(0); |
| 984 | } |
| 985 | #endif /* sCAL */ |
| 986 | |
| 987 | #ifdef PNG_pHYs_SUPPORTED |
| 988 | png_uint_32 PNGAPI |
| 989 | png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 990 | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
| 991 | { |
| 992 | png_uint_32 retval = 0; |
| 993 | |
| 994 | png_debug1(1, "in %s retrieval function" , "pHYs" ); |
| 995 | |
| 996 | if (png_ptr != NULL && info_ptr != NULL && |
| 997 | (info_ptr->valid & PNG_INFO_pHYs) != 0) |
| 998 | { |
| 999 | if (res_x != NULL) |
| 1000 | { |
| 1001 | *res_x = info_ptr->x_pixels_per_unit; |
| 1002 | retval |= PNG_INFO_pHYs; |
| 1003 | } |
| 1004 | |
| 1005 | if (res_y != NULL) |
| 1006 | { |
| 1007 | *res_y = info_ptr->y_pixels_per_unit; |
| 1008 | retval |= PNG_INFO_pHYs; |
| 1009 | } |
| 1010 | |
| 1011 | if (unit_type != NULL) |
| 1012 | { |
| 1013 | *unit_type = (int)info_ptr->phys_unit_type; |
| 1014 | retval |= PNG_INFO_pHYs; |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | return (retval); |
| 1019 | } |
| 1020 | #endif /* pHYs */ |
| 1021 | |
| 1022 | png_uint_32 PNGAPI |
| 1023 | png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1024 | png_colorp *palette, int *num_palette) |
| 1025 | { |
| 1026 | png_debug1(1, "in %s retrieval function" , "PLTE" ); |
| 1027 | |
| 1028 | if (png_ptr != NULL && info_ptr != NULL && |
| 1029 | (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL) |
| 1030 | { |
| 1031 | *palette = info_ptr->palette; |
| 1032 | *num_palette = info_ptr->num_palette; |
| 1033 | png_debug1(3, "num_palette = %d" , *num_palette); |
| 1034 | return (PNG_INFO_PLTE); |
| 1035 | } |
| 1036 | |
| 1037 | return (0); |
| 1038 | } |
| 1039 | |
| 1040 | #ifdef PNG_sBIT_SUPPORTED |
| 1041 | png_uint_32 PNGAPI |
| 1042 | png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1043 | png_color_8p *sig_bit) |
| 1044 | { |
| 1045 | png_debug1(1, "in %s retrieval function" , "sBIT" ); |
| 1046 | |
| 1047 | if (png_ptr != NULL && info_ptr != NULL && |
| 1048 | (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL) |
| 1049 | { |
| 1050 | *sig_bit = &(info_ptr->sig_bit); |
| 1051 | return (PNG_INFO_sBIT); |
| 1052 | } |
| 1053 | |
| 1054 | return (0); |
| 1055 | } |
| 1056 | #endif |
| 1057 | |
| 1058 | #ifdef PNG_TEXT_SUPPORTED |
| 1059 | int PNGAPI |
| 1060 | png_get_text(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1061 | png_textp *text_ptr, int *num_text) |
| 1062 | { |
| 1063 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) |
| 1064 | { |
| 1065 | png_debug1(1, "in 0x%lx retrieval function" , |
| 1066 | (unsigned long)png_ptr->chunk_name); |
| 1067 | |
| 1068 | if (text_ptr != NULL) |
| 1069 | *text_ptr = info_ptr->text; |
| 1070 | |
| 1071 | if (num_text != NULL) |
| 1072 | *num_text = info_ptr->num_text; |
| 1073 | |
| 1074 | return info_ptr->num_text; |
| 1075 | } |
| 1076 | |
| 1077 | if (num_text != NULL) |
| 1078 | *num_text = 0; |
| 1079 | |
| 1080 | return(0); |
| 1081 | } |
| 1082 | #endif |
| 1083 | |
| 1084 | #ifdef PNG_tIME_SUPPORTED |
| 1085 | png_uint_32 PNGAPI |
| 1086 | png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1087 | png_timep *mod_time) |
| 1088 | { |
| 1089 | png_debug1(1, "in %s retrieval function" , "tIME" ); |
| 1090 | |
| 1091 | if (png_ptr != NULL && info_ptr != NULL && |
| 1092 | (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL) |
| 1093 | { |
| 1094 | *mod_time = &(info_ptr->mod_time); |
| 1095 | return (PNG_INFO_tIME); |
| 1096 | } |
| 1097 | |
| 1098 | return (0); |
| 1099 | } |
| 1100 | #endif |
| 1101 | |
| 1102 | #ifdef PNG_tRNS_SUPPORTED |
| 1103 | png_uint_32 PNGAPI |
| 1104 | png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1105 | png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) |
| 1106 | { |
| 1107 | png_uint_32 retval = 0; |
| 1108 | if (png_ptr != NULL && info_ptr != NULL && |
| 1109 | (info_ptr->valid & PNG_INFO_tRNS) != 0) |
| 1110 | { |
| 1111 | png_debug1(1, "in %s retrieval function" , "tRNS" ); |
| 1112 | |
| 1113 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 1114 | { |
| 1115 | if (trans_alpha != NULL) |
| 1116 | { |
| 1117 | *trans_alpha = info_ptr->trans_alpha; |
| 1118 | retval |= PNG_INFO_tRNS; |
| 1119 | } |
| 1120 | |
| 1121 | if (trans_color != NULL) |
| 1122 | *trans_color = &(info_ptr->trans_color); |
| 1123 | } |
| 1124 | |
| 1125 | else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ |
| 1126 | { |
| 1127 | if (trans_color != NULL) |
| 1128 | { |
| 1129 | *trans_color = &(info_ptr->trans_color); |
| 1130 | retval |= PNG_INFO_tRNS; |
| 1131 | } |
| 1132 | |
| 1133 | if (trans_alpha != NULL) |
| 1134 | *trans_alpha = NULL; |
| 1135 | } |
| 1136 | |
| 1137 | if (num_trans != NULL) |
| 1138 | { |
| 1139 | *num_trans = info_ptr->num_trans; |
| 1140 | retval |= PNG_INFO_tRNS; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | return (retval); |
| 1145 | } |
| 1146 | #endif |
| 1147 | |
| 1148 | #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED |
| 1149 | int PNGAPI |
| 1150 | png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1151 | png_unknown_chunkpp unknowns) |
| 1152 | { |
| 1153 | if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) |
| 1154 | { |
| 1155 | *unknowns = info_ptr->unknown_chunks; |
| 1156 | return info_ptr->unknown_chunks_num; |
| 1157 | } |
| 1158 | |
| 1159 | return (0); |
| 1160 | } |
| 1161 | #endif |
| 1162 | |
| 1163 | #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
| 1164 | png_byte PNGAPI |
| 1165 | png_get_rgb_to_gray_status(png_const_structrp png_ptr) |
| 1166 | { |
| 1167 | return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); |
| 1168 | } |
| 1169 | #endif |
| 1170 | |
| 1171 | #ifdef PNG_USER_CHUNKS_SUPPORTED |
| 1172 | png_voidp PNGAPI |
| 1173 | png_get_user_chunk_ptr(png_const_structrp png_ptr) |
| 1174 | { |
| 1175 | return (png_ptr ? png_ptr->user_chunk_ptr : NULL); |
| 1176 | } |
| 1177 | #endif |
| 1178 | |
| 1179 | size_t PNGAPI |
| 1180 | png_get_compression_buffer_size(png_const_structrp png_ptr) |
| 1181 | { |
| 1182 | if (png_ptr == NULL) |
| 1183 | return 0; |
| 1184 | |
| 1185 | #ifdef PNG_WRITE_SUPPORTED |
| 1186 | if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
| 1187 | #endif |
| 1188 | { |
| 1189 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
| 1190 | return png_ptr->IDAT_read_size; |
| 1191 | #else |
| 1192 | return PNG_IDAT_READ_SIZE; |
| 1193 | #endif |
| 1194 | } |
| 1195 | |
| 1196 | #ifdef PNG_WRITE_SUPPORTED |
| 1197 | else |
| 1198 | return png_ptr->zbuffer_size; |
| 1199 | #endif |
| 1200 | } |
| 1201 | |
| 1202 | #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 1203 | /* These functions were added to libpng 1.2.6 and were enabled |
| 1204 | * by default in libpng-1.4.0 */ |
| 1205 | png_uint_32 PNGAPI |
| 1206 | png_get_user_width_max(png_const_structrp png_ptr) |
| 1207 | { |
| 1208 | return (png_ptr ? png_ptr->user_width_max : 0); |
| 1209 | } |
| 1210 | |
| 1211 | png_uint_32 PNGAPI |
| 1212 | png_get_user_height_max(png_const_structrp png_ptr) |
| 1213 | { |
| 1214 | return (png_ptr ? png_ptr->user_height_max : 0); |
| 1215 | } |
| 1216 | |
| 1217 | /* This function was added to libpng 1.4.0 */ |
| 1218 | png_uint_32 PNGAPI |
| 1219 | png_get_chunk_cache_max(png_const_structrp png_ptr) |
| 1220 | { |
| 1221 | return (png_ptr ? png_ptr->user_chunk_cache_max : 0); |
| 1222 | } |
| 1223 | |
| 1224 | /* This function was added to libpng 1.4.1 */ |
| 1225 | png_alloc_size_t PNGAPI |
| 1226 | png_get_chunk_malloc_max(png_const_structrp png_ptr) |
| 1227 | { |
| 1228 | return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); |
| 1229 | } |
| 1230 | #endif /* SET_USER_LIMITS */ |
| 1231 | |
| 1232 | /* These functions were added to libpng 1.4.0 */ |
| 1233 | #ifdef PNG_IO_STATE_SUPPORTED |
| 1234 | png_uint_32 PNGAPI |
| 1235 | png_get_io_state(png_const_structrp png_ptr) |
| 1236 | { |
| 1237 | return png_ptr->io_state; |
| 1238 | } |
| 1239 | |
| 1240 | png_uint_32 PNGAPI |
| 1241 | png_get_io_chunk_type(png_const_structrp png_ptr) |
| 1242 | { |
| 1243 | return png_ptr->chunk_name; |
| 1244 | } |
| 1245 | #endif /* IO_STATE */ |
| 1246 | |
| 1247 | #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED |
| 1248 | # ifdef PNG_GET_PALETTE_MAX_SUPPORTED |
| 1249 | int PNGAPI |
| 1250 | png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr) |
| 1251 | { |
| 1252 | if (png_ptr != NULL && info_ptr != NULL) |
| 1253 | return png_ptr->num_palette_max; |
| 1254 | |
| 1255 | return (-1); |
| 1256 | } |
| 1257 | # endif |
| 1258 | #endif |
| 1259 | |
| 1260 | #endif /* READ || WRITE */ |
| 1261 | |