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 <cassert>
16 #include <iterator>
17 
18 namespace boost { namespace gil {
19 
20 //forwarded declaration (as this file is included in step_iterator.hpp)
21 template <typename Iterator>
22 class memory_based_step_iterator;
23 
24 template <typename Iterator> struct dynamic_x_step_type;
25 
28 template <typename It>
29 struct is_iterator_adaptor : public mpl::false_{};
30 
32 template <typename It>
33 struct iterator_adaptor_get_base;
34 
36 template <typename It, typename NewBaseIt>
37 struct iterator_adaptor_rebind;
38 
40 template <typename It>
41 struct const_iterator_type;
42 
43 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
44 template <typename T> struct const_iterator_type< T*> { typedef const T* type; };
45 template <typename T> struct const_iterator_type<const T*> { typedef const T* type; };
46 
49 template <typename It>
50 struct iterator_is_mutable{};
51 
52 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
53 template <typename T> struct iterator_is_mutable< T*> : public mpl::true_{};
54 template <typename T> struct iterator_is_mutable<const T*> : public mpl::false_{};
55 
60 
61 
62 
64 // HasDynamicXStepTypeConcept
66 
68 template <typename Pixel>
69 struct dynamic_x_step_type<Pixel*> {
70  typedef memory_based_step_iterator<Pixel*> type;
71 };
72 
74 template <typename Pixel>
75 struct dynamic_x_step_type<const Pixel*> {
76  typedef memory_based_step_iterator<const Pixel*> type;
77 };
78 
79 
81 // PixelBasedConcept
83 
84 template <typename Pixel> struct color_space_type< Pixel*> : public color_space_type<Pixel> {};
85 template <typename Pixel> struct color_space_type<const Pixel*> : public color_space_type<Pixel> {};
86 
87 template <typename Pixel> struct channel_mapping_type< Pixel*> : public channel_mapping_type<Pixel> {};
88 template <typename Pixel> struct channel_mapping_type<const Pixel*> : public channel_mapping_type<Pixel> {};
89 
90 template <typename Pixel> struct is_planar< Pixel*> : public is_planar<Pixel> {};
91 template <typename Pixel> struct is_planar<const Pixel*> : public is_planar<Pixel> {};
92 
94 // HomogeneousPixelBasedConcept
96 
97 template <typename Pixel> struct channel_type<Pixel*> : public channel_type<Pixel> {};
98 template <typename Pixel> struct channel_type<const Pixel*> : public channel_type<Pixel> {};
99 
106 
108 // MemoryBasedIteratorConcept
110 
111 template <typename T>
112 struct byte_to_memunit : public mpl::int_<1> {};
113 
114 template <typename P>
115 inline std::ptrdiff_t memunit_step(const P*) { return sizeof(P); }
116 
117 template <typename P>
118 inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) {
119  return (gil_reinterpret_cast_c<const unsigned char*>(p2)-gil_reinterpret_cast_c<const unsigned char*>(p1));
120 }
121 
122 template <typename P>
123 inline void memunit_advance(P* &p, std::ptrdiff_t diff) {
124  p=(P*)((unsigned char*)(p)+diff);
125 }
126 
127 template <typename P>
128 inline P* memunit_advanced(const P* p, std::ptrdiff_t diff) {
129  return (P*)((char*)(p)+diff);
130 }
131 
132 // memunit_advanced_ref
133 // (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough)
134 
135 template <typename P>
136 inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) {
137  return *memunit_advanced(p,diff);
138 }
139 
140 } } // namespace boost::gil
141 
142 #endif
Definition: pixel_iterator.hpp:112