Changeset 43 for vendor/libpng/pngwrite.c
- Timestamp:
- 02/15/10 11:37:15 (2 years ago)
- Files:
-
- 1 modified
-
vendor/libpng/pngwrite.c (modified) (85 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/libpng/pngwrite.c
r11 r43 2 2 /* pngwrite.c - general routines to write a PNG file 3 3 * 4 * Last changed in libpng 1.2. 37 [June 4, 2009]5 * Copyright (c) 1998-20 09Glenn Randers-Pehrson4 * Last changed in libpng 1.2.42 [January 3, 2010] 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson 6 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) … … 14 14 /* Get internal access to png.h */ 15 15 #define PNG_INTERNAL 16 #define PNG_NO_PEDANTIC_WARNINGS 16 17 #include "png.h" 17 18 #ifdef PNG_WRITE_SUPPORTED … … 30 31 { 31 32 png_debug(1, "in png_write_info_before_PLTE"); 33 32 34 if (png_ptr == NULL || info_ptr == NULL) 33 35 return; 34 36 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) 35 37 { 36 png_write_sig(png_ptr); /* Write PNG signature */ 37 #if defined(PNG_MNG_FEATURES_SUPPORTED) 38 /* Write PNG signature */ 39 png_write_sig(png_ptr); 40 #ifdef PNG_MNG_FEATURES_SUPPORTED 38 41 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) 39 42 { 40 43 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 41 png_ptr->mng_features_permitted =0;44 png_ptr->mng_features_permitted = 0; 42 45 } 43 46 #endif … … 46 49 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, 47 50 info_ptr->filter_type, 48 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)51 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 49 52 info_ptr->interlace_type); 50 53 #else … … 54 57 * flag set, and if it does, writes the chunk. 55 58 */ 56 #if defined(PNG_WRITE_gAMA_SUPPORTED)59 #ifdef PNG_WRITE_gAMA_SUPPORTED 57 60 if (info_ptr->valid & PNG_INFO_gAMA) 58 61 { … … 66 69 } 67 70 #endif 68 #if defined(PNG_WRITE_sRGB_SUPPORTED)71 #ifdef PNG_WRITE_sRGB_SUPPORTED 69 72 if (info_ptr->valid & PNG_INFO_sRGB) 70 73 png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); 71 74 #endif 72 #if defined(PNG_WRITE_iCCP_SUPPORTED)75 #ifdef PNG_WRITE_iCCP_SUPPORTED 73 76 if (info_ptr->valid & PNG_INFO_iCCP) 74 77 png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, 75 78 info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); 76 79 #endif 77 #if defined(PNG_WRITE_sBIT_SUPPORTED)80 #ifdef PNG_WRITE_sBIT_SUPPORTED 78 81 if (info_ptr->valid & PNG_INFO_sBIT) 79 82 png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); 80 83 #endif 81 #if defined(PNG_WRITE_cHRM_SUPPORTED)84 #ifdef PNG_WRITE_cHRM_SUPPORTED 82 85 if (info_ptr->valid & PNG_INFO_cHRM) 83 86 { … … 99 102 } 100 103 #endif 101 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)104 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED 102 105 if (info_ptr->unknown_chunks_num) 103 106 { … … 110 113 up++) 111 114 { 112 int keep =png_handle_as_unknown(png_ptr, up->name);115 int keep = png_handle_as_unknown(png_ptr, up->name); 113 116 if (keep != PNG_HANDLE_CHUNK_NEVER && 114 117 up->location && !(up->location & PNG_HAVE_PLTE) && … … 148 151 png_error(png_ptr, "Valid palette required for paletted images"); 149 152 150 #if defined(PNG_WRITE_tRNS_SUPPORTED)153 #ifdef PNG_WRITE_tRNS_SUPPORTED 151 154 if (info_ptr->valid & PNG_INFO_tRNS) 152 155 { 153 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)156 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED 154 157 /* Invert the alpha channel (in tRNS) */ 155 158 if ((png_ptr->transformations & PNG_INVERT_ALPHA) && … … 157 160 { 158 161 int j; 159 for (j =0; j<(int)info_ptr->num_trans; j++)162 for (j = 0; j<(int)info_ptr->num_trans; j++) 160 163 info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); 161 164 } … … 165 168 } 166 169 #endif 167 #if defined(PNG_WRITE_bKGD_SUPPORTED)170 #ifdef PNG_WRITE_bKGD_SUPPORTED 168 171 if (info_ptr->valid & PNG_INFO_bKGD) 169 172 png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); 170 173 #endif 171 #if defined(PNG_WRITE_hIST_SUPPORTED)174 #ifdef PNG_WRITE_hIST_SUPPORTED 172 175 if (info_ptr->valid & PNG_INFO_hIST) 173 176 png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); 174 177 #endif 175 #if defined(PNG_WRITE_oFFs_SUPPORTED)178 #ifdef PNG_WRITE_oFFs_SUPPORTED 176 179 if (info_ptr->valid & PNG_INFO_oFFs) 177 180 png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, 178 181 info_ptr->offset_unit_type); 179 182 #endif 180 #if defined(PNG_WRITE_pCAL_SUPPORTED)183 #ifdef PNG_WRITE_pCAL_SUPPORTED 181 184 if (info_ptr->valid & PNG_INFO_pCAL) 182 185 png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, … … 185 188 #endif 186 189 187 #if defined(PNG_sCAL_SUPPORTED)190 #ifdef PNG_sCAL_SUPPORTED 188 191 if (info_ptr->valid & PNG_INFO_sCAL) 189 #if defined(PNG_WRITE_sCAL_SUPPORTED)190 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)192 #ifdef PNG_WRITE_sCAL_SUPPORTED 193 #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) 191 194 png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, 192 195 info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); … … 203 206 #endif /* sCAL */ 204 207 205 #if defined(PNG_WRITE_pHYs_SUPPORTED)208 #ifdef PNG_WRITE_pHYs_SUPPORTED 206 209 if (info_ptr->valid & PNG_INFO_pHYs) 207 210 png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, … … 209 212 #endif /* pHYs */ 210 213 211 #if defined(PNG_WRITE_tIME_SUPPORTED)214 #ifdef PNG_WRITE_tIME_SUPPORTED 212 215 if (info_ptr->valid & PNG_INFO_tIME) 213 216 { … … 217 220 #endif /* tIME */ 218 221 219 #if defined(PNG_WRITE_sPLT_SUPPORTED)222 #ifdef PNG_WRITE_sPLT_SUPPORTED 220 223 if (info_ptr->valid & PNG_INFO_sPLT) 221 224 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) … … 223 226 #endif /* sPLT */ 224 227 225 #if defined(PNG_WRITE_TEXT_SUPPORTED)228 #ifdef PNG_WRITE_TEXT_SUPPORTED 226 229 /* Check to see if we need to write text chunks */ 227 230 for (i = 0; i < info_ptr->num_text; i++) … … 232 235 if (info_ptr->text[i].compression > 0) 233 236 { 234 #if defined(PNG_WRITE_iTXt_SUPPORTED)237 #ifdef PNG_WRITE_iTXt_SUPPORTED 235 238 /* Write international chunk */ 236 239 png_write_iTXt(png_ptr, … … 249 252 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) 250 253 { 251 #if defined(PNG_WRITE_zTXt_SUPPORTED)254 #ifdef PNG_WRITE_zTXt_SUPPORTED 252 255 /* Write compressed chunk */ 253 256 png_write_zTXt(png_ptr, info_ptr->text[i].key, … … 262 265 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) 263 266 { 264 #if defined(PNG_WRITE_tEXt_SUPPORTED)267 #ifdef PNG_WRITE_tEXt_SUPPORTED 265 268 /* Write uncompressed chunk */ 266 269 png_write_tEXt(png_ptr, info_ptr->text[i].key, … … 277 280 #endif /* tEXt */ 278 281 279 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)282 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED 280 283 if (info_ptr->unknown_chunks_num) 281 284 { 282 png_unknown_chunk *up;283 284 png_debug(5, "writing extra chunks");285 286 for (up = info_ptr->unknown_chunks;287 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;288 up++)289 {290 int keep =png_handle_as_unknown(png_ptr, up->name);285 png_unknown_chunk *up; 286 287 png_debug(5, "writing extra chunks"); 288 289 for (up = info_ptr->unknown_chunks; 290 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; 291 up++) 292 { 293 int keep = png_handle_as_unknown(png_ptr, up->name); 291 294 if (keep != PNG_HANDLE_CHUNK_NEVER && 292 295 up->location && (up->location & PNG_HAVE_PLTE) && … … 297 300 png_write_chunk(png_ptr, up->name, up->data, up->size); 298 301 } 299 }302 } 300 303 } 301 304 #endif … … 311 314 { 312 315 png_debug(1, "in png_write_end"); 316 313 317 if (png_ptr == NULL) 314 318 return; … … 319 323 if (info_ptr != NULL) 320 324 { 321 #if defined(PNG_WRITE_TEXT_SUPPORTED)322 int i; /* Local index variable */323 #endif 324 #if defined(PNG_WRITE_tIME_SUPPORTED)325 #ifdef PNG_WRITE_TEXT_SUPPORTED 326 int i; /* local index variable */ 327 #endif 328 #ifdef PNG_WRITE_tIME_SUPPORTED 325 329 /* Check to see if user has supplied a time chunk */ 326 330 if ((info_ptr->valid & PNG_INFO_tIME) && … … 328 332 png_write_tIME(png_ptr, &(info_ptr->mod_time)); 329 333 #endif 330 #if defined(PNG_WRITE_TEXT_SUPPORTED)334 #ifdef PNG_WRITE_TEXT_SUPPORTED 331 335 /* Loop through comment chunks */ 332 336 for (i = 0; i < info_ptr->num_text; i++) … … 337 341 if (info_ptr->text[i].compression > 0) 338 342 { 339 #if defined(PNG_WRITE_iTXt_SUPPORTED)340 /* Write international chunk */341 png_write_iTXt(png_ptr,342 info_ptr->text[i].compression,343 info_ptr->text[i].key,344 info_ptr->text[i].lang,345 info_ptr->text[i].lang_key,346 info_ptr->text[i].text);347 #else 348 png_warning(png_ptr, "Unable to write international text");349 #endif 350 /* Mark this chunk as written */351 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;343 #ifdef PNG_WRITE_iTXt_SUPPORTED 344 /* Write international chunk */ 345 png_write_iTXt(png_ptr, 346 info_ptr->text[i].compression, 347 info_ptr->text[i].key, 348 info_ptr->text[i].lang, 349 info_ptr->text[i].lang_key, 350 info_ptr->text[i].text); 351 #else 352 png_warning(png_ptr, "Unable to write international text"); 353 #endif 354 /* Mark this chunk as written */ 355 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; 352 356 } 353 357 else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) 354 358 { 355 #if defined(PNG_WRITE_zTXt_SUPPORTED)359 #ifdef PNG_WRITE_zTXt_SUPPORTED 356 360 /* Write compressed chunk */ 357 361 png_write_zTXt(png_ptr, info_ptr->text[i].key, … … 366 370 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) 367 371 { 368 #if defined(PNG_WRITE_tEXt_SUPPORTED)372 #ifdef PNG_WRITE_tEXt_SUPPORTED 369 373 /* Write uncompressed chunk */ 370 374 png_write_tEXt(png_ptr, info_ptr->text[i].key, … … 379 383 } 380 384 #endif 381 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)385 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED 382 386 if (info_ptr->unknown_chunks_num) 383 387 { 384 png_unknown_chunk *up;385 386 png_debug(5, "writing extra chunks");387 388 for (up = info_ptr->unknown_chunks;389 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;390 up++)391 {392 int keep =png_handle_as_unknown(png_ptr, up->name);388 png_unknown_chunk *up; 389 390 png_debug(5, "writing extra chunks"); 391 392 for (up = info_ptr->unknown_chunks; 393 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; 394 up++) 395 { 396 int keep = png_handle_as_unknown(png_ptr, up->name); 393 397 if (keep != PNG_HANDLE_CHUNK_NEVER && 394 398 up->location && (up->location & PNG_AFTER_IDAT) && … … 398 402 png_write_chunk(png_ptr, up->name, up->data, up->size); 399 403 } 400 }404 } 401 405 } 402 406 #endif … … 412 416 * experiences a problem, please try building libpng with 413 417 * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to 414 * png-mng-implement at lists.sf.net . This kludge will be removed 415 * from libpng-1.4.0. 418 * png-mng-implement at lists.sf.net . 416 419 */ 417 #if defined(PNG_WRITE_FLUSH_SUPPORTED) && \418 defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED) 420 #ifdef PNG_WRITE_FLUSH_SUPPORTED 421 # ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED 419 422 png_flush(png_ptr); 420 # endif421 } 422 423 #if defined(PNG_WRITE_tIME_SUPPORTED) 424 #if !defined(_WIN32_WCE)425 /* "t ime.h" functions arenot supported on WindowsCE */423 # endif 424 #endif 425 } 426 427 #ifdef PNG_CONVERT_tIME_SUPPORTED 428 /* "tm" structure is not supported on WindowsCE */ 426 429 void PNGAPI 427 430 png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) 428 431 { 429 432 png_debug(1, "in png_convert_from_struct_tm"); 433 430 434 ptime->year = (png_uint_16)(1900 + ttime->tm_year); 431 435 ptime->month = (png_byte)(ttime->tm_mon + 1); … … 442 446 443 447 png_debug(1, "in png_convert_from_time_t"); 448 444 449 tbuf = gmtime(&ttime); 445 450 png_convert_from_struct_tm(ptime, tbuf); 446 451 } 447 #endif448 452 #endif 449 453 … … 466 470 #endif /* PNG_USER_MEM_SUPPORTED */ 467 471 #ifdef PNG_SETJMP_SUPPORTED 468 volatile469 #endif 470 png_structp png_ptr;472 volatile 473 #endif 474 png_structp png_ptr; 471 475 #ifdef PNG_SETJMP_SUPPORTED 472 476 #ifdef USE_FAR_KEYWORD … … 475 479 #endif 476 480 int i; 481 477 482 png_debug(1, "in png_create_write_struct"); 483 478 484 #ifdef PNG_USER_MEM_SUPPORTED 479 485 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, … … 487 493 /* Added at libpng-1.2.6 */ 488 494 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 489 png_ptr->user_width_max =PNG_USER_WIDTH_MAX;490 png_ptr->user_height_max =PNG_USER_HEIGHT_MAX;495 png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 496 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 491 497 #endif 492 498 … … 499 505 { 500 506 png_free(png_ptr, png_ptr->zbuf); 501 png_ptr->zbuf=NULL; 502 png_destroy_struct(png_ptr); 507 png_ptr->zbuf = NULL; 508 #ifdef PNG_USER_MEM_SUPPORTED 509 png_destroy_struct_2((png_voidp)png_ptr, 510 (png_free_ptr)free_fn, (png_voidp)mem_ptr); 511 #else 512 png_destroy_struct((png_voidp)png_ptr); 513 #endif 503 514 return (NULL); 504 515 } … … 515 526 if (user_png_ver) 516 527 { 517 i=0;518 do519 {520 if (user_png_ver[i] != png_libpng_ver[i])521 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;522 } while (png_libpng_ver[i++]);528 i = 0; 529 do 530 { 531 if (user_png_ver[i] != png_libpng_ver[i]) 532 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 533 } while (png_libpng_ver[i++]); 523 534 } 524 535 … … 534 545 (user_png_ver[0] == '0' && user_png_ver[2] < '9')) 535 546 { 536 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)547 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 537 548 char msg[80]; 538 549 if (user_png_ver) 539 550 { 540 png_snprintf(msg, 80,541 "Application was compiled with png.h from libpng-%.20s",542 user_png_ver);543 png_warning(png_ptr, msg);551 png_snprintf(msg, 80, 552 "Application was compiled with png.h from libpng-%.20s", 553 user_png_ver); 554 png_warning(png_ptr, msg); 544 555 } 545 556 png_snprintf(msg, 80, … … 549 560 #endif 550 561 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 551 png_ptr->flags =0;562 png_ptr->flags = 0; 552 563 #endif 553 564 png_error(png_ptr, … … 559 570 png_ptr->zbuf_size = PNG_ZBUF_SIZE; 560 571 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 561 (png_uint_32)png_ptr->zbuf_size);572 (png_uint_32)png_ptr->zbuf_size); 562 573 563 574 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, 564 575 png_flush_ptr_NULL); 565 576 566 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)577 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 567 578 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 568 579 1, png_doublep_NULL, png_doublep_NULL); … … 570 581 571 582 #ifdef PNG_SETJMP_SUPPORTED 572 /* Applications that neglect to set up their own setjmp() and then encounter 573 a png_error() will longjmp here. Since the jmpbuf is then meaningless we 574 abort instead of returning. */ 583 /* Applications that neglect to set up their own setjmp() and then 584 * encounter a png_error() will longjmp here. Since the jmpbuf is 585 * then meaningless we abort instead of returning. 586 */ 575 587 #ifdef USE_FAR_KEYWORD 576 588 if (setjmp(jmpbuf)) … … 602 614 /* We only come here via pre-1.0.12-compiled applications */ 603 615 if (png_ptr == NULL) return; 604 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)616 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 605 617 if (png_sizeof(png_struct) > png_struct_size || 606 618 png_sizeof(png_info) > png_info_size) 607 619 { 608 620 char msg[80]; 609 png_ptr->warning_fn =NULL;621 png_ptr->warning_fn = NULL; 610 622 if (user_png_ver) 611 623 { 612 png_snprintf(msg, 80,613 "Application was compiled with png.h from libpng-%.20s",614 user_png_ver);615 png_warning(png_ptr, msg);624 png_snprintf(msg, 80, 625 "Application was compiled with png.h from libpng-%.20s", 626 user_png_ver); 627 png_warning(png_ptr, msg); 616 628 } 617 629 png_snprintf(msg, 80, … … 622 634 #endif 623 635 if (png_sizeof(png_struct) > png_struct_size) 624 {625 png_ptr->error_fn=NULL;636 { 637 png_ptr->error_fn = NULL; 626 638 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 627 png_ptr->flags=0;628 #endif 629 png_error(png_ptr,630 "The png struct allocated by the application for writing is too small.");631 }639 png_ptr->flags = 0; 640 #endif 641 png_error(png_ptr, 642 "The png struct allocated by the application for writing is too small."); 643 } 632 644 if (png_sizeof(png_info) > png_info_size) 633 {634 png_ptr->error_fn=NULL;645 { 646 png_ptr->error_fn = NULL; 635 647 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 636 png_ptr->flags=0;637 #endif 638 png_error(png_ptr,639 "The info struct allocated by the application for writing is too small.");640 }648 png_ptr->flags = 0; 649 #endif 650 png_error(png_ptr, 651 "The info struct allocated by the application for writing is too small."); 652 } 641 653 png_write_init_3(&png_ptr, user_png_ver, png_struct_size); 642 654 } … … 648 660 png_size_t png_struct_size) 649 661 { 650 png_structp png_ptr =*ptr_ptr;662 png_structp png_ptr = *ptr_ptr; 651 663 #ifdef PNG_SETJMP_SUPPORTED 652 jmp_buf tmp_jmp; /* To save current jump buffer */664 jmp_buf tmp_jmp; /* to save current jump buffer */ 653 665 #endif 654 666 … … 660 672 do 661 673 { 662 if (user_png_ver[i] != png_libpng_ver[i])663 {674 if (user_png_ver[i] != png_libpng_ver[i]) 675 { 664 676 #ifdef PNG_LEGACY_SUPPORTED 665 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;666 #else 667 png_ptr->warning_fn=NULL;668 png_warning(png_ptr,677 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 678 #else 679 png_ptr->warning_fn = NULL; 680 png_warning(png_ptr, 669 681 "Application uses deprecated png_write_init() and should be recompiled."); 670 break; 671 #endif 672 } 682 #endif 683 } 673 684 } while (png_libpng_ver[i++]); 674 685 … … 681 692 682 693 if (png_sizeof(png_struct) > png_struct_size) 683 {684 png_destroy_struct(png_ptr);685 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);686 *ptr_ptr = png_ptr;687 }694 { 695 png_destroy_struct(png_ptr); 696 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); 697 *ptr_ptr = png_ptr; 698 } 688 699 689 700 /* Reset all variables to 0 */ … … 692 703 /* Added at libpng-1.2.6 */ 693 704 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 694 png_ptr->user_width_max =PNG_USER_WIDTH_MAX;695 png_ptr->user_height_max =PNG_USER_HEIGHT_MAX;705 png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 706 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 696 707 #endif 697 708 … … 707 718 png_ptr->zbuf_size = PNG_ZBUF_SIZE; 708 719 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 709 (png_uint_32)png_ptr->zbuf_size); 710 711 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 720 (png_uint_32)png_ptr->zbuf_size); 721 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 712 722 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 713 723 1, png_doublep_NULL, png_doublep_NULL); … … 724 734 png_uint_32 num_rows) 725 735 { 726 png_uint_32 i; /* Row counter */727 png_bytepp rp; /* Row pointer */736 png_uint_32 i; /* row counter */ 737 png_bytepp rp; /* row pointer */ 728 738 729 739 png_debug(1, "in png_write_rows"); … … 745 755 png_write_image(png_structp png_ptr, png_bytepp image) 746 756 { 747 png_uint_32 i; /* Row index */748 int pass, num_pass; /* Pass variables */749 png_bytepp rp; /* Points to current row */757 png_uint_32 i; /* row index */ 758 int pass, num_pass; /* pass variables */ 759 png_bytepp rp; /* points to current row */ 750 760 751 761 if (png_ptr == NULL) … … 753 763 754 764 png_debug(1, "in png_write_image"); 755 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 765 766 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 756 767 /* Initialize interlace handling. If image is not interlaced, 757 768 * this will set pass to 1 … … 778 789 if (png_ptr == NULL) 779 790 return; 791 780 792 png_debug2(1, "in png_write_row (row %ld, pass %d)", 781 793 png_ptr->row_number, png_ptr->pass); … … 822 834 } 823 835 824 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)836 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 825 837 /* If interlaced and not interested in row, return */ 826 838 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) … … 903 915 png_ptr->row_info.rowbytes); 904 916 905 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)917 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 906 918 /* Handle interlacing */ 907 919 if (png_ptr->interlaced && png_ptr->pass < 6 && … … 923 935 png_do_write_transformations(png_ptr); 924 936 925 #if defined(PNG_MNG_FEATURES_SUPPORTED)937 #ifdef PNG_MNG_FEATURES_SUPPORTED 926 938 /* Write filter_method 64 (intrapixel differencing) only if 927 939 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and … … 948 960 } 949 961 950 #if defined(PNG_WRITE_FLUSH_SUPPORTED)962 #ifdef PNG_WRITE_FLUSH_SUPPORTED 951 963 /* Set the automatic flush interval or 0 to turn flushing off */ 952 964 void PNGAPI … … 954 966 { 955 967 png_debug(1, "in png_set_flush"); 968 956 969 if (png_ptr == NULL) 957 970 return; … … 966 979 967 980 png_debug(1, "in png_write_flush"); 981 968 982 if (png_ptr == NULL) 969 983 return; … … 1026 1040 1027 1041 png_debug(1, "in png_destroy_write_struct"); 1042 1028 1043 if (png_ptr_ptr != NULL) 1029 1044 { … … 1052 1067 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 1053 1068 1054 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)1069 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 1055 1070 if (png_ptr->num_chunk_list) 1056 1071 { 1057 1072 png_free(png_ptr, png_ptr->chunk_list); 1058 png_ptr->chunk_list =NULL;1073 png_ptr->chunk_list = NULL; 1059 1074 png_ptr->num_chunk_list = 0; 1060 1075 } … … 1100 1115 1101 1116 png_debug(1, "in png_write_destroy"); 1117 1102 1118 /* Free any memory zlib uses */ 1103 1119 deflateEnd(&png_ptr->zstream); … … 1106 1122 png_free(png_ptr, png_ptr->zbuf); 1107 1123 png_free(png_ptr, png_ptr->row_buf); 1108 #if ndef PNG_NO_WRITE_FILTER1124 #ifdef PNG_WRITE_FILTER_SUPPORTED 1109 1125 png_free(png_ptr, png_ptr->prev_row); 1110 1126 png_free(png_ptr, png_ptr->sub_row); … … 1114 1130 #endif 1115 1131 1116 #if defined(PNG_TIME_RFC1123_SUPPORTED)1132 #ifdef PNG_TIME_RFC1123_SUPPORTED 1117 1133 png_free(png_ptr, png_ptr->time_buffer); 1118 1134 #endif 1119 1135 1120 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)1136 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 1121 1137 png_free(png_ptr, png_ptr->prev_filters); 1122 1138 png_free(png_ptr, png_ptr->filter_weights); … … 1157 1173 { 1158 1174 png_debug(1, "in png_set_filter"); 1159 if (png_ptr == NULL) 1160 return; 1161 #if defined(PNG_MNG_FEATURES_SUPPORTED) 1175 1176 if (png_ptr == NULL) 1177 return; 1178 #ifdef PNG_MNG_FEATURES_SUPPORTED 1162 1179 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 1163 1180 (method == PNG_INTRAPIXEL_DIFFERENCING)) … … 1168 1185 switch (filters & (PNG_ALL_FILTERS | 0x07)) 1169 1186 { 1170 #if ndef PNG_NO_WRITE_FILTER1187 #ifdef PNG_WRITE_FILTER_SUPPORTED 1171 1188 case 5: 1172 1189 case 6: 1173 1190 case 7: png_warning(png_ptr, "Unknown row filter for method 0"); 1174 #endif /* PNG_ NO_WRITE_FILTER*/1191 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1175 1192 case PNG_FILTER_VALUE_NONE: 1176 png_ptr->do_filter =PNG_FILTER_NONE; break;1177 #if ndef PNG_NO_WRITE_FILTER1193 png_ptr->do_filter = PNG_FILTER_NONE; break; 1194 #ifdef PNG_WRITE_FILTER_SUPPORTED 1178 1195 case PNG_FILTER_VALUE_SUB: 1179 png_ptr->do_filter =PNG_FILTER_SUB; break;1196 png_ptr->do_filter = PNG_FILTER_SUB; break; 1180 1197 case PNG_FILTER_VALUE_UP: 1181 png_ptr->do_filter =PNG_FILTER_UP; break;1198 png_ptr->do_filter = PNG_FILTER_UP; break; 1182 1199 case PNG_FILTER_VALUE_AVG: 1183 png_ptr->do_filter =PNG_FILTER_AVG; break;1200 png_ptr->do_filter = PNG_FILTER_AVG; break; 1184 1201 case PNG_FILTER_VALUE_PAETH: 1185 png_ptr->do_filter =PNG_FILTER_PAETH; break;1202 png_ptr->do_filter = PNG_FILTER_PAETH; break; 1186 1203 default: png_ptr->do_filter = (png_byte)filters; break; 1187 1204 #else 1188 1205 default: png_warning(png_ptr, "Unknown row filter for method 0"); 1189 #endif /* PNG_ NO_WRITE_FILTER*/1206 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1190 1207 } 1191 1208 … … 1201 1218 if (png_ptr->row_buf != NULL) 1202 1219 { 1203 #if ndef PNG_NO_WRITE_FILTER1220 #ifdef PNG_WRITE_FILTER_SUPPORTED 1204 1221 if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) 1205 1222 { … … 1256 1273 1257 1274 if (png_ptr->do_filter == PNG_NO_FILTERS) 1258 #endif /* PNG_ NO_WRITE_FILTER*/1275 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1259 1276 png_ptr->do_filter = PNG_FILTER_NONE; 1260 1277 } … … 1271 1288 * better compression. 1272 1289 */ 1273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)/* GRR 970116 */1290 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ 1274 1291 void PNGAPI 1275 1292 png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, … … 1280 1297 1281 1298 png_debug(1, "in png_set_filter_heuristics"); 1299 1282 1300 if (png_ptr == NULL) 1283 1301 return; … … 1394 1412 { 1395 1413 png_debug(1, "in png_set_compression_level"); 1414 1396 1415 if (png_ptr == NULL) 1397 1416 return; … … 1404 1423 { 1405 1424 png_debug(1, "in png_set_compression_mem_level"); 1425 1406 1426 if (png_ptr == NULL) 1407 1427 return; … … 1414 1434 { 1415 1435 png_debug(1, "in png_set_compression_strategy"); 1436 1416 1437 if (png_ptr == NULL) 1417 1438 return; … … 1434 1455 { 1435 1456 png_warning(png_ptr, "Compression window is being reset to 512"); 1436 window_bits =9;1457 window_bits = 9; 1437 1458 } 1438 1459 #endif … … 1445 1466 { 1446 1467 png_debug(1, "in png_set_compression_method"); 1468 1447 1469 if (png_ptr == NULL) 1448 1470 return; … … 1461 1483 } 1462 1484 1463 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)1485 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED 1464 1486 void PNGAPI 1465 1487 png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr … … 1467 1489 { 1468 1490 png_debug(1, "in png_set_write_user_transform_fn"); 1491 1469 1492 if (png_ptr == NULL) 1470 1493 return; … … 1475 1498 1476 1499 1477 #if defined(PNG_INFO_IMAGE_SUPPORTED)1500 #ifdef PNG_INFO_IMAGE_SUPPORTED 1478 1501 void PNGAPI 1479 1502 png_write_png(png_structp png_ptr, png_infop info_ptr, … … 1482 1505 if (png_ptr == NULL || info_ptr == NULL) 1483 1506 return; 1484 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)1485 /* Invert the alpha channel from opacity to transparency */1486 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)1487 png_set_invert_alpha(png_ptr);1488 #endif1489 1507 1490 1508 /* Write the file header information. */ … … 1493 1511 /* ------ these transformations don't touch the info structure ------- */ 1494 1512 1495 #if defined(PNG_WRITE_INVERT_SUPPORTED)1513 #ifdef PNG_WRITE_INVERT_SUPPORTED 1496 1514 /* Invert monochrome pixels */ 1497 1515 if (transforms & PNG_TRANSFORM_INVERT_MONO) … … 1499 1517 #endif 1500 1518 1501 #if defined(PNG_WRITE_SHIFT_SUPPORTED)1519 #ifdef PNG_WRITE_SHIFT_SUPPORTED 1502 1520 /* Shift the pixels up to a legal bit depth and fill in 1503 1521 * as appropriate to correctly scale the image. … … 1508 1526 #endif 1509 1527 1510 #if defined(PNG_WRITE_PACK_SUPPORTED)1528 #ifdef PNG_WRITE_PACK_SUPPORTED 1511 1529 /* Pack pixels into bytes */ 1512 1530 if (transforms & PNG_TRANSFORM_PACKING) … … 1514 1532 #endif 1515 1533 1516 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)1534 #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED 1517 1535 /* Swap location of alpha bytes from ARGB to RGBA */ 1518 1536 if (transforms & PNG_TRANSFORM_SWAP_ALPHA) … … 1520 1538 #endif 1521 1539 1522 #if defined(PNG_WRITE_FILLER_SUPPORTED)1540 #ifdef PNG_WRITE_FILLER_SUPPORTED 1523 1541 /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */ 1524 1542 if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) … … 1528 1546 #endif 1529 1547 1530 #if defined(PNG_WRITE_BGR_SUPPORTED)1548 #ifdef PNG_WRITE_BGR_SUPPORTED 1531 1549 /* Flip BGR pixels to RGB */ 1532 1550 if (transforms & PNG_TRANSFORM_BGR) … … 1534 1552 #endif 1535 1553 1536 #if defined(PNG_WRITE_SWAP_SUPPORTED)1554 #ifdef PNG_WRITE_SWAP_SUPPORTED 1537 1555 /* Swap bytes of 16-bit files to most significant byte first */ 1538 1556 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) … … 1540 1558 #endif 1541 1559 1542 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)1560 #ifdef PNG_WRITE_PACKSWAP_SUPPORTED 1543 1561 /* Swap bits of 1, 2, 4 bit packed pixel formats */ 1544 1562 if (transforms & PNG_TRANSFORM_PACKSWAP) … … 1546 1564 #endif 1547 1565 1566 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED 1567 /* Invert the alpha channel from opacity to transparency */ 1568 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) 1569 png_set_invert_alpha(png_ptr); 1570 #endif 1571 1548 1572 /* ----------------------- end of transformations ------------------- */ 1549 1573
