write_view.hpp 6.9 KB

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