write_view.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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_WRITE_VIEW_HPP
  9. #define BOOST_GIL_IO_WRITE_VIEW_HPP
  10. #include <boost/type_traits/is_base_and_derived.hpp>
  11. #include <boost/type_traits/is_base_and_derived.hpp>
  12. #include <boost/mpl/and.hpp>
  13. #include <boost/utility/enable_if.hpp>
  14. #include <boost/gil/io/base.hpp>
  15. #include <boost/gil/io/device.hpp>
  16. #include <boost/gil/io/path_spec.hpp>
  17. #include <boost/gil/io/conversion_policies.hpp>
  18. ////////////////////////////////////////////////////////////////////////////////////////
  19. /// \file
  20. /// \brief
  21. /// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
  22. ///
  23. /// \date 2007-2012 \n
  24. ///
  25. ////////////////////////////////////////////////////////////////////////////////////////
  26. namespace boost{ namespace gil {
  27. /// \ingroup IO
  28. template< typename Writer
  29. , typename View
  30. >
  31. inline
  32. void write_view( Writer& writer
  33. , const View& view
  34. , typename enable_if< typename mpl::and_< typename detail::is_writer< Writer >::type
  35. , typename is_format_tag< typename Writer::format_tag_t >::type
  36. , typename is_write_supported< typename get_pixel_type< View >::type
  37. , typename Writer::format_tag_t
  38. >::type
  39. >::type
  40. >::type* /* ptr */ = 0
  41. )
  42. {
  43. writer.apply( view );
  44. }
  45. template< typename Device
  46. , typename View
  47. , typename FormatTag
  48. >
  49. inline
  50. void write_view( Device& device
  51. , const View& view
  52. , const FormatTag& tag
  53. , typename enable_if< typename mpl::and_< typename detail::is_write_device< FormatTag
  54. , Device
  55. >::type
  56. , typename is_format_tag< FormatTag >::type
  57. , typename is_write_supported< typename get_pixel_type< View >::type
  58. , FormatTag
  59. >::type
  60. >::type
  61. >::type* /* ptr */ = 0
  62. )
  63. {
  64. typedef typename get_writer< Device
  65. , FormatTag
  66. >::type writer_t;
  67. writer_t writer = make_writer( device
  68. , tag
  69. );
  70. write_view( writer
  71. , view
  72. );
  73. }
  74. template< typename String
  75. , typename View
  76. , typename FormatTag
  77. >
  78. inline
  79. void write_view( const String& file_name
  80. , const View& view
  81. , const FormatTag& tag
  82. , typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
  83. , typename is_format_tag< FormatTag >::type
  84. , typename is_write_supported< typename get_pixel_type< View >::type
  85. , FormatTag
  86. >::type
  87. >::type
  88. >::type* /* ptr */ = 0
  89. )
  90. {
  91. typedef typename get_writer< String
  92. , FormatTag
  93. >::type writer_t;
  94. writer_t writer = make_writer( file_name
  95. , tag
  96. );
  97. write_view( writer
  98. , view
  99. );
  100. }
  101. /// \ingroup IO
  102. template< typename Device
  103. , typename View
  104. , typename FormatTag
  105. , typename Log
  106. >
  107. inline
  108. void write_view( Device& device
  109. , const View& view
  110. , const image_write_info<FormatTag, Log>& info
  111. , typename enable_if< typename mpl::and_< typename detail::is_write_device< FormatTag
  112. , Device
  113. >::type
  114. , typename is_format_tag< FormatTag >::type
  115. , typename is_write_supported< typename get_pixel_type< View >::type
  116. , FormatTag
  117. >::type
  118. >::type
  119. >::type* /* ptr */ = 0
  120. )
  121. {
  122. typedef typename get_writer< Device
  123. , FormatTag
  124. >::type writer_t;
  125. writer_t writer = make_writer( device
  126. , info
  127. );
  128. write_view( writer
  129. , view
  130. );
  131. }
  132. template< typename String
  133. , typename View
  134. , typename FormatTag
  135. , typename Log
  136. >
  137. inline
  138. void write_view( const String& file_name
  139. , const View& view
  140. , const image_write_info< FormatTag, Log >& info
  141. , typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
  142. , typename is_format_tag< FormatTag >::type
  143. , typename is_write_supported< typename get_pixel_type< View >::type
  144. , FormatTag
  145. >::type
  146. >::type
  147. >::type* /* ptr */ = 0
  148. )
  149. {
  150. typedef typename get_writer< String
  151. , FormatTag
  152. >::type writer_t;
  153. writer_t writer = make_writer( file_name
  154. , info
  155. );
  156. write_view( writer
  157. , view
  158. );
  159. }
  160. ////////////////////////////////////// dynamic_image
  161. // without image_write_info
  162. template< typename Writer
  163. , typename Views
  164. >
  165. inline
  166. void write_view( Writer& writer
  167. , const any_image_view< Views >& view
  168. , typename enable_if< typename mpl::and_< typename detail::is_dynamic_image_writer< Writer >::type
  169. , typename is_format_tag< typename Writer::format_tag_t >::type
  170. >::type
  171. >::type* /* ptr */ = 0
  172. )
  173. {
  174. writer.apply( view );
  175. }
  176. // without image_write_info
  177. template< typename Device
  178. , typename Views
  179. , typename FormatTag
  180. >
  181. inline
  182. void write_view( Device& device
  183. , const any_image_view< Views >& views
  184. , const FormatTag& tag
  185. , typename enable_if< typename mpl::and_< typename detail::is_write_device< FormatTag
  186. , Device
  187. >::type
  188. , typename is_format_tag< FormatTag >::type
  189. >::type
  190. >::type* /* ptr */ = 0
  191. )
  192. {
  193. typedef typename get_dynamic_image_writer< Device
  194. , FormatTag
  195. >::type writer_t;
  196. writer_t writer = make_dynamic_image_writer( device
  197. , tag
  198. );
  199. write_view( writer
  200. , views
  201. );
  202. }
  203. template< typename String
  204. , typename Views
  205. , typename FormatTag
  206. >
  207. inline
  208. void write_view( const String& file_name
  209. , const any_image_view< Views >& views
  210. , const FormatTag& tag
  211. , typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
  212. , typename is_format_tag< FormatTag >::type
  213. >::type
  214. >::type* /* ptr */ = 0
  215. )
  216. {
  217. typedef typename get_dynamic_image_writer< String
  218. , FormatTag
  219. >::type writer_t;
  220. writer_t writer = make_dynamic_image_writer( file_name
  221. , tag
  222. );
  223. write_view( writer
  224. , views
  225. );
  226. }
  227. // with image_write_info
  228. /// \ingroup IO
  229. template< typename Device
  230. , typename Views
  231. , typename FormatTag
  232. , typename Log
  233. >
  234. inline
  235. void write_view( Device& device
  236. , const any_image_view< Views >& views
  237. , const image_write_info< FormatTag
  238. , Log
  239. >& info
  240. , typename enable_if< typename mpl::and_< typename detail::is_write_device< FormatTag
  241. , Device
  242. >::type
  243. , typename is_format_tag< FormatTag >::type
  244. >::type
  245. >::type* /* ptr */ = 0
  246. )
  247. {
  248. typedef typename get_dynamic_image_writer< Device
  249. , FormatTag
  250. >::type writer_t;
  251. writer_t writer = make_dynamic_image_writer( device
  252. , info
  253. );
  254. write_view( writer
  255. , views
  256. );
  257. }
  258. template< typename String
  259. , typename Views
  260. , typename FormatTag
  261. , typename Log
  262. >
  263. inline
  264. void write_view( const String& file_name
  265. , const any_image_view< Views >& views
  266. , const image_write_info< FormatTag
  267. , Log
  268. >& info
  269. , typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
  270. , typename is_format_tag< FormatTag >::type
  271. >::type
  272. >::type* /* ptr */ = 0
  273. )
  274. {
  275. typedef typename get_dynamic_image_writer< String
  276. , FormatTag
  277. >::type writer_t;
  278. writer_t writer = make_dynamic_image_writer( file_name
  279. , info
  280. );
  281. write_view( writer
  282. , views
  283. );
  284. }
  285. } // namespace gil
  286. } // namespace boost
  287. #endif