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

◆ allocate()

std::optional< ImageData > MayaFlux::Kakshya::ImageData::allocate ( uint32_t  width,
uint32_t  height,
uint32_t  channels,
ImageFormat  format 
)
static

Allocate zeroed pixel storage of the variant format calls for.

The variant matches what is_consistent() expects: uint8 for the 8-bit formats, uint16 for the 16-bit and half-float formats, float for the 32-bit float formats. Holds width * height * channels elements.

Returns
The sized ImageData, or nullopt when any dimension or the channel count is zero, or the format has no storage mapping.

Definition at line 5 of file ImageData.cpp.

10{
11 using F = ImageFormat;
12
13 if (width == 0 || height == 0 || channels == 0) {
14 return std::nullopt;
15 }
16
17 ImageData result;
18 result.width = width;
19 result.height = height;
20 result.channels = channels;
21 result.format = format;
22
23 const size_t element_count = static_cast<size_t>(width) * height * channels;
24
25 switch (format) {
26 case F::R8:
27 case F::RG8:
28 case F::RGBA8:
29 case F::RGBA8_SRGB:
30 case F::BGRA8:
31 case F::BGRA8_SRGB:
32 result.pixels.emplace<std::vector<uint8_t>>(element_count);
33 break;
34
35 case F::R16:
36 case F::RG16:
37 case F::RGBA16:
38 case F::R16F:
39 case F::RG16F:
40 case F::RGBA16F:
41 result.pixels.emplace<std::vector<uint16_t>>(element_count);
42 break;
43
44 case F::R32F:
45 case F::RG32F:
46 case F::RGBA32F:
47 result.pixels.emplace<std::vector<float>>(element_count);
48 break;
49
50 default:
51 return std::nullopt;
52 }
53
54 return result;
55}
Kakshya::ImageData ImageData
ImageFormat
User-friendly image format enum.
Definition ImageData.hpp:12
size_t element_count() const
Number of pixel elements (not bytes), dispatched on variant.

References channels, element_count(), format, height, pixels, and width.

Referenced by MayaFlux::Portal::Graphics::TextureLoom::download_image(), and from_bytes().

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