make_scanline_reader.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Copyright 2012 Christian Henning
  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_MAKE_SCANLINE_READER_HPP
  9. #define BOOST_GIL_IO_MAKE_SCANLINE_READER_HPP
  10. #include <boost/gil/detail/mp11.hpp>
  11. #include <boost/gil/io/get_reader.hpp>
  12. #include <type_traits>
  13. namespace boost { namespace gil {
  14. template <typename String, typename FormatTag>
  15. inline
  16. auto make_scanline_reader(String const& file_name, FormatTag const&,
  17. typename std::enable_if
  18. <
  19. mp11::mp_and
  20. <
  21. detail::is_supported_path_spec<String>,
  22. is_format_tag<FormatTag>
  23. >::value
  24. >::type* /*dummy*/ = nullptr)
  25. -> typename get_scanline_reader<String, FormatTag>::type
  26. {
  27. using device_t = typename get_read_device<String, FormatTag>::type;
  28. device_t device(
  29. detail::convert_to_native_string(file_name),
  30. typename detail::file_stream_device<FormatTag>::read_tag());
  31. return typename get_scanline_reader<String, FormatTag>::type(
  32. device, image_read_settings<FormatTag>());
  33. }
  34. template< typename FormatTag >
  35. inline
  36. typename get_scanline_reader< std::wstring
  37. , FormatTag
  38. >::type
  39. make_scanline_reader( const std::wstring& file_name
  40. , FormatTag const&
  41. )
  42. {
  43. const char* str = detail::convert_to_native_string( file_name );
  44. typename get_read_device< std::wstring
  45. , FormatTag
  46. >::type device( str
  47. , typename detail::file_stream_device< FormatTag >::read_tag()
  48. );
  49. delete[] str;
  50. return typename get_scanline_reader< std::wstring
  51. , FormatTag
  52. >::type( device
  53. , image_read_settings< FormatTag >()
  54. );
  55. }
  56. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  57. template< typename FormatTag >
  58. inline
  59. typename get_scanline_reader< std::wstring
  60. , FormatTag
  61. >::type
  62. make_scanline_reader( const filesystem::path& path
  63. , FormatTag const&
  64. )
  65. {
  66. return make_scanline_reader( path.wstring()
  67. , image_read_settings< FormatTag >()
  68. );
  69. }
  70. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  71. template <typename Device, typename FormatTag>
  72. inline
  73. auto make_scanline_reader(Device& io_dev, FormatTag const&,
  74. typename std::enable_if
  75. <
  76. mp11::mp_and
  77. <
  78. detail::is_adaptable_input_device<FormatTag, Device>,
  79. is_format_tag<FormatTag>
  80. >::value
  81. >::type* /*dummy*/ = nullptr)
  82. -> typename get_scanline_reader<Device, FormatTag>::type
  83. {
  84. return make_scanline_reader(io_dev, image_read_settings<FormatTag>());
  85. }
  86. }} // namespace boost::gil
  87. #endif