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

◆ write_normalized_at() [1/4]

void MayaFlux::Kakshya::write_normalized_at ( DataVariant v,
ImageFormat  format,
const std::optional< DataDimension::ValueRange > &  range,
size_t  elem_index,
double  value 
)

Definition at line 186 of file PixelStorage.cpp.

191{
192 std::visit(
193 [&](auto& vec) {
194 using T = typename std::decay_t<decltype(vec)>::value_type;
195
196 if constexpr (std::is_same_v<T, uint8_t>
197 || std::is_same_v<T, uint16_t>
198 || std::is_same_v<T, float>) {
199
200 if (elem_index >= vec.size())
201 return;
202
203 double raw {};
204
205 if (range) {
206 if (std::isnan(value)) {
207 if (!range->invalid)
208 return;
209 raw = *range->invalid;
210 } else {
211 raw = range->min
212 + std::clamp(value, 0.0, 1.0) * (range->max - range->min);
213 }
214 } else if constexpr (std::is_same_v<T, uint8_t>) {
215 raw = std::clamp(value * 255.0, 0.0, 255.0);
216 } else if constexpr (std::is_same_v<T, uint16_t>) {
217 raw = is_float_format(format)
218 ? value
219 : std::clamp(value * 65535.0, 0.0, 65535.0);
220 } else {
221 raw = value;
222 }
223
224 if constexpr (std::is_same_v<T, uint8_t>) {
225 vec[elem_index] = static_cast<uint8_t>(std::clamp(raw, 0.0, 255.0));
226 } else if constexpr (std::is_same_v<T, uint16_t>) {
227 if (is_float_format(format)) {
228 vec[elem_index] = encode_half(static_cast<float>(raw));
229 } else {
230 vec[elem_index] = static_cast<uint16_t>(std::clamp(raw, 0.0, 65535.0));
231 }
232 } else {
233 vec[elem_index] = static_cast<float>(raw);
234 }
235 }
236 },
237 v);
238}
float value
bool is_float_format(ImageFormat format)

References is_float_format(), and value.

Referenced by MayaFlux::Kakshya::VideoStreamContainer::set_value_impl(), and write_normalized_at().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: