Changeset 846 for trunk/src/3rdparty/libpng/pngwrite.c
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/3rdparty/libpng/pngwrite.c
r561 r846 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.4.0 [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.) … … 13 13 14 14 /* Get internal access to png.h */ 15 #define PNG_ INTERNAL15 #define PNG_NO_PEDANTIC_WARNINGS 16 16 #include "png.h" 17 17 #ifdef PNG_WRITE_SUPPORTED 18 #include "pngpriv.h" 18 19 19 20 /* Writes all the PNG information. This is the suggested way to use the … … 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++)160 info_ptr->trans [j] = (png_byte)(255 - info_ptr->trans[j]);161 } 162 #endif 163 png_write_tRNS(png_ptr, info_ptr->trans , &(info_ptr->trans_values),162 for (j = 0; j<(int)info_ptr->num_trans; j++) 163 info_ptr->trans_alpha[j] = (png_byte)(255 - info_ptr->trans_alpha[j]); 164 } 165 #endif 166 png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color), 164 167 info_ptr->num_trans, info_ptr->color_type); 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); … … 199 202 #else /* !WRITE_sCAL */ 200 203 png_warning(png_ptr, 201 "png_write_sCAL not supported; sCAL chunk not written .");204 "png_write_sCAL not supported; sCAL chunk not written"); 202 205 #endif /* WRITE_sCAL */ 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 283 284 285 286 287 288 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 341 342 343 344 345 346 347 #else 348 349 #endif 350 351 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 385 386 387 388 389 390 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 … … 455 459 #ifdef PNG_USER_MEM_SUPPORTED 456 460 return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, 457 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));461 warn_fn, NULL, NULL, NULL)); 458 462 } 459 463 … … 465 469 { 466 470 #endif /* PNG_USER_MEM_SUPPORTED */ 471 volatile int png_cleanup_needed = 0; 467 472 #ifdef PNG_SETJMP_SUPPORTED 468 469 #endif 470 473 volatile 474 #endif 475 png_structp png_ptr; 471 476 #ifdef PNG_SETJMP_SUPPORTED 472 477 #ifdef USE_FAR_KEYWORD … … 475 480 #endif 476 481 int i; 482 477 483 png_debug(1, "in png_create_write_struct"); 484 478 485 #ifdef PNG_USER_MEM_SUPPORTED 479 486 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, … … 487 494 /* Added at libpng-1.2.6 */ 488 495 #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;496 png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 497 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 491 498 #endif 492 499 493 500 #ifdef PNG_SETJMP_SUPPORTED 501 /* Applications that neglect to set up their own setjmp() and then 502 encounter a png_error() will longjmp here. Since the jmpbuf is 503 then meaningless we abort instead of returning. */ 494 504 #ifdef USE_FAR_KEYWORD 495 505 if (setjmp(jmpbuf)) 496 506 #else 497 if (setjmp(png_ptr->jmpbuf)) 498 #endif 499 { 500 png_free(png_ptr, png_ptr->zbuf); 501 png_ptr->zbuf=NULL; 502 png_destroy_struct(png_ptr); 503 return (NULL); 504 } 507 if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */ 508 #endif 505 509 #ifdef USE_FAR_KEYWORD 506 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); 507 #endif 510 png_memcpy(png_jmpbuf(png_ptr), jmpbuf, png_sizeof(jmp_buf)); 511 #endif 512 PNG_ABORT(); 508 513 #endif 509 514 … … 515 520 if (user_png_ver) 516 521 { 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++]);522 i = 0; 523 do 524 { 525 if (user_png_ver[i] != png_libpng_ver[i]) 526 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 527 } while (png_libpng_ver[i++]); 523 528 } 524 529 … … 534 539 (user_png_ver[0] == '0' && user_png_ver[2] < '9')) 535 540 { 536 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)541 #ifdef PNG_STDIO_SUPPORTED 537 542 char msg[80]; 538 543 if (user_png_ver) 539 544 { 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);545 png_snprintf(msg, 80, 546 "Application was compiled with png.h from libpng-%.20s", 547 user_png_ver); 548 png_warning(png_ptr, msg); 544 549 } 545 550 png_snprintf(msg, 80, … … 549 554 #endif 550 555 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 551 png_ptr->flags =0;552 #endif 553 png_ error(png_ptr,556 png_ptr->flags = 0; 557 #endif 558 png_warning(png_ptr, 554 559 "Incompatible libpng version in application and library"); 560 png_cleanup_needed = 1; 555 561 } 556 562 } … … 558 564 /* Initialize zbuf - compression buffer */ 559 565 png_ptr->zbuf_size = PNG_ZBUF_SIZE; 560 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 561 (png_uint_32)png_ptr->zbuf_size); 562 563 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, 564 png_flush_ptr_NULL); 565 566 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 566 if (!png_cleanup_needed) 567 { 568 png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, 569 png_ptr->zbuf_size); 570 if (png_ptr->zbuf == NULL) 571 png_cleanup_needed = 1; 572 } 573 if (png_cleanup_needed) 574 { 575 /* Clean up PNG structure and deallocate any memory. */ 576 png_free(png_ptr, png_ptr->zbuf); 577 png_ptr->zbuf = NULL; 578 #ifdef PNG_USER_MEM_SUPPORTED 579 png_destroy_struct_2((png_voidp)png_ptr, 580 (png_free_ptr)free_fn, (png_voidp)mem_ptr); 581 #else 582 png_destroy_struct((png_voidp)png_ptr); 583 #endif 584 return (NULL); 585 } 586 587 png_set_write_fn(png_ptr, NULL, NULL, NULL); 588 589 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 567 590 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 568 1, png_doublep_NULL, png_doublep_NULL); 569 #endif 570 571 #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. */ 575 #ifdef USE_FAR_KEYWORD 576 if (setjmp(jmpbuf)) 577 PNG_ABORT(); 578 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); 579 #else 580 if (setjmp(png_ptr->jmpbuf)) 581 PNG_ABORT(); 582 #endif 583 #endif 591 1, NULL, NULL); 592 #endif 593 584 594 return (png_ptr); 585 595 } 586 596 587 /* Initialize png_ptr structure, and allocate any memory needed */588 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)589 /* Deprecated. */590 #undef png_write_init591 void PNGAPI592 png_write_init(png_structp png_ptr)593 {594 /* We only come here via pre-1.0.7-compiled applications */595 png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);596 }597 598 void PNGAPI599 png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,600 png_size_t png_struct_size, png_size_t png_info_size)601 {602 /* We only come here via pre-1.0.12-compiled applications */603 if (png_ptr == NULL) return;604 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)605 if (png_sizeof(png_struct) > png_struct_size ||606 png_sizeof(png_info) > png_info_size)607 {608 char msg[80];609 png_ptr->warning_fn=NULL;610 if (user_png_ver)611 {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);616 }617 png_snprintf(msg, 80,618 "Application is running with png.c from libpng-%.20s",619 png_libpng_ver);620 png_warning(png_ptr, msg);621 }622 #endif623 if (png_sizeof(png_struct) > png_struct_size)624 {625 png_ptr->error_fn=NULL;626 #ifdef PNG_ERROR_NUMBERS_SUPPORTED627 png_ptr->flags=0;628 #endif629 png_error(png_ptr,630 "The png struct allocated by the application for writing is too small.");631 }632 if (png_sizeof(png_info) > png_info_size)633 {634 png_ptr->error_fn=NULL;635 #ifdef PNG_ERROR_NUMBERS_SUPPORTED636 png_ptr->flags=0;637 #endif638 png_error(png_ptr,639 "The info struct allocated by the application for writing is too small.");640 }641 png_write_init_3(&png_ptr, user_png_ver, png_struct_size);642 }643 #endif /* PNG_1_0_X || PNG_1_2_X */644 645 646 void PNGAPI647 png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,648 png_size_t png_struct_size)649 {650 png_structp png_ptr=*ptr_ptr;651 #ifdef PNG_SETJMP_SUPPORTED652 jmp_buf tmp_jmp; /* To save current jump buffer */653 #endif654 655 int i = 0;656 657 if (png_ptr == NULL)658 return;659 660 do661 {662 if (user_png_ver[i] != png_libpng_ver[i])663 {664 #ifdef PNG_LEGACY_SUPPORTED665 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;666 #else667 png_ptr->warning_fn=NULL;668 png_warning(png_ptr,669 "Application uses deprecated png_write_init() and should be recompiled.");670 break;671 #endif672 }673 } while (png_libpng_ver[i++]);674 675 png_debug(1, "in png_write_init_3");676 677 #ifdef PNG_SETJMP_SUPPORTED678 /* Save jump buffer and error functions */679 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));680 #endif681 682 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 }688 689 /* Reset all variables to 0 */690 png_memset(png_ptr, 0, png_sizeof(png_struct));691 692 /* Added at libpng-1.2.6 */693 #ifdef PNG_SET_USER_LIMITS_SUPPORTED694 png_ptr->user_width_max=PNG_USER_WIDTH_MAX;695 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;696 #endif697 698 #ifdef PNG_SETJMP_SUPPORTED699 /* Restore jump buffer */700 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));701 #endif702 703 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,704 png_flush_ptr_NULL);705 706 /* Initialize zbuf - compression buffer */707 png_ptr->zbuf_size = PNG_ZBUF_SIZE;708 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)712 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,713 1, png_doublep_NULL, png_doublep_NULL);714 #endif715 }716 597 717 598 /* Write a few rows of image data. If the image is interlaced, … … 724 605 png_uint_32 num_rows) 725 606 { 726 png_uint_32 i; /* Row counter */727 png_bytepp rp; /* Row pointer */607 png_uint_32 i; /* row counter */ 608 png_bytepp rp; /* row pointer */ 728 609 729 610 png_debug(1, "in png_write_rows"); … … 745 626 png_write_image(png_structp png_ptr, png_bytepp image) 746 627 { 747 png_uint_32 i; /* Row index */748 int pass, num_pass; /* Pass variables */749 png_bytepp rp; /* Points to current row */628 png_uint_32 i; /* row index */ 629 int pass, num_pass; /* pass variables */ 630 png_bytepp rp; /* points to current row */ 750 631 751 632 if (png_ptr == NULL) … … 753 634 754 635 png_debug(1, "in png_write_image"); 755 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 636 637 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 756 638 /* Initialize interlace handling. If image is not interlaced, 757 639 * this will set pass to 1 … … 778 660 if (png_ptr == NULL) 779 661 return; 662 780 663 png_debug2(1, "in png_write_row (row %ld, pass %d)", 781 664 png_ptr->row_number, png_ptr->pass); … … 787 670 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) 788 671 png_error(png_ptr, 789 "png_write_info was never called before png_write_row .");672 "png_write_info was never called before png_write_row"); 790 673 791 674 /* Check for transforms that have been set but were defined out */ 792 675 #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) 793 676 if (png_ptr->transformations & PNG_INVERT_MONO) 794 png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined .");677 png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined"); 795 678 #endif 796 679 #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) 797 680 if (png_ptr->transformations & PNG_FILLER) 798 png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined .");681 png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined"); 799 682 #endif 800 683 #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED) 801 684 if (png_ptr->transformations & PNG_PACKSWAP) 802 png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined .");685 png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined"); 803 686 #endif 804 687 #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) 805 688 if (png_ptr->transformations & PNG_PACK) 806 png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined .");689 png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined"); 807 690 #endif 808 691 #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) 809 692 if (png_ptr->transformations & PNG_SHIFT) 810 png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined .");693 png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined"); 811 694 #endif 812 695 #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) 813 696 if (png_ptr->transformations & PNG_BGR) 814 png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined .");697 png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined"); 815 698 #endif 816 699 #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) 817 700 if (png_ptr->transformations & PNG_SWAP_BYTES) 818 png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined .");701 png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined"); 819 702 #endif 820 703 … … 822 705 } 823 706 824 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)707 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 825 708 /* If interlaced and not interested in row, return */ 826 709 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) … … 900 783 901 784 /* Copy user's row into buffer, leaving room for filter byte. */ 902 png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, 903 png_ptr->row_info.rowbytes); 904 905 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 785 png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes); 786 787 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 906 788 /* Handle interlacing */ 907 789 if (png_ptr->interlaced && png_ptr->pass < 6 && … … 923 805 png_do_write_transformations(png_ptr); 924 806 925 #if defined(PNG_MNG_FEATURES_SUPPORTED)807 #ifdef PNG_MNG_FEATURES_SUPPORTED 926 808 /* Write filter_method 64 (intrapixel differencing) only if 927 809 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and … … 948 830 } 949 831 950 #if defined(PNG_WRITE_FLUSH_SUPPORTED)832 #ifdef PNG_WRITE_FLUSH_SUPPORTED 951 833 /* Set the automatic flush interval or 0 to turn flushing off */ 952 834 void PNGAPI … … 954 836 { 955 837 png_debug(1, "in png_set_flush"); 838 956 839 if (png_ptr == NULL) 957 840 return; … … 966 849 967 850 png_debug(1, "in png_write_flush"); 851 968 852 if (png_ptr == NULL) 969 853 return; … … 1026 910 1027 911 png_debug(1, "in png_destroy_write_struct"); 912 1028 913 if (png_ptr_ptr != NULL) 1029 914 { … … 1052 937 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 1053 938 1054 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)939 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 1055 940 if (png_ptr->num_chunk_list) 1056 941 { 1057 942 png_free(png_ptr, png_ptr->chunk_list); 1058 png_ptr->chunk_list=NULL;1059 943 png_ptr->num_chunk_list = 0; 1060 944 } … … 1100 984 1101 985 png_debug(1, "in png_write_destroy"); 986 1102 987 /* Free any memory zlib uses */ 1103 988 deflateEnd(&png_ptr->zstream); … … 1106 991 png_free(png_ptr, png_ptr->zbuf); 1107 992 png_free(png_ptr, png_ptr->row_buf); 1108 #if ndef PNG_NO_WRITE_FILTER993 #ifdef PNG_WRITE_FILTER_SUPPORTED 1109 994 png_free(png_ptr, png_ptr->prev_row); 1110 995 png_free(png_ptr, png_ptr->sub_row); … … 1114 999 #endif 1115 1000 1116 #if defined(PNG_TIME_RFC1123_SUPPORTED)1001 #ifdef PNG_TIME_RFC1123_SUPPORTED 1117 1002 png_free(png_ptr, png_ptr->time_buffer); 1118 1003 #endif 1119 1004 1120 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)1005 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 1121 1006 png_free(png_ptr, png_ptr->prev_filters); 1122 1007 png_free(png_ptr, png_ptr->filter_weights); … … 1157 1042 { 1158 1043 png_debug(1, "in png_set_filter"); 1159 if (png_ptr == NULL) 1160 return; 1161 #if defined(PNG_MNG_FEATURES_SUPPORTED) 1044 1045 if (png_ptr == NULL) 1046 return; 1047 #ifdef PNG_MNG_FEATURES_SUPPORTED 1162 1048 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 1163 1049 (method == PNG_INTRAPIXEL_DIFFERENCING)) … … 1168 1054 switch (filters & (PNG_ALL_FILTERS | 0x07)) 1169 1055 { 1170 #if ndef PNG_NO_WRITE_FILTER1056 #ifdef PNG_WRITE_FILTER_SUPPORTED 1171 1057 case 5: 1172 1058 case 6: 1173 1059 case 7: png_warning(png_ptr, "Unknown row filter for method 0"); 1174 #endif /* PNG_ NO_WRITE_FILTER*/1060 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1175 1061 case PNG_FILTER_VALUE_NONE: 1176 png_ptr->do_filter =PNG_FILTER_NONE; break;1177 #if ndef PNG_NO_WRITE_FILTER1062 png_ptr->do_filter = PNG_FILTER_NONE; break; 1063 #ifdef PNG_WRITE_FILTER_SUPPORTED 1178 1064 case PNG_FILTER_VALUE_SUB: 1179 png_ptr->do_filter =PNG_FILTER_SUB; break;1065 png_ptr->do_filter = PNG_FILTER_SUB; break; 1180 1066 case PNG_FILTER_VALUE_UP: 1181 png_ptr->do_filter =PNG_FILTER_UP; break;1067 png_ptr->do_filter = PNG_FILTER_UP; break; 1182 1068 case PNG_FILTER_VALUE_AVG: 1183 png_ptr->do_filter =PNG_FILTER_AVG; break;1069 png_ptr->do_filter = PNG_FILTER_AVG; break; 1184 1070 case PNG_FILTER_VALUE_PAETH: 1185 png_ptr->do_filter =PNG_FILTER_PAETH; break;1071 png_ptr->do_filter = PNG_FILTER_PAETH; break; 1186 1072 default: png_ptr->do_filter = (png_byte)filters; break; 1187 1073 #else 1188 1074 default: png_warning(png_ptr, "Unknown row filter for method 0"); 1189 #endif /* PNG_ NO_WRITE_FILTER*/1075 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1190 1076 } 1191 1077 … … 1201 1087 if (png_ptr->row_buf != NULL) 1202 1088 { 1203 #if ndef PNG_NO_WRITE_FILTER1089 #ifdef PNG_WRITE_FILTER_SUPPORTED 1204 1090 if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) 1205 1091 { … … 1256 1142 1257 1143 if (png_ptr->do_filter == PNG_NO_FILTERS) 1258 #endif /* PNG_ NO_WRITE_FILTER*/1144 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1259 1145 png_ptr->do_filter = PNG_FILTER_NONE; 1260 1146 } … … 1271 1157 * better compression. 1272 1158 */ 1273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)/* GRR 970116 */1159 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ 1274 1160 void PNGAPI 1275 1161 png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, … … 1280 1166 1281 1167 png_debug(1, "in png_set_filter_heuristics"); 1168 1282 1169 if (png_ptr == NULL) 1283 1170 return; … … 1394 1281 { 1395 1282 png_debug(1, "in png_set_compression_level"); 1283 1396 1284 if (png_ptr == NULL) 1397 1285 return; … … 1404 1292 { 1405 1293 png_debug(1, "in png_set_compression_mem_level"); 1294 1406 1295 if (png_ptr == NULL) 1407 1296 return; … … 1414 1303 { 1415 1304 png_debug(1, "in png_set_compression_strategy"); 1305 1416 1306 if (png_ptr == NULL) 1417 1307 return; … … 1434 1324 { 1435 1325 png_warning(png_ptr, "Compression window is being reset to 512"); 1436 window_bits =9;1326 window_bits = 9; 1437 1327 } 1438 1328 #endif … … 1445 1335 { 1446 1336 png_debug(1, "in png_set_compression_method"); 1337 1447 1338 if (png_ptr == NULL) 1448 1339 return; … … 1461 1352 } 1462 1353 1463 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)1354 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED 1464 1355 void PNGAPI 1465 1356 png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr … … 1467 1358 { 1468 1359 png_debug(1, "in png_set_write_user_transform_fn"); 1360 1469 1361 if (png_ptr == NULL) 1470 1362 return; … … 1475 1367 1476 1368 1477 #if defined(PNG_INFO_IMAGE_SUPPORTED)1369 #ifdef PNG_INFO_IMAGE_SUPPORTED 1478 1370 void PNGAPI 1479 1371 png_write_png(png_structp png_ptr, png_infop info_ptr, … … 1482 1374 if (png_ptr == NULL || info_ptr == NULL) 1483 1375 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 1376 1490 1377 /* Write the file header information. */ … … 1493 1380 /* ------ these transformations don't touch the info structure ------- */ 1494 1381 1495 #if defined(PNG_WRITE_INVERT_SUPPORTED)1382 #ifdef PNG_WRITE_INVERT_SUPPORTED 1496 1383 /* Invert monochrome pixels */ 1497 1384 if (transforms & PNG_TRANSFORM_INVERT_MONO) … … 1499 1386 #endif 1500 1387 1501 #if defined(PNG_WRITE_SHIFT_SUPPORTED)1388 #ifdef PNG_WRITE_SHIFT_SUPPORTED 1502 1389 /* Shift the pixels up to a legal bit depth and fill in 1503 1390 * as appropriate to correctly scale the image. … … 1508 1395 #endif 1509 1396 1510 #if defined(PNG_WRITE_PACK_SUPPORTED)1397 #ifdef PNG_WRITE_PACK_SUPPORTED 1511 1398 /* Pack pixels into bytes */ 1512 1399 if (transforms & PNG_TRANSFORM_PACKING) … … 1514 1401 #endif 1515 1402 1516 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)1403 #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED 1517 1404 /* Swap location of alpha bytes from ARGB to RGBA */ 1518 1405 if (transforms & PNG_TRANSFORM_SWAP_ALPHA) … … 1520 1407 #endif 1521 1408 1522 #if defined(PNG_WRITE_FILLER_SUPPORTED)1409 #ifdef PNG_WRITE_FILLER_SUPPORTED 1523 1410 /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */ 1524 1411 if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) … … 1528 1415 #endif 1529 1416 1530 #if defined(PNG_WRITE_BGR_SUPPORTED)1417 #ifdef PNG_WRITE_BGR_SUPPORTED 1531 1418 /* Flip BGR pixels to RGB */ 1532 1419 if (transforms & PNG_TRANSFORM_BGR) … … 1534 1421 #endif 1535 1422 1536 #if defined(PNG_WRITE_SWAP_SUPPORTED)1423 #ifdef PNG_WRITE_SWAP_SUPPORTED 1537 1424 /* Swap bytes of 16-bit files to most significant byte first */ 1538 1425 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) … … 1540 1427 #endif 1541 1428 1542 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)1429 #ifdef PNG_WRITE_PACKSWAP_SUPPORTED 1543 1430 /* Swap bits of 1, 2, 4 bit packed pixel formats */ 1544 1431 if (transforms & PNG_TRANSFORM_PACKSWAP) … … 1546 1433 #endif 1547 1434 1435 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED 1436 /* Invert the alpha channel from opacity to transparency */ 1437 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) 1438 png_set_invert_alpha(png_ptr); 1439 #endif 1440 1548 1441 /* ----------------------- end of transformations ------------------- */ 1549 1442
Note:
See TracChangeset
for help on using the changeset viewer.