6#include "_decl/decl_vpat.hpp"
16 class VpatConstIterator
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 VpatConstIterator() =
default;
32 explicit VpatConstIterator(Vpat vpat, Size2D<int> size, Point2D<int> pos = Point2D<int>()) noexcept
40 reference operator*() const noexcept
42 return *
reinterpret_cast<Type *
>(currentPixelPtr_);
45 pointer operator->() const noexcept
47 return reinterpret_cast<Type *
>(currentPixelPtr_);
50 VpatConstIterator<Type> &operator++() noexcept
52 auto entrys = vpat_.VpatPtr();
53 currentPos_.SetX(currentPos_.X() + 1);
54 currentPixelPtr_ = currentLinePtr_ + entrys[currentPos_.X()].OffsetX;
55 if (currentPos_.X() < size_.Width())
60 currentPos_.SetY(currentPos_.Y() + 1);
66 VpatConstIterator<Type> operator++(
int)
noexcept
73 VpatConstIterator<Type> &operator--() noexcept
75 auto entrys = vpat_.VpatPtr();
76 currentPos_.SetX(currentPos_.X() - 1);
77 currentPixelPtr_ = currentLinePtr_ + entrys[currentPos_.X()].OffsetX;
78 if (currentPos_.X() >= 0)
82 currentPos_.SetX(size_.Width() - 1);
83 currentPos_.SetY(currentPos_.Y() - 1);
89 VpatConstIterator<Type> operator--(
int)
noexcept
96 VpatConstIterator<Type> &operator+=(
const difference_type offset)
noexcept
98 auto linearPos = Point2DToLinear(currentPos_);
100 currentPos_ = LinearToPoint2D(linearPos);
105 VpatConstIterator<Type> operator+(
const difference_type offset)
const noexcept
108 return tmp += offset;
111 VpatConstIterator<Type> &operator-=(
const difference_type offset)
noexcept
113 return *
this += -offset;
116 VpatConstIterator<Type> operator-(
const difference_type offset)
const noexcept
119 return tmp -= offset;
122 difference_type operator-(
const VpatConstIterator<Type> &rhs)
const noexcept
124 return Point2DToLinear(currentPos_) - Point2DToLinear(rhs.currentPos_);
127 reference operator[](
const difference_type offset)
const noexcept
129 return *(*
this + offset);
132 bool operator==(
const VpatConstIterator<Type> &rhs)
const noexcept
134 return currentPos_ == rhs.currentPos_;
137 bool operator!=(
const VpatConstIterator<Type> &rhs)
const noexcept
139 return !(*
this == rhs);
142 bool operator<(
const VpatConstIterator<Type> &rhs)
const noexcept
144 return Point2DToLinear(currentPos_) < Point2DToLinear(rhs.currentPos_);
147 bool operator>(
const VpatConstIterator<Type> &rhs)
const noexcept
152 bool operator<=(
const VpatConstIterator<Type> &rhs)
const noexcept
154 return !(rhs < *
this);
157 bool operator>=(
const VpatConstIterator<Type> &rhs)
const noexcept
159 return !(*
this < rhs);
163 difference_type Point2DToLinear(Point2D<int> pos)
const noexcept
165 return static_cast<difference_type
>(pos.Y()) *
static_cast<difference_type
>(size_.Width())
166 +
static_cast<difference_type
>(pos.X());
169 Point2D<int> LinearToPoint2D(difference_type pos)
const noexcept
171 return Point2D<int>(
static_cast<int>(pos % size_.Width()),
static_cast<int>(pos / size_.Width()));
174 void ApplyCurrentPos() noexcept
176 auto entrys = vpat_.VpatPtr();
177 currentLinePtr_ =
reinterpret_cast<std::uint8_t *
>(vpat_.BasePtr()) + entrys[currentPos_.Y()].OffsetY;
178 currentPixelPtr_ = currentLinePtr_ + entrys[currentPos_.X()].OffsetX;
183 Point2D<int> currentPos_;
184 std::uint8_t *currentLinePtr_ =
nullptr;
185 std::uint8_t *currentPixelPtr_ =
nullptr;
188 template <
class Type>
189 inline VpatConstIterator<Type>
operator+(
typename VpatConstIterator<Type>::difference_type offset,
190 VpatConstIterator<Type> next)
noexcept
192 return next += offset;
195 template <
class Type>
196 class VpatIterator :
public VpatConstIterator<Type>
199 using Allocator = std::allocator<Type>;
200 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<Type>;
201 using AllocTraits = std::allocator_traits<AllocType>;
203 using Base = VpatConstIterator<Type>;
206 using iterator_category = std::random_access_iterator_tag;
207 using value_type = Type;
208 using pointer =
typename AllocTraits::pointer;
209 using reference = value_type &;
210 using difference_type =
typename AllocTraits::difference_type;
214 reference operator*() const noexcept
216 return const_cast<reference
>(Base::operator*());
219 pointer operator->() const noexcept
221 return const_cast<pointer
>(Base::operator->());
224 VpatIterator<Type> &operator++() noexcept
230 VpatIterator<Type> operator++(
int)
noexcept
237 VpatIterator<Type> &operator--() noexcept
243 VpatIterator<Type> operator--(
int)
noexcept
250 VpatIterator<Type> &operator+=(
const difference_type offset)
noexcept
252 Base::operator+=(offset);
256 VpatIterator<Type> operator+(
const difference_type offset)
const noexcept
259 return tmp += offset;
262 VpatIterator<Type> &operator-=(
const difference_type offset)
noexcept
264 Base::operator-=(offset);
268 using Base::operator-;
270 VpatIterator<Type> operator-(
const difference_type offset)
const noexcept
273 return tmp -= offset;
276 reference operator[](
const difference_type offset)
const noexcept
278 return const_cast<reference
>(Base::operator[](offset));
282 template <
class Type>
283 inline VpatIterator<Type>
operator+(
typename VpatIterator<Type>::difference_type offset,
284 VpatIterator<Type> next)
noexcept
286 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