Boost GIL


pixel_iterator.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3 
4  Use, modification and distribution are subject to the Boost Software License,
5  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6  http://www.boost.org/LICENSE_1_0.txt).
7 
8  See http://opensource.adobe.com/gil for most recent version including documentation.
9 */
10 
11 /*************************************************************************************************/
12 
13 #ifndef BOOST_GIL_PIXEL_ITERATOR_HPP
14 #define BOOST_GIL_PIXEL_ITERATOR_HPP
15 
24 
25 #include <boost/gil/config.hpp>
26 #include <boost/gil/concept.hpp>
27 #include <boost/gil/pixel.hpp>
28 #include <boost/gil/utility.hpp>
29 
30 #include <cassert>
31 #include <iterator>
32 
33 namespace boost { namespace gil {
34 
35 //forwarded declaration (as this file is included in step_iterator.hpp)
36 template <typename Iterator>
37 class memory_based_step_iterator;
38 
39 template <typename Iterator> struct dynamic_x_step_type;
40 
43 template <typename It>
44 struct is_iterator_adaptor : public mpl::false_{};
45 
47 template <typename It>
48 struct iterator_adaptor_get_base;
49 
51 template <typename It, typename NewBaseIt>
52 struct iterator_adaptor_rebind;
53 
55 template <typename It>
56 struct const_iterator_type;
57 
58 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
59 template <typename T> struct const_iterator_type< T*> { typedef const T* type; };
60 template <typename T> struct const_iterator_type<const T*> { typedef const T* type; };
61 
64 template <typename It>
65 struct iterator_is_mutable{};
66 
67 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
68 template <typename T> struct iterator_is_mutable< T*> : public mpl::true_{};
69 template <typename T> struct iterator_is_mutable<const T*> : public mpl::false_{};
70 
75 
76 
77 
79 // HasDynamicXStepTypeConcept
81 
83 template <typename Pixel>
84 struct dynamic_x_step_type<Pixel*> {
85  typedef memory_based_step_iterator<Pixel*> type;
86 };
87 
89 template <typename Pixel>
90 struct dynamic_x_step_type<const Pixel*> {
91  typedef memory_based_step_iterator<const Pixel*> type;
92 };
93 
94 
96 // PixelBasedConcept
98 
99 template <typename Pixel> struct color_space_type< Pixel*> : public color_space_type<Pixel> {};
100 template <typename Pixel> struct color_space_type<const Pixel*> : public color_space_type<Pixel> {};
101 
102 template <typename Pixel> struct channel_mapping_type< Pixel*> : public channel_mapping_type<Pixel> {};
103 template <typename Pixel> struct channel_mapping_type<const Pixel*> : public channel_mapping_type<Pixel> {};
104 
105 template <typename Pixel> struct is_planar< Pixel*> : public is_planar<Pixel> {};
106 template <typename Pixel> struct is_planar<const Pixel*> : public is_planar<Pixel> {};
107 
109 // HomogeneousPixelBasedConcept
111 
112 template <typename Pixel> struct channel_type<Pixel*> : public channel_type<Pixel> {};
113 template <typename Pixel> struct channel_type<const Pixel*> : public channel_type<Pixel> {};
114 
121 
123 // MemoryBasedIteratorConcept
125 
126 template <typename T>
127 struct byte_to_memunit : public mpl::int_<1> {};
128 
129 template <typename P>
130 inline std::ptrdiff_t memunit_step(const P*) { return sizeof(P); }
131 
132 template <typename P>
133 inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) {
134  return (gil_reinterpret_cast_c<const unsigned char*>(p2)-gil_reinterpret_cast_c<const unsigned char*>(p1));
135 }
136 
137 template <typename P>
138 inline void memunit_advance(P* &p, std::ptrdiff_t diff) {
139  p=(P*)((unsigned char*)(p)+diff);
140 }
141 
142 template <typename P>
143 inline P* memunit_advanced(const P* p, std::ptrdiff_t diff) {
144  return (P*)((char*)(p)+diff);
145 }
146 
147 // memunit_advanced_ref
148 // (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough)
149 
150 template <typename P>
151 inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) {
152  return *memunit_advanced(p,diff);
153 }
154 
155 } } // namespace boost::gil
156 
157 #endif
Definition: pixel_iterator.hpp:127
Concept check classes for GIL concepts.
GIL configuration file.
Various utilities not specific to the image library. Some are non-standard STL extensions or generic ...
pixel class and related utilities