File indexing completed on 2025-01-18 09:36:59
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_EXTENSION_IO_TIFF_DETAIL_READER_BACKEND_HPP
0009 #define BOOST_GIL_EXTENSION_IO_TIFF_DETAIL_READER_BACKEND_HPP
0010
0011 #include <boost/gil/extension/io/tiff/tags.hpp>
0012
0013 namespace boost { namespace gil {
0014
0015 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0016 #pragma warning(push)
0017 #pragma warning(disable:4512)
0018 #endif
0019
0020
0021
0022
0023 template< typename Device >
0024 struct reader_backend< Device
0025 , tiff_tag
0026 >
0027 {
0028 public:
0029
0030 using format_tag_t = tiff_tag;
0031
0032 public:
0033
0034 reader_backend( const Device& io_dev
0035 , const image_read_settings< tiff_tag >& settings
0036 )
0037 : _io_dev ( io_dev )
0038 , _settings( settings )
0039 , _info()
0040
0041 , _scanline_length( 0 )
0042
0043 , _red ( nullptr )
0044 , _green( nullptr )
0045 , _blue ( nullptr )
0046 {
0047 init_multipage_read( settings );
0048
0049 read_header();
0050
0051 if( _settings._dim.x == 0 )
0052 {
0053 _settings._dim.x = _info._width;
0054 }
0055
0056 if( _settings._dim.y == 0 )
0057 {
0058 _settings._dim.y = _info._height;
0059 }
0060 }
0061
0062 void read_header()
0063 {
0064 io_error_if( _io_dev.template get_property<tiff_image_width> ( _info._width ) == false
0065 , "cannot read tiff tag." );
0066 io_error_if( _io_dev.template get_property<tiff_image_height> ( _info._height ) == false
0067 , "cannot read tiff tag." );
0068 io_error_if( _io_dev.template get_property<tiff_compression> ( _info._compression ) == false
0069 , "cannot read tiff tag." );
0070 io_error_if( _io_dev.template get_property<tiff_samples_per_pixel> ( _info._samples_per_pixel ) == false
0071 , "cannot read tiff tag." );
0072 io_error_if( _io_dev.template get_property<tiff_bits_per_sample> ( _info._bits_per_sample ) == false
0073 , "cannot read tiff tag." );
0074 io_error_if( _io_dev.template get_property<tiff_sample_format> ( _info._sample_format ) == false
0075 , "cannot read tiff tag." );
0076 io_error_if( _io_dev.template get_property<tiff_planar_configuration> ( _info._planar_configuration ) == false
0077 , "cannot read tiff tag." );
0078 io_error_if( _io_dev.template get_property<tiff_photometric_interpretation>( _info._photometric_interpretation ) == false
0079 , "cannot read tiff tag." );
0080
0081 _info._is_tiled = false;
0082
0083
0084 if( _io_dev.is_tiled() )
0085 {
0086 _info._is_tiled = true;
0087
0088 io_error_if( !_io_dev.template get_property< tiff_tile_width >( _info._tile_width )
0089 , "cannot read tiff_tile_width tag." );
0090 io_error_if( !_io_dev.template get_property< tiff_tile_length >( _info._tile_length )
0091 , "cannot read tiff_tile_length tag." );
0092 }
0093
0094 io_error_if( _io_dev.template get_property<tiff_resolution_unit>( _info._resolution_unit) == false
0095 , "cannot read tiff tag");
0096 io_error_if( _io_dev. template get_property<tiff_x_resolution>( _info._x_resolution ) == false
0097 , "cannot read tiff tag" );
0098 io_error_if( _io_dev. template get_property<tiff_y_resolution>( _info._y_resolution ) == false
0099 , "cannot read tiff tag" );
0100
0101
0102 _io_dev. template get_property <tiff_icc_profile> ( _info._icc_profile );
0103 }
0104
0105
0106 void check_image_size( point_t const& img_dim )
0107 {
0108 if( _settings._dim.x > 0 )
0109 {
0110 if( img_dim.x < _settings._dim.x ) { io_error( "Supplied image is too small" ); }
0111 }
0112 else
0113 {
0114 if( (tiff_image_width::type) img_dim.x < _info._width ) { io_error( "Supplied image is too small" ); }
0115 }
0116
0117
0118 if( _settings._dim.y > 0 )
0119 {
0120 if( img_dim.y < _settings._dim.y ) { io_error( "Supplied image is too small" ); }
0121 }
0122 else
0123 {
0124 if( (tiff_image_height::type) img_dim.y < _info._height ) { io_error( "Supplied image is too small" ); }
0125 }
0126 }
0127
0128 private:
0129
0130 void init_multipage_read( const image_read_settings< tiff_tag >& settings )
0131 {
0132 if( settings._directory > 0 )
0133 {
0134 _io_dev.set_directory( settings._directory );
0135 }
0136 }
0137
0138 public:
0139
0140 Device _io_dev;
0141
0142 image_read_settings< tiff_tag > _settings;
0143 image_read_info< tiff_tag > _info;
0144
0145 std::size_t _scanline_length;
0146
0147
0148 tiff_color_map::red_t _red;
0149 tiff_color_map::green_t _green;
0150 tiff_color_map::blue_t _blue;
0151
0152 rgb16_planar_view_t _palette;
0153 };
0154
0155 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0156 #pragma warning(pop)
0157 #endif
0158
0159 }
0160 }
0161
0162 #endif