Ticket #2373: GIL-read-multipage-TIFF.2.patch
File GIL-read-multipage-TIFF.2.patch, 9.2 KB (added by , 14 years ago) |
---|
-
boost/gil/extension/io/tiff_io.hpp
122 122 protected: 123 123 TIFF *_tp; 124 124 public: 125 tiff_reader(const char* filename ) {125 tiff_reader(const char* filename,tdir_t dirnum=0) { 126 126 io_error_if((_tp=TIFFOpen(filename,"r"))==NULL, 127 127 "tiff_reader: fail to open file"); 128 if(dirnum>0) { 129 io_error_if(TIFFSetDirectory(_tp,dirnum)!=1, 130 "tiff_reader: fail to set directory"); 131 } 128 132 } 129 133 ~tiff_reader() { TIFFClose(_tp); } 130 134 template <typename View> … … 171 175 private: 172 176 CC _cc; 173 177 public: 174 tiff_reader_color_convert(const char* filename ) :175 tiff_reader(filename ) {}176 tiff_reader_color_convert(const char* filename,CC cc_in ) :177 tiff_reader(filename ),_cc(cc_in) {}178 tiff_reader_color_convert(const char* filename,tdir_t dirnum=0) : 179 tiff_reader(filename,dirnum) {} 180 tiff_reader_color_convert(const char* filename,CC cc_in,tdir_t dirnum=0) : 181 tiff_reader(filename,dirnum),_cc(cc_in) {} 178 182 template <typename View> 179 183 void apply(const View& view) { 180 184 point2<std::ptrdiff_t> dims=get_dimensions(); … … 336 340 }; 337 341 338 342 /// \ingroup TIFF_IO 343 /// \brief Returns the number of pages in the TIFF file 344 inline int tiff_get_count(const char* filename) { 345 TIFF *tif; 346 io_error_if((tif=TIFFOpen(filename,"r"))==NULL, 347 "tiff_get_count: fail to open file"); 348 349 int dircount = 0; 350 do { 351 dircount++; 352 } while (TIFFReadDirectory(tif)); 353 354 TIFFClose(tif); 355 return dircount; 356 } 357 358 /// \ingroup TIFF_IO 339 359 /// \brief Returns the width and height of the TIFF file at the specified location. 340 360 /// Throws std::ios_base::failure if the location does not correspond to a valid TIFF file 341 inline point2<std::ptrdiff_t> tiff_read_dimensions(const char* filename ) {342 detail::tiff_reader m(filename );361 inline point2<std::ptrdiff_t> tiff_read_dimensions(const char* filename,tdir_t dirnum=0) { 362 detail::tiff_reader m(filename,dirnum); 343 363 return m.get_dimensions(); 344 364 } 345 365 346 366 /// \ingroup TIFF_IO 347 367 /// \brief Returns the width and height of the TIFF file at the specified location. 348 368 /// Throws std::ios_base::failure if the location does not correspond to a valid TIFF file 349 inline point2<std::ptrdiff_t> tiff_read_dimensions(const std::string& filename ) {350 return tiff_read_dimensions(filename.c_str() );369 inline point2<std::ptrdiff_t> tiff_read_dimensions(const std::string& filename,tdir_t dirnum=0) { 370 return tiff_read_dimensions(filename.c_str(),dirnum); 351 371 } 352 372 353 373 /// \ingroup TIFF_IO … … 356 376 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 357 377 /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view. 358 378 template <typename View> 359 inline void tiff_read_view(const char* filename,const View& view ) {379 inline void tiff_read_view(const char* filename,const View& view,tdir_t dirnum=0) { 360 380 BOOST_STATIC_ASSERT(tiff_read_support<View>::is_supported); 361 detail::tiff_reader m(filename );381 detail::tiff_reader m(filename,dirnum); 362 382 m.apply(view); 363 383 } 364 384 365 385 /// \ingroup TIFF_IO 366 386 /// \brief Loads the image specified by the given tiff image file name into the given view. 367 387 template <typename View> 368 inline void tiff_read_view(const std::string& filename,const View& view ) {369 tiff_read_view(filename.c_str(),view );388 inline void tiff_read_view(const std::string& filename,const View& view,tdir_t dirnum=0) { 389 tiff_read_view(filename.c_str(),view,dirnum); 370 390 } 371 391 372 392 /// \ingroup TIFF_IO … … 375 395 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 376 396 /// compatible with the ones specified by Image 377 397 template <typename Image> 378 void tiff_read_image(const char* filename,Image& im ) {398 void tiff_read_image(const char* filename,Image& im,tdir_t dirnum=0) { 379 399 BOOST_STATIC_ASSERT(tiff_read_support<typename Image::view_t>::is_supported); 380 detail::tiff_reader m(filename );400 detail::tiff_reader m(filename,dirnum); 381 401 m.read_image(im); 382 402 } 383 403 384 404 /// \ingroup TIFF_IO 385 405 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, and loads the pixels into it. 386 406 template <typename Image> 387 inline void tiff_read_image(const std::string& filename,Image& im ) {388 tiff_read_image(filename.c_str(),im );407 inline void tiff_read_image(const std::string& filename,Image& im,tdir_t dirnum=0) { 408 tiff_read_image(filename.c_str(),im,dirnum); 389 409 } 390 410 391 411 /// \ingroup TIFF_IO 392 412 /// \brief Loads and color-converts the image specified by the given tiff image file name into the given view. 393 413 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its dimensions don't match the ones of the view. 394 414 template <typename View,typename CC> 395 inline void tiff_read_and_convert_view(const char* filename,const View& view,CC cc ) {396 detail::tiff_reader_color_convert<CC> m(filename,cc );415 inline void tiff_read_and_convert_view(const char* filename,const View& view,CC cc,tdir_t dirnum=0) { 416 detail::tiff_reader_color_convert<CC> m(filename,cc,dirnum); 397 417 m.apply(view); 398 418 } 399 419 … … 401 421 /// \brief Loads and color-converts the image specified by the given tiff image file name into the given view. 402 422 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its dimensions don't match the ones of the view. 403 423 template <typename View> 404 inline void tiff_read_and_convert_view(const char* filename,const View& view ) {405 detail::tiff_reader_color_convert<default_color_converter> m(filename,default_color_converter() );424 inline void tiff_read_and_convert_view(const char* filename,const View& view,tdir_t dirnum=0) { 425 detail::tiff_reader_color_convert<default_color_converter> m(filename,default_color_converter(),dirnum); 406 426 m.apply(view); 407 427 } 408 428 409 429 /// \ingroup TIFF_IO 410 430 /// \brief Loads and color-converts the image specified by the given tiff image file name into the given view. 411 431 template <typename View,typename CC> 412 inline void tiff_read_and_convert_view(const std::string& filename,const View& view,CC cc ) {413 tiff_read_and_convert_view(filename.c_str(),view,cc );432 inline void tiff_read_and_convert_view(const std::string& filename,const View& view,CC cc,tdir_t dirnum=0) { 433 tiff_read_and_convert_view(filename.c_str(),view,cc,dirnum); 414 434 } 415 435 416 436 /// \ingroup TIFF_IO 417 437 /// \brief Loads and color-converts the image specified by the given tiff image file name into the given view. 418 438 template <typename View> 419 inline void tiff_read_and_convert_view(const std::string& filename,const View& view ) {420 tiff_read_and_convert_view(filename.c_str(),view );439 inline void tiff_read_and_convert_view(const std::string& filename,const View& view,tdir_t dirnum=0) { 440 tiff_read_and_convert_view(filename.c_str(),view,dirnum); 421 441 } 422 442 423 443 /// \ingroup TIFF_IO 424 444 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, loads and color-converts the pixels into it. 425 445 /// Throws std::ios_base::failure if the file is not a valid TIFF file 426 446 template <typename Image,typename CC> 427 void tiff_read_and_convert_image(const char* filename,Image& im,CC cc ) {428 detail::tiff_reader_color_convert<CC> m(filename,cc );447 void tiff_read_and_convert_image(const char* filename,Image& im,CC cc,tdir_t dirnum=0) { 448 detail::tiff_reader_color_convert<CC> m(filename,cc,dirnum); 429 449 m.read_image(im); 430 450 } 431 451 … … 433 453 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, loads and color-converts the pixels into it. 434 454 /// Throws std::ios_base::failure if the file is not a valid TIFF file 435 455 template <typename Image> 436 void tiff_read_and_convert_image(const char* filename,Image& im ) {437 detail::tiff_reader_color_convert<default_color_converter> m(filename,default_color_converter() );456 void tiff_read_and_convert_image(const char* filename,Image& im,tdir_t dirnum=0) { 457 detail::tiff_reader_color_convert<default_color_converter> m(filename,default_color_converter(),dirnum); 438 458 m.read_image(im); 439 459 } 440 460 441 461 /// \ingroup TIFF_IO 442 462 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, loads and color-converts the pixels into it. 443 463 template <typename Image,typename CC> 444 inline void tiff_read_and_convert_image(const std::string& filename,Image& im,CC cc ) {445 tiff_read_and_convert_image(filename.c_str(),im,cc );464 inline void tiff_read_and_convert_image(const std::string& filename,Image& im,CC cc,tdir_t dirnum=0) { 465 tiff_read_and_convert_image(filename.c_str(),im,cc,dirnum); 446 466 } 447 467 448 468 /// \ingroup TIFF_IO 449 469 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, loads and color-converts the pixels into it. 450 470 template <typename Image> 451 inline void tiff_read_and_convert_image(const std::string& filename,Image& im ) {452 tiff_read_and_convert_image(filename.c_str(),im );471 inline void tiff_read_and_convert_image(const std::string& filename,Image& im,tdir_t dirnum=0) { 472 tiff_read_and_convert_image(filename.c_str(),im,dirnum); 453 473 } 454 474 455 475 /// \ingroup TIFF_IO