MayaFlux 0.5.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(Portal::Graphics::ImageFormat format);
24
25/**
26 * @brief True when the format's numeric interpretation is floating point.
27 *
28 * Distinguishes R16F from R16: both occupy U16 storage, but only the
29 * former holds half-float bits rather than a normalised integer.
30 *
31 * @param format Pixel format.
32 */
33[[nodiscard]] MAYAFLUX_API bool is_float_format(Portal::Graphics::ImageFormat format);
34
35/**
36 * @brief Allocate a zeroed DataVariant of the alternative backing a format.
37 * @param format Pixel format determining the element type.
38 * @param element_count Number of elements, not bytes. Typically
39 * width * height * channel_count.
40 * @return Zero-filled variant of the matching alternative.
41 */
42[[nodiscard]] MAYAFLUX_API DataVariant make_empty_storage(
43 Portal::Graphics::ImageFormat format, size_t element_count);
44
45/**
46 * @brief Read one element as a normalised double.
47 *
48 * uint8 divided by 255. uint16 divided by 65535 unless the format is
49 * half-float, in which case the raw bits are returned uninterpreted.
50 * float returned unchanged.
51 *
52 * @param v Source variant.
53 * @param format Pixel format governing the uint16 interpretation.
54 * @param elem_index Element index. Returns 0.0 when out of range.
55 */
56[[nodiscard]] MAYAFLUX_API double read_normalized_at(
57 const DataVariant& v, Portal::Graphics::ImageFormat format, size_t elem_index);
58
59/**
60 * @brief Read one element as a normalised double, with optional range remapping.
61 *
62 * Same as read_normalized_at, but if @p range is provided, the value is
63 * linearly remapped from [range.min, range.max] to [0.0, 1.0]. Values
64 * outside the range are clamped to 0.0 or 1.0.
65 *
66 * @param v Source variant.
67 * @param format Pixel format governing the uint16 interpretation.
68 * @param range Optional value range for remapping.
69 * @param elem_index Element index. Returns 0.0 when out of range.
70 */
71[[nodiscard]]
72MAYAFLUX_API double read_normalized_at(const DataVariant& v,
74 const std::optional<DataDimension::ValueRange>& range,
75 size_t elem_index);
76
77/**
78 * @brief Write one element from a normalised double.
79 *
80 * Inverse of read_normalized_at, with clamping on the integer paths.
81 * Out-of-range indices are ignored.
82 *
83 * @param v Destination variant.
84 * @param format Pixel format governing the uint16 interpretation.
85 * @param elem_index Element index.
86 * @param value Normalised value.
87 */
88MAYAFLUX_API void write_normalized_at(
89 DataVariant& v, Portal::Graphics::ImageFormat format, size_t elem_index, double value);
90
91/**
92 * @brief Write one element from a normalised double, with optional range remapping.
93 *
94 * Inverse of read_normalized_at, with clamping on the integer paths.
95 * If @p range is provided, the value is linearly remapped from [0.0, 1.0]
96 * to [range.min, range.max] before writing. Out-of-range indices are ignored.
97 *
98 * @param v Destination variant.
99 * @param format Pixel format governing the uint16 interpretation.
100 * @param range Optional value range for remapping.
101 * @param elem_index Element index.
102 * @param value Normalised value.
103 */
104MAYAFLUX_API void write_normalized_at(DataVariant& v,
106 const std::optional<DataDimension::ValueRange>& range,
107 size_t elem_index,
108 double value);
109
110/**
111 * @brief True when a format decomposes into whole DataVariant elements.
112 *
113 * False for DEPTH24 and DEPTH24_STENCIL8: both occupy 4 bytes per pixel in
114 * a packed layout that is not a whole number of uint8, uint16, or float
115 * elements. A container allocating storage_element_size * channels * pixels
116 * for either will not match what a bytes_per_pixel-sized write path produces.
117 *
118 * Derived from the format tables rather than enumerated, so it stays
119 * correct if a format is added.
120 *
121 * @param format Pixel format.
122 */
123[[nodiscard]] MAYAFLUX_API bool format_has_variant_storage(Portal::Graphics::ImageFormat format);
124
125/**
126 * @brief True when the format's values are range measurements rather than colour.
127 *
128 * Governs whether a container declares VIDEO_COLOR or VIDEO_DEPTH, and
129 * therefore whether its component axis carries Role::CHANNEL or Role::DEPTH.
130 *
131 * @param format Pixel format.
132 */
133[[nodiscard]] MAYAFLUX_API bool is_depth_format(Portal::Graphics::ImageFormat format);
134
135} // namespace MayaFlux::Kakshya
float value
void write_normalized_at(DataVariant &v, ImageFormat format, const std::optional< DataDimension::ValueRange > &range, size_t elem_index, double value)
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:102
bool is_depth_format(ImageFormat format)
size_t storage_element_size(ImageFormat format)
bool format_has_variant_storage(ImageFormat format)
DataVariant make_empty_storage(ImageFormat format, size_t element_count)
double read_normalized_at(const DataVariant &v, ImageFormat format, const std::optional< DataDimension::ValueRange > &range, size_t elem_index)
bool is_float_format(ImageFormat format)
ImageFormat
User-friendly image format enum.