]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/gil/pixel_iterator.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / pixel_iterator.hpp
CommitLineData
92f5a8d4
TL
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>
7c673cae 15
7c673cae 16#include <iterator>
92f5a8d4 17#include <type_traits>
7c673cae
FG
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
7c673cae
FG
25/// \brief metafunction predicate determining whether the given iterator is a plain one or an adaptor over another iterator.
26/// Examples of adaptors are the step iterator and the dereference iterator adaptor.
27template <typename It>
92f5a8d4 28struct is_iterator_adaptor : public std::false_type {};
7c673cae
FG
29
30/// \brief returns the base iterator for a given iterator adaptor. Provide an specialization when introducing new iterator adaptors
31template <typename It>
32struct iterator_adaptor_get_base;
33
34/// \brief Changes the base iterator of an iterator adaptor. Provide an specialization when introducing new iterator adaptors
35template <typename It, typename NewBaseIt>
36struct iterator_adaptor_rebind;
37
38/// \brief Returns the type of an iterator just like the input iterator, except operating over immutable values
39template <typename It>
40struct const_iterator_type;
41
42// The default implementation when the iterator is a C pointer is to use the standard constness semantics
92f5a8d4
TL
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*; };
7c673cae
FG
45
46/// \brief Metafunction predicate returning whether the given iterator allows for changing its values
47/// \ingroup GILIsMutable
48template <typename It>
49struct iterator_is_mutable{};
50
51// The default implementation when the iterator is a C pointer is to use the standard constness semantics
92f5a8d4
TL
52template <typename T>
53struct iterator_is_mutable<T*> : std::true_type {};
54
55template <typename T>
56struct iterator_is_mutable<T const*> : std::false_type {};
7c673cae
FG
57
58/// \defgroup PixelIteratorModelInterleavedPtr C pointer to a pixel
59/// \ingroup PixelIteratorModel
60/// \brief Iterators over interleaved pixels.
61/// A C pointer to a model of PixelValueConcept is used as an iterator over interleaved pixels. Models PixelIteratorConcept, HomogeneousPixelBasedConcept, HasDynamicXStepTypeConcept, MemoryBasedIteratorConcept
62
63
64
65/////////////////////////////
66// HasDynamicXStepTypeConcept
67/////////////////////////////
68
92f5a8d4 69/// \ingroup PixelIteratorModelInterleavedPtr
7c673cae
FG
70template <typename Pixel>
71struct dynamic_x_step_type<Pixel*> {
92f5a8d4 72 using type = memory_based_step_iterator<Pixel *>;
7c673cae
FG
73};
74
92f5a8d4 75/// \ingroup PixelIteratorModelInterleavedPtr
7c673cae
FG
76template <typename Pixel>
77struct dynamic_x_step_type<const Pixel*> {
92f5a8d4 78 using type = memory_based_step_iterator<const Pixel *>;
7c673cae
FG
79};
80
81
82/////////////////////////////
83// PixelBasedConcept
84/////////////////////////////
85
92f5a8d4
TL
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> {};
7c673cae 94
92f5a8d4
TL
95template <typename Pixel>
96struct channel_mapping_type<Pixel const*> : channel_mapping_type<Pixel> {};
7c673cae 97
92f5a8d4
TL
98template <typename Pixel>
99struct is_planar<Pixel*> : is_planar<Pixel> {};
100
101template <typename Pixel>
102struct is_planar<Pixel const*> : is_planar<Pixel> {};
7c673cae
FG
103
104/////////////////////////////
105// HomogeneousPixelBasedConcept
106/////////////////////////////
107
92f5a8d4
TL
108template <typename Pixel>
109struct channel_type<Pixel*> : channel_type<Pixel> {};
110
111template <typename Pixel>
112struct channel_type<Pixel const*> : channel_type<Pixel> {};
7c673cae
FG
113
114////////////////////////////////////////////////////////////////////////////////////////
92f5a8d4 115/// Support for pixel iterator movement measured in memory units (bytes or bits) as opposed to pixel type.
7c673cae 116/// Necessary to handle image row alignment and channel plane alignment.
7c673cae
FG
117////////////////////////////////////////////////////////////////////////////////////////
118
119/////////////////////////////
120// MemoryBasedIteratorConcept
121/////////////////////////////
122
123template <typename T>
92f5a8d4 124struct byte_to_memunit : std::integral_constant<int, 1> {};
7c673cae
FG
125
126template <typename P>
92f5a8d4 127inline std::ptrdiff_t memunit_step(P const*) { return sizeof(P); }
7c673cae
FG
128
129template <typename P>
92f5a8d4
TL
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));
7c673cae
FG
135}
136
137template <typename P>
92f5a8d4
TL
138inline void memunit_advance(P* &p, std::ptrdiff_t diff)
139{
140 p = (P*)((unsigned char*)(p)+diff);
7c673cae
FG
141}
142
143template <typename P>
92f5a8d4
TL
144inline P* memunit_advanced(const P* p, std::ptrdiff_t diff)
145{
7c673cae
FG
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