media/libpng/pngget.c

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial