diff --git a/include/boost/gil/extension/io/formats/tiff/writer_backend.hpp b/include/boost/gil/extension/io/formats/tiff/writer_backend.hpp index 3290c3b4b..dfefb2da6 100644 --- a/include/boost/gil/extension/io/formats/tiff/writer_backend.hpp +++ b/include/boost/gil/extension/io/formats/tiff/writer_backend.hpp @@ -19,6 +19,8 @@ /// //////////////////////////////////////////////////////////////////////////////////////// +#include + #include namespace boost { namespace gil { @@ -58,11 +60,10 @@ protected: // get the type of the first channel (heterogeneous pixels might be broken for now!) typedef typename channel_traits< typename element_type< pixel_t >::type >::value_type channel_t; + typedef typename color_space_type< View >::type color_space_t; if(! this->_info._photometric_interpretation_user_defined ) { - typedef typename color_space_type< View >::type color_space_t; - // write photometric interpretion - Warning: This value is rather // subjective. The user should better set this value itself. There // is no way to decide if a image is PHOTOMETRIC_MINISWHITE or @@ -87,6 +88,12 @@ protected: tiff_samples_per_pixel::type samples_per_pixel = num_channels< pixel_t >::value; this->_io_dev.template set_property( samples_per_pixel ); + // The other half of the story is that it needs to be premultiplied on the way into the file. + if (boost:: mpl:: contains :: value) { // the pixel type includes alpha_t + this->_info._extra_sample_value = EXTRASAMPLE_ASSOCALPHA; + this->_info._extra_samples = &(this->_info._extra_sample_value); + this->_io_dev.template set_property( this->_info._extra_samples ); + } // write bits per sample // @todo: Settings this value usually requires to write for each sample the bit // value seperately in case they are different, like rgb556. diff --git a/include/boost/gil/extension/io/tiff_tags.hpp b/include/boost/gil/extension/io/tiff_tags.hpp index 6779ff041..7a6ca033f 100644 --- a/include/boost/gil/extension/io/tiff_tags.hpp +++ b/include/boost/gil/extension/io/tiff_tags.hpp @@ -286,6 +286,7 @@ struct image_write_info< tiff_tag, Log > , _tile_length ( 0 ) , _x_resolution ( 0 ) , _y_resolution ( 0 ) + , _extra_samples ( 0 ) {} /// The color space of the image data. @@ -310,7 +311,10 @@ struct image_write_info< tiff_tag, Log > tiff_x_resolution::type _x_resolution; tiff_y_resolution::type _y_resolution; - /// A log to transcript error and warning messages issued by libtiff. + /// Extra Sample type (for alpha) + tiff_extra_samples::type _extra_samples; + uint16_t _extra_sample_value; + /// A log to transcript error and warning messages issued by libtiff. Log _log; };