Boost GIL


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