File indexing completed on 2025-01-18 09:37:00
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_EXTENSION_IO_TIFF_DETAIL_WRITER_BACKEND_HPP
0009 #define BOOST_GIL_EXTENSION_IO_TIFF_DETAIL_WRITER_BACKEND_HPP
0010
0011 #include <boost/gil/extension/io/tiff/tags.hpp>
0012 #include <boost/gil/extension/io/tiff/detail/device.hpp>
0013
0014 #include <boost/gil/detail/mp11.hpp>
0015
0016 namespace boost { namespace gil {
0017
0018 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0019 #pragma warning(push)
0020 #pragma warning(disable:4512)
0021 #endif
0022
0023
0024
0025
0026 template< typename Device >
0027 struct writer_backend< Device
0028 , tiff_tag
0029 >
0030 {
0031 public:
0032
0033 using format_tag_t = tiff_tag;
0034
0035 public:
0036
0037 writer_backend( const Device& io_dev
0038 , const image_write_info< tiff_tag >& info
0039 )
0040 : _io_dev( io_dev )
0041 , _info( info )
0042 {}
0043
0044 protected:
0045
0046 template< typename View >
0047 void write_header( const View& view )
0048 {
0049 using pixel_t = typename View::value_type;
0050
0051
0052 using channel_t = typename channel_traits<typename element_type<pixel_t>::type>::value_type;
0053 using color_space_t = typename color_space_type<View>::type;
0054
0055 if(! this->_info._photometric_interpretation_user_defined )
0056 {
0057
0058
0059
0060
0061
0062
0063
0064 this->_info._photometric_interpretation = detail::photometric_interpretation< color_space_t >::value;
0065 }
0066
0067
0068 tiff_image_width::type width = (tiff_image_width::type) view.width();
0069 tiff_image_height::type height = (tiff_image_height::type) view.height();
0070
0071 this->_io_dev.template set_property< tiff_image_width >( width );
0072 this->_io_dev.template set_property< tiff_image_height >( height );
0073
0074
0075 this->_io_dev.template set_property<tiff_planar_configuration>( this->_info._planar_configuration );
0076
0077
0078 tiff_samples_per_pixel::type samples_per_pixel = num_channels< pixel_t >::value;
0079 this->_io_dev.template set_property<tiff_samples_per_pixel>( samples_per_pixel );
0080
0081 if (mp11::mp_contains<color_space_t, alpha_t>::value)
0082 {
0083 std:: vector <uint16_t> extra_samples {EXTRASAMPLE_ASSOCALPHA};
0084 this->_io_dev.template set_property<tiff_extra_samples>( extra_samples );
0085 }
0086
0087
0088
0089
0090 tiff_bits_per_sample::type bits_per_sample = detail::unsigned_integral_num_bits< channel_t >::value;
0091 this->_io_dev.template set_property<tiff_bits_per_sample>( bits_per_sample );
0092
0093
0094 tiff_sample_format::type sampl_format = detail::sample_format< channel_t >::value;
0095 this->_io_dev.template set_property<tiff_sample_format>( sampl_format );
0096
0097
0098 this->_io_dev.template set_property<tiff_photometric_interpretation>( this->_info._photometric_interpretation );
0099
0100
0101 this->_io_dev.template set_property<tiff_compression>( this->_info._compression );
0102
0103
0104 this->_io_dev.template set_property<tiff_orientation>( this->_info._orientation );
0105
0106
0107 this->_io_dev.template set_property<tiff_rows_per_strip>( this->_io_dev.get_default_strip_size() );
0108
0109
0110 this->_io_dev.template set_property<tiff_resolution_unit>( this->_info._resolution_unit );
0111 this->_io_dev.template set_property<tiff_x_resolution>( this->_info._x_resolution );
0112 this->_io_dev.template set_property<tiff_y_resolution>( this->_info._y_resolution );
0113
0114
0115
0116
0117
0118 if ( 0 != this->_info._icc_profile.size())
0119 this->_io_dev.template set_property<tiff_icc_profile>( this->_info._icc_profile );
0120 }
0121
0122
0123 public:
0124
0125 Device _io_dev;
0126
0127 image_write_info< tiff_tag > _info;
0128 };
0129
0130 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0131 #pragma warning(pop)
0132 #endif
0133
0134 }
0135 }
0136
0137 #endif