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