make_scanline_reader.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Copyright 2012 Christian Henning
  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_MAKE_SCANLINE_READER_HPP
  9. #define BOOST_GIL_IO_MAKE_SCANLINE_READER_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Christian Henning \n
  14. ///
  15. /// \date 2012 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <boost/utility/enable_if.hpp>
  19. #include <boost/gil/io/get_reader.hpp>
  20. namespace boost { namespace gil {
  21. template< typename String
  22. , typename FormatTag
  23. >
  24. inline
  25. typename get_scanline_reader< String
  26. , FormatTag
  27. >::type
  28. make_scanline_reader( const String& file_name
  29. , const FormatTag&
  30. , typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
  31. , is_format_tag< FormatTag >
  32. >
  33. >::type* /* ptr */ = 0
  34. )
  35. {
  36. typename get_read_device< String
  37. , FormatTag
  38. >::type device( detail::convert_to_native_string( file_name )
  39. , typename detail::file_stream_device< FormatTag >::read_tag()
  40. );
  41. return typename get_scanline_reader< String
  42. , FormatTag
  43. >::type( device
  44. , image_read_settings<FormatTag>()
  45. );
  46. }
  47. template< typename FormatTag >
  48. inline
  49. typename get_scanline_reader< std::wstring
  50. , FormatTag
  51. >::type
  52. make_scanline_reader( const std::wstring& file_name
  53. , const FormatTag&
  54. )
  55. {
  56. const char* str = detail::convert_to_native_string( file_name );
  57. typename get_read_device< std::wstring
  58. , FormatTag
  59. >::type device( str
  60. , typename detail::file_stream_device< FormatTag >::read_tag()
  61. );
  62. delete[] str;
  63. return typename get_scanline_reader< std::wstring
  64. , FormatTag
  65. >::type( device
  66. , image_read_settings< FormatTag >()
  67. );
  68. }
  69. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  70. template< typename FormatTag >
  71. inline
  72. typename get_scanline_reader< std::wstring
  73. , FormatTag
  74. >::type
  75. make_scanline_reader( const filesystem::path& path
  76. , const FormatTag&
  77. )
  78. {
  79. return make_scanline_reader( path.wstring()
  80. , image_read_settings< FormatTag >()
  81. );
  82. }
  83. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  84. template< typename Device
  85. , typename FormatTag
  86. >
  87. inline
  88. typename get_scanline_reader< Device
  89. , FormatTag
  90. >::type
  91. make_scanline_reader( Device& io_dev
  92. , const FormatTag&
  93. , typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
  94. , Device
  95. >
  96. , is_format_tag< FormatTag >
  97. >
  98. >::type* /* ptr */ = 0
  99. )
  100. {
  101. return make_scanline_reader( io_dev, image_read_settings< FormatTag >() );
  102. }
  103. } // namespace gil
  104. } // namespace boost
  105. #endif