1 // 2 // Copyright 2007-2008 Christian Henning 3 // 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 7 // 8 #ifndef BOOST_GIL_IO_READER_BASE_HPP 9 #define BOOST_GIL_IO_READER_BASE_HPP 10 11 #include <boost/gil/io/base.hpp> 12 13 #include <boost/assert.hpp> 14 15 namespace boost { namespace gil { 16 17 /// Reader Base Class 18 /// 19 /// It provides some basic functionality which is shared for all readers. 20 /// For instance, it recreates images when necessary. It checks whether 21 /// user supplied coordinates are valid. 22 /// 23 /// @tparam FormatTag A format tag, like jpeg_tag. 24 /// @tparam ConversionPolicy Conversion policy, see coversion_policies.hpp. 25 template< typename FormatTag 26 , typename ConversionPolicy 27 > 28 struct reader_base 29 { 30 public: 31 32 /// 33 /// Default Constructor 34 /// reader_baseboost::gil::reader_base35 reader_base() 36 :_cc_policy() 37 {} 38 39 /// 40 /// Constructor 41 /// reader_baseboost::gil::reader_base42 reader_base( const ConversionPolicy& cc ) 43 :_cc_policy( cc ) 44 {} 45 46 /// Initializes an image. But also does some check ups. 47 /// 48 /// @tparam Image Image which implements boost::gil's ImageConcept. 49 /// 50 /// @param img The image. 51 /// @param info The image read info. 52 template< typename Image > init_imageboost::gil::reader_base53 void init_image( Image& img 54 , const image_read_settings< FormatTag >& settings 55 ) 56 { 57 //setup( backend._settings._dim ); 58 59 BOOST_ASSERT(settings._dim.x && settings._dim.y); 60 61 img.recreate( settings._dim.x 62 , settings._dim.y 63 ); 64 } 65 66 template< typename View > init_viewboost::gil::reader_base67 void init_view( const View& view 68 , const image_read_settings< FormatTag >& 69 ) 70 { 71 setup( view.dimensions() ); 72 } 73 74 private: 75 setupboost::gil::reader_base76 void setup( const point_t& /* dim */ ) 77 { 78 //check_coordinates( dim ); 79 80 //if( dim == point_t( 0, 0 )) 81 //{ 82 // _settings._dim.x = _info._width; 83 // _settings._dim.y = _info._height; 84 //} 85 //else 86 //{ 87 // _settings._dim = dim; 88 //} 89 } 90 check_coordinatesboost::gil::reader_base91 void check_coordinates( const point_t& /* dim */ ) 92 { 93 //using int_t = point_t::value_type; 94 95 //int_t width = static_cast< int_t >( _info._width ); 96 //int_t height = static_cast< int_t >( _info._height ); 97 98 //io_error_if( ( _settings._top_left.x < 0 99 // || _settings._top_left.y < 0 100 // || dim.x < 0 101 // || dim.y < 0 102 // ) 103 // , "User provided view has incorrect size." ); 104 105 106 //io_error_if( ( ( width ) < _settings._top_left.x 107 // && ( width ) <= dim.x 108 // && ( height ) < _settings._top_left.y 109 // && ( height ) <= dim.y ) 110 // , "User provided view has incorrect size." ); 111 112 //io_error_if( ( ( _settings._top_left.x + dim.x ) > width 113 // || ( _settings._top_left.y + dim.y ) > height 114 // ) 115 // , "User provided view has incorrect size." ); 116 } 117 118 protected: 119 120 ConversionPolicy _cc_policy; 121 }; 122 123 } // namespace gil 124 } // namespace boost 125 126 #endif 127