conversion_policies.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Copyright 2007-2008 Christian Henning, Andreas Pokorny
  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_CONVERSION_POLICIES_HPP
  9. #define BOOST_GIL_IO_CONVERSION_POLICIES_HPP
  10. #include <boost/gil/image_view_factory.hpp>
  11. #include <boost/gil/io/error.hpp>
  12. #include <algorithm>
  13. #include <iterator>
  14. #include <type_traits>
  15. namespace boost{namespace gil{ namespace detail {
  16. struct read_and_no_convert
  17. {
  18. public:
  19. using color_converter_type = void *;
  20. template <typename InIterator, typename OutIterator>
  21. void read(
  22. InIterator const& /*begin*/, InIterator const& /*end*/ , OutIterator /*out*/,
  23. typename std::enable_if
  24. <
  25. mpl::not_
  26. <
  27. pixels_are_compatible
  28. <
  29. typename std::iterator_traits<InIterator>::value_type,
  30. typename std::iterator_traits<OutIterator>::value_type
  31. >
  32. >::value
  33. >::type* /*dummy*/ = nullptr)
  34. {
  35. io_error("Data cannot be copied because the pixels are incompatible.");
  36. }
  37. template <typename InIterator, typename OutIterator>
  38. void read(InIterator const& begin, InIterator const& end, OutIterator out,
  39. typename std::enable_if
  40. <
  41. pixels_are_compatible
  42. <
  43. typename std::iterator_traits<InIterator>::value_type,
  44. typename std::iterator_traits<OutIterator>::value_type
  45. >::value
  46. >::type* /*dummy*/ = nullptr)
  47. {
  48. std::copy(begin, end, out);
  49. }
  50. };
  51. template<typename CC>
  52. struct read_and_convert
  53. {
  54. public:
  55. using color_converter_type = default_color_converter;
  56. CC _cc;
  57. read_and_convert()
  58. {}
  59. read_and_convert( const color_converter_type& cc )
  60. : _cc( cc )
  61. {}
  62. template< typename InIterator
  63. , typename OutIterator
  64. >
  65. void read( const InIterator& begin
  66. , const InIterator& end
  67. , OutIterator out
  68. )
  69. {
  70. using deref_t = color_convert_deref_fn<typename std::iterator_traits<InIterator>::reference
  71. , typename std::iterator_traits<OutIterator>::value_type //reference?
  72. , CC
  73. >;
  74. std::transform( begin
  75. , end
  76. , out
  77. , deref_t( _cc )
  78. );
  79. }
  80. };
  81. /// is_read_only metafunction
  82. /// \brief Determines if reader type is read only ( no conversion ).
  83. template< typename Conversion_Policy >
  84. struct is_read_only : mpl::false_ {};
  85. template<>
  86. struct is_read_only< detail::read_and_no_convert > : mpl::true_ {};
  87. } // namespace detail
  88. } // namespace gil
  89. } // namespace boost
  90. #endif