read_and_convert_view.hpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
  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_READ_AND_CONVERT_VIEW_HPP
  9. #define BOOST_GIL_IO_READ_AND_CONVERT_VIEW_HPP
  10. #include <boost/gil/io/base.hpp>
  11. #include <boost/gil/io/conversion_policies.hpp>
  12. #include <boost/gil/io/device.hpp>
  13. #include <boost/gil/io/get_reader.hpp>
  14. #include <boost/gil/io/path_spec.hpp>
  15. #include <boost/gil/detail/mp11.hpp>
  16. #include <type_traits>
  17. namespace boost{ namespace gil {
  18. /// \ingroup IO
  19. /// \brief Reads and color-converts an image view. No memory is allocated.
  20. /// \param reader An image reader.
  21. /// \param img The image in which the data is read into.
  22. /// \param settings Specifies read settings depending on the image format.
  23. /// \param cc Color converter function object.
  24. /// \throw std::ios_base::failure
  25. template <typename Reader, typename View>
  26. inline
  27. void read_and_convert_view(Reader& reader, View const& view,
  28. typename std::enable_if
  29. <
  30. mp11::mp_and
  31. <
  32. detail::is_reader<Reader>,
  33. is_format_tag<typename Reader::format_tag_t>
  34. >::value
  35. >::type* /*dummy*/ = nullptr)
  36. {
  37. reader.check_image_size(view.dimensions());
  38. reader.init_view(view, reader._settings);
  39. reader.apply(view);
  40. }
  41. /// \brief Reads and color-converts an image view. No memory is allocated.
  42. /// \param file It's a device. Must satisfy is_input_device metafunction.
  43. /// \param view The image view in which the data is read into.
  44. /// \param settings Specifies read settings depending on the image format.
  45. /// \param cc Color converter function object.
  46. /// \throw std::ios_base::failure
  47. template <typename Device, typename View, typename ColorConverter, typename FormatTag>
  48. inline
  49. void read_and_convert_view(
  50. Device& device,
  51. View const& view,
  52. image_read_settings<FormatTag> const& settings,
  53. ColorConverter const& cc,
  54. typename std::enable_if
  55. <
  56. mp11::mp_and
  57. <
  58. detail::is_read_device<FormatTag, Device>,
  59. is_format_tag<FormatTag>
  60. >::value
  61. >::type* /*dummy*/ = nullptr)
  62. {
  63. using read_and_convert_t = detail::read_and_convert<ColorConverter>;
  64. using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
  65. reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
  66. read_and_convert_view(reader, view);
  67. }
  68. /// \brief Reads and color-converts an image view. No memory is allocated.
  69. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  70. /// \param view The image view in which the data is read into.
  71. /// \param settings Specifies read settings depending on the image format.
  72. /// \param cc Color converter function object.
  73. /// \throw std::ios_base::failure
  74. template <typename String, typename View, typename ColorConverter, typename FormatTag>
  75. inline
  76. void read_and_convert_view(
  77. String const& file_name,
  78. View const& view,
  79. image_read_settings<FormatTag> const& settings,
  80. ColorConverter const& cc,
  81. typename std::enable_if
  82. <
  83. mp11::mp_and
  84. <
  85. is_format_tag<FormatTag>,
  86. detail::is_supported_path_spec<String>
  87. >::value
  88. >::type* /*dummy*/ = nullptr)
  89. {
  90. using read_and_convert_t = detail::read_and_convert<ColorConverter>;
  91. using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
  92. reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
  93. read_and_convert_view(reader, view);
  94. }
  95. /// \brief Reads and color-converts an image view. No memory is allocated.
  96. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  97. /// \param view The image view in which the data is read into.
  98. /// \param cc Color converter function object.
  99. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  100. /// \throw std::ios_base::failure
  101. template <typename String, typename View, typename ColorConverter, typename FormatTag>
  102. inline
  103. void read_and_convert_view(
  104. String const& file_name,
  105. View const& view,
  106. ColorConverter const& cc,
  107. FormatTag const& tag,
  108. typename std::enable_if
  109. <
  110. mp11::mp_and
  111. <
  112. is_format_tag<FormatTag>,
  113. detail::is_supported_path_spec<String>
  114. >::value
  115. >::type* /*dummy*/ = nullptr)
  116. {
  117. using read_and_convert_t = detail::read_and_convert<ColorConverter>;
  118. using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
  119. reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
  120. read_and_convert_view(reader, view);
  121. }
  122. /// \brief Reads and color-converts an image view. No memory is allocated.
  123. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  124. /// \param view The image view in which the data is read into.
  125. /// \param cc Color converter function object.
  126. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  127. /// \throw std::ios_base::failure
  128. template <typename Device, typename View, typename ColorConverter, typename FormatTag>
  129. inline
  130. void read_and_convert_view(
  131. Device& device,
  132. View const& view,
  133. ColorConverter const& cc,
  134. FormatTag const& tag,
  135. typename std::enable_if
  136. <
  137. mp11::mp_and
  138. <
  139. detail::is_read_device<FormatTag, Device>,
  140. is_format_tag<FormatTag>
  141. >::value
  142. >::type* /*dummy*/ = nullptr)
  143. {
  144. using read_and_convert_t = detail::read_and_convert<ColorConverter>;
  145. using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
  146. reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
  147. read_and_convert_view(reader, view);
  148. }
  149. /// \brief Reads and color-converts an image view. No memory is allocated.
  150. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  151. /// \param view The image view in which the data is read into.
  152. /// \param settings Specifies read settings depending on the image format.
  153. /// \throw std::ios_base::failure
  154. template <typename String, typename View, typename FormatTag>
  155. inline
  156. void read_and_convert_view(
  157. String const& file_name,
  158. View const& view,
  159. image_read_settings<FormatTag> const& settings,
  160. typename std::enable_if
  161. <
  162. mp11::mp_and
  163. <
  164. is_format_tag<FormatTag>,
  165. detail::is_supported_path_spec<String>
  166. >::value
  167. >::type* /*dummy*/ = nullptr)
  168. {
  169. using read_and_convert_t = detail::read_and_convert<default_color_converter>;
  170. using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
  171. reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
  172. read_and_convert_view(reader, view);
  173. }
  174. /// \brief Reads and color-converts an image view. No memory is allocated.
  175. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  176. /// \param view The image view in which the data is read into.
  177. /// \param settings Specifies read settings depending on the image format.
  178. /// \throw std::ios_base::failure
  179. template <typename Device, typename View, typename FormatTag>
  180. inline
  181. void read_and_convert_view(
  182. Device& device,
  183. View const& view,
  184. image_read_settings<FormatTag> const& settings,
  185. typename std::enable_if
  186. <
  187. mp11::mp_and
  188. <
  189. detail::is_read_device<FormatTag, Device>,
  190. is_format_tag<FormatTag>
  191. >::value
  192. >::type* /*dummy*/ = nullptr)
  193. {
  194. using read_and_convert_t = detail::read_and_convert<default_color_converter>;
  195. using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
  196. reader_t reader = make_reader(device, settings, read_and_convert_t{});
  197. read_and_convert_view(reader, view);
  198. }
  199. /// \brief Reads and color-converts an image view. No memory is allocated.
  200. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  201. /// \param view The image view in which the data is read into.
  202. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  203. /// \throw std::ios_base::failure
  204. template <typename String, typename View, typename FormatTag>
  205. inline
  206. void read_and_convert_view(
  207. String const& file_name,
  208. View const& view,
  209. FormatTag const& tag,
  210. typename std::enable_if
  211. <
  212. mp11::mp_and
  213. <
  214. is_format_tag<FormatTag>,
  215. detail::is_supported_path_spec<String>
  216. >::value
  217. >::type* /*dummy*/ = nullptr)
  218. {
  219. using read_and_convert_t = detail::read_and_convert<default_color_converter>;
  220. using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
  221. reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
  222. read_and_convert_view(reader, view);
  223. }
  224. /// \brief Reads and color-converts an image view. No memory is allocated.
  225. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  226. /// \param view The image view in which the data is read into.
  227. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  228. /// \throw std::ios_base::failure
  229. template <typename Device, typename View, typename FormatTag>
  230. inline
  231. void read_and_convert_view(
  232. Device& device,
  233. View const& view,
  234. FormatTag const& tag,
  235. typename std::enable_if
  236. <
  237. mp11::mp_and
  238. <
  239. detail::is_read_device<FormatTag, Device>,
  240. is_format_tag<FormatTag>
  241. >::value
  242. >::type* /*dummy*/ = nullptr)
  243. {
  244. using read_and_convert_t = detail::read_and_convert<default_color_converter>;
  245. using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
  246. reader_t reader = make_reader(device, tag, read_and_convert_t{});
  247. read_and_convert_view(reader, view);
  248. }
  249. }} // namespace boost::gill
  250. #endif