Ticket #35995: patch-libpng15.diff
File patch-libpng15.diff, 11.0 KB (added by raphael-st (Raphael Straub), 12 years ago) |
---|
-
src/vigra_impex/png.cxx
old new 65 65 #include <png.h> 66 66 } 67 67 68 #define STRINGIFY(m_argument) #m_argument 69 68 70 #if PNG_LIBPNG_VER < 10201 69 71 #error "please update your libpng to at least 1.2.1" 70 72 #endif 71 73 74 #if PNG_LIBPNG_VER >= 10400 75 #define PNG_SET_EXPAND_GRAY_1_2_4_TO_8_NAME png_set_expand_gray_1_2_4_to_8 76 #else 77 #define PNG_SET_EXPAND_GRAY_1_2_4_TO_8_NAME png_set_gray_1_2_4_to_8 78 #endif 79 #define PNG_SET_EXPAND_GRAY_1_2_4_TO_8_FUNCTION_NAME STRINGIFY(PNG_SET_EXPAND_GRAY_1_2_4_TO_8_NAME) 80 #define PNG_SET_EXPAND_GRAY_1_2_4_TO_8(m_image) PNG_SET_EXPAND_GRAY_1_2_4_TO_8_NAME(m_image) 81 72 82 // TODO: per-scanline reading/writing 73 83 74 84 namespace { … … 81 91 static void PngError( png_structp png_ptr, png_const_charp error_msg ) 82 92 { 83 93 png_error_message = std::string(error_msg); 84 longjmp( png_ ptr->jmpbuf, 1 );94 longjmp( png_jmpbuf(png_ptr), 1 ); 85 95 } 86 96 87 97 // called on non-fatal errors … … 203 213 // check if the file is a png file 204 214 const unsigned int sig_size = 8; 205 215 png_byte sig[sig_size]; 206 std:: fread( sig, sig_size, 1, file.get() );216 std::size_t readCount = std::fread( sig, sig_size, 1, file.get() ); 207 217 const int no_png = png_sig_cmp( sig, 0, sig_size ); 208 vigra_precondition( !no_png, "given file is not a png file.");218 vigra_precondition( (readCount == 1) && !no_png, "given file is not a png file."); 209 219 210 220 // create png read struct with user defined handlers 211 221 png = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, … … 213 223 vigra_postcondition( png != 0, "could not create the read struct." ); 214 224 215 225 // create info struct 216 if (setjmp(png ->jmpbuf)) {226 if (setjmp(png_jmpbuf(png))) { 217 227 png_destroy_read_struct( &png, &info, NULL ); 218 228 vigra_postcondition( false, png_error_message.insert(0, "error in png_create_info_struct(): ").c_str() ); 219 229 } … … 221 231 vigra_postcondition( info != 0, "could not create the info struct." ); 222 232 223 233 // init png i/o 224 if (setjmp(png ->jmpbuf)) {234 if (setjmp(png_jmpbuf(png))) { 225 235 png_destroy_read_struct( &png, &info, NULL ); 226 236 vigra_postcondition( false, png_error_message.insert(0, "error in png_init_io(): ").c_str() ); 227 237 } 228 238 png_init_io( png, file.get() ); 229 239 230 240 // specify that the signature was already read 231 if (setjmp(png ->jmpbuf)) {241 if (setjmp(png_jmpbuf(png))) { 232 242 png_destroy_read_struct( &png, &info, NULL ); 233 243 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_sig_bytes(): ").c_str() ); 234 244 } … … 244 254 void PngDecoderImpl::init() 245 255 { 246 256 // read all chunks up to the image data 247 if (setjmp(png ->jmpbuf))257 if (setjmp(png_jmpbuf(png))) 248 258 vigra_postcondition( false, png_error_message.insert(0, "error in png_read_info(): ").c_str() ); 249 259 png_read_info( png, info ); 250 260 251 261 // pull over the header fields 252 262 int interlace_method, compression_method, filter_method; 253 if (setjmp(png ->jmpbuf))263 if (setjmp(png_jmpbuf(png))) 254 264 vigra_postcondition( false, png_error_message.insert(0, "error in png_get_IHDR(): ").c_str() ); 255 265 png_get_IHDR( png, info, &width, &height, &bit_depth, &color_type, 256 266 &interlace_method, &compression_method, &filter_method ); … … 264 274 265 275 // transform palette to rgb 266 276 if ( color_type == PNG_COLOR_TYPE_PALETTE) { 267 if (setjmp(png ->jmpbuf))277 if (setjmp(png_jmpbuf(png))) 268 278 vigra_postcondition( false, png_error_message.insert(0, "error in png_palette_to_rgb(): ").c_str() ); 269 279 png_set_palette_to_rgb(png); 270 280 color_type = PNG_COLOR_TYPE_RGB; … … 273 283 274 284 // expand gray values to at least one byte size 275 285 if ( color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8 ) { 276 if (setjmp(png ->jmpbuf))277 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_gray_1_2_4_to_8(): ").c_str());278 png_set_gray_1_2_4_to_8(png);286 if (setjmp(png_jmpbuf(png))) 287 vigra_postcondition( false, png_error_message.insert(0, "error in " PNG_SET_EXPAND_GRAY_1_2_4_TO_8_FUNCTION_NAME " (): ").c_str()); 288 PNG_SET_EXPAND_GRAY_1_2_4_TO_8(png); 279 289 bit_depth = 8; 280 290 } 281 291 … … 283 293 #if 0 284 294 // strip alpha channel 285 295 if ( color_type & PNG_COLOR_MASK_ALPHA ) { 286 if (setjmp(png ->jmpbuf))296 if (setjmp(png_jmpbuf(png))) 287 297 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_strip_alpha(): ").c_str() ); 288 298 png_set_strip_alpha(png); 289 299 color_type ^= PNG_COLOR_MASK_ALPHA; … … 325 335 #if (PNG_LIBPNG_VER > 10008) && defined(PNG_READ_iCCP_SUPPORTED) 326 336 char * dummyName; 327 337 int dummyCompType; 338 #if (PNG_LIBPNG_VER < 10500) 328 339 char * profilePtr; 340 #else 341 png_byte * profilePtr; 342 #endif 329 343 png_uint_32 profileLen; 330 if ( info->valid & PNG_INFO_iCCP) {344 if (png_get_valid( png, info, PNG_INFO_iCCP )) { 331 345 png_get_iCCP(png, info, &dummyName, &dummyCompType, &profilePtr, &profileLen) ; 332 346 iccProfilePtr = (unsigned char *) profilePtr; 333 347 iccProfileLength = profileLen; … … 340 354 // image gamma 341 355 double image_gamma = 0.45455; 342 356 if ( png_get_valid( png, info, PNG_INFO_gAMA ) ) { 343 if (setjmp(png ->jmpbuf))357 if (setjmp(png_jmpbuf(png))) 344 358 vigra_postcondition( false, png_error_message.insert(0, "error in png_get_gAMA(): ").c_str() ); 345 359 png_get_gAMA( png, info, &image_gamma ); 346 360 } … … 349 363 double screen_gamma = 2.2; 350 364 351 365 // set gamma correction 352 if (setjmp(png ->jmpbuf))366 if (setjmp(png_jmpbuf(png))) 353 367 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_gamma(): ").c_str() ); 354 368 png_set_gamma( png, screen_gamma, image_gamma ); 355 369 #endif 356 370 357 371 // interlace handling, get number of read passes needed 358 if (setjmp(png ->jmpbuf))372 if (setjmp(png_jmpbuf(png))) 359 373 vigra_postcondition( false,png_error_message.insert(0, "error in png_set_interlace_handling(): ").c_str()); 360 374 n_interlace_passes = png_set_interlace_handling(png); 361 375 362 376 // update png library state to reflect any changes that were made 363 if (setjmp(png ->jmpbuf))377 if (setjmp(png_jmpbuf(png))) 364 378 vigra_postcondition( false, png_error_message.insert(0, "error in png_read_update_info(): ").c_str() ); 365 379 png_read_update_info( png, info ); 366 380 367 if (setjmp(png ->jmpbuf))381 if (setjmp(png_jmpbuf(png))) 368 382 vigra_postcondition( false,png_error_message.insert(0, "error in png_get_channels(): ").c_str()); 369 383 n_channels = png_get_channels(png, info); 370 384 371 if (setjmp(png ->jmpbuf))385 if (setjmp(png_jmpbuf(png))) 372 386 vigra_postcondition( false,png_error_message.insert(0, "error in png_get_rowbytes(): ").c_str()); 373 387 rowsize = png_get_rowbytes(png, info); 374 388 … … 378 392 379 393 void PngDecoderImpl::nextScanline() 380 394 { 381 for (int i=0; i < n_interlace_passes; i++) { 382 if (setjmp(png->jmpbuf)) 383 vigra_postcondition( false,png_error_message.insert(0, "error in png_read_row(): ").c_str()); 395 if (setjmp(png_jmpbuf(png))) 396 vigra_postcondition( false,png_error_message.insert(0, "error in png_read_row(): ").c_str()); 397 for (int i=0; i < n_interlace_passes; i++) 398 { 384 399 png_read_row(png, row_data.begin(), NULL); 385 400 } 386 401 } … … 545 560 vigra_postcondition( png != 0, "could not create the write struct." ); 546 561 547 562 // create info struct 548 if (setjmp(png ->jmpbuf)) {563 if (setjmp(png_jmpbuf(png))) { 549 564 png_destroy_write_struct( &png, &info ); 550 565 vigra_postcondition( false, png_error_message.insert(0, "error in png_info_struct(): ").c_str() ); 551 566 } … … 556 571 } 557 572 558 573 // init png i/o 559 if (setjmp(png ->jmpbuf)) {574 if (setjmp(png_jmpbuf(png))) { 560 575 png_destroy_write_struct( &png, &info ); 561 576 vigra_postcondition( false, png_error_message.insert(0, "error in png_init_io(): ").c_str() ); 562 577 } … … 571 586 void PngEncoderImpl::finalize() 572 587 { 573 588 // write the IHDR 574 if (setjmp(png ->jmpbuf))589 if (setjmp(png_jmpbuf(png))) 575 590 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_IHDR(): ").c_str() ); 576 591 png_set_IHDR( png, info, width, height, bit_depth, color_type, 577 592 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, … … 579 594 580 595 // set resolution 581 596 if (x_resolution > 0 && y_resolution > 0) { 582 if (setjmp(png ->jmpbuf))597 if (setjmp(png_jmpbuf(png))) 583 598 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_pHYs(): ").c_str() ); 584 599 png_set_pHYs(png, info, (png_uint_32) (x_resolution / 0.0254 + 0.5), 585 600 (png_uint_32) (y_resolution / 0.0254 + 0.5), … … 588 603 589 604 // set offset 590 605 if (position.x > 0 && position.y > 0) { 591 if (setjmp(png ->jmpbuf))606 if (setjmp(png_jmpbuf(png))) 592 607 vigra_postcondition( false, png_error_message.insert(0, "error in png_set_oFFs(): ").c_str() ); 593 608 png_set_oFFs(png, info, position.x, position.y, PNG_OFFSET_PIXEL); 594 609 } … … 596 611 #if (PNG_LIBPNG_VER > 10008) && defined(PNG_WRITE_iCCP_SUPPORTED) 597 612 // set icc profile 598 613 if (iccProfile.size() > 0) { 599 png_set_iCCP(png, info, "icc", 0, 600 (char *)iccProfile.begin(), iccProfile.size()); 614 png_set_iCCP(png, info, (png_charp)("icc"), 0, 615 #if (PNG_LIBPNG_VER < 10500) 616 (png_charp)iccProfile.begin(), (png_uint_32)iccProfile.size()); 617 #else 618 (png_byte*)iccProfile.begin(), (png_uint_32)iccProfile.size()); 619 #endif 601 620 } 602 621 #endif 603 622 604 623 // write the info struct 605 if (setjmp(png ->jmpbuf))624 if (setjmp(png_jmpbuf(png))) 606 625 vigra_postcondition( false, png_error_message.insert(0, "error in png_write_info(): ").c_str() ); 607 626 png_write_info( png, info ); 608 627 … … 634 653 } 635 654 636 655 // write the whole image 637 if (setjmp(png ->jmpbuf))656 if (setjmp(png_jmpbuf(png))) 638 657 vigra_postcondition( false, png_error_message.insert(0, "error in png_write_image(): ").c_str() ); 639 658 png_write_image( png, row_pointers.begin() ); 640 if (setjmp(png ->jmpbuf))659 if (setjmp(png_jmpbuf(png))) 641 660 vigra_postcondition( false, png_error_message.insert(0, "error in png_write_end(): ").c_str() ); 642 661 png_write_end(png, info); 643 662 }