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>
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>
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))))
63 Block &operator=(
const Block &other)
noexcept =
default;
65 Block& operator=(
Block&& other)
noexcept =
default;
96 CVB_FORCE_INLINE
const PixelType &
operator()(
int x,
int y)
const noexcept
98 return *
reinterpret_cast<const PixelType *
>(this->
Access()(x, y));
112 CVB_FORCE_INLINE PixelType &
operator()(
int x,
int y)
noexcept
115 "The underlying access does not support mutable access. Make the Block const.");
116 return *
reinterpret_cast<PixelType *
>(this->
Access()(x, y));
120 template <
class PTy,
size_t... I>
121 CVB_FORCE_INLINE
static void SetElements(PixelType &pt,
const PTy &value, std::index_sequence<I...>)
noexcept
126 expander{0, (set<I>(pt, get<I>(value)), 0)...};
144 template <
class FromPixelType>
145 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
146 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
149 "The underlying access does not support mutable access.");
150 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
151 "Incoming value must have at least as many components as current value.");
153 SetElements(*
reinterpret_cast<PixelType *
>(this->
Access()(x, y)), value,
154 std::make_index_sequence<NumComponents>{});
158 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
161 "The underlying access does not support mutable access.");
162 *
reinterpret_cast<PixelType *
>(this->
Access()(x, y)) = value;
175 CVB_FORCE_INLINE
const PixelType &
operator[](
int idx)
const noexcept
177 return *
reinterpret_cast<const PixelType *
>(this->
Access()[idx]);
193 "The underlying access does not support mutable access. Make the Block const.");
194 return *
reinterpret_cast<PixelType *
>(this->
Access()[idx]);
210 template <
class FromPixelType>
211 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
212 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
215 "The underlying access does not support mutable access.");
216 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
217 "Incoming value must have at least as many components as current value.");
219 SetElements(*
reinterpret_cast<PixelType *
>(this->
Access()[idx]), value,
220 std::make_index_sequence<NumComponents>{});
224 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
227 "The underlying access does not support mutable access.");
228 *
reinterpret_cast<PixelType *
>(this->
Access()[idx]) = value;
236 using AccessRow =
typename AccessTrait::Row;
245 explicit Row(AccessRow row) noexcept
255 Row(
const Row &)
noexcept =
default;
256 Row &operator=(
const Row &)
noexcept =
default;
257 Row(
Row&& other)
noexcept =
default;
258 Row& operator=(
Row&& other)
noexcept =
default;
273 "The underlying access does not support mutable access. Make the Row const.");
274 return *
reinterpret_cast<PixelType *
>(row_[x]);
286 CVB_FORCE_INLINE
const PixelType &
operator[](
int x)
const noexcept
288 return *
reinterpret_cast<const PixelType *
>(row_[x]);
303 template <
class FromPixelType>
304 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
305 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
309 "The underlying access does not support mutable access.");
310 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
311 "Incoming value must have at least as many components as current value.");
313 SetElements(*
reinterpret_cast<PixelType *
>(row_[x]), value, std::make_index_sequence<NumComponents>{});
317 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
320 "The underlying access does not support mutable access.");
321 *
reinterpret_cast<PixelType *
>(row_[x]) = value;
330 using AccessColumn =
typename AccessTrait::Column;
339 explicit Column(AccessColumn col) noexcept
367 "The underlying access does not support mutable access. Make the Column const.");
368 return *
reinterpret_cast<PixelType *
>(col_[y]);
380 CVB_FORCE_INLINE
const PixelType &
operator[](
int y)
const noexcept
382 return *
reinterpret_cast<const PixelType *
>(col_[y]);
397 template <
class FromPixelType>
398 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
399 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
403 "The underlying access does not support mutable access.");
404 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
405 "Incoming value must have at least as many components as current value.");
407 SetElements(*
reinterpret_cast<PixelType *
>(col_[y]), value, std::make_index_sequence<NumComponents>{});
411 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
414 "The underlying access does not support mutable access.");
415 *
reinterpret_cast<PixelType *
>(col_[y]) = value;
449 template <
class T,
int K>
450 class Block<T, ScatterAccess<K>> final :
public BlockBase<ScatterAccess<K>>
452 template <
class Ty,
class OTHER_ACCESSTRAIT>
456 using ComponentType = ComponentOfT<T>;
457 using AccessTrait = ScatterAccess<K>;
459 using ConstPixelType =
461 const ConstRefValue<ComponentType, K>,
462 const PixelType>::type;
471 : BlockBase<ScatterAccess<K>>(other, aoi)
478 : BlockBase<AccessTrait>(std::
move(access), std::
move(size))
483 Block(
const Block &other)
noexcept =
default;
484 Block &operator=(
const Block &other)
noexcept =
default;
485 Block(Block&& other)
noexcept =
default;
486 Block& operator=(Block&& other)
noexcept =
default;
514 template <
class PTy,
class Ty,
size_t... I>
515 static CVB_FORCE_INLINE PTy FillPixelValueElements(Ty addresses, std::index_sequence<I...>)
noexcept
530 using expander =
int[];
534 expander{0, ((void)internal_set<I>(value,
reinterpret_cast<CType *
>(addresses[I])), 0)...};
539 template <
class PTy,
class Ty>
540 static CVB_FORCE_INLINE PTy FillPixelValue(Ty addresses)
noexcept
542 return FillPixelValueElements<PTy>(addresses, std::make_index_sequence<K>());
551 template <
class Ty,
class PTy,
size_t... I>
552 CVB_FORCE_INLINE
static void SetElements(Ty addresses,
const PTy &value, std::index_sequence<I...>)
noexcept
555 using expander =
int[];
557 expander{0, (*
reinterpret_cast<ComponentType *
>(addresses[I]) = get<I>(value), 0)...};
572 CVB_FORCE_INLINE ConstPixelType
operator()(
int x,
int y)
const noexcept
574 auto addresses = this->
Access()(x, y);
575 return FillPixelValue<ConstPixelType>(addresses);
589 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
590 CVB_FORCE_INLINE PixelType
operator()(
int x,
int y)
noexcept
592 auto addresses = this->
Access()(x, y);
593 return FillPixelValue<PixelType>(addresses);
610 template <
class FromPixelType>
611 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
612 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
614 auto addresses = this->
Access()(x, y);
615 SetElements(addresses, value, std::make_index_sequence<K>());
619 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
621 auto addresses = this->
Access()(x, y);
622 SetElements(addresses, value, std::make_index_sequence<K>());
635 CVB_FORCE_INLINE ConstPixelType
operator[](
int idx)
const noexcept
637 auto addresses = this->
Access()[idx];
638 return FillPixelValue<ConstPixelType>(addresses);
651 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
652 CVB_FORCE_INLINE PixelType
operator[](
int idx)
noexcept
654 auto addresses = this->
Access()[idx];
655 return FillPixelValue<PixelType>(addresses);
671 template <
class FromPixelType>
672 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
673 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
675 auto addresses = this->
Access()[idx];
676 SetElements(addresses, value, std::make_index_sequence<K>());
680 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
682 auto addresses = this->
Access()[idx];
683 SetElements(addresses, value, std::make_index_sequence<K>());
700 explicit Row(AccessRow row) noexcept
710 Row(
const Row & other)
noexcept =
default;
711 Row &operator=(
const Row &other)
noexcept =
default;
712 Row(
Row&& other)
noexcept =
default;
713 Row& operator=(
Row && other)
noexcept =
default;
725 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
728 auto addresses = row_[x];
729 return FillPixelValue<PixelType>(addresses);
741 CVB_FORCE_INLINE ConstPixelType
operator[](
int x)
const noexcept
743 auto addresses = row_[x];
744 return FillPixelValue<ConstPixelType>(addresses);
759 template <
class FromPixelType>
760 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
761 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
764 auto addresses = row_[x];
765 SetElements(addresses, value, std::make_index_sequence<K>());
769 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
771 auto addresses = row_[x];
772 SetElements(addresses, value, std::make_index_sequence<K>());
790 explicit Column(AccessColumn col) noexcept
801 Column &operator=(
const Column &other)
noexcept =
default;
815 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
818 auto addresses = col_[y];
819 return FillPixelValue<PixelType>(addresses);
831 CVB_FORCE_INLINE ConstPixelType
operator[](
int y)
const noexcept
833 auto addresses = col_[y];
834 return FillPixelValue<ConstPixelType>(addresses);
849 template <
class FromPixelType>
850 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
851 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
854 auto addresses = col_[y];
855 SetElements(addresses, value, std::make_index_sequence<K>());
859 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
861 auto addresses = col_[y];
862 SetElements(addresses, value, std::make_index_sequence<K>());
875 Row
RowAt(
int y)
const noexcept
877 return Row{this->
Access().RowAt(y)};
889 Column
ColumnAt(
int x)
const noexcept
891 return Column{this->
Access().ColumnAt(x)};
928 template <
class T,
size_t K>
A single column.
Definition: decl_block.hpp:327
Column()=default
Default ctor.
CVB_FORCE_INLINE PixelType & operator[](int y) noexcept
Row access.
Definition: decl_block.hpp:364
CVB_FORCE_INLINE const PixelType & operator[](int y) const noexcept
Row access.
Definition: decl_block.hpp:380
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition: decl_block.hpp:411
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:398
A single row.
Definition: decl_block.hpp:233
CVB_FORCE_INLINE PixelType & operator[](int x) noexcept
Column access.
Definition: decl_block.hpp:270
CVB_FORCE_INLINE const PixelType & operator[](int x) const noexcept
Column access.
Definition: decl_block.hpp:286
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition: decl_block.hpp:317
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:304
Column()=default
Default ctor.
CVB_FORCE_INLINE ConstPixelType operator[](int y) const noexcept
Row access.
Definition: decl_block.hpp:831
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition: decl_block.hpp:859
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:850
CVB_FORCE_INLINE PixelType operator[](int y) noexcept
Row access.
Definition: decl_block.hpp:816
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition: decl_block.hpp:769
CVB_FORCE_INLINE ConstPixelType operator[](int x) const noexcept
Column access.
Definition: decl_block.hpp:741
CVB_FORCE_INLINE PixelType operator[](int x) noexcept
Column access.
Definition: decl_block.hpp:726
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:760
Base class for all typed Cvb::Block types.
Definition: decl_block_base.hpp:23
CVB_FORCE_INLINE const AccessTrait & Access() const noexcept
Gets the pixel access.
Definition: decl_block_base.hpp:88
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:80
Block(ACCESSTRAIT access, Cvb::Size2D< int > size)
Base class for all typed Cvb::Block types.
Definition: decl_block.hpp:53
CVB_FORCE_INLINE PixelType & operator[](int idx) noexcept
Coordinate pixel access operator.
Definition: decl_block.hpp:190
CVB_FORCE_INLINE PixelType & operator()(int x, int y) noexcept
Coordinate pixel access operator.
Definition: decl_block.hpp:112
Block< T, ScatterAccess< K > > ScatterBlock
A Cvb::Block of variant planes.
Definition: decl_block.hpp:929
CVB_FORCE_INLINE void Set(int idx, const PixelType &value) noexcept
Index setter.
Definition: decl_block.hpp:224
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:145
CVB_FORCE_INLINE const PixelType & operator[](int idx) const noexcept
Index pixel access operator.
Definition: decl_block.hpp:175
CVB_FORCE_INLINE void Set(int x, int y, const PixelType &value) noexcept
Coordinate setter.
Definition: decl_block.hpp:158
Row RowAt(int y) const noexcept
Gets the Block::Row at y.
Definition: decl_block.hpp:428
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:211
Column ColumnAt(int x) const noexcept
Gets the Block::Column at x.
Definition: decl_block.hpp:442
static constexpr const bool IsPixelTypeMutable
! Indicates whether the returned values of operator(x,y) or operator[idx] are mutable.
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:96
A single column.
Definition: decl_scatter_access.hpp:369
A single row.
Definition: decl_scatter_access.hpp:269
T Height() const noexcept
Gets the vertical component of the size.
Definition: size_2d.hpp:79
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15