Changeset 561 for trunk/src/3rdparty/libpng/pngwutil.c
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/3rdparty/libpng/pngwutil.c
r2 r561 2 2 /* pngwutil.c - utilities to write a PNG file 3 3 * 4 * Last changed in libpng 1.2.27 [April 29, 2008] 5 * For conditions of distribution and use, see copyright notice in png.h 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson 4 * Last changed in libpng 1.2.40 [September 10, 2009] 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 7 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 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 9 12 */ 10 13 … … 48 51 buf[0] = (png_byte)((i >> 8) & 0xff); 49 52 buf[1] = (png_byte)(i & 0xff); 53 } 54 55 /* Simple function to write the signature. If we have already written 56 * the magic bytes of the signature, or more likely, the PNG stream is 57 * being embedded into another stream and doesn't need its own signature, 58 * we should call png_set_sig_bytes() to tell libpng how many of the 59 * bytes have already been written. 60 */ 61 void /* PRIVATE */ 62 png_write_sig(png_structp png_ptr) 63 { 64 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; 65 66 /* Write the rest of the 8 byte signature */ 67 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], 68 (png_size_t)(8 - png_ptr->sig_bytes)); 69 if (png_ptr->sig_bytes < 3) 70 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; 50 71 } 51 72 … … 63 84 png_bytep data, png_size_t length) 64 85 { 65 if(png_ptr == NULL) return; 86 if (png_ptr == NULL) 87 return; 66 88 png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); 67 png_write_chunk_data(png_ptr, data, length);89 png_write_chunk_data(png_ptr, data, (png_size_t)length); 68 90 png_write_chunk_end(png_ptr); 69 91 } … … 77 99 png_uint_32 length) 78 100 { 79 png_byte buf[4]; 80 png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length); 81 if(png_ptr == NULL) return; 82 83 /* write the length */ 101 png_byte buf[8]; 102 103 png_debug2(0, "Writing %s chunk, length = %lu", chunk_name, 104 (unsigned long)length); 105 106 if (png_ptr == NULL) 107 return; 108 109 /* Write the length and the chunk name */ 84 110 png_save_uint_32(buf, length); 85 png_ write_data(png_ptr, buf, (png_size_t)4);86 87 /* write the chunkname */88 png_ write_data(png_ptr, chunk_name, (png_size_t)4);89 /* reset the crc and run it over the chunk name */111 png_memcpy(buf + 4, chunk_name, 4); 112 png_write_data(png_ptr, buf, (png_size_t)8); 113 /* Put the chunk name into png_ptr->chunk_name */ 114 png_memcpy(png_ptr->chunk_name, chunk_name, 4); 115 /* Reset the crc and run it over the chunk name */ 90 116 png_reset_crc(png_ptr); 91 117 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); … … 100 126 png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) 101 127 { 102 /* write the data, and run the CRC over it */ 103 if(png_ptr == NULL) return; 128 /* Write the data, and run the CRC over it */ 129 if (png_ptr == NULL) 130 return; 104 131 if (data != NULL && length > 0) 105 132 { 133 png_write_data(png_ptr, data, length); 134 /* Update the CRC after writing the data, 135 * in case that the user I/O routine alters it. 136 */ 106 137 png_calculate_crc(png_ptr, data, length); 107 png_write_data(png_ptr, data, length);108 138 } 109 139 } … … 115 145 png_byte buf[4]; 116 146 117 if (png_ptr == NULL) return;118 119 /* write the crc*/147 if (png_ptr == NULL) return; 148 149 /* Write the crc in a single operation */ 120 150 png_save_uint_32(buf, png_ptr->crc); 121 151 … … 123 153 } 124 154 125 /* Simple function to write the signature. If we have already written126 * the magic bytes of the signature, or more likely, the PNG stream is127 * being embedded into another stream and doesn't need its own signature,128 * we should call png_set_sig_bytes() to tell libpng how many of the129 * bytes have already been written.130 */131 void /* PRIVATE */132 png_write_sig(png_structp png_ptr)133 {134 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};135 /* write the rest of the 8 byte signature */136 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],137 (png_size_t)8 - png_ptr->sig_bytes);138 if(png_ptr->sig_bytes < 3)139 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;140 }141 142 155 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) 143 /* 144 * This pair of functions encapsulates the operation of (a) compressing a 156 /* This pair of functions encapsulates the operation of (a) compressing a 145 157 * text string, and (b) issuing it later as a series of chunk data writes. 146 158 * The compression_state structure is shared context for these functions … … 150 162 typedef struct 151 163 { 152 char *input; /* the uncompressed input data */153 int input_len; /* its length */154 int num_output_ptr; /* number of output pointers used */155 int max_output_ptr; /* size of output_ptr */156 png_charpp output_ptr; /* array of pointers to output */164 char *input; /* The uncompressed input data */ 165 int input_len; /* Its length */ 166 int num_output_ptr; /* Number of output pointers used */ 167 int max_output_ptr; /* Size of output_ptr */ 168 png_charpp output_ptr; /* Array of pointers to output */ 157 169 } compression_state; 158 170 159 /* compress given text into storage in the png_ptr structure */171 /* Compress given text into storage in the png_ptr structure */ 160 172 static int /* PRIVATE */ 161 173 png_text_compress(png_structp png_ptr, … … 171 183 comp->input_len = 0; 172 184 173 /* we may just want to pass the text right through */185 /* We may just want to pass the text right through */ 174 186 if (compression == PNG_TEXT_COMPRESSION_NONE) 175 187 { … … 205 217 */ 206 218 207 /* set up the compression buffers */219 /* Set up the compression buffers */ 208 220 png_ptr->zstream.avail_in = (uInt)text_len; 209 221 png_ptr->zstream.next_in = (Bytef *)text; … … 211 223 png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; 212 224 213 /* this is the same compression loop as in png_write_row() */225 /* This is the same compression loop as in png_write_row() */ 214 226 do 215 227 { 216 /* compress the data */228 /* Compress the data */ 217 229 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); 218 230 if (ret != Z_OK) 219 231 { 220 /* error */232 /* Error */ 221 233 if (png_ptr->zstream.msg != NULL) 222 234 png_error(png_ptr, png_ptr->zstream.msg); … … 224 236 png_error(png_ptr, "zlib error"); 225 237 } 226 /* check to see if we need more room */238 /* Check to see if we need more room */ 227 239 if (!(png_ptr->zstream.avail_out)) 228 240 { 229 /* make sure the output array has room */241 /* Make sure the output array has room */ 230 242 if (comp->num_output_ptr >= comp->max_output_ptr) 231 243 { … … 240 252 old_ptr = comp->output_ptr; 241 253 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 242 (png_uint_32) (comp->max_output_ptr *243 png_sizeof(png_charpp)));254 (png_uint_32) 255 (comp->max_output_ptr * png_sizeof(png_charpp))); 244 256 png_memcpy(comp->output_ptr, old_ptr, old_max 245 * png_sizeof 257 * png_sizeof(png_charp)); 246 258 png_free(png_ptr, old_ptr); 247 259 } 248 260 else 249 261 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 250 (png_uint_32) (comp->max_output_ptr *251 png_sizeof(png_charp)));262 (png_uint_32) 263 (comp->max_output_ptr * png_sizeof(png_charp))); 252 264 } 253 265 254 /* save the data */ 255 comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr, 266 /* Save the data */ 267 comp->output_ptr[comp->num_output_ptr] = 268 (png_charp)png_malloc(png_ptr, 256 269 (png_uint_32)png_ptr->zbuf_size); 257 270 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, … … 263 276 png_ptr->zstream.next_out = png_ptr->zbuf; 264 277 } 265 /* continue until we don't have any more to compress */278 /* Continue until we don't have any more to compress */ 266 279 } while (png_ptr->zstream.avail_in); 267 280 268 /* finish the compression */281 /* Finish the compression */ 269 282 do 270 283 { 271 /* tell zlib we are finished */284 /* Tell zlib we are finished */ 272 285 ret = deflate(&png_ptr->zstream, Z_FINISH); 273 286 274 287 if (ret == Z_OK) 275 288 { 276 /* check to see if we need more room */289 /* Check to see if we need more room */ 277 290 if (!(png_ptr->zstream.avail_out)) 278 291 { 279 /* check to make sure our output array has room */292 /* Check to make sure our output array has room */ 280 293 if (comp->num_output_ptr >= comp->max_output_ptr) 281 294 { … … 292 305 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 293 306 (png_uint_32)(comp->max_output_ptr * 294 png_sizeof (png_charpp)));307 png_sizeof(png_charp))); 295 308 png_memcpy(comp->output_ptr, old_ptr, 296 old_max * png_sizeof 309 old_max * png_sizeof(png_charp)); 297 310 png_free(png_ptr, old_ptr); 298 311 } … … 300 313 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 301 314 (png_uint_32)(comp->max_output_ptr * 302 png_sizeof 315 png_sizeof(png_charp))); 303 316 } 304 317 305 /* save offthe data */318 /* Save the data */ 306 319 comp->output_ptr[comp->num_output_ptr] = 307 (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size); 320 (png_charp)png_malloc(png_ptr, 321 (png_uint_32)png_ptr->zbuf_size); 308 322 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 309 323 png_ptr->zbuf_size); … … 317 331 else if (ret != Z_STREAM_END) 318 332 { 319 /* we got an error */333 /* We got an error */ 320 334 if (png_ptr->zstream.msg != NULL) 321 335 png_error(png_ptr, png_ptr->zstream.msg); … … 325 339 } while (ret != Z_STREAM_END); 326 340 327 /* text length is number of buffers plus last buffer */341 /* Text length is number of buffers plus last buffer */ 328 342 text_len = png_ptr->zbuf_size * comp->num_output_ptr; 329 343 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) … … 333 347 } 334 348 335 /* ship the compressed text out via chunk writes */349 /* Ship the compressed text out via chunk writes */ 336 350 static void /* PRIVATE */ 337 351 png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) … … 339 353 int i; 340 354 341 /* handle the no-compression case */355 /* Handle the no-compression case */ 342 356 if (comp->input) 343 357 { 344 358 png_write_chunk_data(png_ptr, (png_bytep)comp->input, 345 359 (png_size_t)comp->input_len); 346 347 } 348 349 /* write saved output buffers, if any */360 return; 361 } 362 363 /* Write saved output buffers, if any */ 350 364 for (i = 0; i < comp->num_output_ptr; i++) 351 365 { 352 png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],353 png_ptr->zbuf_size);366 png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], 367 (png_size_t)png_ptr->zbuf_size); 354 368 png_free(png_ptr, comp->output_ptr[i]); 355 comp->output_ptr[i]=NULL;369 comp->output_ptr[i]=NULL; 356 370 } 357 371 if (comp->max_output_ptr != 0) 358 372 png_free(png_ptr, comp->output_ptr); 359 comp->output_ptr=NULL;360 /* write anything left in zbuf */373 comp->output_ptr=NULL; 374 /* Write anything left in zbuf */ 361 375 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) 362 376 png_write_chunk_data(png_ptr, png_ptr->zbuf, 363 png_ptr->zbuf_size - png_ptr->zstream.avail_out);364 365 /* reset zlib for another zTXt/iTXt or image data */377 (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); 378 379 /* Reset zlib for another zTXt/iTXt or image data */ 366 380 deflateReset(&png_ptr->zstream); 367 381 png_ptr->zstream.data_type = Z_BINARY; … … 383 397 int ret; 384 398 385 png_byte buf[13]; /* buffer to store the IHDR info */ 386 387 png_debug(1, "in png_write_IHDR\n"); 399 png_byte buf[13]; /* Buffer to store the IHDR info */ 400 401 png_debug(1, "in png_write_IHDR"); 402 388 403 /* Check that we have valid input data from the application info */ 389 404 switch (color_type) … … 397 412 case 8: 398 413 case 16: png_ptr->channels = 1; break; 399 default: png_error(png_ptr, "Invalid bit depth for grayscale image");414 default: png_error(png_ptr, "Invalid bit depth for grayscale image"); 400 415 } 401 416 break; … … 469 484 #endif 470 485 471 /* save offthe relevent information */486 /* Save the relevent information */ 472 487 png_ptr->bit_depth = (png_byte)bit_depth; 473 488 png_ptr->color_type = (png_byte)color_type; … … 482 497 png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); 483 498 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); 484 /* set the usr info, so any transformations can modify it */499 /* Set the usr info, so any transformations can modify it */ 485 500 png_ptr->usr_width = png_ptr->width; 486 501 png_ptr->usr_bit_depth = png_ptr->bit_depth; 487 502 png_ptr->usr_channels = png_ptr->channels; 488 503 489 /* pack the header information into the buffer */504 /* Pack the header information into the buffer */ 490 505 png_save_uint_32(buf, width); 491 506 png_save_uint_32(buf + 4, height); … … 496 511 buf[12] = (png_byte)interlace_type; 497 512 498 /* write the chunk */499 png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);500 501 /* initialize zlib with PNG info */513 /* Write the chunk */ 514 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13); 515 516 /* Initialize zlib with PNG info */ 502 517 png_ptr->zstream.zalloc = png_zalloc; 503 518 png_ptr->zstream.zfree = png_zfree; … … 542 557 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 543 558 /* libpng is not interested in zstream.data_type */ 544 /* set it to a predefined value, to avoid its evaluation inside zlib */559 /* Set it to a predefined value, to avoid its evaluation inside zlib */ 545 560 png_ptr->zstream.data_type = Z_BINARY; 546 561 … … 548 563 } 549 564 550 /* write the palette. We are careful not to trust png_color to be in the565 /* Write the palette. We are careful not to trust png_color to be in the 551 566 * correct order for PNG, so people can redefine it to any convenient 552 567 * structure. … … 562 577 png_byte buf[3]; 563 578 564 png_debug(1, "in png_write_PLTE\n"); 579 png_debug(1, "in png_write_PLTE"); 580 565 581 if (( 566 582 #if defined(PNG_MNG_FEATURES_SUPPORTED) … … 588 604 589 605 png_ptr->num_palette = (png_uint_16)num_pal; 590 png_debug1(3, "num_palette = %d\n", png_ptr->num_palette); 591 592 png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3); 606 png_debug1(3, "num_palette = %d", png_ptr->num_palette); 607 608 png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, 609 (png_uint_32)(num_pal * 3)); 593 610 #ifndef PNG_NO_POINTER_INDEXING 594 611 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) … … 614 631 } 615 632 616 /* write an IDAT chunk */633 /* Write an IDAT chunk */ 617 634 void /* PRIVATE */ 618 635 png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) … … 621 638 PNG_IDAT; 622 639 #endif 623 png_debug(1, "in png_write_IDAT\n"); 640 641 png_debug(1, "in png_write_IDAT"); 624 642 625 643 /* Optimize the CMF field in the zlib stream. */ … … 631 649 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) 632 650 { 633 /* Avoid memory underflows and multiplication overflows. */ 634 /* The conditions below are practically always satisfied; 635 however, they still must be checked. */ 651 /* Avoid memory underflows and multiplication overflows. 652 * 653 * The conditions below are practically always satisfied; 654 * however, they still must be checked. 655 */ 636 656 if (length >= 2 && 637 657 png_ptr->height < 16384 && png_ptr->width < 16384) … … 662 682 } 663 683 664 png_write_chunk(png_ptr, png_IDAT, data, length);684 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length); 665 685 png_ptr->mode |= PNG_HAVE_IDAT; 666 686 } 667 687 668 /* write an IEND chunk */688 /* Write an IEND chunk */ 669 689 void /* PRIVATE */ 670 690 png_write_IEND(png_structp png_ptr) … … 673 693 PNG_IEND; 674 694 #endif 675 png_debug(1, "in png_write_IEND\n"); 676 png_write_chunk(png_ptr, png_IEND, png_bytep_NULL, 695 696 png_debug(1, "in png_write_IEND"); 697 698 png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL, 677 699 (png_size_t)0); 678 700 png_ptr->mode |= PNG_HAVE_IEND; … … 680 702 681 703 #if defined(PNG_WRITE_gAMA_SUPPORTED) 682 /* write a gAMA chunk */704 /* Write a gAMA chunk */ 683 705 #ifdef PNG_FLOATING_POINT_SUPPORTED 684 706 void /* PRIVATE */ … … 691 713 png_byte buf[4]; 692 714 693 png_debug(1, "in png_write_gAMA\n"); 715 png_debug(1, "in png_write_gAMA"); 716 694 717 /* file_gamma is saved in 1/100,000ths */ 695 718 igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5); 696 719 png_save_uint_32(buf, igamma); 697 png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);720 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); 698 721 } 699 722 #endif … … 707 730 png_byte buf[4]; 708 731 709 png_debug(1, "in png_write_gAMA\n"); 732 png_debug(1, "in png_write_gAMA"); 733 710 734 /* file_gamma is saved in 1/100,000ths */ 711 735 png_save_uint_32(buf, (png_uint_32)file_gamma); 712 png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);736 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); 713 737 } 714 738 #endif … … 716 740 717 741 #if defined(PNG_WRITE_sRGB_SUPPORTED) 718 /* write a sRGB chunk */742 /* Write a sRGB chunk */ 719 743 void /* PRIVATE */ 720 744 png_write_sRGB(png_structp png_ptr, int srgb_intent) … … 725 749 png_byte buf[1]; 726 750 727 png_debug(1, "in png_write_sRGB\n"); 728 if(srgb_intent >= PNG_sRGB_INTENT_LAST) 751 png_debug(1, "in png_write_sRGB"); 752 753 if (srgb_intent >= PNG_sRGB_INTENT_LAST) 729 754 png_warning(png_ptr, 730 755 "Invalid sRGB rendering intent specified"); 731 756 buf[0]=(png_byte)srgb_intent; 732 png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);757 png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1); 733 758 } 734 759 #endif 735 760 736 761 #if defined(PNG_WRITE_iCCP_SUPPORTED) 737 /* write an iCCP chunk */762 /* Write an iCCP chunk */ 738 763 void /* PRIVATE */ 739 764 png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, … … 748 773 int embedded_profile_len = 0; 749 774 750 png_debug(1, "in png_write_iCCP \n");775 png_debug(1, "in png_write_iCCP"); 751 776 752 777 comp.num_output_ptr = 0; … … 756 781 comp.input_len = 0; 757 782 758 if ( name == NULL ||(name_len = png_check_keyword(png_ptr, name,783 if ((name_len = png_check_keyword(png_ptr, name, 759 784 &new_name)) == 0) 760 {761 png_warning(png_ptr, "Empty keyword in iCCP chunk");762 785 return; 763 }764 786 765 787 if (compression_type != PNG_COMPRESSION_TYPE_BASE) … … 771 793 if (profile_len > 3) 772 794 embedded_profile_len = 773 ((*( (png_bytep)profile ))<<24) | 774 ((*( (png_bytep)profile+1))<<16) | 775 ((*( (png_bytep)profile+2))<< 8) | 776 ((*( (png_bytep)profile+3)) ); 795 ((*( (png_bytep)profile ))<<24) | 796 ((*( (png_bytep)profile + 1))<<16) | 797 ((*( (png_bytep)profile + 2))<< 8) | 798 ((*( (png_bytep)profile + 3)) ); 799 800 if (embedded_profile_len < 0) 801 { 802 png_warning(png_ptr, 803 "Embedded profile length in iCCP chunk is negative"); 804 png_free(png_ptr, new_name); 805 return; 806 } 777 807 778 808 if (profile_len < embedded_profile_len) 779 { 780 png_warning(png_ptr, 781 "Embedded profile length too large in iCCP chunk"); 782 return; 783 } 809 { 810 png_warning(png_ptr, 811 "Embedded profile length too large in iCCP chunk"); 812 png_free(png_ptr, new_name); 813 return; 814 } 784 815 785 816 if (profile_len > embedded_profile_len) 786 787 788 789 790 817 { 818 png_warning(png_ptr, 819 "Truncating profile to actual length in iCCP chunk"); 820 profile_len = embedded_profile_len; 821 } 791 822 792 823 if (profile_len) 793 profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len, 794 PNG_COMPRESSION_TYPE_BASE, &comp); 795 796 /* make sure we include the NULL after the name and the compression type */ 797 png_write_chunk_start(png_ptr, png_iCCP, 798 (png_uint_32)name_len+profile_len+2); 799 new_name[name_len+1]=0x00; 800 png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2); 824 profile_len = png_text_compress(png_ptr, profile, 825 (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); 826 827 /* Make sure we include the NULL after the name and the compression type */ 828 png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, 829 (png_uint_32)(name_len + profile_len + 2)); 830 new_name[name_len + 1] = 0x00; 831 png_write_chunk_data(png_ptr, (png_bytep)new_name, 832 (png_size_t)(name_len + 2)); 801 833 802 834 if (profile_len) … … 809 841 810 842 #if defined(PNG_WRITE_sPLT_SUPPORTED) 811 /* write a sPLT chunk */843 /* Write a sPLT chunk */ 812 844 void /* PRIVATE */ 813 845 png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) … … 826 858 #endif 827 859 828 png_debug(1, "in png_write_sPLT\n"); 829 if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr, 830 spalette->name, &new_name))==0) 831 { 832 png_warning(png_ptr, "Empty keyword in sPLT chunk"); 860 png_debug(1, "in png_write_sPLT"); 861 862 if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0) 833 863 return; 834 } 835 836 /* make sure we include the NULL after the name */837 png_write_chunk_start(png_ptr, png_sPLT,838 (png_uint_32)(name_len + 2 + palette_size));839 png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);840 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);841 842 /* loop through each palette entry, writing appropriately */864 865 /* Make sure we include the NULL after the name */ 866 png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, 867 (png_uint_32)(name_len + 2 + palette_size)); 868 png_write_chunk_data(png_ptr, (png_bytep)new_name, 869 (png_size_t)(name_len + 1)); 870 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1); 871 872 /* Loop through each palette entry, writing appropriately */ 843 873 #ifndef PNG_NO_POINTER_INDEXING 844 for (ep = spalette->entries; ep<spalette->entries +spalette->nentries; ep++)845 { 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 874 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++) 875 { 876 if (spalette->depth == 8) 877 { 878 entrybuf[0] = (png_byte)ep->red; 879 entrybuf[1] = (png_byte)ep->green; 880 entrybuf[2] = (png_byte)ep->blue; 881 entrybuf[3] = (png_byte)ep->alpha; 882 png_save_uint_16(entrybuf + 4, ep->frequency); 883 } 884 else 885 { 886 png_save_uint_16(entrybuf + 0, ep->red); 887 png_save_uint_16(entrybuf + 2, ep->green); 888 png_save_uint_16(entrybuf + 4, ep->blue); 889 png_save_uint_16(entrybuf + 6, ep->alpha); 890 png_save_uint_16(entrybuf + 8, ep->frequency); 891 } 892 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); 863 893 } 864 894 #else … … 866 896 for (i=0; i>spalette->nentries; i++) 867 897 { 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 png_write_chunk_data(png_ptr, entrybuf,entry_size);898 if (spalette->depth == 8) 899 { 900 entrybuf[0] = (png_byte)ep[i].red; 901 entrybuf[1] = (png_byte)ep[i].green; 902 entrybuf[2] = (png_byte)ep[i].blue; 903 entrybuf[3] = (png_byte)ep[i].alpha; 904 png_save_uint_16(entrybuf + 4, ep[i].frequency); 905 } 906 else 907 { 908 png_save_uint_16(entrybuf + 0, ep[i].red); 909 png_save_uint_16(entrybuf + 2, ep[i].green); 910 png_save_uint_16(entrybuf + 4, ep[i].blue); 911 png_save_uint_16(entrybuf + 6, ep[i].alpha); 912 png_save_uint_16(entrybuf + 8, ep[i].frequency); 913 } 914 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); 885 915 } 886 916 #endif … … 892 922 893 923 #if defined(PNG_WRITE_sBIT_SUPPORTED) 894 /* write the sBIT chunk */924 /* Write the sBIT chunk */ 895 925 void /* PRIVATE */ 896 926 png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) … … 902 932 png_size_t size; 903 933 904 png_debug(1, "in png_write_sBIT\n"); 905 /* make sure we don't depend upon the order of PNG_COLOR_8 */ 934 png_debug(1, "in png_write_sBIT"); 935 936 /* Make sure we don't depend upon the order of PNG_COLOR_8 */ 906 937 if (color_type & PNG_COLOR_MASK_COLOR) 907 938 { … … 943 974 } 944 975 945 png_write_chunk(png_ptr, png_sBIT, buf, size);976 png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size); 946 977 } 947 978 #endif 948 979 949 980 #if defined(PNG_WRITE_cHRM_SUPPORTED) 950 /* write the cHRM chunk */981 /* Write the cHRM chunk */ 951 982 #ifdef PNG_FLOATING_POINT_SUPPORTED 952 983 void /* PRIVATE */ … … 959 990 #endif 960 991 png_byte buf[32]; 961 png_uint_32 itemp; 962 963 png_debug(1, "in png_write_cHRM\n"); 964 /* each value is saved in 1/100,000ths */ 965 if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 || 966 white_x + white_y > 1.0) 967 { 968 png_warning(png_ptr, "Invalid cHRM white point specified"); 969 #if !defined(PNG_NO_CONSOLE_IO) 970 fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y); 971 #endif 972 return; 973 } 974 itemp = (png_uint_32)(white_x * 100000.0 + 0.5); 975 png_save_uint_32(buf, itemp); 976 itemp = (png_uint_32)(white_y * 100000.0 + 0.5); 977 png_save_uint_32(buf + 4, itemp); 978 979 if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0) 980 { 981 png_warning(png_ptr, "Invalid cHRM red point specified"); 982 return; 983 } 984 itemp = (png_uint_32)(red_x * 100000.0 + 0.5); 985 png_save_uint_32(buf + 8, itemp); 986 itemp = (png_uint_32)(red_y * 100000.0 + 0.5); 987 png_save_uint_32(buf + 12, itemp); 988 989 if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0) 990 { 991 png_warning(png_ptr, "Invalid cHRM green point specified"); 992 return; 993 } 994 itemp = (png_uint_32)(green_x * 100000.0 + 0.5); 995 png_save_uint_32(buf + 16, itemp); 996 itemp = (png_uint_32)(green_y * 100000.0 + 0.5); 997 png_save_uint_32(buf + 20, itemp); 998 999 if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0) 1000 { 1001 png_warning(png_ptr, "Invalid cHRM blue point specified"); 1002 return; 1003 } 1004 itemp = (png_uint_32)(blue_x * 100000.0 + 0.5); 1005 png_save_uint_32(buf + 24, itemp); 1006 itemp = (png_uint_32)(blue_y * 100000.0 + 0.5); 1007 png_save_uint_32(buf + 28, itemp); 1008 1009 png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); 992 993 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, 994 int_green_x, int_green_y, int_blue_x, int_blue_y; 995 996 png_debug(1, "in png_write_cHRM"); 997 998 int_white_x = (png_uint_32)(white_x * 100000.0 + 0.5); 999 int_white_y = (png_uint_32)(white_y * 100000.0 + 0.5); 1000 int_red_x = (png_uint_32)(red_x * 100000.0 + 0.5); 1001 int_red_y = (png_uint_32)(red_y * 100000.0 + 0.5); 1002 int_green_x = (png_uint_32)(green_x * 100000.0 + 0.5); 1003 int_green_y = (png_uint_32)(green_y * 100000.0 + 0.5); 1004 int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5); 1005 int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5); 1006 1007 #if !defined(PNG_NO_CHECK_cHRM) 1008 if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, 1009 int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) 1010 #endif 1011 { 1012 /* Each value is saved in 1/100,000ths */ 1013 1014 png_save_uint_32(buf, int_white_x); 1015 png_save_uint_32(buf + 4, int_white_y); 1016 1017 png_save_uint_32(buf + 8, int_red_x); 1018 png_save_uint_32(buf + 12, int_red_y); 1019 1020 png_save_uint_32(buf + 16, int_green_x); 1021 png_save_uint_32(buf + 20, int_green_y); 1022 1023 png_save_uint_32(buf + 24, int_blue_x); 1024 png_save_uint_32(buf + 28, int_blue_y); 1025 1026 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); 1027 } 1010 1028 } 1011 1029 #endif … … 1022 1040 png_byte buf[32]; 1023 1041 1024 png_debug(1, "in png_write_cHRM\n"); 1025 /* each value is saved in 1/100,000ths */ 1026 if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L) 1027 { 1028 png_warning(png_ptr, "Invalid fixed cHRM white point specified"); 1029 #if !defined(PNG_NO_CONSOLE_IO) 1030 fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y); 1031 #endif 1032 return; 1033 } 1034 png_save_uint_32(buf, (png_uint_32)white_x); 1035 png_save_uint_32(buf + 4, (png_uint_32)white_y); 1036 1037 if (red_x + red_y > 100000L) 1038 { 1039 png_warning(png_ptr, "Invalid cHRM fixed red point specified"); 1040 return; 1041 } 1042 png_save_uint_32(buf + 8, (png_uint_32)red_x); 1043 png_save_uint_32(buf + 12, (png_uint_32)red_y); 1044 1045 if (green_x + green_y > 100000L) 1046 { 1047 png_warning(png_ptr, "Invalid fixed cHRM green point specified"); 1048 return; 1049 } 1050 png_save_uint_32(buf + 16, (png_uint_32)green_x); 1051 png_save_uint_32(buf + 20, (png_uint_32)green_y); 1052 1053 if (blue_x + blue_y > 100000L) 1054 { 1055 png_warning(png_ptr, "Invalid fixed cHRM blue point specified"); 1056 return; 1057 } 1058 png_save_uint_32(buf + 24, (png_uint_32)blue_x); 1059 png_save_uint_32(buf + 28, (png_uint_32)blue_y); 1060 1061 png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); 1042 png_debug(1, "in png_write_cHRM"); 1043 1044 /* Each value is saved in 1/100,000ths */ 1045 #if !defined(PNG_NO_CHECK_cHRM) 1046 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, 1047 green_x, green_y, blue_x, blue_y)) 1048 #endif 1049 { 1050 png_save_uint_32(buf, (png_uint_32)white_x); 1051 png_save_uint_32(buf + 4, (png_uint_32)white_y); 1052 1053 png_save_uint_32(buf + 8, (png_uint_32)red_x); 1054 png_save_uint_32(buf + 12, (png_uint_32)red_y); 1055 1056 png_save_uint_32(buf + 16, (png_uint_32)green_x); 1057 png_save_uint_32(buf + 20, (png_uint_32)green_y); 1058 1059 png_save_uint_32(buf + 24, (png_uint_32)blue_x); 1060 png_save_uint_32(buf + 28, (png_uint_32)blue_y); 1061 1062 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); 1063 } 1062 1064 } 1063 1065 #endif … … 1065 1067 1066 1068 #if defined(PNG_WRITE_tRNS_SUPPORTED) 1067 /* write the tRNS chunk */1069 /* Write the tRNS chunk */ 1068 1070 void /* PRIVATE */ 1069 1071 png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, … … 1075 1077 png_byte buf[6]; 1076 1078 1077 png_debug(1, "in png_write_tRNS\n"); 1079 png_debug(1, "in png_write_tRNS"); 1080 1078 1081 if (color_type == PNG_COLOR_TYPE_PALETTE) 1079 1082 { 1080 1083 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) 1081 1084 { 1082 png_warning(png_ptr, "Invalid number of transparent colors specified");1085 png_warning(png_ptr, "Invalid number of transparent colors specified"); 1083 1086 return; 1084 1087 } 1085 /* write the chunk out as it is */ 1086 png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans); 1088 /* Write the chunk out as it is */ 1089 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, 1090 (png_size_t)num_trans); 1087 1091 } 1088 1092 else if (color_type == PNG_COLOR_TYPE_GRAY) 1089 1093 { 1090 /* one 16 bit value */1091 if (tran->gray >= (1 << png_ptr->bit_depth))1094 /* One 16 bit value */ 1095 if (tran->gray >= (1 << png_ptr->bit_depth)) 1092 1096 { 1093 1097 png_warning(png_ptr, … … 1096 1100 } 1097 1101 png_save_uint_16(buf, tran->gray); 1098 png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);1102 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2); 1099 1103 } 1100 1104 else if (color_type == PNG_COLOR_TYPE_RGB) 1101 1105 { 1102 /* three 16 bit values */1106 /* Three 16 bit values */ 1103 1107 png_save_uint_16(buf, tran->red); 1104 1108 png_save_uint_16(buf + 2, tran->green); 1105 1109 png_save_uint_16(buf + 4, tran->blue); 1106 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))1107 1108 1109 1110 1111 1112 png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);1110 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) 1111 { 1112 png_warning(png_ptr, 1113 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); 1114 return; 1115 } 1116 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6); 1113 1117 } 1114 1118 else … … 1120 1124 1121 1125 #if defined(PNG_WRITE_bKGD_SUPPORTED) 1122 /* write the background chunk */1126 /* Write the background chunk */ 1123 1127 void /* PRIVATE */ 1124 1128 png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) … … 1129 1133 png_byte buf[6]; 1130 1134 1131 png_debug(1, "in png_write_bKGD\n"); 1135 png_debug(1, "in png_write_bKGD"); 1136 1132 1137 if (color_type == PNG_COLOR_TYPE_PALETTE) 1133 1138 { … … 1137 1142 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && 1138 1143 #endif 1139 back->index > png_ptr->num_palette)1144 back->index >= png_ptr->num_palette) 1140 1145 { 1141 1146 png_warning(png_ptr, "Invalid background palette index"); … … 1143 1148 } 1144 1149 buf[0] = back->index; 1145 png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);1150 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1); 1146 1151 } 1147 1152 else if (color_type & PNG_COLOR_MASK_COLOR) … … 1150 1155 png_save_uint_16(buf + 2, back->green); 1151 1156 png_save_uint_16(buf + 4, back->blue); 1152 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))1153 1154 1155 1156 1157 1158 png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);1157 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) 1158 { 1159 png_warning(png_ptr, 1160 "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); 1161 return; 1162 } 1163 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6); 1159 1164 } 1160 1165 else 1161 1166 { 1162 if (back->gray >= (1 << png_ptr->bit_depth))1167 if (back->gray >= (1 << png_ptr->bit_depth)) 1163 1168 { 1164 1169 png_warning(png_ptr, … … 1167 1172 } 1168 1173 png_save_uint_16(buf, back->gray); 1169 png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);1174 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2); 1170 1175 } 1171 1176 } … … 1173 1178 1174 1179 #if defined(PNG_WRITE_hIST_SUPPORTED) 1175 /* write the histogram */1180 /* Write the histogram */ 1176 1181 void /* PRIVATE */ 1177 1182 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) … … 1183 1188 png_byte buf[3]; 1184 1189 1185 png_debug(1, "in png_write_hIST\n"); 1190 png_debug(1, "in png_write_hIST"); 1191 1186 1192 if (num_hist > (int)png_ptr->num_palette) 1187 1193 { 1188 png_debug2(3, "num_hist = %d, num_palette = %d \n", num_hist,1194 png_debug2(3, "num_hist = %d, num_palette = %d", num_hist, 1189 1195 png_ptr->num_palette); 1190 1196 png_warning(png_ptr, "Invalid number of histogram entries specified"); … … 1192 1198 } 1193 1199 1194 png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); 1200 png_write_chunk_start(png_ptr, (png_bytep)png_hIST, 1201 (png_uint_32)(num_hist * 2)); 1195 1202 for (i = 0; i < num_hist; i++) 1196 1203 { … … 1222 1229 int kwarn=0; 1223 1230 1224 png_debug(1, "in png_check_keyword\n"); 1231 png_debug(1, "in png_check_keyword"); 1232 1225 1233 *new_key = NULL; 1226 1234 … … 1231 1239 } 1232 1240 1233 png_debug1(2, "Keyword to be checked is '%s' \n", key);1241 png_debug1(2, "Keyword to be checked is '%s'", key); 1234 1242 1235 1243 *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); … … 1272 1280 while (*kp == ' ') 1273 1281 { 1274 *(kp--) = '\0';1275 key_len--;1282 *(kp--) = '\0'; 1283 key_len--; 1276 1284 } 1277 1285 } … … 1285 1293 while (*kp == ' ') 1286 1294 { 1287 kp++;1288 key_len--;1289 } 1290 } 1291 1292 png_debug1(2, "Checking for multiple internal spaces in '%s' \n", kp);1295 kp++; 1296 key_len--; 1297 } 1298 } 1299 1300 png_debug1(2, "Checking for multiple internal spaces in '%s'", kp); 1293 1301 1294 1302 /* Remove multiple internal spaces. */ … … 1312 1320 } 1313 1321 *dp = '\0'; 1314 if (kwarn)1322 if (kwarn) 1315 1323 png_warning(png_ptr, "extra interior spaces removed from keyword"); 1316 1324 … … 1318 1326 { 1319 1327 png_free(png_ptr, *new_key); 1320 *new_key=NULL;1328 *new_key=NULL; 1321 1329 png_warning(png_ptr, "Zero length keyword"); 1322 1330 } … … 1325 1333 { 1326 1334 png_warning(png_ptr, "keyword length must be 1 - 79 characters"); 1327 new_key[79] = '\0';1335 (*new_key)[79] = '\0'; 1328 1336 key_len = 79; 1329 1337 } … … 1334 1342 1335 1343 #if defined(PNG_WRITE_tEXt_SUPPORTED) 1336 /* write a tEXt chunk */1344 /* Write a tEXt chunk */ 1337 1345 void /* PRIVATE */ 1338 1346 png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, … … 1345 1353 png_charp new_key; 1346 1354 1347 png_debug(1, "in png_write_tEXt\n"); 1348 if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1349 { 1350 png_warning(png_ptr, "Empty keyword in tEXt chunk"); 1355 png_debug(1, "in png_write_tEXt"); 1356 1357 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1351 1358 return; 1352 }1353 1359 1354 1360 if (text == NULL || *text == '\0') … … 1357 1363 text_len = png_strlen(text); 1358 1364 1359 /* make sure we include the 0 after the key */ 1360 png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1); 1365 /* Make sure we include the 0 after the key */ 1366 png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, 1367 (png_uint_32)(key_len + text_len + 1)); 1361 1368 /* 1362 1369 * We leave it to the application to meet PNG-1.0 requirements on the … … 1365 1372 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. 1366 1373 */ 1367 png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); 1374 png_write_chunk_data(png_ptr, (png_bytep)new_key, 1375 (png_size_t)(key_len + 1)); 1368 1376 if (text_len) 1369 png_write_chunk_data(png_ptr, (png_bytep)text, text_len);1377 png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len); 1370 1378 1371 1379 png_write_chunk_end(png_ptr); … … 1375 1383 1376 1384 #if defined(PNG_WRITE_zTXt_SUPPORTED) 1377 /* write a compressed text chunk */1385 /* Write a compressed text chunk */ 1378 1386 void /* PRIVATE */ 1379 1387 png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, … … 1388 1396 compression_state comp; 1389 1397 1390 png_debug(1, "in png_write_zTXt \n");1398 png_debug(1, "in png_write_zTXt"); 1391 1399 1392 1400 comp.num_output_ptr = 0; … … 1396 1404 comp.input_len = 0; 1397 1405 1398 if ( key == NULL ||(key_len = png_check_keyword(png_ptr, key, &new_key))==0)1399 { 1400 png_ warning(png_ptr, "Empty keyword in zTXt chunk");1406 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1407 { 1408 png_free(png_ptr, new_key); 1401 1409 return; 1402 1410 } … … 1411 1419 text_len = png_strlen(text); 1412 1420 1413 /* compute the compressed data; do it now for the length */1421 /* Compute the compressed data; do it now for the length */ 1414 1422 text_len = png_text_compress(png_ptr, text, text_len, compression, 1415 1423 &comp); 1416 1424 1417 /* write start of chunk */ 1418 png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32) 1419 (key_len+text_len+2)); 1420 /* write key */ 1421 png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); 1425 /* Write start of chunk */ 1426 png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, 1427 (png_uint_32)(key_len+text_len + 2)); 1428 /* Write key */ 1429 png_write_chunk_data(png_ptr, (png_bytep)new_key, 1430 (png_size_t)(key_len + 1)); 1422 1431 png_free(png_ptr, new_key); 1423 1432 1424 1433 buf[0] = (png_byte)compression; 1425 /* write compression */1434 /* Write compression */ 1426 1435 png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1); 1427 /* write the compressed data */1436 /* Write the compressed data */ 1428 1437 png_write_compressed_data_out(png_ptr, &comp); 1429 1438 1430 /* close the chunk */1439 /* Close the chunk */ 1431 1440 png_write_chunk_end(png_ptr); 1432 1441 } … … 1434 1443 1435 1444 #if defined(PNG_WRITE_iTXt_SUPPORTED) 1436 /* write an iTXt chunk */1445 /* Write an iTXt chunk */ 1437 1446 void /* PRIVATE */ 1438 1447 png_write_iTXt(png_structp png_ptr, int compression, png_charp key, … … 1443 1452 #endif 1444 1453 png_size_t lang_len, key_len, lang_key_len, text_len; 1445 png_charp new_lang, new_key; 1454 png_charp new_lang; 1455 png_charp new_key = NULL; 1446 1456 png_byte cbuf[2]; 1447 1457 compression_state comp; 1448 1458 1449 png_debug(1, "in png_write_iTXt \n");1459 png_debug(1, "in png_write_iTXt"); 1450 1460 1451 1461 comp.num_output_ptr = 0; … … 1454 1464 comp.input = NULL; 1455 1465 1456 if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1457 { 1458 png_warning(png_ptr, "Empty keyword in iTXt chunk"); 1466 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1459 1467 return; 1460 } 1461 if ( lang == NULL ||(lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)1468 1469 if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0) 1462 1470 { 1463 1471 png_warning(png_ptr, "Empty language field in iTXt chunk"); … … 1467 1475 1468 1476 if (lang_key == NULL) 1469 lang_key_len = 0;1477 lang_key_len = 0; 1470 1478 else 1471 lang_key_len = png_strlen(lang_key);1479 lang_key_len = png_strlen(lang_key); 1472 1480 1473 1481 if (text == NULL) 1474 1482 text_len = 0; 1475 1483 else 1476 text_len = png_strlen(text);1477 1478 /* compute the compressed data; do it now for the length */1484 text_len = png_strlen(text); 1485 1486 /* Compute the compressed data; do it now for the length */ 1479 1487 text_len = png_text_compress(png_ptr, text, text_len, compression-2, 1480 1488 &comp); 1481 1489 1482 1490 1483 /* make sure we include the compression flag, the compression byte,1491 /* Make sure we include the compression flag, the compression byte, 1484 1492 * and the NULs after the key, lang, and lang_key parts */ 1485 1493 1486 png_write_chunk_start(png_ptr, png_iTXt,1494 png_write_chunk_start(png_ptr, (png_bytep)png_iTXt, 1487 1495 (png_uint_32)( 1488 1496 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ … … 1492 1500 + text_len)); 1493 1501 1494 /* 1495 * We leave it to the application to meet PNG-1.0 requirements on the 1502 /* We leave it to the application to meet PNG-1.0 requirements on the 1496 1503 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of 1497 1504 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. 1498 1505 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. 1499 1506 */ 1500 png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); 1501 1502 /* set the compression flag */ 1507 png_write_chunk_data(png_ptr, (png_bytep)new_key, 1508 (png_size_t)(key_len + 1)); 1509 1510 /* Set the compression flag */ 1503 1511 if (compression == PNG_ITXT_COMPRESSION_NONE || \ 1504 1512 compression == PNG_TEXT_COMPRESSION_NONE) … … 1506 1514 else /* compression == PNG_ITXT_COMPRESSION_zTXt */ 1507 1515 cbuf[0] = 1; 1508 /* set the compression method */1516 /* Set the compression method */ 1509 1517 cbuf[1] = 0; 1510 png_write_chunk_data(png_ptr, cbuf, 2);1518 png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); 1511 1519 1512 1520 cbuf[0] = 0; 1513 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1); 1514 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1); 1521 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), 1522 (png_size_t)(lang_len + 1)); 1523 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), 1524 (png_size_t)(lang_key_len + 1)); 1515 1525 png_write_compressed_data_out(png_ptr, &comp); 1516 1526 … … 1522 1532 1523 1533 #if defined(PNG_WRITE_oFFs_SUPPORTED) 1524 /* write the oFFs chunk */1534 /* Write the oFFs chunk */ 1525 1535 void /* PRIVATE */ 1526 1536 png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, … … 1532 1542 png_byte buf[9]; 1533 1543 1534 png_debug(1, "in png_write_oFFs\n"); 1544 png_debug(1, "in png_write_oFFs"); 1545 1535 1546 if (unit_type >= PNG_OFFSET_LAST) 1536 1547 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); … … 1540 1551 buf[8] = (png_byte)unit_type; 1541 1552 1542 png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);1553 png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9); 1543 1554 } 1544 1555 #endif 1545 1556 #if defined(PNG_WRITE_pCAL_SUPPORTED) 1546 /* write the pCAL chunk (described in the PNG extensions document) */1557 /* Write the pCAL chunk (described in the PNG extensions document) */ 1547 1558 void /* PRIVATE */ 1548 1559 png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, … … 1558 1569 int i; 1559 1570 1560 png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams); 1571 png_debug1(1, "in png_write_pCAL (%d parameters)", nparams); 1572 1561 1573 if (type >= PNG_EQUATION_LAST) 1562 1574 png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); 1563 1575 1564 1576 purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; 1565 png_debug1(3, "pCAL purpose length = %d \n", (int)purpose_len);1577 png_debug1(3, "pCAL purpose length = %d", (int)purpose_len); 1566 1578 units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); 1567 png_debug1(3, "pCAL units length = %d \n", (int)units_len);1579 png_debug1(3, "pCAL units length = %d", (int)units_len); 1568 1580 total_len = purpose_len + units_len + 10; 1569 1581 1570 params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams1571 *png_sizeof(png_uint_32)));1582 params_len = (png_uint_32p)png_malloc(png_ptr, 1583 (png_uint_32)(nparams * png_sizeof(png_uint_32))); 1572 1584 1573 1585 /* Find the length of each parameter, making sure we don't count the … … 1576 1588 { 1577 1589 params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); 1578 png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]); 1590 png_debug2(3, "pCAL parameter %d length = %lu", i, 1591 (unsigned long) params_len[i]); 1579 1592 total_len += (png_size_t)params_len[i]; 1580 1593 } 1581 1594 1582 png_debug1(3, "pCAL total length = %d\n", (int)total_len); 1583 png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len); 1584 png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len); 1595 png_debug1(3, "pCAL total length = %d", (int)total_len); 1596 png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len); 1597 png_write_chunk_data(png_ptr, (png_bytep)new_purpose, 1598 (png_size_t)purpose_len); 1585 1599 png_save_int_32(buf, X0); 1586 1600 png_save_int_32(buf + 4, X1); … … 1604 1618 1605 1619 #if defined(PNG_WRITE_sCAL_SUPPORTED) 1606 /* write the sCAL chunk */1620 /* Write the sCAL chunk */ 1607 1621 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) 1608 1622 void /* PRIVATE */ … … 1615 1629 png_size_t total_len; 1616 1630 1617 png_debug(1, "in png_write_sCAL \n");1631 png_debug(1, "in png_write_sCAL"); 1618 1632 1619 1633 buf[0] = (char)unit; … … 1640 1654 #endif 1641 1655 1642 png_debug1(3, "sCAL total length = %u \n", (unsigned int)total_len);1643 png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);1656 png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); 1657 png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len); 1644 1658 } 1645 1659 #else … … 1655 1669 png_size_t wlen, hlen, total_len; 1656 1670 1657 png_debug(1, "in png_write_sCAL_s \n");1671 png_debug(1, "in png_write_sCAL_s"); 1658 1672 1659 1673 wlen = png_strlen(width); … … 1667 1681 1668 1682 buf[0] = (png_byte)unit; 1669 png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */1670 png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */1671 1672 png_debug1(3, "sCAL total length = %u \n", (unsigned int)total_len);1673 png_write_chunk(png_ptr, png_sCAL, buf, total_len);1683 png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ 1684 png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ 1685 1686 png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); 1687 png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len); 1674 1688 } 1675 1689 #endif … … 1678 1692 1679 1693 #if defined(PNG_WRITE_pHYs_SUPPORTED) 1680 /* write the pHYs chunk */1694 /* Write the pHYs chunk */ 1681 1695 void /* PRIVATE */ 1682 1696 png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, … … 1689 1703 png_byte buf[9]; 1690 1704 1691 png_debug(1, "in png_write_pHYs\n"); 1705 png_debug(1, "in png_write_pHYs"); 1706 1692 1707 if (unit_type >= PNG_RESOLUTION_LAST) 1693 1708 png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); … … 1697 1712 buf[8] = (png_byte)unit_type; 1698 1713 1699 png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);1714 png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9); 1700 1715 } 1701 1716 #endif … … 1713 1728 png_byte buf[7]; 1714 1729 1715 png_debug(1, "in png_write_tIME\n"); 1730 png_debug(1, "in png_write_tIME"); 1731 1716 1732 if (mod_time->month > 12 || mod_time->month < 1 || 1717 1733 mod_time->day > 31 || mod_time->day < 1 || … … 1729 1745 buf[6] = mod_time->second; 1730 1746 1731 png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);1732 } 1733 #endif 1734 1735 /* initializes the row writing capability of libpng */1747 png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7); 1748 } 1749 #endif 1750 1751 /* Initializes the row writing capability of libpng */ 1736 1752 void /* PRIVATE */ 1737 1753 png_write_start_row(png_structp png_ptr) … … 1739 1755 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1740 1756 #ifdef PNG_USE_LOCAL_ARRAYS 1741 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */1742 1743 /* start of interlace block */1757 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1758 1759 /* Start of interlace block */ 1744 1760 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1745 1761 1746 /* offset to next interlace block */1762 /* Offset to next interlace block */ 1747 1763 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1748 1764 1749 /* start of interlace block in the y direction */1765 /* Start of interlace block in the y direction */ 1750 1766 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 1751 1767 1752 /* offset to next interlace block in the y direction */1768 /* Offset to next interlace block in the y direction */ 1753 1769 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1754 1770 #endif … … 1757 1773 png_size_t buf_size; 1758 1774 1759 png_debug(1, "in png_write_start_row\n"); 1775 png_debug(1, "in png_write_start_row"); 1776 1760 1777 buf_size = (png_size_t)(PNG_ROWBYTES( 1761 png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1); 1762 1763 /* set up row buffer */ 1764 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); 1778 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); 1779 1780 /* Set up row buffer */ 1781 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, 1782 (png_uint_32)buf_size); 1765 1783 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; 1766 1784 1767 #ifndef PNG_NO_WRITE_FILTER ING1768 /* set up filtering buffer, if using this filter */1785 #ifndef PNG_NO_WRITE_FILTER 1786 /* Set up filtering buffer, if using this filter */ 1769 1787 if (png_ptr->do_filter & PNG_FILTER_SUB) 1770 1788 { 1771 1789 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, 1772 (png_ ptr->rowbytes + 1));1790 (png_uint_32)(png_ptr->rowbytes + 1)); 1773 1791 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; 1774 1792 } … … 1777 1795 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) 1778 1796 { 1779 /* set up previous row buffer */ 1780 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); 1781 png_memset(png_ptr->prev_row, 0, buf_size); 1797 /* Set up previous row buffer */ 1798 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, 1799 (png_uint_32)buf_size); 1800 png_memset(png_ptr->prev_row, 0, buf_size); 1782 1801 1783 1802 if (png_ptr->do_filter & PNG_FILTER_UP) 1784 1803 { 1785 1804 png_ptr->up_row = (png_bytep)png_malloc(png_ptr, 1786 1805 (png_uint_32)(png_ptr->rowbytes + 1)); 1787 1806 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; 1788 1807 } … … 1791 1810 { 1792 1811 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, 1793 1812 (png_uint_32)(png_ptr->rowbytes + 1)); 1794 1813 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; 1795 1814 } … … 1798 1817 { 1799 1818 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 1800 1819 (png_uint_32)(png_ptr->rowbytes + 1)); 1801 1820 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 1802 1821 } 1803 #endif /* PNG_NO_WRITE_FILTERING */ 1804 } 1822 } 1823 #endif /* PNG_NO_WRITE_FILTER */ 1805 1824 1806 1825 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1807 /* if interlaced, we need to set up width and height of pass */1826 /* If interlaced, we need to set up width and height of pass */ 1808 1827 if (png_ptr->interlaced) 1809 1828 { … … 1837 1856 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1838 1857 #ifdef PNG_USE_LOCAL_ARRAYS 1839 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */1840 1841 /* start of interlace block */1858 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1859 1860 /* Start of interlace block */ 1842 1861 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1843 1862 1844 /* offset to next interlace block */1863 /* Offset to next interlace block */ 1845 1864 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1846 1865 1847 /* start of interlace block in the y direction */1866 /* Start of interlace block in the y direction */ 1848 1867 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 1849 1868 1850 /* offset to next interlace block in the y direction */1869 /* Offset to next interlace block in the y direction */ 1851 1870 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1852 1871 #endif … … 1855 1874 int ret; 1856 1875 1857 png_debug(1, "in png_write_finish_row\n"); 1858 /* next row */ 1876 png_debug(1, "in png_write_finish_row"); 1877 1878 /* Next row */ 1859 1879 png_ptr->row_number++; 1860 1880 1861 /* see if we are done */1881 /* See if we are done */ 1862 1882 if (png_ptr->row_number < png_ptr->num_rows) 1863 1883 return; 1864 1884 1865 1885 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1866 /* if interlaced, go to next pass */1886 /* If interlaced, go to next pass */ 1867 1887 if (png_ptr->interlaced) 1868 1888 { … … 1874 1894 else 1875 1895 { 1876 /* loop until we find a non-zero width or height pass */1896 /* Loop until we find a non-zero width or height pass */ 1877 1897 do 1878 1898 { … … 1894 1914 } 1895 1915 1896 /* reset the row above the image for the next pass */1916 /* Reset the row above the image for the next pass */ 1897 1917 if (png_ptr->pass < 7) 1898 1918 { … … 1900 1920 png_memset(png_ptr->prev_row, 0, 1901 1921 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* 1902 png_ptr->usr_bit_depth, png_ptr->width))+1);1922 png_ptr->usr_bit_depth, png_ptr->width)) + 1); 1903 1923 return; 1904 1924 } … … 1906 1926 #endif 1907 1927 1908 /* if we get here, we've just written the last row, so we need1928 /* If we get here, we've just written the last row, so we need 1909 1929 to flush the compressor */ 1910 1930 do 1911 1931 { 1912 /* tell the compressor we are done */1932 /* Tell the compressor we are done */ 1913 1933 ret = deflate(&png_ptr->zstream, Z_FINISH); 1914 /* check for an error */1934 /* Check for an error */ 1915 1935 if (ret == Z_OK) 1916 1936 { 1917 /* check to see if we need more room */1937 /* Check to see if we need more room */ 1918 1938 if (!(png_ptr->zstream.avail_out)) 1919 1939 { … … 1932 1952 } while (ret != Z_STREAM_END); 1933 1953 1934 /* write any extra space */1954 /* Write any extra space */ 1935 1955 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) 1936 1956 { … … 1955 1975 { 1956 1976 #ifdef PNG_USE_LOCAL_ARRAYS 1957 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */1958 1959 /* start of interlace block */1977 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1978 1979 /* Start of interlace block */ 1960 1980 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1961 1981 1962 /* offset to next interlace block */1982 /* Offset to next interlace block */ 1963 1983 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1964 1984 #endif 1965 1985 1966 png_debug(1, "in png_do_write_interlace\n"); 1967 /* we don't have to do anything on the last pass (6) */ 1986 png_debug(1, "in png_do_write_interlace"); 1987 1988 /* We don't have to do anything on the last pass (6) */ 1968 1989 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1969 1990 if (row != NULL && row_info != NULL && pass < 6) … … 1972 1993 #endif 1973 1994 { 1974 /* each pixel depth is handled separately */1995 /* Each pixel depth is handled separately */ 1975 1996 switch (row_info->pixel_depth) 1976 1997 { … … 2083 2104 png_size_t pixel_bytes; 2084 2105 2085 /* start at the beginning */2106 /* Start at the beginning */ 2086 2107 dp = row; 2087 /* find out how many bytes each pixel takes up */2108 /* Find out how many bytes each pixel takes up */ 2088 2109 pixel_bytes = (row_info->pixel_depth >> 3); 2089 /* loop through the row, only looking at the pixels that2110 /* Loop through the row, only looking at the pixels that 2090 2111 matter */ 2091 2112 for (i = png_pass_start[pass]; i < row_width; 2092 2113 i += png_pass_inc[pass]) 2093 2114 { 2094 /* find out where the original pixel is */2115 /* Find out where the original pixel is */ 2095 2116 sp = row + (png_size_t)i * pixel_bytes; 2096 /* move the pixel */2117 /* Move the pixel */ 2097 2118 if (dp != sp) 2098 2119 png_memcpy(dp, sp, pixel_bytes); 2099 /* next pixel */2120 /* Next pixel */ 2100 2121 dp += pixel_bytes; 2101 2122 } … … 2103 2124 } 2104 2125 } 2105 /* set new row width */2126 /* Set new row width */ 2106 2127 row_info->width = (row_info->width + 2107 2128 png_pass_inc[pass] - 1 - … … 2131 2152 png_byte filter_to_do = png_ptr->do_filter; 2132 2153 png_uint_32 row_bytes = row_info->rowbytes; 2133 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2154 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2134 2155 int num_p_filters = (int)png_ptr->num_prev_filters; 2135 #endif 2136 2137 png_debug(1, "in png_write_find_filter\n"); 2138 /* find out how many bytes offset each pixel is */ 2156 #endif 2157 2158 png_debug(1, "in png_write_find_filter"); 2159 2160 /* Find out how many bytes offset each pixel is */ 2139 2161 bpp = (row_info->pixel_depth + 7) >> 3; 2140 2162 … … 2223 2245 } 2224 2246 2225 /* sub filter */2247 /* Sub filter */ 2226 2248 if (filter_to_do == PNG_FILTER_SUB) 2227 /* it's the only filter so no testing is needed */2249 /* It's the only filter so no testing is needed */ 2228 2250 { 2229 2251 png_bytep rp, lp, dp; … … 2340 2362 } 2341 2363 2342 /* up filter */2364 /* Up filter */ 2343 2365 if (filter_to_do == PNG_FILTER_UP) 2344 2366 { … … 2443 2465 } 2444 2466 2445 /* avg filter */2467 /* Avg filter */ 2446 2468 if (filter_to_do == PNG_FILTER_AVG) 2447 2469 { … … 2744 2766 png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) 2745 2767 { 2746 png_debug(1, "in png_write_filtered_row\n"); 2747 png_debug1(2, "filter = %d\n", filtered_row[0]); 2748 /* set up the zlib input buffer */ 2768 png_debug(1, "in png_write_filtered_row"); 2769 2770 png_debug1(2, "filter = %d", filtered_row[0]); 2771 /* Set up the zlib input buffer */ 2749 2772 2750 2773 png_ptr->zstream.next_in = filtered_row; 2751 2774 png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1; 2752 /* repeat until we have compressed all the data */2775 /* Repeat until we have compressed all the data */ 2753 2776 do 2754 2777 { 2755 int ret; /* return of zlib */2756 2757 /* compress the data */2778 int ret; /* Return of zlib */ 2779 2780 /* Compress the data */ 2758 2781 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); 2759 /* check for compression errors */2782 /* Check for compression errors */ 2760 2783 if (ret != Z_OK) 2761 2784 { … … 2766 2789 } 2767 2790 2768 /* see if it is time to write another IDAT */2791 /* See if it is time to write another IDAT */ 2769 2792 if (!(png_ptr->zstream.avail_out)) 2770 2793 { 2771 /* write the IDAT and reset the zlib output buffer */2794 /* Write the IDAT and reset the zlib output buffer */ 2772 2795 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); 2773 2796 png_ptr->zstream.next_out = png_ptr->zbuf; 2774 2797 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 2775 2798 } 2776 /* repeat until all data has been compressed */2799 /* Repeat until all data has been compressed */ 2777 2800 } while (png_ptr->zstream.avail_in); 2778 2801 2779 /* swap the current and previous rows */2802 /* Swap the current and previous rows */ 2780 2803 if (png_ptr->prev_row != NULL) 2781 2804 { … … 2787 2810 } 2788 2811 2789 /* finish row - updates counters and flushes zlib if last row */2812 /* Finish row - updates counters and flushes zlib if last row */ 2790 2813 png_write_finish_row(png_ptr); 2791 2814
Note:
See TracChangeset
for help on using the changeset viewer.