3#include "../../global.hpp"
5#include "../../_detail/block/block_helper_linear_value.hpp"
6#include "../../_detail/block/block_helper_ref_value.hpp"
7#include "../../_detail/block/detail_block_point_helper.hpp"
9#include "decl_block_base.hpp"
22 template <
class T,
class ACCESSTRAIT>
25 template <
class Ty,
class OTHER_ACCESSTRAIT>
29 using ComponentType = ComponentOfT<T>;
30 using AccessTrait = ACCESSTRAIT;
32 using ConstPixelType =
const T;
38 static constexpr const size_t NumComponents = NumComponentsOfV<T>;
39 static_assert(NumComponents > 0,
"Cvb: NumComponents must be at least 1");
42 template <
class OTHER_ACCESSTRAIT>
46 if (!IsAligned<PixelType>(other.
Access()(0, 0))
47 || (aoi.Width() > 1 && !IsAligned<PixelType>(other.
Access()(1, 0)))
48 || (aoi.Height() > 1 && !IsAligned<PixelType>(other.
Access()(0, 1))))
55 :
BlockBase<ACCESSTRAIT>(std::move(access), std::move(size))
57 if (!IsAligned<PixelType>(access(0, 0)) || (size.
Width() > 1 && !IsAligned<PixelType>(access(1, 0)))
58 || (size.
Height() > 1 && !IsAligned<PixelType>(access(0, 1))))
108 CVB_FORCE_INLINE
const PixelType &
operator()(
int x,
int y)
const noexcept
110 return *
reinterpret_cast<const PixelType *
>(this->
Access()(x, y));
124 CVB_FORCE_INLINE PixelType &
operator()(
int x,
int y)
noexcept
127 "The underlying access does not support mutable access. Make the Block const.");
128 return *
reinterpret_cast<PixelType *
>(this->
Access()(x, y));
132 template <
class PTy,
size_t... I>
133 CVB_FORCE_INLINE
static void SetElements(PixelType &pt,
const PTy &value, std::index_sequence<I...>)
noexcept
138 expander{0, (set<I>(pt, get<I>(value)), 0)...};
156 template <
class FromPixelType>
157 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
158 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
161 "The underlying access does not support mutable access.");
162 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
163 "Incoming value must have at least as many components as current value.");
165 SetElements(*
reinterpret_cast<PixelType *
>(this->
Access()(x, y)), value,
166 std::make_index_sequence<NumComponents>{});
170 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
173 "The underlying access does not support mutable access.");
174 *
reinterpret_cast<PixelType *
>(this->
Access()(x, y)) = value;
187 CVB_FORCE_INLINE
const PixelType &
operator[](
int idx)
const noexcept
189 return *
reinterpret_cast<const PixelType *
>(this->
Access()[idx]);
205 "The underlying access does not support mutable access. Make the Block const.");
206 return *
reinterpret_cast<PixelType *
>(this->
Access()[idx]);
222 template <
class FromPixelType>
223 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
224 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
227 "The underlying access does not support mutable access.");
228 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
229 "Incoming value must have at least as many components as current value.");
231 SetElements(*
reinterpret_cast<PixelType *
>(this->
Access()[idx]), value,
232 std::make_index_sequence<NumComponents>{});
236 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
239 "The underlying access does not support mutable access.");
240 *
reinterpret_cast<PixelType *
>(this->
Access()[idx]) = value;
248 using AccessRow =
typename AccessTrait::Row;
257 Row(AccessRow row) noexcept
288 "The underlying access does not support mutable access. Make the Row const.");
289 return *
reinterpret_cast<PixelType *
>(row_[x]);
301 CVB_FORCE_INLINE
const PixelType &
operator[](
int x)
const noexcept
303 return *
reinterpret_cast<const PixelType *
>(row_[x]);
318 template <
class FromPixelType>
319 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
320 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
324 "The underlying access does not support mutable access.");
325 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
326 "Incoming value must have at least as many components as current value.");
328 SetElements(*
reinterpret_cast<PixelType *
>(row_[x]), value, std::make_index_sequence<NumComponents>{});
332 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
335 "The underlying access does not support mutable access.");
336 *
reinterpret_cast<PixelType *
>(row_[x]) = value;
345 using AccessColumn =
typename AccessTrait::Column;
354 Column(AccessColumn col) noexcept
385 "The underlying access does not support mutable access. Make the Column const.");
386 return *
reinterpret_cast<PixelType *
>(col_[y]);
398 CVB_FORCE_INLINE
const PixelType &
operator[](
int y)
const noexcept
400 return *
reinterpret_cast<const PixelType *
>(col_[y]);
415 template <
class FromPixelType>
416 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
417 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
421 "The underlying access does not support mutable access.");
422 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
423 "Incoming value must have at least as many components as current value.");
425 SetElements(*
reinterpret_cast<PixelType *
>(col_[y]), value, std::make_index_sequence<NumComponents>{});
429 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
432 "The underlying access does not support mutable access.");
433 *
reinterpret_cast<PixelType *
>(col_[y]) = value;
448 return {this->
Access().RowAt(y)};
462 return {this->
Access().ColumnAt(x)};
467 template <
class T,
int K>
468 class Block<T, ScatterAccess<K>> final :
public BlockBase<ScatterAccess<K>>
470 template <
class Ty,
class OTHER_ACCESSTRAIT>
474 using ComponentType = ComponentOfT<T>;
475 using AccessTrait = ScatterAccess<K>;
477 using ConstPixelType =
479 const ConstRefValue<ComponentType, K>,
480 const PixelType>::type;
489 : BlockBase<ScatterAccess<K>>(other, aoi)
496 : BlockBase<AccessTrait>(std::
move(access), std::
move(size))
505 Block(
const Block &other)
noexcept =
default;
513 Block &
operator=(
const Block &other)
noexcept =
default;
543 template <
class PTy,
class Ty,
size_t... I>
544 static CVB_FORCE_INLINE PTy FillPixelValueElements(Ty addresses, std::index_sequence<I...>)
noexcept
559 using expander =
int[];
563 expander{0, ((void)internal_set<I>(value,
reinterpret_cast<CType *
>(addresses[I])), 0)...};
568 template <
class PTy,
class Ty>
569 static CVB_FORCE_INLINE PTy FillPixelValue(Ty addresses)
noexcept
571 return FillPixelValueElements<PTy>(addresses, std::make_index_sequence<K>());
580 template <
class Ty,
class PTy,
size_t... I>
581 CVB_FORCE_INLINE
static void SetElements(Ty addresses,
const PTy &value, std::index_sequence<I...>)
noexcept
584 using expander =
int[];
586 expander{0, (*
reinterpret_cast<ComponentType *
>(addresses[I]) = get<I>(value), 0)...};
601 CVB_FORCE_INLINE ConstPixelType
operator()(
int x,
int y)
const noexcept
603 auto addresses = this->
Access()(x, y);
604 return FillPixelValue<ConstPixelType>(addresses);
618 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
619 CVB_FORCE_INLINE PixelType
operator()(
int x,
int y)
noexcept
621 auto addresses = this->
Access()(x, y);
622 return FillPixelValue<PixelType>(addresses);
639 template <
class FromPixelType>
640 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
641 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
643 auto addresses = this->
Access()(x, y);
644 SetElements(addresses, value, std::make_index_sequence<K>());
648 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
650 auto addresses = this->
Access()(x, y);
651 SetElements(addresses, value, std::make_index_sequence<K>());
664 CVB_FORCE_INLINE ConstPixelType
operator[](
int idx)
const noexcept
666 auto addresses = this->
Access()[idx];
667 return FillPixelValue<ConstPixelType>(addresses);
680 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
681 CVB_FORCE_INLINE PixelType
operator[](
int idx)
noexcept
683 auto addresses = this->
Access()[idx];
684 return FillPixelValue<PixelType>(addresses);
700 template <
class FromPixelType>
701 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
702 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
704 auto addresses = this->
Access()[idx];
705 SetElements(addresses, value, std::make_index_sequence<K>());
709 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
711 auto addresses = this->
Access()[idx];
712 SetElements(addresses, value, std::make_index_sequence<K>());
729 Row(AccessRow row) noexcept
757 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
760 auto addresses = row_[x];
761 return FillPixelValue<PixelType>(addresses);
773 CVB_FORCE_INLINE ConstPixelType
operator[](
int x)
const noexcept
775 auto addresses = row_[x];
776 return FillPixelValue<ConstPixelType>(addresses);
791 template <
class FromPixelType>
792 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
793 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
796 auto addresses = row_[x];
797 SetElements(addresses, value, std::make_index_sequence<K>());
801 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
803 auto addresses = row_[x];
804 SetElements(addresses, value, std::make_index_sequence<K>());
822 Column(AccessColumn col) noexcept
850 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
853 auto addresses = col_[y];
854 return FillPixelValue<PixelType>(addresses);
866 CVB_FORCE_INLINE ConstPixelType
operator[](
int y)
const noexcept
868 auto addresses = col_[y];
869 return FillPixelValue<ConstPixelType>(addresses);
884 template <
class FromPixelType>
885 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
886 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
889 auto addresses = col_[y];
890 SetElements(addresses, value, std::make_index_sequence<K>());
894 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
896 auto addresses = col_[y];
897 SetElements(addresses, value, std::make_index_sequence<K>());
910 Row
RowAt(
int y)
const noexcept
912 return {this->
Access().RowAt(y)};
924 Column
ColumnAt(
int x)
const noexcept
926 return {this->
Access().ColumnAt(x)};
963 template <
class T,
size_t K>
A single column.
Definition: decl_block.hpp:342
Column()=default
Default ctor.
Column(const Column &)=default
Copy ctor.
CVB_FORCE_INLINE PixelType & operator[](int y) noexcept
Row access.
Definition: decl_block.hpp:382
CVB_FORCE_INLINE const PixelType & operator[](int y) const noexcept
Row access.
Definition: decl_block.hpp:398
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition: decl_block.hpp:429
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:416
Column & operator=(const Column &)=default
Copy assignment.
A single row.
Definition: decl_block.hpp:245
CVB_FORCE_INLINE PixelType & operator[](int x) noexcept
Column access.
Definition: decl_block.hpp:285
Row(const Row &)=default
Copy ctor.
Row & operator=(const Row &)=default
Copy assignment.
CVB_FORCE_INLINE const PixelType & operator[](int x) const noexcept
Column access.
Definition: decl_block.hpp:301
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition: decl_block.hpp:332
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:319
Column()=default
Default ctor.
Column(const Column &)=default
Copy ctor.
CVB_FORCE_INLINE ConstPixelType operator[](int y) const noexcept
Row access.
Definition: decl_block.hpp:866
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition: decl_block.hpp:894
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:885
Column & operator=(const Column &)=default
Copy assignment.
CVB_FORCE_INLINE PixelType operator[](int y) noexcept
Row access.
Definition: decl_block.hpp:851
Row(const Row &)=default
Copy ctor.
Row & operator=(const Row &)=default
Copy assignment.
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition: decl_block.hpp:801
CVB_FORCE_INLINE ConstPixelType operator[](int x) const noexcept
Column access.
Definition: decl_block.hpp:773
CVB_FORCE_INLINE PixelType operator[](int x) noexcept
Column access.
Definition: decl_block.hpp:758
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:792
Base class for all typed Cvb::Block types.
Definition: decl_block_base.hpp:25
CVB_FORCE_INLINE const AccessTrait & Access() const noexcept
Gets the pixel access.
Definition: decl_block_base.hpp:101
Non-owning view on a 2d-plane of data.
Definition: decl_block.hpp:24
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:92
Block(ACCESSTRAIT access, Cvb::Size2D< int > size)
Definition: decl_block.hpp:54
CVB_FORCE_INLINE PixelType & operator[](int idx) noexcept
Coordinate pixel access operator.
Definition: decl_block.hpp:202
CVB_FORCE_INLINE PixelType & operator()(int x, int y) noexcept
Coordinate pixel access operator.
Definition: decl_block.hpp:124
Block< T, ScatterAccess< K > > ScatterBlock
A Cvb::Block of variant planes.
Definition: decl_block.hpp:964
CVB_FORCE_INLINE void Set(int idx, const PixelType &value) noexcept
Index setter.
Definition: decl_block.hpp:236
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:157
CVB_FORCE_INLINE const PixelType & operator[](int idx) const noexcept
Index pixel access operator.
Definition: decl_block.hpp:187
CVB_FORCE_INLINE void Set(int x, int y, const PixelType &value) noexcept
Coordinate setter.
Definition: decl_block.hpp:170
Row RowAt(int y) const noexcept
Gets the Block::Row at y.
Definition: decl_block.hpp:446
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:223
Block(const Block &other) noexcept=default
Copy ctor.
Column ColumnAt(int x) const noexcept
Gets the Block::Column at x.
Definition: decl_block.hpp:460
~Block()=default
Default dtor.
Block & operator=(const Block &other) noexcept=default
Copy operator.
static constexpr const bool IsPixelTypeMutable
! Indicates whether the returned values of operator(x,y) or operator[idx] are mutable.
Definition: decl_block.hpp:35
CVB_FORCE_INLINE const PixelType & operator()(int x, int y) const noexcept
Coordinate pixel access operator.
Definition: decl_block.hpp:108
A single column.
Definition: decl_scatter_access.hpp:373
A single row.
Definition: decl_scatter_access.hpp:270
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:24