write_view.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_WRITE_VIEW_HPP
  9. #define BOOST_GIL_IO_WRITE_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_writer.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. template<typename Writer, typename View>
  20. inline
  21. void write_view(Writer& writer, View const& view,
  22. typename std::enable_if
  23. <
  24. mp11::mp_and
  25. <
  26. typename detail::is_writer<Writer>::type,
  27. typename is_format_tag<typename Writer::format_tag_t>::type,
  28. typename is_write_supported
  29. <
  30. typename get_pixel_type<View>::type,
  31. typename Writer::format_tag_t
  32. >::type
  33. >::value
  34. >::type* /* ptr */ = nullptr)
  35. {
  36. writer.apply(view);
  37. }
  38. /// \ingroup IO
  39. template<typename Device, typename View, typename FormatTag>
  40. inline
  41. void write_view(Device& device, View const& view, FormatTag const& tag,
  42. typename std::enable_if
  43. <
  44. mp11::mp_and
  45. <
  46. typename detail::is_write_device<FormatTag, Device>::type,
  47. typename is_format_tag<FormatTag>::type,
  48. typename is_write_supported
  49. <
  50. typename get_pixel_type<View>::type,
  51. FormatTag
  52. >::type
  53. >::value
  54. >::type* /* ptr */ = nullptr)
  55. {
  56. using writer_t = typename get_writer<Device, FormatTag>::type;
  57. writer_t writer = make_writer(device, tag);
  58. write_view(writer, view);
  59. }
  60. /// \ingroup IO
  61. template<typename String, typename View, typename FormatTag>
  62. inline
  63. void write_view(String const& file_name, View const& view, FormatTag const& tag,
  64. typename std::enable_if
  65. <
  66. mp11::mp_and
  67. <
  68. typename detail::is_supported_path_spec<String>::type,
  69. typename is_format_tag<FormatTag>::type,
  70. typename is_write_supported
  71. <
  72. typename get_pixel_type<View>::type,
  73. FormatTag
  74. >::type
  75. >::value
  76. >::type* /* ptr */ = nullptr)
  77. {
  78. using writer_t = typename get_writer<String, FormatTag>::type;
  79. writer_t writer = make_writer(file_name, tag);
  80. write_view(writer, view);
  81. }
  82. /// \ingroup IO
  83. template<typename Device, typename View, typename FormatTag, typename Log>
  84. inline
  85. void write_view(
  86. Device& device, View const& view, image_write_info<FormatTag, Log> const& info,
  87. typename std::enable_if
  88. <
  89. mp11::mp_and
  90. <
  91. typename detail::is_write_device<FormatTag, Device>::type,
  92. typename is_format_tag<FormatTag>::type,
  93. typename is_write_supported
  94. <
  95. typename get_pixel_type<View>::type,
  96. FormatTag
  97. >::type
  98. >::value
  99. >::type* /* ptr */ = nullptr)
  100. {
  101. using writer_t = typename get_writer<Device, FormatTag>::type;
  102. writer_t writer = make_writer(device, info);
  103. write_view(writer, view);
  104. }
  105. /// \ingroup IO
  106. template<typename String, typename View, typename FormatTag, typename Log>
  107. inline
  108. void write_view(
  109. String const& file_name, View const& view, image_write_info<FormatTag, Log> const& info,
  110. typename std::enable_if
  111. <
  112. mp11::mp_and
  113. <
  114. typename detail::is_supported_path_spec<String>::type,
  115. typename is_format_tag<FormatTag>::type,
  116. typename is_write_supported
  117. <
  118. typename get_pixel_type<View>::type,
  119. FormatTag
  120. >::type
  121. >::value
  122. >::type* /* ptr */ = nullptr)
  123. {
  124. using writer_t = typename get_writer<String, FormatTag>::type;
  125. writer_t writer = make_writer(file_name, info);
  126. write_view(writer, view);
  127. }
  128. ////////////////////////////////////// dynamic_image
  129. // without image_write_info
  130. template <typename Writer, typename ...Views>
  131. inline
  132. void write_view(Writer& writer, any_image_view<Views...> const& view,
  133. typename std::enable_if
  134. <
  135. mp11::mp_and
  136. <
  137. typename detail::is_dynamic_image_writer<Writer>::type,
  138. typename is_format_tag<typename Writer::format_tag_t>::type
  139. >::value
  140. >::type * /* ptr */ = nullptr)
  141. {
  142. writer.apply(view);
  143. }
  144. // without image_write_info
  145. template <typename Device, typename ...Views, typename FormatTag>
  146. inline
  147. void write_view(
  148. Device& device, any_image_view<Views...> const& views, FormatTag const& tag,
  149. typename std::enable_if
  150. <
  151. mp11::mp_and
  152. <
  153. typename detail::is_write_device<FormatTag, Device>::type,
  154. typename is_format_tag<FormatTag>::type
  155. >::value
  156. >::type * /* ptr */ = 0)
  157. {
  158. using writer_t = typename get_dynamic_image_writer<Device, FormatTag>::type;
  159. writer_t writer = make_dynamic_image_writer(device, tag);
  160. write_view(writer, views);
  161. }
  162. template <typename String, typename ...Views, typename FormatTag>
  163. inline
  164. void write_view(
  165. String const& file_name, any_image_view<Views...> const& views, FormatTag const& tag,
  166. typename std::enable_if
  167. <
  168. mp11::mp_and
  169. <
  170. typename detail::is_supported_path_spec<String>::type,
  171. typename is_format_tag<FormatTag>::type
  172. >::value
  173. >::type * /* ptr */ = nullptr)
  174. {
  175. using writer_t = typename get_dynamic_image_writer<String, FormatTag>::type;
  176. writer_t writer = make_dynamic_image_writer(file_name, tag);
  177. write_view(writer, views);
  178. }
  179. // with image_write_info
  180. /// \ingroup IO
  181. template <typename Device, typename ...Views, typename FormatTag, typename Log>
  182. inline
  183. void write_view(
  184. Device& device, any_image_view<Views...> const& views, image_write_info<FormatTag, Log> const& info,
  185. typename std::enable_if
  186. <
  187. mp11::mp_and
  188. <
  189. typename detail::is_write_device<FormatTag, Device>::type,
  190. typename is_format_tag<FormatTag>::type
  191. >::value
  192. >::type * /* ptr */ = 0)
  193. {
  194. using writer_t = typename get_dynamic_image_writer<Device, FormatTag>::type;
  195. writer_t writer = make_dynamic_image_writer(device, info);
  196. write_view(writer, views);
  197. }
  198. template <typename String, typename ...Views, typename FormatTag, typename Log>
  199. inline
  200. void write_view(
  201. String const& file_name, any_image_view<Views...> const& views, image_write_info<FormatTag, Log> const& info,
  202. typename std::enable_if
  203. <
  204. mp11::mp_and
  205. <
  206. typename detail::is_supported_path_spec<String>::type,
  207. typename is_format_tag<FormatTag>::type
  208. >::value
  209. >::type * /* ptr */ = nullptr)
  210. {
  211. using writer_t = typename get_dynamic_image_writer<String, FormatTag>::type;
  212. writer_t writer = make_dynamic_image_writer(file_name, info);
  213. write_view(writer, views);
  214. }
  215. }} // namespace boost::gil
  216. #endif