read_and_convert_view.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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_AND_CONVERT_VIEW_HPP
  9. #define BOOST_GIL_IO_READ_AND_CONVERT_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. #include <boost/gil/io/conversion_policies.hpp>
  25. namespace boost{ namespace gil {
  26. /// \ingroup IO
  27. /// \brief Reads and color-converts an image view. No memory is allocated.
  28. /// \param reader An image reader.
  29. /// \param img The image in which the data is read into.
  30. /// \param settings Specifies read settings depending on the image format.
  31. /// \param cc Color converter function object.
  32. /// \throw std::ios_base::failure
  33. template< typename Reader
  34. , typename View
  35. >
  36. inline
  37. void read_and_convert_view( Reader& reader
  38. , const View& view
  39. , typename enable_if< mpl::and_< detail::is_reader< Reader >
  40. , is_format_tag< typename Reader::format_tag_t >
  41. >
  42. >::type* /* ptr */ = 0
  43. )
  44. {
  45. reader.check_image_size( view.dimensions() );
  46. reader.init_view( view
  47. , reader._settings
  48. );
  49. reader.apply( view );
  50. }
  51. /// \brief Reads and color-converts an image view. No memory is allocated.
  52. /// \param file It's a device. Must satisfy is_input_device metafunction.
  53. /// \param view The image view in which the data is read into.
  54. /// \param settings Specifies read settings depending on the image format.
  55. /// \param cc Color converter function object.
  56. /// \throw std::ios_base::failure
  57. template< typename Device
  58. , typename View
  59. , typename ColorConverter
  60. , typename FormatTag
  61. >
  62. inline
  63. void read_and_convert_view( Device& device
  64. , const View& view
  65. , const image_read_settings< FormatTag >& settings
  66. , const ColorConverter& cc
  67. , typename enable_if< mpl::and_< detail::is_read_device< FormatTag
  68. , Device
  69. >
  70. , is_format_tag< FormatTag >
  71. >
  72. >::type* /* ptr */ = 0
  73. )
  74. {
  75. typedef typename get_reader< Device
  76. , FormatTag
  77. , detail::read_and_convert< ColorConverter >
  78. >::type reader_t;
  79. reader_t reader = make_reader( device
  80. , settings
  81. , detail::read_and_convert< ColorConverter >( cc )
  82. );
  83. read_and_convert_view( reader
  84. , view
  85. );
  86. }
  87. /// \brief Reads and color-converts an image view. No memory is allocated.
  88. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  89. /// \param view The image view in which the data is read into.
  90. /// \param settings Specifies read settings depending on the image format.
  91. /// \param cc Color converter function object.
  92. /// \throw std::ios_base::failure
  93. template < typename String
  94. , typename View
  95. , typename ColorConverter
  96. , typename FormatTag
  97. >
  98. inline
  99. void read_and_convert_view( const String& file_name
  100. , const View& view
  101. , const image_read_settings< FormatTag >& settings
  102. , const ColorConverter& cc
  103. , typename enable_if< mpl::and_< is_format_tag< FormatTag >
  104. , detail::is_supported_path_spec< String >
  105. >
  106. >::type* /* ptr */ = 0
  107. )
  108. {
  109. typedef typename get_reader< String
  110. , FormatTag
  111. , detail::read_and_convert< ColorConverter >
  112. >::type reader_t;
  113. reader_t reader = make_reader( file_name
  114. , settings
  115. , detail::read_and_convert< ColorConverter >( cc )
  116. );
  117. read_and_convert_view( reader
  118. , view
  119. );
  120. }
  121. /// \brief Reads and color-converts an image view. No memory is allocated.
  122. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  123. /// \param view The image view in which the data is read into.
  124. /// \param cc Color converter function object.
  125. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  126. /// \throw std::ios_base::failure
  127. template < typename String
  128. , typename View
  129. , typename ColorConverter
  130. , typename FormatTag
  131. >
  132. inline
  133. void read_and_convert_view( const String& file_name
  134. , const View& view
  135. , const ColorConverter& cc
  136. , const FormatTag& tag
  137. , typename enable_if< mpl::and_< is_format_tag< FormatTag >
  138. , detail::is_supported_path_spec< String >
  139. >
  140. >::type* /* ptr */ = 0
  141. )
  142. {
  143. typedef typename get_reader< String
  144. , FormatTag
  145. , detail::read_and_convert< ColorConverter >
  146. >::type reader_t;
  147. reader_t reader = make_reader( file_name
  148. , tag
  149. , detail::read_and_convert< ColorConverter >( cc )
  150. );
  151. read_and_convert_view( reader
  152. , view
  153. );
  154. }
  155. /// \brief Reads and color-converts an image view. No memory is allocated.
  156. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  157. /// \param view The image view in which the data is read into.
  158. /// \param cc Color converter function object.
  159. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  160. /// \throw std::ios_base::failure
  161. template < typename Device
  162. , typename View
  163. , typename ColorConverter
  164. , typename FormatTag
  165. >
  166. inline
  167. void read_and_convert_view( Device& device
  168. , const View& view
  169. , const ColorConverter& cc
  170. , const FormatTag& tag
  171. , typename enable_if< mpl::and_< detail::is_read_device< FormatTag
  172. , Device
  173. >
  174. , is_format_tag< FormatTag >
  175. >
  176. >::type* /* ptr */ = 0
  177. )
  178. {
  179. typedef typename get_reader< Device
  180. , FormatTag
  181. , detail::read_and_convert< ColorConverter >
  182. >::type reader_t;
  183. reader_t reader = make_reader( device
  184. , tag
  185. , detail::read_and_convert< ColorConverter >( cc )
  186. );
  187. read_and_convert_view( reader
  188. , view
  189. );
  190. }
  191. /// \brief Reads and color-converts an image view. No memory is allocated.
  192. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  193. /// \param view The image view in which the data is read into.
  194. /// \param settings Specifies read settings depending on the image format.
  195. /// \throw std::ios_base::failure
  196. template < typename String
  197. , typename View
  198. , typename FormatTag
  199. >
  200. inline
  201. void read_and_convert_view( const String& file_name
  202. , const View& view
  203. , const image_read_settings< FormatTag >& settings
  204. , typename enable_if< mpl::and_< is_format_tag< FormatTag >
  205. , detail::is_supported_path_spec< String >
  206. >
  207. >::type* /* ptr */ = 0
  208. )
  209. {
  210. typedef typename get_reader< String
  211. , FormatTag
  212. , detail::read_and_convert< default_color_converter >
  213. >::type reader_t;
  214. reader_t reader = make_reader( file_name
  215. , settings
  216. , detail::read_and_convert< default_color_converter >()
  217. );
  218. read_and_convert_view( reader
  219. , view
  220. );
  221. }
  222. /// \brief Reads and color-converts an image view. No memory is allocated.
  223. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  224. /// \param view The image view in which the data is read into.
  225. /// \param settings Specifies read settings depending on the image format.
  226. /// \throw std::ios_base::failure
  227. template < typename Device
  228. , typename View
  229. , typename FormatTag
  230. >
  231. inline
  232. void read_and_convert_view( Device& device
  233. , const View& view
  234. , const image_read_settings< FormatTag >& settings
  235. , typename enable_if< mpl::and_< detail::is_read_device< FormatTag
  236. , Device
  237. >
  238. , is_format_tag< FormatTag >
  239. >
  240. >::type* /* ptr */ = 0
  241. )
  242. {
  243. typedef typename get_reader< Device
  244. , FormatTag
  245. , detail::read_and_convert< default_color_converter >
  246. >::type reader_t;
  247. reader_t reader = make_reader( device
  248. , settings
  249. , detail::read_and_convert< default_color_converter >()
  250. );
  251. read_and_convert_view( reader
  252. , view
  253. );
  254. }
  255. /// \brief Reads and color-converts an image view. No memory is allocated.
  256. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  257. /// \param view The image view in which the data is read into.
  258. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  259. /// \throw std::ios_base::failure
  260. template < typename String
  261. , typename View
  262. , typename FormatTag
  263. >
  264. inline
  265. void read_and_convert_view( const String& file_name
  266. , const View& view
  267. , const FormatTag& tag
  268. , typename enable_if< mpl::and_< is_format_tag< FormatTag >
  269. , detail::is_supported_path_spec< String >
  270. >
  271. >::type* /* ptr */ = 0
  272. )
  273. {
  274. typedef typename get_reader< String
  275. , FormatTag
  276. , detail::read_and_convert< default_color_converter >
  277. >::type reader_t;
  278. reader_t reader = make_reader( file_name
  279. , tag
  280. , detail::read_and_convert< default_color_converter >()
  281. );
  282. read_and_convert_view( reader
  283. , view
  284. );
  285. }
  286. /// \brief Reads and color-converts an image view. No memory is allocated.
  287. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  288. /// \param view The image view in which the data is read into.
  289. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  290. /// \throw std::ios_base::failure
  291. template < typename Device
  292. , typename View
  293. , typename FormatTag
  294. >
  295. inline
  296. void read_and_convert_view( Device& device
  297. , const View& view
  298. , const FormatTag& tag
  299. , typename enable_if< mpl::and_< detail::is_read_device< FormatTag
  300. , Device
  301. >
  302. , is_format_tag< FormatTag >
  303. >
  304. >::type* /* ptr */ = 0
  305. )
  306. {
  307. typedef typename get_reader< Device
  308. , FormatTag
  309. , detail::read_and_convert< default_color_converter >
  310. >::type reader_t;
  311. reader_t reader = make_reader( device
  312. , tag
  313. , detail::read_and_convert< default_color_converter >()
  314. );
  315. read_and_convert_view( reader
  316. , view
  317. );
  318. }
  319. } // namespace gil
  320. } // namespace boost
  321. #endif