6#include "_decl/decl_linear_access.hpp"
16 class LinearConstIterator
19 using Allocator = std::allocator<Type>;
20 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<Type>;
21 using AllocTraits = std::allocator_traits<AllocType>;
24 using iterator_category = std::random_access_iterator_tag;
25 using value_type = Type;
26 using pointer =
typename AllocTraits::pointer;
27 using reference =
const value_type &;
28 using difference_type =
typename AllocTraits::difference_type;
30 LinearConstIterator() =
default;
32 explicit LinearConstIterator(LinearAccessData linearAccessData, Size2D<int> size,
33 Point2D<int> pos = Point2D<int>()) noexcept
34 : linearAccessData_(linearAccessData)
41 reference operator*() const noexcept
43 return *
reinterpret_cast<Type *
>(currentPixelPtr_);
46 pointer operator->() const noexcept
48 return reinterpret_cast<Type *
>(currentPixelPtr_);
51 LinearConstIterator<Type> &operator++() noexcept
53 currentPos_.SetX(currentPos_.X() + 1);
54 currentPixelPtr_ += linearAccessData_.XInc();
55 if (currentPos_.X() < size_.Width())
60 currentPos_.SetY(currentPos_.Y() + 1);
61 currentLinePtr_ += linearAccessData_.YInc();
62 currentPixelPtr_ = currentLinePtr_;
67 LinearConstIterator<Type> operator++(
int)
noexcept
74 LinearConstIterator<Type> &operator--() noexcept
76 currentPos_.SetX(currentPos_.X() - 1);
77 currentPixelPtr_ -= linearAccessData_.XInc();
78 if (currentPos_.X() >= 0)
82 currentPos_.SetX(size_.Width() - 1);
83 currentPos_.SetY(currentPos_.Y() - 1);
84 currentLinePtr_ -= linearAccessData_.YInc();
85 currentPixelPtr_ = currentLinePtr_ + currentPos_.X() * linearAccessData_.XInc();
90 LinearConstIterator<Type> operator--(
int)
noexcept
97 LinearConstIterator<Type> &operator+=(
const difference_type offset)
noexcept
99 auto linearPos = Point2DToLinear(currentPos_);
101 currentPos_ = LinearToPoint2D(linearPos);
106 LinearConstIterator<Type> operator+(
const difference_type offset)
const noexcept
109 return tmp += offset;
112 LinearConstIterator<Type> &operator-=(
const difference_type offset)
noexcept
114 return *
this += -offset;
117 LinearConstIterator<Type> operator-(
const difference_type offset)
const noexcept
120 return tmp -= offset;
123 difference_type operator-(
const LinearConstIterator<Type> &rhs)
const noexcept
125 return Point2DToLinear(currentPos_) - Point2DToLinear(rhs.currentPos_);
128 reference operator[](
const difference_type offset)
const noexcept
130 return *(*
this + offset);
133 bool operator==(
const LinearConstIterator<Type> &rhs)
const noexcept
135 return currentPos_ == rhs.currentPos_;
138 bool operator!=(
const LinearConstIterator<Type> &rhs)
const noexcept
140 return !(*
this == rhs);
143 bool operator<(
const LinearConstIterator<Type> &rhs)
const noexcept
145 return Point2DToLinear(currentPos_) < Point2DToLinear(rhs.currentPos_);
148 bool operator>(
const LinearConstIterator<Type> &rhs)
const noexcept
153 bool operator<=(
const LinearConstIterator<Type> &rhs)
const noexcept
155 return !(rhs < *
this);
158 bool operator>=(
const LinearConstIterator<Type> &rhs)
const noexcept
160 return !(*
this < rhs);
164 difference_type Point2DToLinear(Point2D<int> pos)
const noexcept
166 return static_cast<difference_type
>(pos.Y()) *
static_cast<difference_type
>(size_.Width())
167 +
static_cast<difference_type
>(pos.X());
170 Point2D<int> LinearToPoint2D(difference_type pos)
const noexcept
172 return Point2D<int>(
static_cast<int>(pos % size_.Width()),
static_cast<int>(pos / size_.Width()));
175 void ApplyCurrentPos() noexcept
178 reinterpret_cast<std::uint8_t *
>(linearAccessData_.BasePtr()) + currentPos_.Y() * linearAccessData_.YInc();
179 currentPixelPtr_ = currentLinePtr_ + currentPos_.X() * linearAccessData_.XInc();
182 LinearAccessData linearAccessData_;
184 Point2D<int> currentPos_;
185 std::uint8_t *currentLinePtr_ =
nullptr;
186 std::uint8_t *currentPixelPtr_ =
nullptr;
189 template <
class Type>
190 inline LinearConstIterator<Type>
operator+(
typename LinearConstIterator<Type>::difference_type offset,
191 LinearConstIterator<Type> next)
noexcept
193 return next += offset;
196 template <
class Type>
197 class LinearIterator :
public LinearConstIterator<Type>
200 using Allocator = std::allocator<Type>;
201 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<Type>;
202 using AllocTraits = std::allocator_traits<AllocType>;
204 using Base = LinearConstIterator<Type>;
207 using iterator_category = std::random_access_iterator_tag;
208 using value_type = Type;
209 using pointer =
typename AllocTraits::pointer;
210 using reference = value_type &;
211 using difference_type =
typename AllocTraits::difference_type;
215 reference operator*() const noexcept
217 return const_cast<reference
>(Base::operator*());
220 pointer operator->() const noexcept
222 return const_cast<pointer
>(Base::operator->());
225 LinearIterator<Type> &operator++() noexcept
231 LinearIterator<Type> operator++(
int)
noexcept
238 LinearIterator<Type> &operator--() noexcept
244 LinearIterator<Type> operator--(
int)
noexcept
251 LinearIterator<Type> &operator+=(
const difference_type offset)
noexcept
253 Base::operator+=(offset);
257 LinearIterator<Type> operator+(
const difference_type offset)
const noexcept
260 return tmp += offset;
263 LinearIterator<Type> &operator-=(
const difference_type offset)
noexcept
265 Base::operator-=(offset);
269 using Base::operator-;
271 LinearIterator<Type> operator-(
const difference_type offset)
const noexcept
274 return tmp -= offset;
277 reference operator[](
const difference_type offset)
const noexcept
279 return const_cast<reference
>(Base::operator[](offset));
283 template <
class Type>
284 inline LinearIterator<Type>
operator+(
typename LinearIterator<Type>::difference_type offset,
285 LinearIterator<Type> next)
noexcept
287 return next += offset;
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
AffineMatrix2D operator+(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Add two affine matrices.
Definition affine_matrix_2d.hpp:223