| OLD | NEW |
| 1 | 1 |
| 2 /* pngwrite.c - general routines to write a PNG file | 2 /* pngwrite.c - general routines to write a PNG file |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.27 [April 29, 2008] | 4 * Last changed in libpng 1.2.31 [August 19, 2008] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * For conditions of distribution and use, see copyright notice in png.h |
| 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson | 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 /* get internal access to png.h */ | 11 /* get internal access to png.h */ |
| 12 #define PNG_INTERNAL | 12 #define PNG_INTERNAL |
| 13 #include "png.h" | 13 #include "png.h" |
| 14 #ifdef PNG_WRITE_SUPPORTED | 14 #ifdef PNG_WRITE_SUPPORTED |
| (...skipping 10 matching lines...) Expand all Loading... |
| 25 void PNGAPI | 25 void PNGAPI |
| 26 png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) | 26 png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) |
| 27 { | 27 { |
| 28 png_debug(1, "in png_write_info_before_PLTE\n"); | 28 png_debug(1, "in png_write_info_before_PLTE\n"); |
| 29 if (png_ptr == NULL || info_ptr == NULL) | 29 if (png_ptr == NULL || info_ptr == NULL) |
| 30 return; | 30 return; |
| 31 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) | 31 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) |
| 32 { | 32 { |
| 33 png_write_sig(png_ptr); /* write PNG signature */ | 33 png_write_sig(png_ptr); /* write PNG signature */ |
| 34 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 34 #if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 35 if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) | 35 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)
) |
| 36 { | 36 { |
| 37 png_warning(png_ptr,"MNG features are not allowed in a PNG datastream"); | 37 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); |
| 38 png_ptr->mng_features_permitted=0; | 38 png_ptr->mng_features_permitted=0; |
| 39 } | 39 } |
| 40 #endif | 40 #endif |
| 41 /* write IHDR information. */ | 41 /* write IHDR information. */ |
| 42 png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, | 42 png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
| 43 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, | 43 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, |
| 44 info_ptr->filter_type, | 44 info_ptr->filter_type, |
| 45 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) | 45 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 46 info_ptr->interlace_type); | 46 info_ptr->interlace_type); |
| 47 #else | 47 #else |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 #endif | 389 #endif |
| 390 } | 390 } |
| 391 | 391 |
| 392 png_ptr->mode |= PNG_AFTER_IDAT; | 392 png_ptr->mode |= PNG_AFTER_IDAT; |
| 393 | 393 |
| 394 /* write end of PNG file */ | 394 /* write end of PNG file */ |
| 395 png_write_IEND(png_ptr); | 395 png_write_IEND(png_ptr); |
| 396 /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, |
| 397 * and restored again in libpng-1.2.30, may cause some applications that |
| 398 * do not set png_ptr->output_flush_fn to crash. If your application |
| 399 * experiences a problem, please try building libpng with |
| 400 * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to |
| 401 * png-mng-implement at lists.sf.net . This kludge will be removed |
| 402 * from libpng-1.4.0. |
| 403 */ |
| 404 #if defined(PNG_WRITE_FLUSH_SUPPORTED) && \ |
| 405 defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED) |
| 406 png_flush(png_ptr); |
| 407 #endif |
| 396 } | 408 } |
| 397 | 409 |
| 398 #if defined(PNG_WRITE_tIME_SUPPORTED) | 410 #if defined(PNG_WRITE_tIME_SUPPORTED) |
| 399 #if !defined(_WIN32_WCE) | 411 #if !defined(_WIN32_WCE) |
| 400 /* "time.h" functions are not supported on WindowsCE */ | 412 /* "time.h" functions are not supported on WindowsCE */ |
| 401 void PNGAPI | 413 void PNGAPI |
| 402 png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) | 414 png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) |
| 403 { | 415 { |
| 404 png_debug(1, "in png_convert_from_struct_tm\n"); | 416 png_debug(1, "in png_convert_from_struct_tm\n"); |
| 405 ptime->year = (png_uint_16)(1900 + ttime->tm_year); | 417 ptime->year = (png_uint_16)(1900 + ttime->tm_year); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 432 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); | 444 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); |
| 433 } | 445 } |
| 434 | 446 |
| 435 /* Alternate initialize png_ptr structure, and allocate any memory needed */ | 447 /* Alternate initialize png_ptr structure, and allocate any memory needed */ |
| 436 png_structp PNGAPI | 448 png_structp PNGAPI |
| 437 png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, | 449 png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, |
| 438 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, | 450 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
| 439 png_malloc_ptr malloc_fn, png_free_ptr free_fn) | 451 png_malloc_ptr malloc_fn, png_free_ptr free_fn) |
| 440 { | 452 { |
| 441 #endif /* PNG_USER_MEM_SUPPORTED */ | 453 #endif /* PNG_USER_MEM_SUPPORTED */ |
| 442 png_structp png_ptr; | 454 #ifdef PNG_SETJMP_SUPPORTED |
| 455 volatile |
| 456 #endif |
| 457 png_structp png_ptr; |
| 443 #ifdef PNG_SETJMP_SUPPORTED | 458 #ifdef PNG_SETJMP_SUPPORTED |
| 444 #ifdef USE_FAR_KEYWORD | 459 #ifdef USE_FAR_KEYWORD |
| 445 jmp_buf jmpbuf; | 460 jmp_buf jmpbuf; |
| 446 #endif | 461 #endif |
| 447 #endif | 462 #endif |
| 448 int i; | 463 int i; |
| 449 png_debug(1, "in png_create_write_struct\n"); | 464 png_debug(1, "in png_create_write_struct\n"); |
| 450 #ifdef PNG_USER_MEM_SUPPORTED | 465 #ifdef PNG_USER_MEM_SUPPORTED |
| 451 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, | 466 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
| 452 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); | 467 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 463 #endif | 478 #endif |
| 464 | 479 |
| 465 #ifdef PNG_SETJMP_SUPPORTED | 480 #ifdef PNG_SETJMP_SUPPORTED |
| 466 #ifdef USE_FAR_KEYWORD | 481 #ifdef USE_FAR_KEYWORD |
| 467 if (setjmp(jmpbuf)) | 482 if (setjmp(jmpbuf)) |
| 468 #else | 483 #else |
| 469 if (setjmp(png_ptr->jmpbuf)) | 484 if (setjmp(png_ptr->jmpbuf)) |
| 470 #endif | 485 #endif |
| 471 { | 486 { |
| 472 png_free(png_ptr, png_ptr->zbuf); | 487 png_free(png_ptr, png_ptr->zbuf); |
| 473 png_ptr->zbuf=NULL; | 488 png_ptr->zbuf=NULL; |
| 474 png_destroy_struct(png_ptr); | 489 png_destroy_struct(png_ptr); |
| 475 return (NULL); | 490 return (NULL); |
| 476 } | 491 } |
| 477 #ifdef USE_FAR_KEYWORD | 492 #ifdef USE_FAR_KEYWORD |
| 478 png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); | 493 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); |
| 479 #endif | 494 #endif |
| 480 #endif | 495 #endif |
| 481 | 496 |
| 482 #ifdef PNG_USER_MEM_SUPPORTED | 497 #ifdef PNG_USER_MEM_SUPPORTED |
| 483 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); | 498 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
| 484 #endif /* PNG_USER_MEM_SUPPORTED */ | 499 #endif /* PNG_USER_MEM_SUPPORTED */ |
| 485 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); | 500 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
| 486 | 501 |
| 487 if(user_png_ver) | 502 if (user_png_ver) |
| 488 { | 503 { |
| 489 i=0; | 504 i=0; |
| 490 do | 505 do |
| 491 { | 506 { |
| 492 if(user_png_ver[i] != png_libpng_ver[i]) | 507 if (user_png_ver[i] != png_libpng_ver[i]) |
| 493 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; | 508 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 494 } while (png_libpng_ver[i++]); | 509 } while (png_libpng_ver[i++]); |
| 495 } | 510 } |
| 496 | 511 |
| 497 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) | 512 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
| 498 { | 513 { |
| 499 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so | 514 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
| 500 * we must recompile any applications that use any older library version. | 515 * we must recompile any applications that use any older library version. |
| 501 * For versions after libpng 1.0, we will be compatible, so we need | 516 * For versions after libpng 1.0, we will be compatible, so we need |
| 502 * only check the first digit. | 517 * only check the first digit. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 1, png_doublep_NULL, png_doublep_NULL); | 555 1, png_doublep_NULL, png_doublep_NULL); |
| 541 #endif | 556 #endif |
| 542 | 557 |
| 543 #ifdef PNG_SETJMP_SUPPORTED | 558 #ifdef PNG_SETJMP_SUPPORTED |
| 544 /* Applications that neglect to set up their own setjmp() and then encounter | 559 /* Applications that neglect to set up their own setjmp() and then encounter |
| 545 a png_error() will longjmp here. Since the jmpbuf is then meaningless we | 560 a png_error() will longjmp here. Since the jmpbuf is then meaningless we |
| 546 abort instead of returning. */ | 561 abort instead of returning. */ |
| 547 #ifdef USE_FAR_KEYWORD | 562 #ifdef USE_FAR_KEYWORD |
| 548 if (setjmp(jmpbuf)) | 563 if (setjmp(jmpbuf)) |
| 549 PNG_ABORT(); | 564 PNG_ABORT(); |
| 550 png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); | 565 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); |
| 551 #else | 566 #else |
| 552 if (setjmp(png_ptr->jmpbuf)) | 567 if (setjmp(png_ptr->jmpbuf)) |
| 553 PNG_ABORT(); | 568 PNG_ABORT(); |
| 554 #endif | 569 #endif |
| 555 #endif | 570 #endif |
| 556 return (png_ptr); | 571 return (png_ptr); |
| 557 } | 572 } |
| 558 | 573 |
| 559 /* Initialize png_ptr structure, and allocate any memory needed */ | 574 /* Initialize png_ptr structure, and allocate any memory needed */ |
| 560 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) | 575 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) |
| 561 /* Deprecated. */ | 576 /* Deprecated. */ |
| 562 #undef png_write_init | 577 #undef png_write_init |
| 563 void PNGAPI | 578 void PNGAPI |
| 564 png_write_init(png_structp png_ptr) | 579 png_write_init(png_structp png_ptr) |
| 565 { | 580 { |
| 566 /* We only come here via pre-1.0.7-compiled applications */ | 581 /* We only come here via pre-1.0.7-compiled applications */ |
| 567 png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); | 582 png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); |
| 568 } | 583 } |
| 569 | 584 |
| 570 void PNGAPI | 585 void PNGAPI |
| 571 png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, | 586 png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, |
| 572 png_size_t png_struct_size, png_size_t png_info_size) | 587 png_size_t png_struct_size, png_size_t png_info_size) |
| 573 { | 588 { |
| 574 /* We only come here via pre-1.0.12-compiled applications */ | 589 /* We only come here via pre-1.0.12-compiled applications */ |
| 575 if(png_ptr == NULL) return; | 590 if (png_ptr == NULL) return; |
| 576 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) | 591 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 577 if(png_sizeof(png_struct) > png_struct_size || | 592 if (png_sizeof(png_struct) > png_struct_size || |
| 578 png_sizeof(png_info) > png_info_size) | 593 png_sizeof(png_info) > png_info_size) |
| 579 { | 594 { |
| 580 char msg[80]; | 595 char msg[80]; |
| 581 png_ptr->warning_fn=NULL; | 596 png_ptr->warning_fn=NULL; |
| 582 if (user_png_ver) | 597 if (user_png_ver) |
| 583 { | 598 { |
| 584 png_snprintf(msg, 80, | 599 png_snprintf(msg, 80, |
| 585 "Application was compiled with png.h from libpng-%.20s", | 600 "Application was compiled with png.h from libpng-%.20s", |
| 586 user_png_ver); | 601 user_png_ver); |
| 587 png_warning(png_ptr, msg); | 602 png_warning(png_ptr, msg); |
| 588 } | 603 } |
| 589 png_snprintf(msg, 80, | 604 png_snprintf(msg, 80, |
| 590 "Application is running with png.c from libpng-%.20s", | 605 "Application is running with png.c from libpng-%.20s", |
| 591 png_libpng_ver); | 606 png_libpng_ver); |
| 592 png_warning(png_ptr, msg); | 607 png_warning(png_ptr, msg); |
| 593 } | 608 } |
| 594 #endif | 609 #endif |
| 595 if(png_sizeof(png_struct) > png_struct_size) | 610 if (png_sizeof(png_struct) > png_struct_size) |
| 596 { | 611 { |
| 597 png_ptr->error_fn=NULL; | 612 png_ptr->error_fn=NULL; |
| 598 #ifdef PNG_ERROR_NUMBERS_SUPPORTED | 613 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 599 png_ptr->flags=0; | 614 png_ptr->flags=0; |
| 600 #endif | 615 #endif |
| 601 png_error(png_ptr, | 616 png_error(png_ptr, |
| 602 "The png struct allocated by the application for writing is too small."); | 617 "The png struct allocated by the application for writing is too small."); |
| 603 } | 618 } |
| 604 if(png_sizeof(png_info) > png_info_size) | 619 if (png_sizeof(png_info) > png_info_size) |
| 605 { | 620 { |
| 606 png_ptr->error_fn=NULL; | 621 png_ptr->error_fn=NULL; |
| 607 #ifdef PNG_ERROR_NUMBERS_SUPPORTED | 622 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 608 png_ptr->flags=0; | 623 png_ptr->flags=0; |
| 609 #endif | 624 #endif |
| 610 png_error(png_ptr, | 625 png_error(png_ptr, |
| 611 "The info struct allocated by the application for writing is too small.")
; | 626 "The info struct allocated by the application for writing is too small.")
; |
| 612 } | 627 } |
| 613 png_write_init_3(&png_ptr, user_png_ver, png_struct_size); | 628 png_write_init_3(&png_ptr, user_png_ver, png_struct_size); |
| 614 } | 629 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 631 | 646 |
| 632 do | 647 do |
| 633 { | 648 { |
| 634 if (user_png_ver[i] != png_libpng_ver[i]) | 649 if (user_png_ver[i] != png_libpng_ver[i]) |
| 635 { | 650 { |
| 636 #ifdef PNG_LEGACY_SUPPORTED | 651 #ifdef PNG_LEGACY_SUPPORTED |
| 637 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; | 652 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 638 #else | 653 #else |
| 639 png_ptr->warning_fn=NULL; | 654 png_ptr->warning_fn=NULL; |
| 640 png_warning(png_ptr, | 655 png_warning(png_ptr, |
| 641 "Application uses deprecated png_write_init() and should be recompiled."); | 656 "Application uses deprecated png_write_init() and should be recompiled."); |
| 642 break; | 657 break; |
| 643 #endif | 658 #endif |
| 644 } | 659 } |
| 645 } while (png_libpng_ver[i++]); | 660 } while (png_libpng_ver[i++]); |
| 646 | 661 |
| 647 png_debug(1, "in png_write_init_3\n"); | 662 png_debug(1, "in png_write_init_3\n"); |
| 648 | 663 |
| 649 #ifdef PNG_SETJMP_SUPPORTED | 664 #ifdef PNG_SETJMP_SUPPORTED |
| 650 /* save jump buffer and error functions */ | 665 /* save jump buffer and error functions */ |
| 651 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); | 666 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
| 652 #endif | 667 #endif |
| 653 | 668 |
| 654 if (png_sizeof(png_struct) > png_struct_size) | 669 if (png_sizeof(png_struct) > png_struct_size) |
| 655 { | 670 { |
| 656 png_destroy_struct(png_ptr); | 671 png_destroy_struct(png_ptr); |
| 657 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); | 672 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 658 *ptr_ptr = png_ptr; | 673 *ptr_ptr = png_ptr; |
| 659 } | 674 } |
| 660 | 675 |
| 661 /* reset all variables to 0 */ | 676 /* reset all variables to 0 */ |
| 662 png_memset(png_ptr, 0, png_sizeof (png_struct)); | 677 png_memset(png_ptr, 0, png_sizeof(png_struct)); |
| 663 | 678 |
| 664 /* added at libpng-1.2.6 */ | 679 /* added at libpng-1.2.6 */ |
| 665 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | 680 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 666 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; | 681 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
| 667 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; | 682 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
| 668 #endif | 683 #endif |
| 669 | 684 |
| 670 #ifdef PNG_SETJMP_SUPPORTED | 685 #ifdef PNG_SETJMP_SUPPORTED |
| 671 /* restore jump buffer */ | 686 /* restore jump buffer */ |
| 672 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); | 687 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
| 673 #endif | 688 #endif |
| 674 | 689 |
| 675 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, | 690 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, |
| 676 png_flush_ptr_NULL); | 691 png_flush_ptr_NULL); |
| 677 | 692 |
| 678 /* initialize zbuf - compression buffer */ | 693 /* initialize zbuf - compression buffer */ |
| 679 png_ptr->zbuf_size = PNG_ZBUF_SIZE; | 694 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 680 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, | 695 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 681 (png_uint_32)png_ptr->zbuf_size); | 696 (png_uint_32)png_ptr->zbuf_size); |
| 682 | 697 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 911 #if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 897 /* Write filter_method 64 (intrapixel differencing) only if | 912 /* Write filter_method 64 (intrapixel differencing) only if |
| 898 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and | 913 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and |
| 899 * 2. Libpng did not write a PNG signature (this filter_method is only | 914 * 2. Libpng did not write a PNG signature (this filter_method is only |
| 900 * used in PNG datastreams that are embedded in MNG datastreams) and | 915 * used in PNG datastreams that are embedded in MNG datastreams) and |
| 901 * 3. The application called png_permit_mng_features with a mask that | 916 * 3. The application called png_permit_mng_features with a mask that |
| 902 * included PNG_FLAG_MNG_FILTER_64 and | 917 * included PNG_FLAG_MNG_FILTER_64 and |
| 903 * 4. The filter_method is 64 and | 918 * 4. The filter_method is 64 and |
| 904 * 5. The color_type is RGB or RGBA | 919 * 5. The color_type is RGB or RGBA |
| 905 */ | 920 */ |
| 906 if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && | 921 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 907 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) | 922 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
| 908 { | 923 { |
| 909 /* Intrapixel differencing */ | 924 /* Intrapixel differencing */ |
| 910 png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); | 925 png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 911 } | 926 } |
| 912 #endif | 927 #endif |
| 913 | 928 |
| 914 /* Find a filter if necessary, filter the row and write it out. */ | 929 /* Find a filter if necessary, filter the row and write it out. */ |
| 915 png_write_find_filter(png_ptr, &(png_ptr->row_info)); | 930 png_write_find_filter(png_ptr, &(png_ptr->row_info)); |
| 916 | 931 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 { | 1035 { |
| 1021 if (png_ptr != NULL) | 1036 if (png_ptr != NULL) |
| 1022 { | 1037 { |
| 1023 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); | 1038 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
| 1024 | 1039 |
| 1025 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 1040 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
| 1026 if (png_ptr->num_chunk_list) | 1041 if (png_ptr->num_chunk_list) |
| 1027 { | 1042 { |
| 1028 png_free(png_ptr, png_ptr->chunk_list); | 1043 png_free(png_ptr, png_ptr->chunk_list); |
| 1029 png_ptr->chunk_list=NULL; | 1044 png_ptr->chunk_list=NULL; |
| 1030 png_ptr->num_chunk_list=0; | 1045 png_ptr->num_chunk_list = 0; |
| 1031 } | 1046 } |
| 1032 #endif | 1047 #endif |
| 1033 } | 1048 } |
| 1034 | 1049 |
| 1035 #ifdef PNG_USER_MEM_SUPPORTED | 1050 #ifdef PNG_USER_MEM_SUPPORTED |
| 1036 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, | 1051 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
| 1037 (png_voidp)mem_ptr); | 1052 (png_voidp)mem_ptr); |
| 1038 #else | 1053 #else |
| 1039 png_destroy_struct((png_voidp)info_ptr); | 1054 png_destroy_struct((png_voidp)info_ptr); |
| 1040 #endif | 1055 #endif |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1069 png_free_ptr free_fn; | 1084 png_free_ptr free_fn; |
| 1070 #endif | 1085 #endif |
| 1071 | 1086 |
| 1072 png_debug(1, "in png_write_destroy\n"); | 1087 png_debug(1, "in png_write_destroy\n"); |
| 1073 /* free any memory zlib uses */ | 1088 /* free any memory zlib uses */ |
| 1074 deflateEnd(&png_ptr->zstream); | 1089 deflateEnd(&png_ptr->zstream); |
| 1075 | 1090 |
| 1076 /* free our memory. png_free checks NULL for us. */ | 1091 /* free our memory. png_free checks NULL for us. */ |
| 1077 png_free(png_ptr, png_ptr->zbuf); | 1092 png_free(png_ptr, png_ptr->zbuf); |
| 1078 png_free(png_ptr, png_ptr->row_buf); | 1093 png_free(png_ptr, png_ptr->row_buf); |
| 1079 #ifndef PNG_NO_WRITE_FILTERING | 1094 #ifndef PNG_NO_WRITE_FILTER |
| 1080 png_free(png_ptr, png_ptr->prev_row); | 1095 png_free(png_ptr, png_ptr->prev_row); |
| 1081 png_free(png_ptr, png_ptr->sub_row); | 1096 png_free(png_ptr, png_ptr->sub_row); |
| 1082 png_free(png_ptr, png_ptr->up_row); | 1097 png_free(png_ptr, png_ptr->up_row); |
| 1083 png_free(png_ptr, png_ptr->avg_row); | 1098 png_free(png_ptr, png_ptr->avg_row); |
| 1084 png_free(png_ptr, png_ptr->paeth_row); | 1099 png_free(png_ptr, png_ptr->paeth_row); |
| 1085 #endif | 1100 #endif |
| 1086 | 1101 |
| 1087 #if defined(PNG_TIME_RFC1123_SUPPORTED) | 1102 #if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1088 png_free(png_ptr, png_ptr->time_buffer); | 1103 png_free(png_ptr, png_ptr->time_buffer); |
| 1089 #endif | 1104 #endif |
| 1090 | 1105 |
| 1091 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) | 1106 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 1092 png_free(png_ptr, png_ptr->prev_filters); | 1107 png_free(png_ptr, png_ptr->prev_filters); |
| 1093 png_free(png_ptr, png_ptr->filter_weights); | 1108 png_free(png_ptr, png_ptr->filter_weights); |
| 1094 png_free(png_ptr, png_ptr->inv_filter_weights); | 1109 png_free(png_ptr, png_ptr->inv_filter_weights); |
| 1095 png_free(png_ptr, png_ptr->filter_costs); | 1110 png_free(png_ptr, png_ptr->filter_costs); |
| 1096 png_free(png_ptr, png_ptr->inv_filter_costs); | 1111 png_free(png_ptr, png_ptr->inv_filter_costs); |
| 1097 #endif | 1112 #endif |
| 1098 | 1113 |
| 1099 #ifdef PNG_SETJMP_SUPPORTED | 1114 #ifdef PNG_SETJMP_SUPPORTED |
| 1100 /* reset structure */ | 1115 /* reset structure */ |
| 1101 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); | 1116 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
| 1102 #endif | 1117 #endif |
| 1103 | 1118 |
| 1104 error_fn = png_ptr->error_fn; | 1119 error_fn = png_ptr->error_fn; |
| 1105 warning_fn = png_ptr->warning_fn; | 1120 warning_fn = png_ptr->warning_fn; |
| 1106 error_ptr = png_ptr->error_ptr; | 1121 error_ptr = png_ptr->error_ptr; |
| 1107 #ifdef PNG_USER_MEM_SUPPORTED | 1122 #ifdef PNG_USER_MEM_SUPPORTED |
| 1108 free_fn = png_ptr->free_fn; | 1123 free_fn = png_ptr->free_fn; |
| 1109 #endif | 1124 #endif |
| 1110 | 1125 |
| 1111 png_memset(png_ptr, 0, png_sizeof (png_struct)); | 1126 png_memset(png_ptr, 0, png_sizeof(png_struct)); |
| 1112 | 1127 |
| 1113 png_ptr->error_fn = error_fn; | 1128 png_ptr->error_fn = error_fn; |
| 1114 png_ptr->warning_fn = warning_fn; | 1129 png_ptr->warning_fn = warning_fn; |
| 1115 png_ptr->error_ptr = error_ptr; | 1130 png_ptr->error_ptr = error_ptr; |
| 1116 #ifdef PNG_USER_MEM_SUPPORTED | 1131 #ifdef PNG_USER_MEM_SUPPORTED |
| 1117 png_ptr->free_fn = free_fn; | 1132 png_ptr->free_fn = free_fn; |
| 1118 #endif | 1133 #endif |
| 1119 | 1134 |
| 1120 #ifdef PNG_SETJMP_SUPPORTED | 1135 #ifdef PNG_SETJMP_SUPPORTED |
| 1121 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); | 1136 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
| 1122 #endif | 1137 #endif |
| 1123 } | 1138 } |
| 1124 | 1139 |
| 1125 /* Allow the application to select one or more row filters to use. */ | 1140 /* Allow the application to select one or more row filters to use. */ |
| 1126 void PNGAPI | 1141 void PNGAPI |
| 1127 png_set_filter(png_structp png_ptr, int method, int filters) | 1142 png_set_filter(png_structp png_ptr, int method, int filters) |
| 1128 { | 1143 { |
| 1129 png_debug(1, "in png_set_filter\n"); | 1144 png_debug(1, "in png_set_filter\n"); |
| 1130 if (png_ptr == NULL) | 1145 if (png_ptr == NULL) |
| 1131 return; | 1146 return; |
| 1132 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 1147 #if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 1133 if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && | 1148 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 1134 (method == PNG_INTRAPIXEL_DIFFERENCING)) | 1149 (method == PNG_INTRAPIXEL_DIFFERENCING)) |
| 1135 method = PNG_FILTER_TYPE_BASE; | 1150 method = PNG_FILTER_TYPE_BASE; |
| 1136 #endif | 1151 #endif |
| 1137 if (method == PNG_FILTER_TYPE_BASE) | 1152 if (method == PNG_FILTER_TYPE_BASE) |
| 1138 { | 1153 { |
| 1139 switch (filters & (PNG_ALL_FILTERS | 0x07)) | 1154 switch (filters & (PNG_ALL_FILTERS | 0x07)) |
| 1140 { | 1155 { |
| 1141 #ifndef PNG_NO_WRITE_FILTER | 1156 #ifndef PNG_NO_WRITE_FILTER |
| 1142 case 5: | 1157 case 5: |
| 1143 case 6: | 1158 case 6: |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 png_write_image(png_ptr, info_ptr->row_pointers); | 1538 png_write_image(png_ptr, info_ptr->row_pointers); |
| 1524 | 1539 |
| 1525 /* It is REQUIRED to call this to finish writing the rest of the file */ | 1540 /* It is REQUIRED to call this to finish writing the rest of the file */ |
| 1526 png_write_end(png_ptr, info_ptr); | 1541 png_write_end(png_ptr, info_ptr); |
| 1527 | 1542 |
| 1528 transforms = transforms; /* quiet compiler warnings */ | 1543 transforms = transforms; /* quiet compiler warnings */ |
| 1529 params = params; | 1544 params = params; |
| 1530 } | 1545 } |
| 1531 #endif | 1546 #endif |
| 1532 #endif /* PNG_WRITE_SUPPORTED */ | 1547 #endif /* PNG_WRITE_SUPPORTED */ |
| OLD | NEW |