MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PixelStorage.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Kakshya {
7
8/**
9 * @brief Byte width of the DataVariant element backing a given ImageFormat.
10 *
11 * Returns 1 for uint8 storage, 2 for uint16, 4 for float. Defaults to 1
12 * for any format without an explicit mapping.
13 *
14 * Size determines the alternative unambiguously only because DataVariant's
15 * pixel alternatives are uint8, uint16, and float: 4 means float, not
16 * uint32. Half-float formats return 2, since the uint16 bits are the
17 * IEEE-754 binary16 encoding rather than a UNORM value; consumers needing
18 * the decoded magnitude must check is_float_format().
19 *
20 * @param format Pixel format.
21 * @return Element size in bytes.
22 */
23[[nodiscard]] MAYAFLUX_API size_t storage_element_size(ImageFormat format);
24
25/**
26 * @brief Linearly blend two frames of the same size and format.
27 *
28 * Works on 8-bit and 32-bit float storage. Returns false, leaving @p out
29 * untouched, for any other element size or when the frames differ in size.
30 *
31 * @param format Pixel format of both frames.
32 * @param a Frame at weight 0.
33 * @param b Frame at weight 1.
34 * @param out Destination for a.size() bytes.
35 * @param weight Blend factor from @p a to @p b.
36 * @return True if @p out holds the blend.
37 */
38MAYAFLUX_API bool blend_frames(ImageFormat format, std::span<const uint8_t> a, std::span<const uint8_t> b,
39 uint8_t* out, double weight);
40
41/**
42 * @brief True when the format's numeric interpretation is floating point.
43 *
44 * Distinguishes R16F from R16: both occupy U16 storage, but only the
45 * former holds half-float bits rather than a normalised integer.
46 *
47 * @param format Pixel format.
48 */
49[[nodiscard]] MAYAFLUX_API bool is_float_format(ImageFormat format);
50
51/**
52 * @brief Allocate a zeroed DataVariant of the alternative backing a format.
53 * @param format Pixel format determining the element type.
54 * @param element_count Number of elements, not bytes. Typically
55 * width * height * channel_count.
56 * @return Zero-filled variant of the matching alternative.
57 */
58[[nodiscard]] MAYAFLUX_API DataVariant make_empty_storage(
59 ImageFormat format, size_t element_count);
60
61/**
62 * @brief Read one element as a normalised double.
63 *
64 * uint8 divided by 255. uint16 divided by 65535 unless the format is
65 * half-float, in which case the raw bits are returned uninterpreted.
66 * float returned unchanged.
67 *
68 * @param v Source variant.
69 * @param format Pixel format governing the uint16 interpretation.
70 * @param elem_index Element index. Returns 0.0 when out of range.
71 */
72[[nodiscard]] MAYAFLUX_API double read_normalized_at(
73 const DataVariant& v, ImageFormat format, size_t elem_index);
74
75/**
76 * @brief Read one element as a normalised double, with optional range remapping.
77 *
78 * Same as read_normalized_at, but if @p range is provided, the value is
79 * linearly remapped from [range.min, range.max] to [0.0, 1.0]. Values
80 * outside the range are clamped to 0.0 or 1.0.
81 *
82 * @param v Source variant.
83 * @param format Pixel format governing the uint16 interpretation.
84 * @param range Optional value range for remapping.
85 * @param elem_index Element index. Returns 0.0 when out of range.
86 */
87[[nodiscard]]
88MAYAFLUX_API double read_normalized_at(const DataVariant& v,
90 const std::optional<DataDimension::ValueRange>& range,
91 size_t elem_index);
92
93/**
94 * @brief Write one element from a normalised double.
95 *
96 * Inverse of read_normalized_at, with clamping on the integer paths.
97 * Out-of-range indices are ignored.
98 *
99 * @param v Destination variant.
100 * @param format Pixel format governing the uint16 interpretation.
101 * @param elem_index Element index.
102 * @param value Normalised value.
103 */
104MAYAFLUX_API void write_normalized_at(
105 DataVariant& v, ImageFormat format, size_t elem_index, double value);
106
107/**
108 * @brief Write one element from a normalised double, with optional range remapping.
109 *
110 * Inverse of read_normalized_at, with clamping on the integer paths.
111 * If @p range is provided, the value is linearly remapped from [0.0, 1.0]
112 * to [range.min, range.max] before writing. Out-of-range indices are ignored.
113 *
114 * @param v Destination variant.
115 * @param format Pixel format governing the uint16 interpretation.
116 * @param range Optional value range for remapping.
117 * @param elem_index Element index.
118 * @param value Normalised value.
119 */
120MAYAFLUX_API void write_normalized_at(DataVariant& v,
122 const std::optional<DataDimension::ValueRange>& range,
123 size_t elem_index,
124 double value);
125
126/**
127 * @brief True when a format decomposes into whole DataVariant elements.
128 *
129 * False for DEPTH24 and DEPTH24_STENCIL8: both occupy 4 bytes per pixel in
130 * a packed layout that is not a whole number of uint8, uint16, or float
131 * elements. A container allocating storage_element_size * channels * pixels
132 * for either will not match what a bytes_per_pixel-sized write path produces.
133 *
134 * Derived from the format tables rather than enumerated, so it stays
135 * correct if a format is added.
136 *
137 * @param format Pixel format.
138 */
139[[nodiscard]] MAYAFLUX_API bool format_has_variant_storage(ImageFormat format);
140
141/**
142 * @brief True when the format's values are range measurements rather than colour.
143 *
144 * Governs whether a container declares VIDEO_COLOR or VIDEO_DEPTH, and
145 * therefore whether its component axis carries Role::CHANNEL or Role::DEPTH.
146 *
147 * @param format Pixel format.
148 */
149[[nodiscard]] MAYAFLUX_API bool is_depth_format(ImageFormat format);
150
151} // namespace MayaFlux::Kakshya
bool format
size_t a
double weight
size_t b
std::vector< float > * out
glm::vec3 value
bool is_depth_format(ImageFormat format)
True when the format's values are range measurements rather than colour.
ImageFormat
User-friendly image format enum.
Definition ImageData.hpp:12
DataVariant make_empty_storage(ImageFormat format, size_t element_count)
Allocate a zeroed DataVariant of the alternative backing a format.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:70
size_t storage_element_size(ImageFormat format)
Byte width of the DataVariant element backing a given ImageFormat.
bool blend_frames(ImageFormat format, std::span< const uint8_t > a, std::span< const uint8_t > b, uint8_t *out, double weight)
Linearly blend two frames of the same size and format.
double read_normalized_at(const DataVariant &v, ImageFormat format, const std::optional< DataDimension::ValueRange > &range, size_t elem_index)
Read one element as a normalised double, with optional range remapping.
bool is_float_format(ImageFormat format)
True when the format's numeric interpretation is floating point.
void 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.
bool format_has_variant_storage(ImageFormat format)
True when a format decomposes into whole DataVariant elements.