MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ as_normalised_float()

MAYAFLUX_API std::span< const float > MayaFlux::Kakshya::as_normalised_float ( const DataVariant variant,
std::vector< float > &  storage 
)

Extract a DataVariant holding pixel data as a normalised float span.

Normalisation factors: uint8_t -> divided by 255.0f uint16_t -> divided by 65535.0f float -> zero-copy span directly into the variant's storage

Does not mutate the variant. Writes into storage only when conversion is required. Returns an empty span if the active alternative is not one of the three pixel types (double, complex, and GLM variants return empty).

Parameters
variantSource DataVariant.
storageCaller-supplied buffer. Reuse across calls to avoid per-frame allocation. Untouched when float is active.
Returns
Normalised float span. Points into storage for uint8/uint16, directly into the variant's internal storage for float.

Definition at line 61 of file DataUtils.cpp.

63{
64 return std::visit([&storage](const auto& vec) -> std::span<const float> {
65 using T = typename std::decay_t<decltype(vec)>::value_type;
66
67 if constexpr (std::is_same_v<T, float>) {
68 return { vec.data(), vec.size() };
69
70 } else if constexpr (std::is_same_v<T, uint8_t>) {
71 storage.resize(vec.size());
72 constexpr float k = 1.0F / 255.0F;
73
74 std::transform(Parallel::par_unseq,
75 vec.begin(), vec.end(), storage.begin(),
76 [](uint8_t v) { return static_cast<float>(v) * k; });
77 return { storage.data(), storage.size() };
78
79 } else if constexpr (std::is_same_v<T, uint16_t>) {
80 storage.resize(vec.size());
81 constexpr float k = 1.0F / 65535.0F;
82
83 std::transform(Parallel::par_unseq,
84 vec.begin(), vec.end(), storage.begin(),
85 [](uint16_t v) { return static_cast<float>(v) * k; });
86 return { storage.data(), storage.size() };
87
88 } else {
89 return {};
90 }
91 },
92 variant);
93}
Eigen::MatrixXd storage
float k

References k, and storage.

Referenced by MayaFlux::Yantra::VisionAnalyzer< InputType, OutputType >::analyze_implementation(), MayaFlux::Buffers::download_and_normalise(), MayaFlux::Kakshya::WindowContainer::processed_frame_as_float(), and MayaFlux::Kakshya::VideoStreamContainer::processed_frame_as_float().

+ Here is the caller graph for this function: