Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:00

0001 //
0002 // Copyright 2012 Christian Henning
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
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) //assignment operator could not be generated
0021 #endif
0022 
0023 ///
0024 /// TIFF Writer Backend
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         // get the type of the first channel (heterogeneous pixels might be broken for now!)
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             // write photometric interpretion - Warning: This value is rather
0058             // subjective. The user should better set this value itself. There
0059             // is no way to decide if a image is PHOTOMETRIC_MINISWHITE or
0060             // PHOTOMETRIC_MINISBLACK. If the user has not manually set it, then
0061             // this writer will assume PHOTOMETRIC_MINISBLACK for gray_t images,
0062             // PHOTOMETRIC_RGB for rgb_t images, and PHOTOMETRIC_SEPARATED (as
0063             // is conventional) for cmyk_t images.
0064             this->_info._photometric_interpretation = detail::photometric_interpretation< color_space_t >::value;
0065         }
0066 
0067         // write dimensions
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         // write planar configuration
0075         this->_io_dev.template set_property<tiff_planar_configuration>( this->_info._planar_configuration );
0076 
0077         // write samples per pixel
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 /*constexpr*/ (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         // write bits per sample
0088         // @todo: Settings this value usually requires to write for each sample the bit
0089         // value seperately in case they are different, like rgb556.
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         // write sample format
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         // write photometric format
0098         this->_io_dev.template set_property<tiff_photometric_interpretation>( this->_info._photometric_interpretation );
0099 
0100         // write compression
0101         this->_io_dev.template set_property<tiff_compression>( this->_info._compression );
0102 
0103         // write orientation
0104         this->_io_dev.template set_property<tiff_orientation>( this->_info._orientation );
0105 
0106         // write rows per strip
0107         this->_io_dev.template set_property<tiff_rows_per_strip>( this->_io_dev.get_default_strip_size() );
0108 
0109         // write x, y resolution and units
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         /// Optional and / or non-baseline tags below here
0115 
0116         // write ICC colour profile, if it's there
0117         // http://www.color.org/icc_specs2.xalter
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 } // namespace gil
0135 } // namespace boost
0136 
0137 #endif