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
19namespace boost { namespace gil {
20
21//forwarded declaration (as this file is included in step_iterator.hpp)
22template <typename Iterator>
23class memory_based_step_iterator;
24
27template <typename It>
28struct is_iterator_adaptor : public std::false_type {};
29
31template <typename It>
33
35template <typename It, typename NewBaseIt>
37
39template <typename It>
41
42// The default implementation when the iterator is a C pointer is to use the standard constness semantics
43template <typename T> struct const_iterator_type<T*> { using type = T const*; };
44template <typename T> struct const_iterator_type<T const*> { using type = T const*; };
45
48template <typename It>
50
51// The default implementation when the iterator is a C pointer is to use the standard constness semantics
52template <typename T>
53struct iterator_is_mutable<T*> : std::true_type {};
54
55template <typename T>
56struct iterator_is_mutable<T const*> : std::false_type {};
57
62
63
64
66// HasDynamicXStepTypeConcept
68
70template <typename Pixel>
71struct dynamic_x_step_type<Pixel*> {
72 using type = memory_based_step_iterator<Pixel *>;
73};
74
76template <typename Pixel>
77struct dynamic_x_step_type<const Pixel*> {
78 using type = memory_based_step_iterator<const Pixel *>;
79};
80
81
83// PixelBasedConcept
85
86template <typename Pixel>
87struct color_space_type<Pixel*> : color_space_type<Pixel> {};
88
89template <typename Pixel>
90struct color_space_type<Pixel const*> : color_space_type<Pixel> {};
91
92template <typename Pixel>
93struct channel_mapping_type<Pixel*> : channel_mapping_type<Pixel> {};
94
95template <typename Pixel>
96struct channel_mapping_type<Pixel const*> : channel_mapping_type<Pixel> {};
97
98template <typename Pixel>
99struct is_planar<Pixel*> : is_planar<Pixel> {};
100
101template <typename Pixel>
102struct is_planar<Pixel const*> : is_planar<Pixel> {};
103
105// HomogeneousPixelBasedConcept
107
108template <typename Pixel>
109struct channel_type<Pixel*> : channel_type<Pixel> {};
110
111template <typename Pixel>
112struct channel_type<Pixel const*> : channel_type<Pixel> {};
113
118
120// MemoryBasedIteratorConcept
122
123template <typename T>
124struct byte_to_memunit : std::integral_constant<int, 1> {};
125
126template <typename P>
127inline std::ptrdiff_t memunit_step(P const*) { return sizeof(P); }
128
129template <typename P>
130inline 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
137template <typename P>
138inline void memunit_advance(P* &p, std::ptrdiff_t diff)
139{
140 p = (P*)((unsigned char*)(p)+diff);
141}
142
143template <typename P>
144inline 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
152template <typename P>
153inline 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
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
Definition pixel_iterator.hpp:124
Returns the type of an iterator just like the input iterator, except operating over immutable values.
Definition pixel_iterator.hpp:40
metafunction predicate determining whether the given iterator is a plain one or an adaptor over anoth...
Definition pixel_iterator.hpp:28
returns the base iterator for a given iterator adaptor. Provide an specialization when introducing ne...
Definition metafunctions.hpp:36
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