3#include "../../global.hpp"
5#include "../../_detail/block/block_helper_linear_value.hpp"
6#include "../../_detail/block/block_helper_ref_value.hpp"
8#include "decl_block_base.hpp"
21 template <
class T,
class ACCESSTRAIT>
22 class Block final :
public BlockBase<ACCESSTRAIT>
24 template <
class Ty,
class OTHER_ACCESSTRAIT>
28 using ComponentType = ComponentOfT<T>;
29 using AccessTrait = ACCESSTRAIT;
31 using ConstPixelType =
const T;
37 static constexpr const size_t NumComponents = NumComponentsOfV<T>;
38 static_assert(NumComponents > 0,
"Cvb: NumComponents must be at least 1");
41 template <
class OTHER_ACCESSTRAIT>
42 explicit Block(
const Block<T, OTHER_ACCESSTRAIT> &other,
Cvb::Rect<int> aoi)
43 : BlockBase<ACCESSTRAIT>(other, aoi)
45 if (!IsAligned<PixelType>(other.
Access()(0, 0))
46 || (aoi.
Width() > 1 && !IsAligned<PixelType>(other.
Access()(1, 0)))
47 || (aoi.
Height() > 1 && !IsAligned<PixelType>(other.
Access()(0, 1))))
54 : BlockBase<ACCESSTRAIT>(std::move(access), size)
56 if (!IsAligned<PixelType>(access(0, 0)) || (size.
Width() > 1 && !IsAligned<PixelType>(access(1, 0)))
57 || (size.
Height() > 1 && !IsAligned<PixelType>(access(0, 1))))
62 Block &operator=(
const Block &other)
noexcept =
default;
64 Block &operator=(
Block &&other)
noexcept =
default;
95 CVB_FORCE_INLINE
const PixelType &
operator()(
int x,
int y)
const noexcept
97 return *
reinterpret_cast<const PixelType *
>(this->
Access()(x, y));
111 CVB_FORCE_INLINE PixelType &
operator()(
int x,
int y)
noexcept
114 "The underlying access does not support mutable access. Make the Block const.");
115 return *
reinterpret_cast<PixelType *
>(this->
Access()(x, y));
119 template <
class PTy,
size_t... I>
120 CVB_FORCE_INLINE
static void SetElements(PixelType &pt,
const PTy &value, std::index_sequence<I...>)
noexcept
122 using expander =
int[];
125 expander{0, (set<I>(pt, get<I>(value)), 0)...};
143 template <
class FromPixelType>
144 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
145 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
148 "The underlying access does not support mutable access.");
149 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
150 "Incoming value must have at least as many components as current value.");
152 SetElements(*
reinterpret_cast<PixelType *
>(this->
Access()(x, y)), value,
153 std::make_index_sequence<NumComponents>{});
157 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
160 "The underlying access does not support mutable access.");
161 *
reinterpret_cast<PixelType *
>(this->
Access()(x, y)) = value;
174 CVB_FORCE_INLINE
const PixelType &
operator[](
int idx)
const noexcept
176 return *
reinterpret_cast<const PixelType *
>(this->
Access()[idx]);
192 "The underlying access does not support mutable access. Make the Block const.");
193 return *
reinterpret_cast<PixelType *
>(this->
Access()[idx]);
209 template <
class FromPixelType>
210 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
211 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
214 "The underlying access does not support mutable access.");
215 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
216 "Incoming value must have at least as many components as current value.");
218 SetElements(*
reinterpret_cast<PixelType *
>(this->
Access()[idx]), value,
219 std::make_index_sequence<NumComponents>{});
235 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
238 "The underlying access does not support mutable access.");
239 *
reinterpret_cast<PixelType *
>(this->
Access()[idx]) = value;
247 using AccessRow =
typename AccessTrait::Row;
256 explicit Row(AccessRow row) noexcept
265 Row(
const Row &)
noexcept =
default;
266 Row &operator=(
const Row &)
noexcept =
default;
267 Row(Row &&other)
noexcept =
default;
268 Row &operator=(Row &&other)
noexcept =
default;
283 "The underlying access does not support mutable access. Make the Row const.");
284 return *
reinterpret_cast<PixelType *
>(row_[x]);
296 CVB_FORCE_INLINE
const PixelType &
operator[](
int x)
const noexcept
298 return *
reinterpret_cast<const PixelType *
>(row_[x]);
313 template <
class FromPixelType>
314 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
315 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
319 "The underlying access does not support mutable access.");
320 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
321 "Incoming value must have at least as many components as current value.");
323 SetElements(*
reinterpret_cast<PixelType *
>(row_[x]), value, std::make_index_sequence<NumComponents>{});
327 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
330 "The underlying access does not support mutable access.");
331 *
reinterpret_cast<PixelType *
>(row_[x]) = value;
340 using AccessColumn =
typename AccessTrait::Column;
349 explicit Column(AccessColumn col) noexcept
358 Column(
const Column &) =
default;
359 Column &operator=(
const Column &) =
default;
360 Column(Column &&other)
noexcept =
default;
361 Column &operator=(Column &&other)
noexcept =
default;
376 "The underlying access does not support mutable access. Make the Column const.");
377 return *
reinterpret_cast<PixelType *
>(col_[y]);
389 CVB_FORCE_INLINE
const PixelType &
operator[](
int y)
const noexcept
391 return *
reinterpret_cast<const PixelType *
>(col_[y]);
406 template <
class FromPixelType>
407 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
408 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
412 "The underlying access does not support mutable access.");
413 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
414 "Incoming value must have at least as many components as current value.");
416 SetElements(*
reinterpret_cast<PixelType *
>(col_[y]), value, std::make_index_sequence<NumComponents>{});
420 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
423 "The underlying access does not support mutable access.");
424 *
reinterpret_cast<PixelType *
>(col_[y]) = value;
439 return Row{this->
Access().RowAt(y)};
453 return Column{this->
Access().ColumnAt(x)};
458 template <
class T,
int K>
459 class Block<T, ScatterAccess<K>> final :
public BlockBase<ScatterAccess<K>>
461 template <
class Ty,
class OTHER_ACCESSTRAIT>
465 using ComponentType = ComponentOfT<T>;
466 using AccessTrait = ScatterAccess<K>;
468 using ConstPixelType =
470 const ConstRefValue<ComponentType, K>,
471 const PixelType>::type;
480 : BlockBase<ScatterAccess<K>>(other, aoi)
486 explicit Block(AccessTrait access, Cvb::Size2D<int> size)
487 : BlockBase<AccessTrait>(std::
move(access), std::
move(size))
491 Block(
const Block &other)
noexcept =
default;
492 Block &operator=(
const Block &other)
noexcept =
default;
493 Block(Block &&other)
noexcept =
default;
494 Block &operator=(Block &&other)
noexcept =
default;
509 auto SubBlock(Cvb::Rect<int> aoi)
const -> Block<T,
decltype(this->
Access().NewMoved(Cvb::Rect<int>{}))>
511 return Block<T,
decltype(this->
Access().NewMoved(Cvb::Rect<int>{}))>{*
this, aoi};
522 template <
class PTy,
class Ty,
size_t... I>
523 static CVB_FORCE_INLINE PTy FillPixelValueElements(Ty addresses, std::index_sequence<I...>)
noexcept
541 using CType =
typename std::conditional<std::is_const<PTy>::value,
const ComponentType, ComponentType>::type;
542 typename std::remove_const<PTy>::type value;
543 expander{0, ((void)internal_set<I>(value,
reinterpret_cast<CType *
>(addresses[I])), 0)...};
548 template <
class PTy,
class Ty>
549 static CVB_FORCE_INLINE PTy FillPixelValue(Ty addresses)
noexcept
551 return FillPixelValueElements<PTy>(addresses, std::make_index_sequence<K>());
560 template <
class Ty,
class PTy,
size_t... I>
561 CVB_FORCE_INLINE
static void SetElements(Ty addresses,
const PTy &value, std::index_sequence<I...>)
noexcept
564 using expander =
int[];
566 expander{0, (*
reinterpret_cast<ComponentType *
>(addresses[I]) = get<I>(value), 0)...};
581 CVB_FORCE_INLINE ConstPixelType
operator()(
int x,
int y)
const noexcept
583 auto addresses = this->
Access()(x, y);
584 return FillPixelValue<ConstPixelType>(addresses);
598 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
599 CVB_FORCE_INLINE PixelType
operator()(
int x,
int y)
noexcept
601 auto addresses = this->
Access()(x, y);
602 return FillPixelValue<PixelType>(addresses);
619 template <
class FromPixelType>
620 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
621 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
623 auto addresses = this->
Access()(x, y);
624 SetElements(addresses, value, std::make_index_sequence<K>());
628 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
630 auto addresses = this->
Access()(x, y);
631 SetElements(addresses, value, std::make_index_sequence<K>());
644 CVB_FORCE_INLINE ConstPixelType
operator[](
int idx)
const noexcept
646 auto addresses = this->
Access()[idx];
647 return FillPixelValue<ConstPixelType>(addresses);
660 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
661 CVB_FORCE_INLINE PixelType
operator[](
int idx)
noexcept
663 auto addresses = this->
Access()[idx];
664 return FillPixelValue<PixelType>(addresses);
680 template <
class FromPixelType>
681 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
682 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
684 auto addresses = this->
Access()[idx];
685 SetElements(addresses, value, std::make_index_sequence<K>());
689 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
691 auto addresses = this->
Access()[idx];
692 SetElements(addresses, value, std::make_index_sequence<K>());
709 explicit Row(AccessRow row) noexcept
718 Row(
const Row &other)
noexcept =
default;
719 Row &operator=(
const Row &other)
noexcept =
default;
720 Row(Row &&other)
noexcept =
default;
721 Row &operator=(Row &&other)
noexcept =
default;
733 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
736 auto addresses = row_[x];
737 return FillPixelValue<PixelType>(addresses);
749 CVB_FORCE_INLINE ConstPixelType
operator[](
int x)
const noexcept
751 auto addresses = row_[x];
752 return FillPixelValue<ConstPixelType>(addresses);
767 template <
class FromPixelType>
768 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
769 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
772 auto addresses = row_[x];
773 SetElements(addresses, value, std::make_index_sequence<K>());
777 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
779 auto addresses = row_[x];
780 SetElements(addresses, value, std::make_index_sequence<K>());
798 explicit Column(AccessColumn col) noexcept
807 Column(
const Column &other)
noexcept =
default;
808 Column &operator=(
const Column &other)
noexcept =
default;
809 Column(Column &&other)
noexcept =
default;
810 Column &operator=(Column &&other)
noexcept =
default;
822 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
825 auto addresses = col_[y];
826 return FillPixelValue<PixelType>(addresses);
838 CVB_FORCE_INLINE ConstPixelType
operator[](
int y)
const noexcept
840 auto addresses = col_[y];
841 return FillPixelValue<ConstPixelType>(addresses);
856 template <
class FromPixelType>
857 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
858 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
861 auto addresses = col_[y];
862 SetElements(addresses, value, std::make_index_sequence<K>());
866 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
868 auto addresses = col_[y];
869 SetElements(addresses, value, std::make_index_sequence<K>());
882 Row
RowAt(
int y)
const noexcept
884 return Row{this->
Access().RowAt(y)};
935 template <
class T,
size_t K>
A single column.
Definition decl_block.hpp:337
Column()=default
Default ctor.
CVB_FORCE_INLINE PixelType & operator[](int y) noexcept
Row access.
Definition decl_block.hpp:373
CVB_FORCE_INLINE const PixelType & operator[](int y) const noexcept
Row access.
Definition decl_block.hpp:389
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition decl_block.hpp:420
CVB_FORCE_INLINE auto Set(int y, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
Row setter.
Definition decl_block.hpp:407
CVB_FORCE_INLINE PixelType & operator[](int x) noexcept
Column access.
Definition decl_block.hpp:280
CVB_FORCE_INLINE const PixelType & operator[](int x) const noexcept
Column access.
Definition decl_block.hpp:296
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition decl_block.hpp:327
CVB_FORCE_INLINE auto Set(int x, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
Column setter.
Definition decl_block.hpp:314
Column()=default
Default ctor.
CVB_FORCE_INLINE ConstPixelType operator[](int y) const noexcept
Row access.
Definition decl_block.hpp:838
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition decl_block.hpp:866
CVB_FORCE_INLINE auto Set(int y, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
Row setter.
Definition decl_block.hpp:857
CVB_FORCE_INLINE PixelType operator[](int y) noexcept
Row access.
Definition decl_block.hpp:823
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition decl_block.hpp:777
CVB_FORCE_INLINE ConstPixelType operator[](int x) const noexcept
Column access.
Definition decl_block.hpp:749
CVB_FORCE_INLINE PixelType operator[](int x) noexcept
Column access.
Definition decl_block.hpp:734
CVB_FORCE_INLINE auto Set(int x, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
Column setter.
Definition decl_block.hpp:768
CVB_FORCE_INLINE const AccessTrait & Access() const noexcept
Gets the pixel access.
Definition decl_block_base.hpp:87
Non-owning view on a 2d-plane of data.
Definition decl_block.hpp:23
auto SubBlock(Cvb::Rect< int > aoi) const -> Block< T, decltype(this->Access().NewMoved(Cvb::Rect< int >{}))>
Creates a new sub Block from this block.
Definition decl_block.hpp:79
Block(ACCESSTRAIT access, Cvb::Size2D< int > size)
Definition decl_block.hpp:53
CVB_FORCE_INLINE PixelType & operator[](int idx) noexcept
Coordinate pixel access operator.
Definition decl_block.hpp:189
CVB_FORCE_INLINE PixelType & operator()(int x, int y) noexcept
Coordinate pixel access operator.
Definition decl_block.hpp:111
Block< T, ScatterAccess< K > > ScatterBlock
Definition decl_block.hpp:936
Block< T, VpatAccess > VpatPlaneBlock
Definition decl_block.hpp:927
CVB_FORCE_INLINE void Set(int idx, const PixelType &value) noexcept
Index setter.
Definition decl_block.hpp:235
CVB_FORCE_INLINE auto Set(int x, int y, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
Coordinate setter.
Definition decl_block.hpp:144
CVB_FORCE_INLINE const PixelType & operator[](int idx) const noexcept
Index pixel access operator.
Definition decl_block.hpp:174
Block< T, LinearAccess > LinearPlaneBlock
Definition decl_block.hpp:918
CVB_FORCE_INLINE void Set(int x, int y, const PixelType &value) noexcept
Coordinate setter.
Definition decl_block.hpp:157
Row RowAt(int y) const noexcept
Gets the Block::Row at y.
Definition decl_block.hpp:437
CVB_FORCE_INLINE auto Set(int idx, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
Index setter.
Definition decl_block.hpp:210
Column ColumnAt(int x) const noexcept
Gets the Block::Column at x.
Definition decl_block.hpp:451
Block< T, ArrayAccess > ArrayPlaneBlock
A Cvb::Block of a contiguous plane.
Definition decl_block.hpp:909
static constexpr const bool IsPixelTypeMutable
Definition decl_block.hpp:34
CVB_FORCE_INLINE const PixelType & operator()(int x, int y) const noexcept
Coordinate pixel access operator.
Definition decl_block.hpp:95
Rectangle object.
Definition rect.hpp:24
T Height() const noexcept
Gets the height of the rectangle.
Definition rect.hpp:184
T Width() const noexcept
Gets the width of the rectangle.
Definition rect.hpp:164
A single column.
Definition decl_scatter_access.hpp:367
A single row.
Definition decl_scatter_access.hpp:268
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
Root namespace for the Image Manager interface.
Definition version.hpp:11