read_view.hpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
  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_READ_VIEW_HPP
  9. #define BOOST_GIL_IO_READ_VIEW_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
  14. ///
  15. /// \date 2007-2012 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <boost/type_traits/is_base_and_derived.hpp>
  19. #include <boost/mpl/and.hpp>
  20. #include <boost/utility/enable_if.hpp>
  21. #include <boost/gil/io/base.hpp>
  22. #include <boost/gil/io/device.hpp>
  23. #include <boost/gil/io/path_spec.hpp>
  24. namespace boost{ namespace gil {
  25. /// \ingroup IO
  26. /// \brief Reads an image view without conversion. No memory is allocated.
  27. /// \param reader An image reader.
  28. /// \param view The image view in which the data is read into.
  29. /// \param settings Specifies read settings depending on the image format.
  30. /// \throw std::ios_base::failure
  31. template < typename Reader
  32. , typename View
  33. >
  34. inline
  35. void read_view( Reader reader
  36. , const View& view
  37. , typename enable_if< typename mpl::and_< detail::is_reader< Reader >
  38. , typename is_format_tag< typename Reader::format_tag_t >::type
  39. , typename is_read_supported< typename get_pixel_type< View >::type
  40. , typename Reader::format_tag_t
  41. >::type
  42. >::type
  43. >::type* /* ptr */ = 0
  44. )
  45. {
  46. reader.check_image_size( view.dimensions() );
  47. reader.init_view( view
  48. , reader._settings
  49. );
  50. reader.apply( view );
  51. }
  52. /// \brief Reads an image view without conversion. No memory is allocated.
  53. /// \param file It's a device. Must satisfy is_input_device metafunction.
  54. /// \param view The image view in which the data is read into.
  55. /// \param settings Specifies read settings depending on the image format.
  56. /// \throw std::ios_base::failure
  57. template < typename Device
  58. , typename View
  59. , typename FormatTag
  60. >
  61. inline
  62. void read_view( Device& file
  63. , const View& view
  64. , const image_read_settings< FormatTag >& settings
  65. , typename enable_if< typename mpl::and_< detail::is_read_device< FormatTag
  66. , Device
  67. >
  68. , typename is_format_tag< FormatTag >::type
  69. , typename is_read_supported< typename get_pixel_type< View >::type
  70. , FormatTag
  71. >::type
  72. >::type
  73. >::type* /* ptr */ = 0
  74. )
  75. {
  76. typedef typename get_reader< Device
  77. , FormatTag
  78. , detail::read_and_no_convert
  79. >::type reader_t;
  80. reader_t reader = make_reader( file
  81. , settings
  82. , detail::read_and_no_convert()
  83. );
  84. read_view( reader
  85. , view
  86. );
  87. }
  88. /// \brief Reads an image view without conversion. No memory is allocated.
  89. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  90. /// \param view The image view in which the data is read into.
  91. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  92. /// \throw std::ios_base::failure
  93. template< typename Device
  94. , typename View
  95. , typename FormatTag
  96. >
  97. inline
  98. void read_view( Device& file
  99. , const View& view
  100. , const FormatTag& tag
  101. , typename enable_if< typename mpl::and_< typename is_format_tag< FormatTag >::type
  102. , detail::is_read_device< FormatTag
  103. , Device
  104. >
  105. , typename is_read_supported< typename get_pixel_type< View >::type
  106. , FormatTag
  107. >::type
  108. >::type
  109. >::type* /* ptr */ = 0
  110. )
  111. {
  112. typedef typename get_reader< Device
  113. , FormatTag
  114. , detail::read_and_no_convert
  115. >::type reader_t;
  116. reader_t reader = make_reader( file
  117. , tag
  118. , detail::read_and_no_convert()
  119. );
  120. read_view( reader
  121. , view
  122. );
  123. }
  124. /// \brief Reads an image view without conversion. No memory is allocated.
  125. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  126. /// \param view The image view in which the data is read into.
  127. /// \param settings Specifies read settings depending on the image format.
  128. /// \throw std::ios_base::failure
  129. template < typename String
  130. , typename View
  131. , typename FormatTag
  132. >
  133. inline
  134. void read_view( const String& file_name
  135. , const View& view
  136. , const image_read_settings< FormatTag >& settings
  137. , typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
  138. , typename is_format_tag< FormatTag >::type
  139. , typename is_read_supported< typename get_pixel_type< View >::type
  140. , FormatTag
  141. >::type
  142. >::type
  143. >::type* /* ptr */ = 0
  144. )
  145. {
  146. typedef typename get_reader< String
  147. , FormatTag
  148. , detail::read_and_no_convert
  149. >::type reader_t;
  150. reader_t reader = make_reader( file_name
  151. , settings
  152. , detail::read_and_no_convert()
  153. );
  154. read_view( reader
  155. , view
  156. );
  157. }
  158. /// \brief Reads an image view without conversion. No memory is allocated.
  159. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  160. /// \param view The image view in which the data is read into.
  161. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  162. /// \throw std::ios_base::failure
  163. template < typename String
  164. , typename View
  165. , typename FormatTag
  166. >
  167. inline
  168. void read_view( const String& file_name
  169. , const View& view
  170. , const FormatTag& tag
  171. , typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
  172. , typename is_format_tag< FormatTag >::type
  173. , typename is_read_supported< typename get_pixel_type< View >::type
  174. , FormatTag
  175. >::type
  176. >::type
  177. >::type* /* ptr */ = 0
  178. )
  179. {
  180. typedef typename get_reader< String
  181. , FormatTag
  182. , detail::read_and_no_convert
  183. >::type reader_t;
  184. reader_t reader = make_reader( file_name
  185. , tag
  186. , detail::read_and_no_convert()
  187. );
  188. read_view( reader
  189. , view
  190. );
  191. }
  192. } // namespace gil
  193. } // namespace boost
  194. #endif