2 // Copyright 2012 Christian Henning
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 #ifndef BOOST_GIL_EXTENSION_IO_TIFF_DETAIL_WRITER_BACKEND_HPP
9 #define BOOST_GIL_EXTENSION_IO_TIFF_DETAIL_WRITER_BACKEND_HPP
11 #include <boost/gil/extension/io/tiff/tags.hpp>
12 #include <boost/gil/extension/io/tiff/detail/device.hpp>
14 #include <boost/gil/detail/mp11.hpp>
16 namespace boost { namespace gil {
18 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
20 #pragma warning(disable:4512) //assignment operator could not be generated
24 /// TIFF Writer Backend
26 template< typename Device >
27 struct writer_backend< Device
33 using format_tag_t = tiff_tag;
37 writer_backend( const Device& io_dev
38 , const image_write_info< tiff_tag >& info
46 template< typename View >
47 void write_header( const View& view )
49 using pixel_t = typename View::value_type;
51 // get the type of the first channel (heterogeneous pixels might be broken for now!)
52 using channel_t = typename channel_traits<typename element_type<pixel_t>::type>::value_type;
53 using color_space_t = typename color_space_type<View>::type;
55 if(! this->_info._photometric_interpretation_user_defined )
57 // write photometric interpretion - Warning: This value is rather
58 // subjective. The user should better set this value itself. There
59 // is no way to decide if a image is PHOTOMETRIC_MINISWHITE or
60 // PHOTOMETRIC_MINISBLACK. If the user has not manually set it, then
61 // this writer will assume PHOTOMETRIC_MINISBLACK for gray_t images,
62 // PHOTOMETRIC_RGB for rgb_t images, and PHOTOMETRIC_SEPARATED (as
63 // is conventional) for cmyk_t images.
64 this->_info._photometric_interpretation = detail::photometric_interpretation< color_space_t >::value;
68 tiff_image_width::type width = (tiff_image_width::type) view.width();
69 tiff_image_height::type height = (tiff_image_height::type) view.height();
71 this->_io_dev.template set_property< tiff_image_width >( width );
72 this->_io_dev.template set_property< tiff_image_height >( height );
74 // write planar configuration
75 this->_io_dev.template set_property<tiff_planar_configuration>( this->_info._planar_configuration );
77 // write samples per pixel
78 tiff_samples_per_pixel::type samples_per_pixel = num_channels< pixel_t >::value;
79 this->_io_dev.template set_property<tiff_samples_per_pixel>( samples_per_pixel );
81 if /*constexpr*/ (mp11::mp_contains<color_space_t, alpha_t>::value)
83 std:: vector <uint16_t> extra_samples {EXTRASAMPLE_ASSOCALPHA};
84 this->_io_dev.template set_property<tiff_extra_samples>( extra_samples );
87 // write bits per sample
88 // @todo: Settings this value usually requires to write for each sample the bit
89 // value seperately in case they are different, like rgb556.
90 tiff_bits_per_sample::type bits_per_sample = detail::unsigned_integral_num_bits< channel_t >::value;
91 this->_io_dev.template set_property<tiff_bits_per_sample>( bits_per_sample );
93 // write sample format
94 tiff_sample_format::type sampl_format = detail::sample_format< channel_t >::value;
95 this->_io_dev.template set_property<tiff_sample_format>( sampl_format );
97 // write photometric format
98 this->_io_dev.template set_property<tiff_photometric_interpretation>( this->_info._photometric_interpretation );
101 this->_io_dev.template set_property<tiff_compression>( this->_info._compression );
104 this->_io_dev.template set_property<tiff_orientation>( this->_info._orientation );
106 // write rows per strip
107 this->_io_dev.template set_property<tiff_rows_per_strip>( this->_io_dev.get_default_strip_size() );
109 // write x, y resolution and units
110 this->_io_dev.template set_property<tiff_resolution_unit>( this->_info._resolution_unit );
111 this->_io_dev.template set_property<tiff_x_resolution>( this->_info._x_resolution );
112 this->_io_dev.template set_property<tiff_y_resolution>( this->_info._y_resolution );
114 /// Optional and / or non-baseline tags below here
116 // write ICC colour profile, if it's there
117 // http://www.color.org/icc_specs2.xalter
118 if ( 0 != this->_info._icc_profile.size())
119 this->_io_dev.template set_property<tiff_icc_profile>( this->_info._icc_profile );
127 image_write_info< tiff_tag > _info;
130 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)