diff -rwbBui gil/boost/gil/extension/io/tiff_io.hpp boost/boost/include/boost-1_34/boost/gil/extension/io/tiff_io.hpp
|
old
|
new
|
|
| 23 | 23 | #include <vector> |
| 24 | 24 | #include <string> |
| 25 | 25 | #include <algorithm> |
| | 26 | #include <boost/gil/color_base_algorithm.hpp> |
| | 27 | #include <boost/gil/image_view_factory.hpp> |
| | 28 | #include <boost/gil/rgba.hpp> |
| 26 | 29 | #include <boost/static_assert.hpp> |
| 27 | 30 | #include <tiffio.h> |
| 28 | 31 | #include "../../gil_all.hpp" |
| … |
… |
|
| 94 | 115 | BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); |
| 95 | 116 | }; |
| 96 | 117 | template <> |
| | 118 | struct tiff_write_support_private<bits8,rgba_t> { |
| | 119 | BOOST_STATIC_CONSTANT(bool,is_supported=true); |
| | 120 | BOOST_STATIC_CONSTANT(int,bit_depth=8); |
| | 121 | BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); |
| | 122 | }; |
| | 123 | template <> |
| 97 | 124 | struct tiff_write_support_private<bits16,gray_t> { |
| 98 | 125 | BOOST_STATIC_CONSTANT(bool,is_supported=true); |
| 99 | 126 | BOOST_STATIC_CONSTANT(int,bit_depth=16); |
| … |
… |
|
| 106 | 133 | BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); |
| 107 | 134 | }; |
| 108 | 135 | template <> |
| | 136 | struct tiff_write_support_private<bits16,rgba_t> { |
| | 137 | BOOST_STATIC_CONSTANT(bool,is_supported=true); |
| | 138 | BOOST_STATIC_CONSTANT(int,bit_depth=16); |
| | 139 | BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); |
| | 140 | }; |
| | 141 | template <> |
| 109 | 142 | struct tiff_write_support_private<bits32f,gray_t> { |
| 110 | 143 | BOOST_STATIC_CONSTANT(bool,is_supported=true); |
| 111 | 144 | BOOST_STATIC_CONSTANT(int,bit_depth=32); |
| … |
… |
|
| 117 | 150 | BOOST_STATIC_CONSTANT(int,bit_depth=32); |
| 118 | 151 | BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); |
| 119 | 152 | }; |
| | 153 | template <> |
| | 154 | struct tiff_write_support_private<bits32f,rgba_t> { |
| | 155 | BOOST_STATIC_CONSTANT(bool,is_supported=true); |
| | 156 | BOOST_STATIC_CONSTANT(int,bit_depth=32); |
| | 157 | BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); |
| | 158 | }; |
| 120 | 159 | |
| 121 | 160 | class tiff_reader { |
| 122 | 161 | protected: |
| … |
… |
|
| 286 | 357 | } |
| 287 | 358 | }; |
| 288 | 359 | |
| | 360 | template <typename SrcColorSpace, typename DstColorSpace> |
| | 361 | struct premultiplier_impl |
| | 362 | : public default_color_converter_impl<SrcColorSpace,DstColorSpace> { |
| | 363 | template <typename SrcP, typename DstP> // Model PixelConcept |
| | 364 | void operator()(const SrcP& src, DstP& dst) const { |
| | 365 | get_color <red_t> (dst) = channel_multiply (get_color <red_t> (src), get_color <alpha_t> (src)); |
| | 366 | get_color <green_t> (dst) = channel_multiply (get_color <green_t> (src), get_color <alpha_t> (src)); |
| | 367 | get_color <blue_t> (dst) = channel_multiply (get_color <blue_t> (src), get_color <alpha_t> (src)); |
| | 368 | get_color <alpha_t> (dst) = get_color <alpha_t> (src); |
| | 369 | } |
| | 370 | }; |
| | 371 | |
| | 372 | struct premultiplier { |
| | 373 | template <typename SrcP, typename DstP> // Model PixelConcept |
| | 374 | void operator()(const SrcP& src,DstP& dst) const { |
| | 375 | typedef typename color_space_type<SrcP>::type SrcColorSpace; |
| | 376 | typedef typename color_space_type<DstP>::type DstColorSpace; |
| | 377 | premultiplier_impl<SrcColorSpace,DstColorSpace>()(src,dst); |
| | 378 | } |
| | 379 | }; |
| | 380 | |
| 289 | 381 | class tiff_writer { |
| 290 | 382 | protected: |
| 291 | 383 | TIFF* _tp; |
| … |
… |
|
| 308 | 402 | io_error_if(TIFFSetField(_tp,TIFFTAG_BITSPERSAMPLE, tiff_write_support_private<typename channel_type<View>::type, |
| 309 | 403 | typename color_space_type<View>::type>::bit_depth)!=1); |
| 310 | 404 | io_error_if(TIFFSetField(_tp,TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(_tp, 0))!=1); |
| | 405 | |
| | 406 | if (3 < num_channels<View>::value) { |
| | 407 | uint16_t alphaStyle = EXTRASAMPLE_ASSOCALPHA; |
| | 408 | io_error_if(TIFFSetField(_tp,TIFFTAG_EXTRASAMPLES, 1, & alphaStyle)!=1); |
| | 409 | } |
| | 410 | |
| | 411 | View ccv = color_converted_view <typename View:: value_type> (view, premultiplier ()); |
| | 412 | View const & outputView = 3 < num_channels<View>::value? ccv: view; |
| | 413 | |
| 311 | 414 | std::vector<pixel<typename channel_type<View>::type, |
| 312 | 415 | layout<typename color_space_type<View>::type> > > row(view.width()); |
| | 416 | |
| 313 | 417 | for (int y=0;y<view.height();++y) { |
| 314 | | std::copy(view.row_begin(y),view.row_end(y),row.begin()); |
| | 418 | std::copy(outputView.row_begin(y),outputView.row_end(y),row.begin()); |
| 315 | 419 | io_error_if(TIFFWriteScanline(_tp,&row.front(),y,0)!=1, |
| 316 | 420 | "tiff_write_view: fail to write file"); |
| 317 | 421 | } |