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));
95 CVB_FORCE_INLINE
const PixelType &
operator()(
int x,
int y)
const noexcept {
…}
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>{});
144 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept {
…}
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;
157 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept {
…}
174 CVB_FORCE_INLINE
const PixelType &
operator[](
int idx)
const noexcept
176 return *
reinterpret_cast<const PixelType *
>(this->
Access()[idx]);
174 CVB_FORCE_INLINE
const PixelType &
operator[](
int idx)
const noexcept {
…}
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>{});
210 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept {
…}
223 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
226 "The underlying access does not support mutable access.");
227 *
reinterpret_cast<PixelType *
>(this->
Access()[idx]) = value;
223 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept {
…}
235 using AccessRow =
typename AccessTrait::Row;
244 explicit Row(AccessRow row) noexcept
253 Row(
const Row &)
noexcept =
default;
254 Row &operator=(
const Row &)
noexcept =
default;
255 Row(Row &&other)
noexcept =
default;
256 Row &operator=(Row &&other)
noexcept =
default;
271 "The underlying access does not support mutable access. Make the Row const.");
272 return *
reinterpret_cast<PixelType *
>(row_[x]);
284 CVB_FORCE_INLINE
const PixelType &
operator[](
int x)
const noexcept
286 return *
reinterpret_cast<const PixelType *
>(row_[x]);
284 CVB_FORCE_INLINE
const PixelType &
operator[](
int x)
const noexcept {
…}
301 template <
class FromPixelType>
302 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
303 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
307 "The underlying access does not support mutable access.");
308 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
309 "Incoming value must have at least as many components as current value.");
311 SetElements(*
reinterpret_cast<PixelType *
>(row_[x]), value, std::make_index_sequence<NumComponents>{});
302 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept {
…}
315 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
318 "The underlying access does not support mutable access.");
319 *
reinterpret_cast<PixelType *
>(row_[x]) = value;
315 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept {
…}
328 using AccessColumn =
typename AccessTrait::Column;
337 explicit Column(AccessColumn col) noexcept
346 Column(
const Column &) =
default;
347 Column &operator=(
const Column &) =
default;
348 Column(Column &&other)
noexcept =
default;
349 Column &operator=(Column &&other)
noexcept =
default;
364 "The underlying access does not support mutable access. Make the Column const.");
365 return *
reinterpret_cast<PixelType *
>(col_[y]);
377 CVB_FORCE_INLINE
const PixelType &
operator[](
int y)
const noexcept
379 return *
reinterpret_cast<const PixelType *
>(col_[y]);
377 CVB_FORCE_INLINE
const PixelType &
operator[](
int y)
const noexcept {
…}
394 template <
class FromPixelType>
395 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
396 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
400 "The underlying access does not support mutable access.");
401 static_assert(NumComponentsOfV<FromPixelType> >= NumComponents || NumComponentsOfV<FromPixelType> == -1,
402 "Incoming value must have at least as many components as current value.");
404 SetElements(*
reinterpret_cast<PixelType *
>(col_[y]), value, std::make_index_sequence<NumComponents>{});
395 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept {
…}
408 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
411 "The underlying access does not support mutable access.");
412 *
reinterpret_cast<PixelType *
>(col_[y]) = value;
408 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept {
…}
427 return Row{this->
Access().RowAt(y)};
441 return Column{this->
Access().ColumnAt(x)};
22 class Block final :
public BlockBase<ACCESSTRAIT> {
…};
446 template <
class T,
int K>
447 class Block<T, ScatterAccess<K>> final :
public BlockBase<ScatterAccess<K>>
449 template <
class Ty,
class OTHER_ACCESSTRAIT>
453 using ComponentType = ComponentOfT<T>;
454 using AccessTrait = ScatterAccess<K>;
456 using ConstPixelType =
458 const ConstRefValue<ComponentType, K>,
459 const PixelType>::type;
468 : BlockBase<ScatterAccess<K>>(other, aoi)
474 explicit Block(AccessTrait access, Cvb::Size2D<int> size)
475 : BlockBase<AccessTrait>(std::
move(access), std::
move(size))
479 Block(
const Block &other)
noexcept =
default;
480 Block &operator=(
const Block &other)
noexcept =
default;
481 Block(Block &&other)
noexcept =
default;
482 Block &operator=(Block &&other)
noexcept =
default;
497 auto SubBlock(Cvb::Rect<int> aoi)
const -> Block<T,
decltype(this->
Access().NewMoved(Cvb::Rect<int>{}))>
499 return Block<T,
decltype(this->
Access().NewMoved(Cvb::Rect<int>{}))>{*
this, aoi};
510 template <
class PTy,
class Ty,
size_t... I>
511 static CVB_FORCE_INLINE PTy FillPixelValueElements(Ty addresses, std::index_sequence<I...>)
noexcept
529 using CType =
typename std::conditional<std::is_const<PTy>::value,
const ComponentType, ComponentType>::type;
530 typename std::remove_const<PTy>::type value;
531 expander{0, ((void)internal_set<I>(value,
reinterpret_cast<CType *
>(addresses[I])), 0)...};
536 template <
class PTy,
class Ty>
537 static CVB_FORCE_INLINE PTy FillPixelValue(Ty addresses)
noexcept
539 return FillPixelValueElements<PTy>(addresses, std::make_index_sequence<K>());
548 template <
class Ty,
class PTy,
size_t... I>
549 CVB_FORCE_INLINE
static void SetElements(Ty addresses,
const PTy &value, std::index_sequence<I...>)
noexcept
552 using expander =
int[];
554 expander{0, (*
reinterpret_cast<ComponentType *
>(addresses[I]) = get<I>(value), 0)...};
569 CVB_FORCE_INLINE ConstPixelType
operator()(
int x,
int y)
const noexcept
571 auto addresses = this->
Access()(x, y);
572 return FillPixelValue<ConstPixelType>(addresses);
586 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
587 CVB_FORCE_INLINE PixelType
operator()(
int x,
int y)
noexcept
589 auto addresses = this->
Access()(x, y);
590 return FillPixelValue<PixelType>(addresses);
607 template <
class FromPixelType>
608 CVB_FORCE_INLINE
auto Set(
int x,
int y,
const FromPixelType &value)
noexcept
609 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
611 auto addresses = this->
Access()(x, y);
612 SetElements(addresses, value, std::make_index_sequence<K>());
616 CVB_FORCE_INLINE
void Set(
int x,
int y,
const PixelType &value)
noexcept
618 auto addresses = this->
Access()(x, y);
619 SetElements(addresses, value, std::make_index_sequence<K>());
632 CVB_FORCE_INLINE ConstPixelType
operator[](
int idx)
const noexcept
634 auto addresses = this->
Access()[idx];
635 return FillPixelValue<ConstPixelType>(addresses);
648 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
649 CVB_FORCE_INLINE PixelType
operator[](
int idx)
noexcept
651 auto addresses = this->
Access()[idx];
652 return FillPixelValue<PixelType>(addresses);
668 template <
class FromPixelType>
669 CVB_FORCE_INLINE
auto Set(
int idx,
const FromPixelType &value)
noexcept
670 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
void>
672 auto addresses = this->
Access()[idx];
673 SetElements(addresses, value, std::make_index_sequence<K>());
677 CVB_FORCE_INLINE
void Set(
int idx,
const PixelType &value)
noexcept
679 auto addresses = this->
Access()[idx];
680 SetElements(addresses, value, std::make_index_sequence<K>());
697 explicit Row(AccessRow row) noexcept
706 Row(
const Row &other)
noexcept =
default;
707 Row &operator=(
const Row &other)
noexcept =
default;
708 Row(Row &&other)
noexcept =
default;
709 Row &operator=(Row &&other)
noexcept =
default;
721 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
724 auto addresses = row_[x];
725 return FillPixelValue<PixelType>(addresses);
737 CVB_FORCE_INLINE ConstPixelType
operator[](
int x)
const noexcept
739 auto addresses = row_[x];
740 return FillPixelValue<ConstPixelType>(addresses);
737 CVB_FORCE_INLINE ConstPixelType
operator[](
int x)
const noexcept {
…}
755 template <
class FromPixelType>
756 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept
757 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
760 auto addresses = row_[x];
761 SetElements(addresses, value, std::make_index_sequence<K>());
756 CVB_FORCE_INLINE
auto Set(
int x,
const FromPixelType &value)
noexcept {
…}
765 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept
767 auto addresses = row_[x];
768 SetElements(addresses, value, std::make_index_sequence<K>());
765 CVB_FORCE_INLINE
void Set(
int x,
const PixelType &value)
noexcept {
…}
786 explicit Column(AccessColumn col) noexcept
795 Column(
const Column &other)
noexcept =
default;
796 Column &operator=(
const Column &other)
noexcept =
default;
797 Column(Column &&other)
noexcept =
default;
798 Column &operator=(Column &&other)
noexcept =
default;
810 template <
bool ENABLE = IsPixelTypeMutable, std::enable_if_t<ENABLE,
int> = 0>
813 auto addresses = col_[y];
814 return FillPixelValue<PixelType>(addresses);
826 CVB_FORCE_INLINE ConstPixelType
operator[](
int y)
const noexcept
828 auto addresses = col_[y];
829 return FillPixelValue<ConstPixelType>(addresses);
826 CVB_FORCE_INLINE ConstPixelType
operator[](
int y)
const noexcept {
…}
844 template <
class FromPixelType>
845 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept
846 -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value,
849 auto addresses = col_[y];
850 SetElements(addresses, value, std::make_index_sequence<K>());
845 CVB_FORCE_INLINE
auto Set(
int y,
const FromPixelType &value)
noexcept {
…}
854 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept
856 auto addresses = col_[y];
857 SetElements(addresses, value, std::make_index_sequence<K>());
854 CVB_FORCE_INLINE
void Set(
int y,
const PixelType &value)
noexcept {
…}
870 Row
RowAt(
int y)
const noexcept
872 return Row{this->
Access().RowAt(y)};
923 template <
class T,
size_t K>
A single column.
Definition decl_block.hpp:325
Column()=default
Default ctor.
CVB_FORCE_INLINE PixelType & operator[](int y) noexcept
Row access.
Definition decl_block.hpp:361
CVB_FORCE_INLINE const PixelType & operator[](int y) const noexcept
Row access.
Definition decl_block.hpp:377
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition decl_block.hpp:408
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:395
CVB_FORCE_INLINE PixelType & operator[](int x) noexcept
Column access.
Definition decl_block.hpp:268
CVB_FORCE_INLINE const PixelType & operator[](int x) const noexcept
Column access.
Definition decl_block.hpp:284
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition decl_block.hpp:315
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:302
Column()=default
Default ctor.
CVB_FORCE_INLINE ConstPixelType operator[](int y) const noexcept
Row access.
Definition decl_block.hpp:826
CVB_FORCE_INLINE void Set(int y, const PixelType &value) noexcept
Row setter.
Definition decl_block.hpp:854
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:845
CVB_FORCE_INLINE PixelType operator[](int y) noexcept
Row access.
Definition decl_block.hpp:811
Row()=default
Default ctor.
CVB_FORCE_INLINE void Set(int x, const PixelType &value) noexcept
Column setter.
Definition decl_block.hpp:765
CVB_FORCE_INLINE ConstPixelType operator[](int x) const noexcept
Column access.
Definition decl_block.hpp:737
CVB_FORCE_INLINE PixelType operator[](int x) noexcept
Column access.
Definition decl_block.hpp:722
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:756
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:924
Block< T, VpatAccess > VpatPlaneBlock
Definition decl_block.hpp:915
CVB_FORCE_INLINE void Set(int idx, const PixelType &value) noexcept
Index setter.
Definition decl_block.hpp:223
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:906
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:425
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:439
Block< T, ArrayAccess > ArrayPlaneBlock
A Cvb::Block of a contiguous plane.
Definition decl_block.hpp:897
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
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 c_bayer_to_rgb.h:17