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 
27 template <typename It>
28 struct is_iterator_adaptor : public std::false_type {};
29 
31 template <typename It>
32 struct iterator_adaptor_get_base;
33 
35 template <typename It, typename NewBaseIt>
37 
39 template <typename It>
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 
48 template <typename It>
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 
62 
63 
64 
66 // HasDynamicXStepTypeConcept
68 
70 template <typename Pixel>
71 struct dynamic_x_step_type<Pixel*> {
72  using type = memory_based_step_iterator<Pixel *>;
73 };
74 
76 template <typename Pixel>
77 struct dynamic_x_step_type<const Pixel*> {
78  using type = memory_based_step_iterator<const Pixel *>;
79 };
80 
81 
83 // PixelBasedConcept
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 
105 // HomogeneousPixelBasedConcept
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 
118 
120 // MemoryBasedIteratorConcept
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
Definition: pixel_iterator.hpp:124
Changes the base iterator of an iterator adaptor. Provide an specialization when introducing new iter...
Definition: pixel_iterator.hpp:36
Metafunction predicate returning whether the given iterator allows for changing its values.
Definition: pixel_iterator.hpp:49
Returns the type of an iterator just like the input iterator, except operating over immutable values.
Definition: pixel_iterator.hpp:40