read_view.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_VIEW_HPP
  9. #define BOOST_GIL_IO_READ_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 an image view without conversion. No memory is allocated.
  20. /// \param reader An image reader.
  21. /// \param view The image view in which the data is read into.
  22. /// \param settings Specifies read settings depending on the image format.
  23. /// \throw std::ios_base::failure
  24. template <typename Reader, typename View>
  25. inline
  26. void read_view(Reader reader, View const& view,
  27. typename std::enable_if
  28. <
  29. mp11::mp_and
  30. <
  31. detail::is_reader<Reader>,
  32. typename is_format_tag<typename Reader::format_tag_t>::type,
  33. typename is_read_supported
  34. <
  35. typename get_pixel_type<View>::type,
  36. typename Reader::format_tag_t
  37. >::type
  38. >::value
  39. >::type* /*dummy*/ = nullptr)
  40. {
  41. reader.check_image_size(view.dimensions());
  42. reader.init_view(view, reader._settings);
  43. reader.apply(view);
  44. }
  45. /// \brief Reads an image view without conversion. No memory is allocated.
  46. /// \param file It's a device. Must satisfy is_input_device metafunction.
  47. /// \param view The image view in which the data is read into.
  48. /// \param settings Specifies read settings depending on the image format.
  49. /// \throw std::ios_base::failure
  50. template <typename Device, typename View, typename FormatTag>
  51. inline
  52. void read_view(
  53. Device& file,
  54. View const& view,
  55. image_read_settings<FormatTag> const& settings,
  56. typename std::enable_if
  57. <
  58. mp11::mp_and
  59. <
  60. detail::is_read_device<FormatTag, Device>,
  61. typename is_format_tag<FormatTag>::type,
  62. typename is_read_supported
  63. <
  64. typename get_pixel_type<View>::type,
  65. FormatTag
  66. >::type
  67. >::value
  68. >::type* /*dummy*/ = nullptr)
  69. {
  70. using reader_t =
  71. typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
  72. reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
  73. read_view(reader, view);
  74. }
  75. /// \brief Reads an image view without conversion. No memory is allocated.
  76. /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
  77. /// \param view The image view in which the data is read into.
  78. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  79. /// \throw std::ios_base::failure
  80. template <typename Device, typename View, typename FormatTag>
  81. inline
  82. void read_view(Device& file, View const& view, FormatTag const& tag,
  83. typename std::enable_if
  84. <
  85. mp11::mp_and
  86. <
  87. typename is_format_tag<FormatTag>::type,
  88. detail::is_read_device<FormatTag, Device>,
  89. typename is_read_supported
  90. <
  91. typename get_pixel_type<View>::type,
  92. FormatTag
  93. >::type
  94. >::value>::type* /*dummy*/ = nullptr)
  95. {
  96. using reader_t =
  97. typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
  98. reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
  99. read_view(reader, view);
  100. }
  101. /// \brief Reads an image view without conversion. No memory is allocated.
  102. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  103. /// \param view The image view in which the data is read into.
  104. /// \param settings Specifies read settings depending on the image format.
  105. /// \throw std::ios_base::failure
  106. template <typename String, typename View, typename FormatTag>
  107. inline
  108. void read_view(
  109. String const& file_name,
  110. View const& view,
  111. image_read_settings<FormatTag> const& settings,
  112. typename std::enable_if
  113. <
  114. mp11::mp_and
  115. <
  116. typename detail::is_supported_path_spec<String>::type,
  117. typename is_format_tag<FormatTag>::type,
  118. typename is_read_supported
  119. <
  120. typename get_pixel_type<View>::type,
  121. FormatTag
  122. >::type
  123. >::value
  124. >::type* /*dummy*/ = nullptr)
  125. {
  126. using reader_t =
  127. typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
  128. reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
  129. read_view(reader, view);
  130. }
  131. /// \brief Reads an image view without conversion. No memory is allocated.
  132. /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
  133. /// \param view The image view in which the data is read into.
  134. /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
  135. /// \throw std::ios_base::failure
  136. template <typename String, typename View, typename FormatTag>
  137. inline
  138. void read_view(String const& file_name, View const& view, FormatTag const& tag,
  139. typename std::enable_if
  140. <
  141. mp11::mp_and
  142. <
  143. typename detail::is_supported_path_spec<String>::type,
  144. typename is_format_tag<FormatTag>::type,
  145. typename is_read_supported
  146. <
  147. typename get_pixel_type<View>::type,
  148. FormatTag
  149. >::type
  150. >::value
  151. >::type* /*dummy*/ = nullptr)
  152. {
  153. using reader_t =
  154. typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
  155. reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
  156. read_view(reader, view);
  157. }
  158. }} // namespace boost::gil
  159. #endif