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

◆ to_image() [2/2]

std::shared_ptr< Core::VKImage > MayaFlux::Kakshya::WindowContainer::to_image ( const std::shared_ptr< Buffers::VKBuffer > &  staging) const

Upload the full surface readback to a new VKImage, reusing a caller-supplied persistent staging buffer.

Allocates the VKImage without pixel data, then uploads via the provided staging buffer, bypassing the per-call VkBuffer allocation inside TextureLoom. Use TextureLoom::create_streaming_staging() to allocate the staging buffer once before the render loop.

Parameters
stagingHost-visible staging VKBuffer sized to at least width * height * bytes_per_pixel.
Returns
Newly created VKImage, or nullptr on failure.

Definition at line 213 of file WindowContainer.cpp.

215{
216 std::shared_lock lock(m_data_mutex);
217
218 if (m_processed_data.empty()) {
220 "WindowContainer::to_image(staging) : no readback data for '{}'",
221 m_window->get_create_info().title);
222 return nullptr;
223 }
224
225 const auto* pixels = std::get_if<std::vector<uint8_t>>(&m_processed_data[0]);
226 if (!pixels || pixels->empty()) {
228 "WindowContainer::to_image(staging) : processed_data[0] is not uint8_t or is empty for '{}'",
229 m_window->get_create_info().title);
230 return nullptr;
231 }
232
233 const auto fmt = query_surface_format(m_window);
234 const auto img_fmt = surface_format_to_image_format(fmt);
235 const uint32_t w = m_structure.get_width();
236 const uint32_t h = m_structure.get_height();
237
239
240 auto img = loom.create_2d(w, h, img_fmt, nullptr);
241 if (!img) {
243 "WindowContainer::to_image(staging) : VKImage allocation failed for '{}'",
244 m_window->get_create_info().title);
245 return nullptr;
246 }
247
248 loom.upload_data(img, pixels->data(), pixels->size(), staging);
249 return img;
250}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
const std::vector< float > * pixels
Definition Decoder.cpp:58
uint32_t h
Definition InkPress.cpp:28
std::shared_ptr< Core::Window > m_window
void lock() override
Acquire a lock for thread-safe access.
std::vector< DataVariant > m_processed_data
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
Core::GraphicsSurfaceInfo::SurfaceFormat query_surface_format(const std::shared_ptr< Core::Window > &window)
Query the actual vk::Format in use by the window's live swapchain, translated back to the MayaFlux su...
static uint64_t get_height(const std::vector< DataDimension > &dimensions)
Extract height from image/video dimensions.
static uint64_t get_width(const std::vector< DataDimension > &dimensions)
Extract width from image/video dimensions.

References MayaFlux::Journal::ContainerProcessing, MayaFlux::Kakshya::ContainerDataStructure::get_height(), MayaFlux::Kakshya::ContainerDataStructure::get_width(), h, MayaFlux::Portal::Graphics::TextureLoom::instance(), MayaFlux::Journal::Kakshya, lock(), m_data_mutex, m_processed_data, m_structure, m_window, MF_RT_ERROR, MF_RT_WARN, pixels, and MayaFlux::Kakshya::query_surface_format().

+ Here is the call graph for this function: