pngset.c revision a0bb96c34e65378853ee518bac502842d26c2d1a
1 2/* pngset.c - storage of image information into info struct 3 * 4 * Last changed in libpng 1.2.38 [July 16, 2009] 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 8 * 9 * This code is released under the libpng license. 10 * For conditions of distribution and use, see the disclaimer 11 * and license in png.h 12 * 13 * The functions here are used during reads to store data from the file 14 * into the info struct, and during writes to store application data 15 * into the info struct for writing into the file. This abstracts the 16 * info struct and allows us to change the structure in the future. 17 */ 18 19#define PNG_INTERNAL 20#include "png.h" 21#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 22 23#if defined(PNG_bKGD_SUPPORTED) 24void PNGAPI 25png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) 26{ 27 png_debug1(1, "in %s storage function", "bKGD"); 28 if (png_ptr == NULL || info_ptr == NULL) 29 return; 30 31 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); 32 info_ptr->valid |= PNG_INFO_bKGD; 33} 34#endif 35 36#if defined(PNG_cHRM_SUPPORTED) 37#ifdef PNG_FLOATING_POINT_SUPPORTED 38void PNGAPI 39png_set_cHRM(png_structp png_ptr, png_infop info_ptr, 40 double white_x, double white_y, double red_x, double red_y, 41 double green_x, double green_y, double blue_x, double blue_y) 42{ 43 png_debug1(1, "in %s storage function", "cHRM"); 44 if (png_ptr == NULL || info_ptr == NULL) 45 return; 46 47 info_ptr->x_white = (float)white_x; 48 info_ptr->y_white = (float)white_y; 49 info_ptr->x_red = (float)red_x; 50 info_ptr->y_red = (float)red_y; 51 info_ptr->x_green = (float)green_x; 52 info_ptr->y_green = (float)green_y; 53 info_ptr->x_blue = (float)blue_x; 54 info_ptr->y_blue = (float)blue_y; 55#ifdef PNG_FIXED_POINT_SUPPORTED 56 info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5); 57 info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5); 58 info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5); 59 info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5); 60 info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5); 61 info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5); 62 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5); 63 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5); 64#endif 65 info_ptr->valid |= PNG_INFO_cHRM; 66} 67#endif /* PNG_FLOATING_POINT_SUPPORTED */ 68 69#ifdef PNG_FIXED_POINT_SUPPORTED 70void PNGAPI 71png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, 72 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, 73 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, 74 png_fixed_point blue_x, png_fixed_point blue_y) 75{ 76 png_debug1(1, "in %s storage function", "cHRM fixed"); 77 if (png_ptr == NULL || info_ptr == NULL) 78 return; 79 80#if !defined(PNG_NO_CHECK_cHRM) 81 if (png_check_cHRM_fixed(png_ptr, 82 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) 83#endif 84 { 85 info_ptr->int_x_white = white_x; 86 info_ptr->int_y_white = white_y; 87 info_ptr->int_x_red = red_x; 88 info_ptr->int_y_red = red_y; 89 info_ptr->int_x_green = green_x; 90 info_ptr->int_y_green = green_y; 91 info_ptr->int_x_blue = blue_x; 92 info_ptr->int_y_blue = blue_y; 93#ifdef PNG_FLOATING_POINT_SUPPORTED 94 info_ptr->x_white = (float)(white_x/100000.); 95 info_ptr->y_white = (float)(white_y/100000.); 96 info_ptr->x_red = (float)( red_x/100000.); 97 info_ptr->y_red = (float)( red_y/100000.); 98 info_ptr->x_green = (float)(green_x/100000.); 99 info_ptr->y_green = (float)(green_y/100000.); 100 info_ptr->x_blue = (float)( blue_x/100000.); 101 info_ptr->y_blue = (float)( blue_y/100000.); 102#endif 103 info_ptr->valid |= PNG_INFO_cHRM; 104 } 105} 106#endif /* PNG_FIXED_POINT_SUPPORTED */ 107#endif /* PNG_cHRM_SUPPORTED */ 108 109#if defined(PNG_gAMA_SUPPORTED) 110#ifdef PNG_FLOATING_POINT_SUPPORTED 111void PNGAPI 112png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) 113{ 114 double png_gamma; 115 png_debug1(1, "in %s storage function", "gAMA"); 116 if (png_ptr == NULL || info_ptr == NULL) 117 return; 118 119 /* Check for overflow */ 120 if (file_gamma > 21474.83) 121 { 122 png_warning(png_ptr, "Limiting gamma to 21474.83"); 123 png_gamma=21474.83; 124 } 125 else 126 png_gamma = file_gamma; 127 info_ptr->gamma = (float)png_gamma; 128#ifdef PNG_FIXED_POINT_SUPPORTED 129 info_ptr->int_gamma = (int)(png_gamma*100000.+.5); 130#endif 131 info_ptr->valid |= PNG_INFO_gAMA; 132 if (png_gamma == 0.0) 133 png_warning(png_ptr, "Setting gamma=0"); 134} 135#endif 136void PNGAPI 137png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point 138 int_gamma) 139{ 140 png_fixed_point png_gamma; 141 142 png_debug1(1, "in %s storage function", "gAMA"); 143 if (png_ptr == NULL || info_ptr == NULL) 144 return; 145 146 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX) 147 { 148 png_warning(png_ptr, "Limiting gamma to 21474.83"); 149 png_gamma=PNG_UINT_31_MAX; 150 } 151 else 152 { 153 if (int_gamma < 0) 154 { 155 png_warning(png_ptr, "Setting negative gamma to zero"); 156 png_gamma = 0; 157 } 158 else 159 png_gamma = int_gamma; 160 } 161#ifdef PNG_FLOATING_POINT_SUPPORTED 162 info_ptr->gamma = (float)(png_gamma/100000.); 163#endif 164#ifdef PNG_FIXED_POINT_SUPPORTED 165 info_ptr->int_gamma = png_gamma; 166#endif 167 info_ptr->valid |= PNG_INFO_gAMA; 168 if (png_gamma == 0) 169 png_warning(png_ptr, "Setting gamma=0"); 170} 171#endif 172 173#if defined(PNG_hIST_SUPPORTED) 174void PNGAPI 175png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) 176{ 177 int i; 178 179 png_debug1(1, "in %s storage function", "hIST"); 180 if (png_ptr == NULL || info_ptr == NULL) 181 return; 182 if (info_ptr->num_palette == 0 || info_ptr->num_palette 183 > PNG_MAX_PALETTE_LENGTH) 184 { 185 png_warning(png_ptr, 186 "Invalid palette size, hIST allocation skipped."); 187 return; 188 } 189 190#ifdef PNG_FREE_ME_SUPPORTED 191 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); 192#endif 193 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in 194 * version 1.2.1 195 */ 196 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, 197 (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16))); 198 if (png_ptr->hist == NULL) 199 { 200 png_warning(png_ptr, "Insufficient memory for hIST chunk data."); 201 return; 202 } 203 204 for (i = 0; i < info_ptr->num_palette; i++) 205 png_ptr->hist[i] = hist[i]; 206 info_ptr->hist = png_ptr->hist; 207 info_ptr->valid |= PNG_INFO_hIST; 208 209#ifdef PNG_FREE_ME_SUPPORTED 210 info_ptr->free_me |= PNG_FREE_HIST; 211#else 212 png_ptr->flags |= PNG_FLAG_FREE_HIST; 213#endif 214} 215#endif 216 217void PNGAPI 218png_set_IHDR(png_structp png_ptr, png_infop info_ptr, 219 png_uint_32 width, png_uint_32 height, int bit_depth, 220 int color_type, int interlace_type, int compression_type, 221 int filter_type) 222{ 223 png_debug1(1, "in %s storage function", "IHDR"); 224 if (png_ptr == NULL || info_ptr == NULL) 225 return; 226 227 /* Check for width and height valid values */ 228 if (width == 0 || height == 0) 229 png_error(png_ptr, "Image width or height is zero in IHDR"); 230#ifdef PNG_SET_USER_LIMITS_SUPPORTED 231 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max) 232 png_error(png_ptr, "image size exceeds user limits in IHDR"); 233#else 234 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX) 235 png_error(png_ptr, "image size exceeds user limits in IHDR"); 236#endif 237 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX) 238 png_error(png_ptr, "Invalid image size in IHDR"); 239 if ( width > (PNG_UINT_32_MAX 240 >> 3) /* 8-byte RGBA pixels */ 241 - 64 /* bigrowbuf hack */ 242 - 1 /* filter byte */ 243 - 7*8 /* rounding of width to multiple of 8 pixels */ 244 - 8) /* extra max_pixel_depth pad */ 245 png_warning(png_ptr, "Width is too large for libpng to process pixels"); 246 247 /* Check other values */ 248 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && 249 bit_depth != 8 && bit_depth != 16) 250 png_error(png_ptr, "Invalid bit depth in IHDR"); 251 252 if (color_type < 0 || color_type == 1 || 253 color_type == 5 || color_type > 6) 254 png_error(png_ptr, "Invalid color type in IHDR"); 255 256 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || 257 ((color_type == PNG_COLOR_TYPE_RGB || 258 color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 259 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) 260 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); 261 262 if (interlace_type >= PNG_INTERLACE_LAST) 263 png_error(png_ptr, "Unknown interlace method in IHDR"); 264 265 if (compression_type != PNG_COMPRESSION_TYPE_BASE) 266 png_error(png_ptr, "Unknown compression method in IHDR"); 267 268#if defined(PNG_MNG_FEATURES_SUPPORTED) 269 /* Accept filter_method 64 (intrapixel differencing) only if 270 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 271 * 2. Libpng did not read a PNG signature (this filter_method is only 272 * used in PNG datastreams that are embedded in MNG datastreams) and 273 * 3. The application called png_permit_mng_features with a mask that 274 * included PNG_FLAG_MNG_FILTER_64 and 275 * 4. The filter_method is 64 and 276 * 5. The color_type is RGB or RGBA 277 */ 278 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) 279 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 280 if (filter_type != PNG_FILTER_TYPE_BASE) 281 { 282 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 283 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && 284 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && 285 (color_type == PNG_COLOR_TYPE_RGB || 286 color_type == PNG_COLOR_TYPE_RGB_ALPHA))) 287 png_error(png_ptr, "Unknown filter method in IHDR"); 288 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) 289 png_warning(png_ptr, "Invalid filter method in IHDR"); 290 } 291#else 292 if (filter_type != PNG_FILTER_TYPE_BASE) 293 png_error(png_ptr, "Unknown filter method in IHDR"); 294#endif 295 296 info_ptr->width = width; 297 info_ptr->height = height; 298 info_ptr->bit_depth = (png_byte)bit_depth; 299 info_ptr->color_type =(png_byte) color_type; 300 info_ptr->compression_type = (png_byte)compression_type; 301 info_ptr->filter_type = (png_byte)filter_type; 302 info_ptr->interlace_type = (png_byte)interlace_type; 303 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 304 info_ptr->channels = 1; 305 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) 306 info_ptr->channels = 3; 307 else 308 info_ptr->channels = 1; 309 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) 310 info_ptr->channels++; 311 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); 312 313 /* Check for potential overflow */ 314 if (width > (PNG_UINT_32_MAX 315 >> 3) /* 8-byte RGBA pixels */ 316 - 64 /* bigrowbuf hack */ 317 - 1 /* filter byte */ 318 - 7*8 /* rounding of width to multiple of 8 pixels */ 319 - 8) /* extra max_pixel_depth pad */ 320 info_ptr->rowbytes = (png_size_t)0; 321 else 322 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); 323} 324 325#if defined(PNG_oFFs_SUPPORTED) 326void PNGAPI 327png_set_oFFs(png_structp png_ptr, png_infop info_ptr, 328 png_int_32 offset_x, png_int_32 offset_y, int unit_type) 329{ 330 png_debug1(1, "in %s storage function", "oFFs"); 331 if (png_ptr == NULL || info_ptr == NULL) 332 return; 333 334 info_ptr->x_offset = offset_x; 335 info_ptr->y_offset = offset_y; 336 info_ptr->offset_unit_type = (png_byte)unit_type; 337 info_ptr->valid |= PNG_INFO_oFFs; 338} 339#endif 340 341#if defined(PNG_pCAL_SUPPORTED) 342void PNGAPI 343png_set_pCAL(png_structp png_ptr, png_infop info_ptr, 344 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, 345 png_charp units, png_charpp params) 346{ 347 png_uint_32 length; 348 int i; 349 350 png_debug1(1, "in %s storage function", "pCAL"); 351 if (png_ptr == NULL || info_ptr == NULL) 352 return; 353 354 length = png_strlen(purpose) + 1; 355 png_debug1(3, "allocating purpose for info (%lu bytes)", 356 (unsigned long)length); 357 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); 358 if (info_ptr->pcal_purpose == NULL) 359 { 360 png_warning(png_ptr, "Insufficient memory for pCAL purpose."); 361 return; 362 } 363 png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); 364 365 png_debug(3, "storing X0, X1, type, and nparams in info"); 366 info_ptr->pcal_X0 = X0; 367 info_ptr->pcal_X1 = X1; 368 info_ptr->pcal_type = (png_byte)type; 369 info_ptr->pcal_nparams = (png_byte)nparams; 370 371 length = png_strlen(units) + 1; 372 png_debug1(3, "allocating units for info (%lu bytes)", 373 (unsigned long)length); 374 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); 375 if (info_ptr->pcal_units == NULL) 376 { 377 png_warning(png_ptr, "Insufficient memory for pCAL units."); 378 return; 379 } 380 png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); 381 382 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, 383 (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); 384 if (info_ptr->pcal_params == NULL) 385 { 386 png_warning(png_ptr, "Insufficient memory for pCAL params."); 387 return; 388 } 389 390 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); 391 392 for (i = 0; i < nparams; i++) 393 { 394 length = png_strlen(params[i]) + 1; 395 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, 396 (unsigned long)length); 397 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); 398 if (info_ptr->pcal_params[i] == NULL) 399 { 400 png_warning(png_ptr, "Insufficient memory for pCAL parameter."); 401 return; 402 } 403 png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); 404 } 405 406 info_ptr->valid |= PNG_INFO_pCAL; 407#ifdef PNG_FREE_ME_SUPPORTED 408 info_ptr->free_me |= PNG_FREE_PCAL; 409#endif 410} 411#endif 412 413#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) 414#ifdef PNG_FLOATING_POINT_SUPPORTED 415void PNGAPI 416png_set_sCAL(png_structp png_ptr, png_infop info_ptr, 417 int unit, double width, double height) 418{ 419 png_debug1(1, "in %s storage function", "sCAL"); 420 if (png_ptr == NULL || info_ptr == NULL) 421 return; 422 423 info_ptr->scal_unit = (png_byte)unit; 424 info_ptr->scal_pixel_width = width; 425 info_ptr->scal_pixel_height = height; 426 427 info_ptr->valid |= PNG_INFO_sCAL; 428} 429#else 430#ifdef PNG_FIXED_POINT_SUPPORTED 431void PNGAPI 432png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, 433 int unit, png_charp swidth, png_charp sheight) 434{ 435 png_uint_32 length; 436 437 png_debug1(1, "in %s storage function", "sCAL"); 438 if (png_ptr == NULL || info_ptr == NULL) 439 return; 440 441 info_ptr->scal_unit = (png_byte)unit; 442 443 length = png_strlen(swidth) + 1; 444 png_debug1(3, "allocating unit for info (%u bytes)", 445 (unsigned int)length); 446 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length); 447 if (info_ptr->scal_s_width == NULL) 448 { 449 png_warning(png_ptr, 450 "Memory allocation failed while processing sCAL."); 451 return; 452 } 453 png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); 454 455 length = png_strlen(sheight) + 1; 456 png_debug1(3, "allocating unit for info (%u bytes)", 457 (unsigned int)length); 458 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length); 459 if (info_ptr->scal_s_height == NULL) 460 { 461 png_free (png_ptr, info_ptr->scal_s_width); 462 info_ptr->scal_s_width = NULL; 463 png_warning(png_ptr, 464 "Memory allocation failed while processing sCAL."); 465 return; 466 } 467 png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); 468 info_ptr->valid |= PNG_INFO_sCAL; 469#ifdef PNG_FREE_ME_SUPPORTED 470 info_ptr->free_me |= PNG_FREE_SCAL; 471#endif 472} 473#endif 474#endif 475#endif 476 477#if defined(PNG_pHYs_SUPPORTED) 478void PNGAPI 479png_set_pHYs(png_structp png_ptr, png_infop info_ptr, 480 png_uint_32 res_x, png_uint_32 res_y, int unit_type) 481{ 482 png_debug1(1, "in %s storage function", "pHYs"); 483 if (png_ptr == NULL || info_ptr == NULL) 484 return; 485 486 info_ptr->x_pixels_per_unit = res_x; 487 info_ptr->y_pixels_per_unit = res_y; 488 info_ptr->phys_unit_type = (png_byte)unit_type; 489 info_ptr->valid |= PNG_INFO_pHYs; 490} 491#endif 492 493void PNGAPI 494png_set_PLTE(png_structp png_ptr, png_infop info_ptr, 495 png_colorp palette, int num_palette) 496{ 497 498 png_debug1(1, "in %s storage function", "PLTE"); 499 if (png_ptr == NULL || info_ptr == NULL) 500 return; 501 502 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) 503 { 504 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 505 png_error(png_ptr, "Invalid palette length"); 506 else 507 { 508 png_warning(png_ptr, "Invalid palette length"); 509 return; 510 } 511 } 512 513 /* 514 * It may not actually be necessary to set png_ptr->palette here; 515 * we do it for backward compatibility with the way the png_handle_tRNS 516 * function used to do the allocation. 517 */ 518#ifdef PNG_FREE_ME_SUPPORTED 519 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); 520#endif 521 522 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead 523 * of num_palette entries, in case of an invalid PNG file that has 524 * too-large sample values. 525 */ 526 png_ptr->palette = (png_colorp)png_malloc(png_ptr, 527 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); 528 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH * 529 png_sizeof(png_color)); 530 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); 531 info_ptr->palette = png_ptr->palette; 532 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; 533 534#ifdef PNG_FREE_ME_SUPPORTED 535 info_ptr->free_me |= PNG_FREE_PLTE; 536#else 537 png_ptr->flags |= PNG_FLAG_FREE_PLTE; 538#endif 539 540 info_ptr->valid |= PNG_INFO_PLTE; 541} 542 543#if defined(PNG_sBIT_SUPPORTED) 544void PNGAPI 545png_set_sBIT(png_structp png_ptr, png_infop info_ptr, 546 png_color_8p sig_bit) 547{ 548 png_debug1(1, "in %s storage function", "sBIT"); 549 if (png_ptr == NULL || info_ptr == NULL) 550 return; 551 552 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); 553 info_ptr->valid |= PNG_INFO_sBIT; 554} 555#endif 556 557#if defined(PNG_sRGB_SUPPORTED) 558void PNGAPI 559png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) 560{ 561 png_debug1(1, "in %s storage function", "sRGB"); 562 if (png_ptr == NULL || info_ptr == NULL) 563 return; 564 565 info_ptr->srgb_intent = (png_byte)intent; 566 info_ptr->valid |= PNG_INFO_sRGB; 567} 568 569void PNGAPI 570png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, 571 int intent) 572{ 573#if defined(PNG_gAMA_SUPPORTED) 574#ifdef PNG_FLOATING_POINT_SUPPORTED 575 float file_gamma; 576#endif 577#ifdef PNG_FIXED_POINT_SUPPORTED 578 png_fixed_point int_file_gamma; 579#endif 580#endif 581#if defined(PNG_cHRM_SUPPORTED) 582#ifdef PNG_FLOATING_POINT_SUPPORTED 583 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; 584#endif 585 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 586 int_green_y, int_blue_x, int_blue_y; 587#endif 588 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); 589 if (png_ptr == NULL || info_ptr == NULL) 590 return; 591 592 png_set_sRGB(png_ptr, info_ptr, intent); 593 594#if defined(PNG_gAMA_SUPPORTED) 595#ifdef PNG_FLOATING_POINT_SUPPORTED 596 file_gamma = (float).45455; 597 png_set_gAMA(png_ptr, info_ptr, file_gamma); 598#endif 599#ifdef PNG_FIXED_POINT_SUPPORTED 600 int_file_gamma = 45455L; 601 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); 602#endif 603#endif 604 605#if defined(PNG_cHRM_SUPPORTED) 606 int_white_x = 31270L; 607 int_white_y = 32900L; 608 int_red_x = 64000L; 609 int_red_y = 33000L; 610 int_green_x = 30000L; 611 int_green_y = 60000L; 612 int_blue_x = 15000L; 613 int_blue_y = 6000L; 614 615#ifdef PNG_FLOATING_POINT_SUPPORTED 616 white_x = (float).3127; 617 white_y = (float).3290; 618 red_x = (float).64; 619 red_y = (float).33; 620 green_x = (float).30; 621 green_y = (float).60; 622 blue_x = (float).15; 623 blue_y = (float).06; 624#endif 625 626#if !defined(PNG_NO_CHECK_cHRM) 627 if (png_check_cHRM_fixed(png_ptr, 628 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 629 int_green_y, int_blue_x, int_blue_y)) 630#endif 631 { 632#ifdef PNG_FIXED_POINT_SUPPORTED 633 png_set_cHRM_fixed(png_ptr, info_ptr, 634 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 635 int_green_y, int_blue_x, int_blue_y); 636#endif 637#ifdef PNG_FLOATING_POINT_SUPPORTED 638 png_set_cHRM(png_ptr, info_ptr, 639 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 640#endif 641 } 642#endif /* cHRM */ 643} 644#endif /* sRGB */ 645 646 647#if defined(PNG_iCCP_SUPPORTED) 648void PNGAPI 649png_set_iCCP(png_structp png_ptr, png_infop info_ptr, 650 png_charp name, int compression_type, 651 png_charp profile, png_uint_32 proflen) 652{ 653 png_charp new_iccp_name; 654 png_charp new_iccp_profile; 655 png_uint_32 length; 656 657 png_debug1(1, "in %s storage function", "iCCP"); 658 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) 659 return; 660 661 length = png_strlen(name)+1; 662 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); 663 if (new_iccp_name == NULL) 664 { 665 png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); 666 return; 667 } 668 png_memcpy(new_iccp_name, name, length); 669 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen); 670 if (new_iccp_profile == NULL) 671 { 672 png_free (png_ptr, new_iccp_name); 673 png_warning(png_ptr, 674 "Insufficient memory to process iCCP profile."); 675 return; 676 } 677 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); 678 679 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); 680 681 info_ptr->iccp_proflen = proflen; 682 info_ptr->iccp_name = new_iccp_name; 683 info_ptr->iccp_profile = new_iccp_profile; 684 /* Compression is always zero but is here so the API and info structure 685 * does not have to change if we introduce multiple compression types */ 686 info_ptr->iccp_compression = (png_byte)compression_type; 687#ifdef PNG_FREE_ME_SUPPORTED 688 info_ptr->free_me |= PNG_FREE_ICCP; 689#endif 690 info_ptr->valid |= PNG_INFO_iCCP; 691} 692#endif 693 694#if defined(PNG_TEXT_SUPPORTED) 695void PNGAPI 696png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, 697 int num_text) 698{ 699 int ret; 700 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); 701 if (ret) 702 png_error(png_ptr, "Insufficient memory to store text"); 703} 704 705int /* PRIVATE */ 706png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, 707 int num_text) 708{ 709 int i; 710 711 png_debug1(1, "in %s storage function", (png_ptr->chunk_name[0] == '\0' ? 712 "text" : (png_const_charp)png_ptr->chunk_name)); 713 714 if (png_ptr == NULL || info_ptr == NULL || num_text == 0) 715 return(0); 716 717 /* Make sure we have enough space in the "text" array in info_struct 718 * to hold all of the incoming text_ptr objects. 719 */ 720 if (info_ptr->num_text + num_text > info_ptr->max_text) 721 { 722 if (info_ptr->text != NULL) 723 { 724 png_textp old_text; 725 int old_max; 726 727 old_max = info_ptr->max_text; 728 info_ptr->max_text = info_ptr->num_text + num_text + 8; 729 old_text = info_ptr->text; 730 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, 731 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); 732 if (info_ptr->text == NULL) 733 { 734 png_free(png_ptr, old_text); 735 return(1); 736 } 737 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * 738 png_sizeof(png_text))); 739 png_free(png_ptr, old_text); 740 } 741 else 742 { 743 info_ptr->max_text = num_text + 8; 744 info_ptr->num_text = 0; 745 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, 746 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); 747 if (info_ptr->text == NULL) 748 return(1); 749#ifdef PNG_FREE_ME_SUPPORTED 750 info_ptr->free_me |= PNG_FREE_TEXT; 751#endif 752 } 753 png_debug1(3, "allocated %d entries for info_ptr->text", 754 info_ptr->max_text); 755 } 756 for (i = 0; i < num_text; i++) 757 { 758 png_size_t text_length, key_len; 759 png_size_t lang_len, lang_key_len; 760 png_textp textp = &(info_ptr->text[info_ptr->num_text]); 761 762 if (text_ptr[i].key == NULL) 763 continue; 764 765 key_len = png_strlen(text_ptr[i].key); 766 767 if (text_ptr[i].compression <= 0) 768 { 769 lang_len = 0; 770 lang_key_len = 0; 771 } 772 else 773#ifdef PNG_iTXt_SUPPORTED 774 { 775 /* Set iTXt data */ 776 if (text_ptr[i].lang != NULL) 777 lang_len = png_strlen(text_ptr[i].lang); 778 else 779 lang_len = 0; 780 if (text_ptr[i].lang_key != NULL) 781 lang_key_len = png_strlen(text_ptr[i].lang_key); 782 else 783 lang_key_len = 0; 784 } 785#else 786 { 787 png_warning(png_ptr, "iTXt chunk not supported."); 788 continue; 789 } 790#endif 791 792 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') 793 { 794 text_length = 0; 795#ifdef PNG_iTXt_SUPPORTED 796 if (text_ptr[i].compression > 0) 797 textp->compression = PNG_ITXT_COMPRESSION_NONE; 798 else 799#endif 800 textp->compression = PNG_TEXT_COMPRESSION_NONE; 801 } 802 else 803 { 804 text_length = png_strlen(text_ptr[i].text); 805 textp->compression = text_ptr[i].compression; 806 } 807 808 textp->key = (png_charp)png_malloc_warn(png_ptr, 809 (png_uint_32) 810 (key_len + text_length + lang_len + lang_key_len + 4)); 811 if (textp->key == NULL) 812 return(1); 813 png_debug2(2, "Allocated %lu bytes at %x in png_set_text", 814 (png_uint_32) 815 (key_len + lang_len + lang_key_len + text_length + 4), 816 (int)textp->key); 817 818 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len)); 819 *(textp->key + key_len) = '\0'; 820#ifdef PNG_iTXt_SUPPORTED 821 if (text_ptr[i].compression > 0) 822 { 823 textp->lang = textp->key + key_len + 1; 824 png_memcpy(textp->lang, text_ptr[i].lang, lang_len); 825 *(textp->lang + lang_len) = '\0'; 826 textp->lang_key = textp->lang + lang_len + 1; 827 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); 828 *(textp->lang_key + lang_key_len) = '\0'; 829 textp->text = textp->lang_key + lang_key_len + 1; 830 } 831 else 832#endif 833 { 834#ifdef PNG_iTXt_SUPPORTED 835 textp->lang=NULL; 836 textp->lang_key=NULL; 837#endif 838 textp->text = textp->key + key_len + 1; 839 } 840 if (text_length) 841 png_memcpy(textp->text, text_ptr[i].text, 842 (png_size_t)(text_length)); 843 *(textp->text + text_length) = '\0'; 844 845#ifdef PNG_iTXt_SUPPORTED 846 if (textp->compression > 0) 847 { 848 textp->text_length = 0; 849 textp->itxt_length = text_length; 850 } 851 else 852#endif 853 { 854 textp->text_length = text_length; 855#ifdef PNG_iTXt_SUPPORTED 856 textp->itxt_length = 0; 857#endif 858 } 859 info_ptr->num_text++; 860 png_debug1(3, "transferred text chunk %d", info_ptr->num_text); 861 } 862 return(0); 863} 864#endif 865 866#if defined(PNG_tIME_SUPPORTED) 867void PNGAPI 868png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) 869{ 870 png_debug1(1, "in %s storage function", "tIME"); 871 if (png_ptr == NULL || info_ptr == NULL || 872 (png_ptr->mode & PNG_WROTE_tIME)) 873 return; 874 875 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); 876 info_ptr->valid |= PNG_INFO_tIME; 877} 878#endif 879 880#if defined(PNG_tRNS_SUPPORTED) 881void PNGAPI 882png_set_tRNS(png_structp png_ptr, png_infop info_ptr, 883 png_bytep trans, int num_trans, png_color_16p trans_values) 884{ 885 png_debug1(1, "in %s storage function", "tRNS"); 886 if (png_ptr == NULL || info_ptr == NULL) 887 return; 888 889 if (trans != NULL) 890 { 891 /* 892 * It may not actually be necessary to set png_ptr->trans here; 893 * we do it for backward compatibility with the way the png_handle_tRNS 894 * function used to do the allocation. 895 */ 896 897#ifdef PNG_FREE_ME_SUPPORTED 898 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); 899#endif 900 901 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ 902 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, 903 (png_uint_32)PNG_MAX_PALETTE_LENGTH); 904 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) 905 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); 906 } 907 908 if (trans_values != NULL) 909 { 910 int sample_max = (1 << info_ptr->bit_depth); 911 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && 912 (int)trans_values->gray > sample_max) || 913 (info_ptr->color_type == PNG_COLOR_TYPE_RGB && 914 ((int)trans_values->red > sample_max || 915 (int)trans_values->green > sample_max || 916 (int)trans_values->blue > sample_max))) 917 png_warning(png_ptr, 918 "tRNS chunk has out-of-range samples for bit_depth"); 919 png_memcpy(&(info_ptr->trans_values), trans_values, 920 png_sizeof(png_color_16)); 921 if (num_trans == 0) 922 num_trans = 1; 923 } 924 925 info_ptr->num_trans = (png_uint_16)num_trans; 926 if (num_trans != 0) 927 { 928 info_ptr->valid |= PNG_INFO_tRNS; 929#ifdef PNG_FREE_ME_SUPPORTED 930 info_ptr->free_me |= PNG_FREE_TRNS; 931#else 932 png_ptr->flags |= PNG_FLAG_FREE_TRNS; 933#endif 934 } 935} 936#endif 937 938#if defined(PNG_sPLT_SUPPORTED) 939void PNGAPI 940png_set_sPLT(png_structp png_ptr, 941 png_infop info_ptr, png_sPLT_tp entries, int nentries) 942/* 943 * entries - array of png_sPLT_t structures 944 * to be added to the list of palettes 945 * in the info structure. 946 * nentries - number of palette structures to be 947 * added. 948 */ 949{ 950 png_sPLT_tp np; 951 int i; 952 953 if (png_ptr == NULL || info_ptr == NULL) 954 return; 955 956 np = (png_sPLT_tp)png_malloc_warn(png_ptr, 957 (info_ptr->splt_palettes_num + nentries) * 958 (png_uint_32)png_sizeof(png_sPLT_t)); 959 if (np == NULL) 960 { 961 png_warning(png_ptr, "No memory for sPLT palettes."); 962 return; 963 } 964 965 png_memcpy(np, info_ptr->splt_palettes, 966 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); 967 png_free(png_ptr, info_ptr->splt_palettes); 968 info_ptr->splt_palettes=NULL; 969 970 for (i = 0; i < nentries; i++) 971 { 972 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; 973 png_sPLT_tp from = entries + i; 974 png_uint_32 length; 975 976 length = png_strlen(from->name) + 1; 977 to->name = (png_charp)png_malloc_warn(png_ptr, length); 978 if (to->name == NULL) 979 { 980 png_warning(png_ptr, 981 "Out of memory while processing sPLT chunk"); 982 continue; 983 } 984 png_memcpy(to->name, from->name, length); 985 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, 986 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); 987 if (to->entries == NULL) 988 { 989 png_warning(png_ptr, 990 "Out of memory while processing sPLT chunk"); 991 png_free(png_ptr, to->name); 992 to->name = NULL; 993 continue; 994 } 995 png_memcpy(to->entries, from->entries, 996 from->nentries * png_sizeof(png_sPLT_entry)); 997 to->nentries = from->nentries; 998 to->depth = from->depth; 999 } 1000 1001 info_ptr->splt_palettes = np; 1002 info_ptr->splt_palettes_num += nentries; 1003 info_ptr->valid |= PNG_INFO_sPLT; 1004#ifdef PNG_FREE_ME_SUPPORTED 1005 info_ptr->free_me |= PNG_FREE_SPLT; 1006#endif 1007} 1008#endif /* PNG_sPLT_SUPPORTED */ 1009 1010#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 1011void PNGAPI 1012png_set_unknown_chunks(png_structp png_ptr, 1013 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) 1014{ 1015 png_unknown_chunkp np; 1016 int i; 1017 1018 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) 1019 return; 1020 1021 np = (png_unknown_chunkp)png_malloc_warn(png_ptr, 1022 (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * 1023 png_sizeof(png_unknown_chunk))); 1024 if (np == NULL) 1025 { 1026 png_warning(png_ptr, 1027 "Out of memory while processing unknown chunk."); 1028 return; 1029 } 1030 1031 png_memcpy(np, info_ptr->unknown_chunks, 1032 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); 1033 png_free(png_ptr, info_ptr->unknown_chunks); 1034 info_ptr->unknown_chunks=NULL; 1035 1036 for (i = 0; i < num_unknowns; i++) 1037 { 1038 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; 1039 png_unknown_chunkp from = unknowns + i; 1040 1041 png_memcpy((png_charp)to->name, 1042 (png_charp)from->name, 1043 png_sizeof(from->name)); 1044 to->name[png_sizeof(to->name)-1] = '\0'; 1045 to->size = from->size; 1046 /* Note our location in the read or write sequence */ 1047 to->location = (png_byte)(png_ptr->mode & 0xff); 1048 1049 if (from->size == 0) 1050 to->data=NULL; 1051 else 1052 { 1053 to->data = (png_bytep)png_malloc_warn(png_ptr, 1054 (png_uint_32)from->size); 1055 if (to->data == NULL) 1056 { 1057 png_warning(png_ptr, 1058 "Out of memory while processing unknown chunk."); 1059 to->size = 0; 1060 } 1061 else 1062 png_memcpy(to->data, from->data, from->size); 1063 } 1064 } 1065 1066 info_ptr->unknown_chunks = np; 1067 info_ptr->unknown_chunks_num += num_unknowns; 1068#ifdef PNG_FREE_ME_SUPPORTED 1069 info_ptr->free_me |= PNG_FREE_UNKN; 1070#endif 1071} 1072void PNGAPI 1073png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, 1074 int chunk, int location) 1075{ 1076 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < 1077 (int)info_ptr->unknown_chunks_num) 1078 info_ptr->unknown_chunks[chunk].location = (png_byte)location; 1079} 1080#endif 1081 1082#if defined(PNG_1_0_X) || defined(PNG_1_2_X) 1083#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ 1084 defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) 1085void PNGAPI 1086png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) 1087{ 1088 /* This function is deprecated in favor of png_permit_mng_features() 1089 and will be removed from libpng-1.3.0 */ 1090 png_debug(1, "in png_permit_empty_plte, DEPRECATED."); 1091 if (png_ptr == NULL) 1092 return; 1093 png_ptr->mng_features_permitted = (png_byte) 1094 ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) | 1095 ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); 1096} 1097#endif 1098#endif 1099 1100#if defined(PNG_MNG_FEATURES_SUPPORTED) 1101png_uint_32 PNGAPI 1102png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) 1103{ 1104 png_debug(1, "in png_permit_mng_features"); 1105 if (png_ptr == NULL) 1106 return (png_uint_32)0; 1107 png_ptr->mng_features_permitted = 1108 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); 1109 return (png_uint_32)png_ptr->mng_features_permitted; 1110} 1111#endif 1112 1113#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 1114void PNGAPI 1115png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep 1116 chunk_list, int num_chunks) 1117{ 1118 png_bytep new_list, p; 1119 int i, old_num_chunks; 1120 if (png_ptr == NULL) 1121 return; 1122 if (num_chunks == 0) 1123 { 1124 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) 1125 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; 1126 else 1127 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; 1128 1129 if (keep == PNG_HANDLE_CHUNK_ALWAYS) 1130 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; 1131 else 1132 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; 1133 return; 1134 } 1135 if (chunk_list == NULL) 1136 return; 1137 old_num_chunks = png_ptr->num_chunk_list; 1138 new_list=(png_bytep)png_malloc(png_ptr, 1139 (png_uint_32) 1140 (5*(num_chunks + old_num_chunks))); 1141 if (png_ptr->chunk_list != NULL) 1142 { 1143 png_memcpy(new_list, png_ptr->chunk_list, 1144 (png_size_t)(5*old_num_chunks)); 1145 png_free(png_ptr, png_ptr->chunk_list); 1146 png_ptr->chunk_list=NULL; 1147 } 1148 png_memcpy(new_list + 5*old_num_chunks, chunk_list, 1149 (png_size_t)(5*num_chunks)); 1150 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5) 1151 *p=(png_byte)keep; 1152 png_ptr->num_chunk_list = old_num_chunks + num_chunks; 1153 png_ptr->chunk_list = new_list; 1154#ifdef PNG_FREE_ME_SUPPORTED 1155 png_ptr->free_me |= PNG_FREE_LIST; 1156#endif 1157} 1158#endif 1159 1160#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 1161void PNGAPI 1162png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, 1163 png_user_chunk_ptr read_user_chunk_fn) 1164{ 1165 png_debug(1, "in png_set_read_user_chunk_fn"); 1166 if (png_ptr == NULL) 1167 return; 1168 png_ptr->read_user_chunk_fn = read_user_chunk_fn; 1169 png_ptr->user_chunk_ptr = user_chunk_ptr; 1170} 1171#endif 1172 1173#if defined(PNG_INFO_IMAGE_SUPPORTED) 1174void PNGAPI 1175png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) 1176{ 1177 png_debug1(1, "in %s storage function", "rows"); 1178 1179 if (png_ptr == NULL || info_ptr == NULL) 1180 return; 1181 1182 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) 1183 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); 1184 info_ptr->row_pointers = row_pointers; 1185 if (row_pointers) 1186 info_ptr->valid |= PNG_INFO_IDAT; 1187} 1188#endif 1189 1190#ifdef PNG_WRITE_SUPPORTED 1191void PNGAPI 1192png_set_compression_buffer_size(png_structp png_ptr, 1193 png_uint_32 size) 1194{ 1195 if (png_ptr == NULL) 1196 return; 1197 png_free(png_ptr, png_ptr->zbuf); 1198 png_ptr->zbuf_size = (png_size_t)size; 1199 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); 1200 png_ptr->zstream.next_out = png_ptr->zbuf; 1201 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 1202} 1203#endif 1204 1205void PNGAPI 1206png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) 1207{ 1208 if (png_ptr && info_ptr) 1209 info_ptr->valid &= ~mask; 1210} 1211 1212 1213#ifndef PNG_1_0_X 1214#ifdef PNG_ASSEMBLER_CODE_SUPPORTED 1215/* Function was added to libpng 1.2.0 and should always exist by default */ 1216void PNGAPI 1217png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) 1218{ 1219/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ 1220 if (png_ptr != NULL) 1221 png_ptr->asm_flags = 0; 1222 asm_flags = asm_flags; /* Quiet the compiler */ 1223} 1224 1225/* This function was added to libpng 1.2.0 */ 1226void PNGAPI 1227png_set_mmx_thresholds (png_structp png_ptr, 1228 png_byte mmx_bitdepth_threshold, 1229 png_uint_32 mmx_rowbytes_threshold) 1230{ 1231/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ 1232 if (png_ptr == NULL) 1233 return; 1234 /* Quiet the compiler */ 1235 mmx_bitdepth_threshold = mmx_bitdepth_threshold; 1236 mmx_rowbytes_threshold = mmx_rowbytes_threshold; 1237} 1238#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ 1239 1240#ifdef PNG_SET_USER_LIMITS_SUPPORTED 1241/* This function was added to libpng 1.2.6 */ 1242void PNGAPI 1243png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, 1244 png_uint_32 user_height_max) 1245{ 1246 /* Images with dimensions larger than these limits will be 1247 * rejected by png_set_IHDR(). To accept any PNG datastream 1248 * regardless of dimensions, set both limits to 0x7ffffffL. 1249 */ 1250 if (png_ptr == NULL) 1251 return; 1252 png_ptr->user_width_max = user_width_max; 1253 png_ptr->user_height_max = user_height_max; 1254} 1255#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 1256 1257#endif /* ?PNG_1_0_X */ 1258#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ 1259