CVB++ 15.0
decl_vpat.hpp
1#pragma once
2
3#include <cstdint>
4#include <cassert>
5
6#include "../_cexports/c_img.h"
7
8#include "../global.hpp"
9#include "../point_2d.hpp"
10#include "../rect.hpp"
11
12#include "decl_access_base.hpp"
13
14namespace Cvb
15{
16
17 CVB_BEGIN_INLINE_NS
18
19 class ImagePlane;
20
22
23 class Vpat final : public ValueAccessBase<Vpat>
24 {
26 friend ImagePlane;
28
29 public:
31
32 struct Entry final
33 {
38 };
39
40 private:
41 Vpat(const Image &image, int plane);
42 Vpat(std::uint8_t *base, Entry *vpat, Point2D<int> origin, int width)
43 : origin_(origin)
44 , basePtr_(base)
45 , vpatPtr_(vpat)
46 , width_(width)
47 {
48 assert(origin.X() >= 0 && origin.Y() >= 0); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
49 assert(base != nullptr && vpat != nullptr
50 && width > 0); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
51 }
52
53 public:
59 Vpat() noexcept;
60
71 Vpat(std::uint8_t *base, Entry *vpat, int width)
72 : Vpat(base, vpat, {}, width)
73 {
74 }
75
76 Vpat(const Vpat &other) noexcept = default;
77 Vpat &operator=(const Vpat &other) noexcept = default;
78 Vpat(Vpat &&other) noexcept = default;
79 Vpat &operator=(Vpat &&other) noexcept = default;
80 ~Vpat() = default;
81
83
90 Vpat NewMoved(const Cvb::Rect<int> newAoi) const noexcept
91 {
92 return Vpat{basePtr_, vpatPtr_, origin_ + Cvb::Point2D<int>{newAoi.Left(), newAoi.Top()}, newAoi.Width()};
93 }
94
96
104 std::uint8_t *BasePtr() const noexcept
105 {
106 return basePtr_;
107 }
108
110
117 Entry *VpatPtr() const noexcept
118 {
119 return vpatPtr_;
120 }
121
129 Point2D<int> Origin() const noexcept
130 {
131 return origin_;
132 }
133
139 CVB_FORCE_INLINE int Width() const noexcept
140 {
141 return this->width_;
142 }
143
150 bool Valid() const noexcept
151 {
152 return this->basePtr_ != nullptr && this->vpatPtr_ != nullptr && origin_.X() >= 0 && origin_.Y() >= 0
153 && this->width_ > 0;
154 }
155
157 explicit operator bool() const noexcept
158 {
159 return this->Valid();
160 }
161
172 CVB_FORCE_INLINE const void *operator()(int x, int y) const noexcept
173 {
174 return reinterpret_cast<const void *>(this->basePtr_ + vpatPtr_[origin_.Y() + y].OffsetY
175 + vpatPtr_[origin_.X() + x].OffsetX);
176 }
177
188 CVB_FORCE_INLINE void *operator()(int x, int y) noexcept
189 {
190 return reinterpret_cast<void *>(this->basePtr_ + vpatPtr_[origin_.Y() + y].OffsetY
191 + vpatPtr_[origin_.X() + x].OffsetX);
192 }
193
203 CVB_FORCE_INLINE const void *operator[](int idx) const noexcept
204 {
205 const int y = idx / this->width_;
206 const int x = idx % this->width_; // calculating / and % is faster than idx - width_ * y as the compiler
207 // generate only a single idiv (or sdiv) for both lines
208 return reinterpret_cast<const void *>(this->basePtr_ + vpatPtr_[origin_.Y() + y].OffsetY
209 + vpatPtr_[origin_.X() + x].OffsetX);
210 }
211
221 CVB_FORCE_INLINE void *operator[](int idx) noexcept
222 {
223 const int y = idx / this->width_;
224 const int x = idx % this->width_; // calculating / and % is faster than idx - width_ * y as the compiler
225 // generate only a single idiv (or sdiv) for both lines
226 return reinterpret_cast<void *>(this->basePtr_ + vpatPtr_[origin_.Y() + y].OffsetY
227 + vpatPtr_[origin_.X() + x].OffsetX);
228 }
229
234 class Row
235 {
236 friend class Vpat;
237
238 std::uint8_t *rowbasePtr_;
239 Entry *vpatPtr_;
240
241 /*
242 * \brief Ctor.
243 *
244 * \param [in] rowBase Base address of the line regarding \a vpat.
245 * \param [in] vpat The virtual pixel access table.
246 */
247 Row(std::uint8_t *rowBase, Entry *vpat) noexcept
248 : rowbasePtr_(rowBase)
249 , vpatPtr_(vpat)
250 {
251 }
252
253 public:
255 Row() noexcept
256 : rowbasePtr_(0)
257 , vpatPtr_(nullptr)
258 {
259 }
260
261 Row(const Row &other) noexcept = default;
262 Row &operator=(const Row &other) noexcept = default;
263 Row(Row &&other) noexcept = default;
264 Row &operator=(Row &&other) noexcept = default;
265 ~Row() = default;
266
276 CVB_FORCE_INLINE void *operator[](int x) noexcept
277 {
278 return reinterpret_cast<void *>(rowbasePtr_ + vpatPtr_[x].OffsetX);
279 }
280
290 CVB_FORCE_INLINE const void *operator[](int x) const noexcept
291 {
292 return reinterpret_cast<const void *>(rowbasePtr_ + vpatPtr_[x].OffsetX);
293 }
294 };
295
300 class Column
301 {
302 friend class Vpat;
303
304 std::uint8_t *colbasePtr_;
305 Entry *vpatPtr_;
306
307 /*
308 * \brief Ctor.
309 *
310 * \param [in] colBase Base address of the line regarding \a vpat.
311 * \param [in] vpat The virtual pixel access table.
312 */
313 Column(std::uint8_t *colBase, Entry *vpat) noexcept
314 : colbasePtr_(colBase)
315 , vpatPtr_(vpat)
316 {
317 }
318
319 public:
321 Column() noexcept
322 : colbasePtr_(0)
323 , vpatPtr_(nullptr)
324 {
325 }
326
327 Column(const Column &other) noexcept = default;
328 Column &operator=(const Column &other) noexcept = default;
329 Column(Column &&other) noexcept = default;
330 Column &operator=(Column &&other) noexcept = default;
331 ~Column() = default;
332
342 CVB_FORCE_INLINE void *operator[](int y) noexcept
343 {
344 return reinterpret_cast<void *>(colbasePtr_ + vpatPtr_[y].OffsetY);
345 }
346
356 CVB_FORCE_INLINE const void *operator[](int y) const noexcept
357 {
358 return reinterpret_cast<const void *>(colbasePtr_ + vpatPtr_[y].OffsetY);
359 }
360 };
361
371 Row RowAt(int y) const noexcept
372 {
373 return {basePtr_ + vpatPtr_[y].OffsetY, vpatPtr_};
374 }
375
385 Column ColumnAt(int x) const noexcept
386 {
387 return {basePtr_ + vpatPtr_[x].OffsetX, vpatPtr_};
388 }
389
390 private:
391 Point2D<int> origin_;
392 std::uint8_t *basePtr_ = nullptr;
393 Entry *vpatPtr_ = nullptr;
394 int width_ = 0;
395 };
396
397 inline Vpat::Vpat() noexcept = default;
398
407 inline bool operator!=(const Vpat &lhs, const Vpat &rhs) noexcept
408 {
409 return lhs.BasePtr() != rhs.BasePtr() || lhs.VpatPtr() != rhs.VpatPtr() || lhs.Origin() != rhs.Origin()
410 || lhs.Width() != rhs.Width();
411 }
412
421 inline bool operator==(const Vpat &lhs, const Vpat &rhs) noexcept
422 {
423 return !(lhs != rhs);
424 }
425
426 using VpatAccess = Vpat;
427
428 CVB_END_INLINE_NS
429
430} // namespace Cvb
The Common Vision Blox image.
Definition decl_image.hpp:50
Image plane information container.
Definition decl_image_plane.hpp:29
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
Rectangle object.
Definition rect.hpp:24
Common base class for access traits, providing typed Value access to planes.
Definition decl_access_base.hpp:23
A single column.
Definition decl_vpat.hpp:301
CVB_FORCE_INLINE const void * operator[](int y) const noexcept
Value access.
Definition decl_vpat.hpp:356
CVB_FORCE_INLINE void * operator[](int y) noexcept
Value access.
Definition decl_vpat.hpp:342
Column() noexcept
Default ctor of invalid column.
Definition decl_vpat.hpp:321
A single row.
Definition decl_vpat.hpp:235
CVB_FORCE_INLINE void * operator[](int x) noexcept
Value access.
Definition decl_vpat.hpp:276
Row() noexcept
Default ctor of invalid row.
Definition decl_vpat.hpp:255
CVB_FORCE_INLINE const void * operator[](int x) const noexcept
Value access.
Definition decl_vpat.hpp:290
Virtual Pixel Access Table.
Definition decl_vpat.hpp:24
CVB_FORCE_INLINE void * operator[](int idx) noexcept
Index pixel access operator.
Definition decl_vpat.hpp:221
bool Valid() const noexcept
Gets whether this vpat access object is valid.
Definition decl_vpat.hpp:150
bool operator==(const Vpat &lhs, const Vpat &rhs) noexcept
Equality operator.
Definition decl_vpat.hpp:421
Vpat() noexcept
CVB_FORCE_INLINE int Width() const noexcept
Gets the pixel width of the underlying plane.
Definition decl_vpat.hpp:139
Entry * VpatPtr() const noexcept
Pointer to the native VPAT structure.
Definition decl_vpat.hpp:117
std::uint8_t * BasePtr() const noexcept
VPAT base pointer.
Definition decl_vpat.hpp:104
Vpat NewMoved(const Cvb::Rect< int > newAoi) const noexcept
Creates a new, moved linear access object.
Definition decl_vpat.hpp:90
CVB_FORCE_INLINE const void * operator()(int x, int y) const noexcept
Coordinate pixel access operator.
Definition decl_vpat.hpp:172
Point2D< int > Origin() const noexcept
Gets the origin of the Vpat() for this access trait.
Definition decl_vpat.hpp:129
Row RowAt(int y) const noexcept
Gets the Vpat::Row at y.
Definition decl_vpat.hpp:371
CVB_FORCE_INLINE void * operator()(int x, int y) noexcept
Coordinate pixel access operator.
Definition decl_vpat.hpp:188
Column ColumnAt(int x) const noexcept
Gets the Vpat::Column at x.
Definition decl_vpat.hpp:385
CVB_FORCE_INLINE const void * operator[](int idx) const noexcept
Index pixel access operator.
Definition decl_vpat.hpp:203
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
One entry of the VPAT.
Definition decl_vpat.hpp:33
std::intptr_t OffsetX
X-offset from line start in bytes.
Definition decl_vpat.hpp:35
std::intptr_t OffsetY
Y-offset from line start in bytes.
Definition decl_vpat.hpp:37