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/utilities.hpp>
13 #include <boost/gil/pixel.hpp>
14 
15 #include <iterator>
16 
17 namespace boost { namespace gil {
18 
19 //forwarded declaration (as this file is included in step_iterator.hpp)
20 template <typename Iterator>
21 class memory_based_step_iterator;
22 
23 template <typename Iterator> struct dynamic_x_step_type;
24 
27 template <typename It>
28 struct is_iterator_adaptor : public mpl::false_{};
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> struct iterator_is_mutable< T*> : public mpl::true_{};
53 template <typename T> struct iterator_is_mutable<const T*> : public mpl::false_{};
54 
59 
60 
61 
63 // HasDynamicXStepTypeConcept
65 
67 template <typename Pixel>
68 struct dynamic_x_step_type<Pixel*> {
69  using type = memory_based_step_iterator<Pixel *>;
70 };
71 
73 template <typename Pixel>
74 struct dynamic_x_step_type<const Pixel*> {
75  using type = memory_based_step_iterator<const Pixel *>;
76 };
77 
78 
80 // PixelBasedConcept
82 
83 template <typename Pixel> struct color_space_type< Pixel*> : public color_space_type<Pixel> {};
84 template <typename Pixel> struct color_space_type<const Pixel*> : public color_space_type<Pixel> {};
85 
86 template <typename Pixel> struct channel_mapping_type< Pixel*> : public channel_mapping_type<Pixel> {};
87 template <typename Pixel> struct channel_mapping_type<const Pixel*> : public channel_mapping_type<Pixel> {};
88 
89 template <typename Pixel> struct is_planar< Pixel*> : public is_planar<Pixel> {};
90 template <typename Pixel> struct is_planar<const Pixel*> : public is_planar<Pixel> {};
91 
93 // HomogeneousPixelBasedConcept
95 
96 template <typename Pixel> struct channel_type<Pixel*> : public channel_type<Pixel> {};
97 template <typename Pixel> struct channel_type<const Pixel*> : public channel_type<Pixel> {};
98 
105 
107 // MemoryBasedIteratorConcept
109 
110 template <typename T>
111 struct byte_to_memunit : public mpl::int_<1> {};
112 
113 template <typename P>
114 inline std::ptrdiff_t memunit_step(const P*) { return sizeof(P); }
115 
116 template <typename P>
117 inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) {
118  return (gil_reinterpret_cast_c<const unsigned char*>(p2)-gil_reinterpret_cast_c<const unsigned char*>(p1));
119 }
120 
121 template <typename P>
122 inline void memunit_advance(P* &p, std::ptrdiff_t diff) {
123  p=(P*)((unsigned char*)(p)+diff);
124 }
125 
126 template <typename P>
127 inline P* memunit_advanced(const P* p, std::ptrdiff_t diff) {
128  return (P*)((char*)(p)+diff);
129 }
130 
131 // memunit_advanced_ref
132 // (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough)
133 
134 template <typename P>
135 inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) {
136  return *memunit_advanced(p,diff);
137 }
138 
139 } } // namespace boost::gil
140 
141 #endif
Definition: pixel_iterator.hpp:111
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