]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/gil/pixel_iterator.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / pixel_iterator.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
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_PIXEL_ITERATOR_HPP
9 #define BOOST_GIL_PIXEL_ITERATOR_HPP
10
11 #include <boost/gil/concepts.hpp>
12 #include <boost/gil/dynamic_step.hpp>
13 #include <boost/gil/utilities.hpp>
14 #include <boost/gil/pixel.hpp>
15
16 #include <iterator>
17 #include <type_traits>
18
19 namespace boost { namespace gil {
20
21 //forwarded declaration (as this file is included in step_iterator.hpp)
22 template <typename Iterator>
23 class memory_based_step_iterator;
24
25 /// \brief metafunction predicate determining whether the given iterator is a plain one or an adaptor over another iterator.
26 /// Examples of adaptors are the step iterator and the dereference iterator adaptor.
27 template <typename It>
28 struct is_iterator_adaptor : public std::false_type {};
29
30 /// \brief returns the base iterator for a given iterator adaptor. Provide an specialization when introducing new iterator adaptors
31 template <typename It>
32 struct iterator_adaptor_get_base;
33
34 /// \brief Changes the base iterator of an iterator adaptor. Provide an specialization when introducing new iterator adaptors
35 template <typename It, typename NewBaseIt>
36 struct iterator_adaptor_rebind;
37
38 /// \brief Returns the type of an iterator just like the input iterator, except operating over immutable values
39 template <typename It>
40 struct const_iterator_type;
41
42 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
43 template <typename T> struct const_iterator_type<T*> { using type = T const*; };
44 template <typename T> struct const_iterator_type<T const*> { using type = T const*; };
45
46 /// \brief Metafunction predicate returning whether the given iterator allows for changing its values
47 /// \ingroup GILIsMutable
48 template <typename It>
49 struct iterator_is_mutable{};
50
51 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
52 template <typename T>
53 struct iterator_is_mutable<T*> : std::true_type {};
54
55 template <typename T>
56 struct iterator_is_mutable<T const*> : std::false_type {};
57
58 /// \defgroup PixelIteratorModelInterleavedPtr C pointer to a pixel
59 /// \ingroup PixelIteratorModel
60 /// \brief Iterators over interleaved pixels.
61 /// A C pointer to a model of PixelValueConcept is used as an iterator over interleaved pixels. Models PixelIteratorConcept, HomogeneousPixelBasedConcept, HasDynamicXStepTypeConcept, MemoryBasedIteratorConcept
62
63
64
65 /////////////////////////////
66 // HasDynamicXStepTypeConcept
67 /////////////////////////////
68
69 /// \ingroup PixelIteratorModelInterleavedPtr
70 template <typename Pixel>
71 struct dynamic_x_step_type<Pixel*> {
72 using type = memory_based_step_iterator<Pixel *>;
73 };
74
75 /// \ingroup PixelIteratorModelInterleavedPtr
76 template <typename Pixel>
77 struct dynamic_x_step_type<const Pixel*> {
78 using type = memory_based_step_iterator<const Pixel *>;
79 };
80
81
82 /////////////////////////////
83 // PixelBasedConcept
84 /////////////////////////////
85
86 template <typename Pixel>
87 struct color_space_type<Pixel*> : color_space_type<Pixel> {};
88
89 template <typename Pixel>
90 struct color_space_type<Pixel const*> : color_space_type<Pixel> {};
91
92 template <typename Pixel>
93 struct channel_mapping_type<Pixel*> : channel_mapping_type<Pixel> {};
94
95 template <typename Pixel>
96 struct channel_mapping_type<Pixel const*> : channel_mapping_type<Pixel> {};
97
98 template <typename Pixel>
99 struct is_planar<Pixel*> : is_planar<Pixel> {};
100
101 template <typename Pixel>
102 struct is_planar<Pixel const*> : is_planar<Pixel> {};
103
104 /////////////////////////////
105 // HomogeneousPixelBasedConcept
106 /////////////////////////////
107
108 template <typename Pixel>
109 struct channel_type<Pixel*> : channel_type<Pixel> {};
110
111 template <typename Pixel>
112 struct channel_type<Pixel const*> : channel_type<Pixel> {};
113
114 ////////////////////////////////////////////////////////////////////////////////////////
115 /// Support for pixel iterator movement measured in memory units (bytes or bits) as opposed to pixel type.
116 /// Necessary to handle image row alignment and channel plane alignment.
117 ////////////////////////////////////////////////////////////////////////////////////////
118
119 /////////////////////////////
120 // MemoryBasedIteratorConcept
121 /////////////////////////////
122
123 template <typename T>
124 struct byte_to_memunit : std::integral_constant<int, 1> {};
125
126 template <typename P>
127 inline std::ptrdiff_t memunit_step(P const*) { return sizeof(P); }
128
129 template <typename P>
130 inline std::ptrdiff_t memunit_distance(P const* p1, P const* p2)
131 {
132 return (
133 gil_reinterpret_cast_c<unsigned char const*>(p2) -
134 gil_reinterpret_cast_c<unsigned char const*>(p1));
135 }
136
137 template <typename P>
138 inline void memunit_advance(P* &p, std::ptrdiff_t diff)
139 {
140 p = (P*)((unsigned char*)(p)+diff);
141 }
142
143 template <typename P>
144 inline P* memunit_advanced(const P* p, std::ptrdiff_t diff)
145 {
146 return (P*)((char*)(p)+diff);
147 }
148
149 // memunit_advanced_ref
150 // (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough)
151
152 template <typename P>
153 inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) {
154 return *memunit_advanced(p,diff);
155 }
156
157 } } // namespace boost::gil
158
159 #endif