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