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 GIL_PIXEL_ITERATOR_H
14 #define GIL_PIXEL_ITERATOR_H
15 
24 
25 #include <cassert>
26 #include <iterator>
27 #include "gil_concept.hpp"
28 #include "utilities.hpp"
29 #include "pixel.hpp"
30 
31 namespace boost { namespace gil {
32 
33 //forwarded declaration (as this file is included in step_iterator.hpp)
34 template <typename Iterator>
35 class memory_based_step_iterator;
36 
37 template <typename Iterator> struct dynamic_x_step_type;
38 
41 template <typename It>
42 struct is_iterator_adaptor : public mpl::false_{};
43 
45 template <typename It>
46 struct iterator_adaptor_get_base;
47 
49 template <typename It, typename NewBaseIt>
50 struct iterator_adaptor_rebind;
51 
53 template <typename It>
54 struct const_iterator_type;
55 
56 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
57 template <typename T> struct const_iterator_type< T*> { typedef const T* type; };
58 template <typename T> struct const_iterator_type<const T*> { typedef const T* type; };
59 
62 template <typename It>
63 struct iterator_is_mutable{};
64 
65 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
66 template <typename T> struct iterator_is_mutable< T*> : public mpl::true_{};
67 template <typename T> struct iterator_is_mutable<const T*> : public mpl::false_{};
68 
73 
74 
75 
77 // HasDynamicXStepTypeConcept
79 
81 template <typename Pixel>
82 struct dynamic_x_step_type<Pixel*> {
83  typedef memory_based_step_iterator<Pixel*> type;
84 };
85 
87 template <typename Pixel>
88 struct dynamic_x_step_type<const Pixel*> {
89  typedef memory_based_step_iterator<const Pixel*> type;
90 };
91 
92 
94 // PixelBasedConcept
96 
97 template <typename Pixel> struct color_space_type< Pixel*> : public color_space_type<Pixel> {};
98 template <typename Pixel> struct color_space_type<const Pixel*> : public color_space_type<Pixel> {};
99 
100 template <typename Pixel> struct channel_mapping_type< Pixel*> : public channel_mapping_type<Pixel> {};
101 template <typename Pixel> struct channel_mapping_type<const Pixel*> : public channel_mapping_type<Pixel> {};
102 
103 template <typename Pixel> struct is_planar< Pixel*> : public is_planar<Pixel> {};
104 template <typename Pixel> struct is_planar<const Pixel*> : public is_planar<Pixel> {};
105 
107 // HomogeneousPixelBasedConcept
109 
110 template <typename Pixel> struct channel_type<Pixel*> : public channel_type<Pixel> {};
111 template <typename Pixel> struct channel_type<const Pixel*> : public channel_type<Pixel> {};
112 
119 
121 // MemoryBasedIteratorConcept
123 
124 template <typename T>
125 struct byte_to_memunit : public mpl::int_<1> {};
126 
127 template <typename P>
128 inline std::ptrdiff_t memunit_step(const P*) { return sizeof(P); }
129 
130 template <typename P>
131 inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) {
132  return (gil_reinterpret_cast_c<const unsigned char*>(p2)-gil_reinterpret_cast_c<const unsigned char*>(p1));
133 }
134 
135 template <typename P>
136 inline void memunit_advance(P* &p, std::ptrdiff_t diff) {
137  p=(P*)((unsigned char*)(p)+diff);
138 }
139 
140 template <typename P>
141 inline P* memunit_advanced(const P* p, std::ptrdiff_t diff) {
142  return (P*)((char*)(p)+diff);
143 }
144 
145 // memunit_advanced_ref
146 // (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough)
147 
148 template <typename P>
149 inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) {
150  return *memunit_advanced(p,diff);
151 }
152 
153 } } // namespace boost::gil
154 
155 #endif
Definition: pixel_iterator.hpp:125
Concept check classes for GIL concepts.
pixel class and related utilities
Various utilities not specific to the image library. Some are non-standard STL extensions or generic ...