reader_base.hpp 3.2 KB

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