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

◆ write_normalized_at() [1/2]

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

Write one element from a normalised double, with optional range remapping.

Inverse of read_normalized_at, with clamping on the integer paths. If range is provided, the value is linearly remapped from [0.0, 1.0] to [range.min, range.max] before writing. Out-of-range indices are ignored.

Parameters
vDestination variant.
formatPixel format governing the uint16 interpretation.
rangeOptional value range for remapping.
elem_indexElement index.
valueNormalised value.

Definition at line 222 of file PixelStorage.cpp.

227{
228 std::visit(
229 [&](auto& vec) {
230 using T = typename std::decay_t<decltype(vec)>::value_type;
231
232 if constexpr (std::is_same_v<T, uint8_t>
233 || std::is_same_v<T, uint16_t>
234 || std::is_same_v<T, float>) {
235
236 if (elem_index >= vec.size())
237 return;
238
239 double raw {};
240
241 if (range) {
242 if (std::isnan(value)) {
243 if (!range->invalid)
244 return;
245 raw = *range->invalid;
246 } else {
247 raw = range->min
248 + std::clamp(value, 0.0, 1.0) * (range->max - range->min);
249 }
250 } else if constexpr (std::is_same_v<T, uint8_t>) {
251 raw = std::clamp(value * 255.0, 0.0, 255.0);
252 } else if constexpr (std::is_same_v<T, uint16_t>) {
254 ? value
255 : std::clamp(value * 65535.0, 0.0, 65535.0);
256 } else {
257 raw = value;
258 }
259
260 if constexpr (std::is_same_v<T, uint8_t>) {
261 vec[elem_index] = static_cast<uint8_t>(std::clamp(raw, 0.0, 255.0));
262 } else if constexpr (std::is_same_v<T, uint16_t>) {
263 if (is_float_format(format)) {
264 vec[elem_index] = encode_half(static_cast<float>(raw));
265 } else {
266 vec[elem_index] = static_cast<uint16_t>(std::clamp(raw, 0.0, 65535.0));
267 }
268 } else {
269 vec[elem_index] = static_cast<float>(raw);
270 }
271 }
272 },
273 v);
274}
bool format
glm::vec3 value
bool is_float_format(ImageFormat format)
True when the format's numeric interpretation is floating point.

References format, 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: