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

◆ download_image()

std::optional< Kakshya::ImageData > MayaFlux::Portal::Graphics::TextureLoom::download_image ( const std::shared_ptr< Core::VKImage > &  image,
const std::shared_ptr< Buffers::VKBuffer > &  staging = nullptr,
vk::ImageLayout  restore_layout = vk::ImageLayout::eShaderReadOnlyOptimal,
vk::PipelineStageFlags  restore_stage = vk::PipelineStageFlagBits::eFragmentShader 
)

Download the base level of an image as typed pixels.

Blocking. The element type of the returned storage follows the format: one byte per channel gives uint8, two gives uint16, four gives float.

Parameters
imageSource image. Must satisfy readable_format().
stagingPersistent host-visible staging buffer of at least the base level's byte size, or nullptr for a per-call one.
restore_layoutLayout the image is left in.
restore_stagePipeline stage that consumes the image after restore.
Returns
The pixels with width, height, channels and format set, or nullopt, with an error logged, if the image is not readable or the loom is not initialised.

Definition at line 637 of file TextureLoom.cpp.

642{
643 if (!is_initialized()) {
645 "download_image: TextureLoom is not initialised");
646 return std::nullopt;
647 }
648
649 const auto format = readable_format(image);
650 if (!format) {
652 "download_image: image is not readable as a single-layer 2D base level");
653 return std::nullopt;
654 }
655
656 const size_t byte_count = calculate_image_size(image->get_width(), image->get_height(), 1, *format);
657
658 auto result = Kakshya::ImageData::allocate(
659 image->get_width(), image->get_height(), get_channel_count(*format), *format);
660 if (!result || result->byte_size() != byte_count) {
662 "download_image: format {} has no typed pixel storage matching its size", static_cast<int>(*format));
663 return std::nullopt;
664 }
665
666 download_data(image, result->data(), byte_count, staging, false, restore_layout, restore_stage);
667
668 if (!result->is_consistent()) {
670 "download_image: downloaded pixels do not match format {}", static_cast<int>(*format));
671 return std::nullopt;
672 }
673
674 return result;
675}
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:47
bool format
void download_data(const std::shared_ptr< Core::VKImage > &image, void *data, size_t size, const std::shared_ptr< Buffers::VKBuffer > &staging, bool deferred=false, vk::ImageLayout restore_layout=vk::ImageLayout::eShaderReadOnlyOptimal, vk::PipelineStageFlags restore_stage=vk::PipelineStageFlagBits::eFragmentShader)
Download pixel data from a VKImage, reusing a caller-supplied persistent staging buffer.
static uint32_t get_channel_count(ImageFormat format)
Get the number of color channels for a given format.
static size_t calculate_image_size(uint32_t width, uint32_t height, uint32_t depth, ImageFormat format)
Calculate image data size.
static std::optional< ImageFormat > readable_format(const std::shared_ptr< Core::VKImage > &image)
ImageFormat of an image that can be read back as one flat block.
bool is_initialized() const
Check if manager is initialized.
@ ImageProcessing
Image processing tasks (filters, transformations)
@ Portal
High-level user-facing API layer.
static std::optional< ImageData > allocate(uint32_t width, uint32_t height, uint32_t channels, ImageFormat format)
Allocate zeroed pixel storage of the variant format calls for.
Definition ImageData.cpp:5

References MayaFlux::Kakshya::ImageData::allocate(), calculate_image_size(), download_data(), format, get_channel_count(), image, MayaFlux::Journal::ImageProcessing, is_initialized(), MF_ERROR, MayaFlux::Journal::Portal, and readable_format().

Referenced by MayaFlux::IO::download_image().

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