reader_base.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. Copyright 2007-2008 Christian Henning
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. /*************************************************************************************************/
  8. #ifndef BOOST_GIL_IO_READER_BASE_HPP
  9. #define BOOST_GIL_IO_READER_BASE_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Christian Henning \n
  14. ///
  15. /// \date 2007-2008 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <boost/gil/io/base.hpp>
  19. namespace boost { namespace gil {
  20. /// Reader Base Class
  21. ///
  22. /// It provides some basic functionality which is shared for all readers.
  23. /// For instance, it recreates images when necessary. It checks whether
  24. /// user supplied coordinates are valid.
  25. ///
  26. /// @tparam FormatTag A format tag, like jpeg_tag.
  27. /// @tparam ConversionPolicy Conversion policy, see coversion_policies.hpp.
  28. template< typename FormatTag
  29. , typename ConversionPolicy
  30. >
  31. struct reader_base
  32. {
  33. public:
  34. ///
  35. /// Default Constructor
  36. ///
  37. reader_base()
  38. :_cc_policy()
  39. {}
  40. ///
  41. /// Constructor
  42. ///
  43. reader_base( const ConversionPolicy& cc )
  44. :_cc_policy( cc )
  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 >
  53. void init_image( Image& img
  54. , const image_read_settings< FormatTag >& settings
  55. )
  56. {
  57. //setup( backend._settings._dim );
  58. assert( settings._dim.x && settings._dim.y );
  59. img.recreate( settings._dim.x
  60. , settings._dim.y
  61. );
  62. }
  63. template< typename View >
  64. void init_view( const View& view
  65. , const image_read_settings< FormatTag >&
  66. )
  67. {
  68. setup( view.dimensions() );
  69. }
  70. private:
  71. void setup( const point_t& /* dim */ )
  72. {
  73. //check_coordinates( dim );
  74. //if( dim == point_t( 0, 0 ))
  75. //{
  76. // _settings._dim.x = _info._width;
  77. // _settings._dim.y = _info._height;
  78. //}
  79. //else
  80. //{
  81. // _settings._dim = dim;
  82. //}
  83. }
  84. void check_coordinates( const point_t& /* dim */ )
  85. {
  86. //typedef point_t::value_type int_t;
  87. //int_t width = static_cast< int_t >( _info._width );
  88. //int_t height = static_cast< int_t >( _info._height );
  89. //io_error_if( ( _settings._top_left.x < 0
  90. // || _settings._top_left.y < 0
  91. // || dim.x < 0
  92. // || dim.y < 0
  93. // )
  94. // , "User provided view has incorrect size." );
  95. //io_error_if( ( ( width ) < _settings._top_left.x
  96. // && ( width ) <= dim.x
  97. // && ( height ) < _settings._top_left.y
  98. // && ( height ) <= dim.y )
  99. // , "User provided view has incorrect size." );
  100. //io_error_if( ( ( _settings._top_left.x + dim.x ) > width
  101. // || ( _settings._top_left.y + dim.y ) > height
  102. // )
  103. // , "User provided view has incorrect size." );
  104. }
  105. protected:
  106. ConversionPolicy _cc_policy;
  107. };
  108. } // namespace gil
  109. } // namespace boost
  110. #endif