Crop a region from the last readback and upload it as a VKImage.
Performs a CPU-side crop via extract_region_data; no additional GPU work beyond the readback that populated processed_data[0]. Region coordinates follow IMAGE_COLOR convention: [SPATIAL_Y, SPATIAL_X]. The returned image dimensions are derived from the region extent.
343{
345
348 "WindowContainer::region_to_image — no readback data for '{}'",
350 return nullptr;
351 }
352
354 if (!src || src->empty()) {
356 "WindowContainer::region_to_image — processed_data[0] is not uint8_t or is empty for '{}'",
358 return nullptr;
359 }
360
361 std::vector<uint8_t> cropped;
362 try {
363 cropped = extract_region_data<uint8_t>(
364 std::span<const uint8_t> { src->data(), src->size() },
365 region,
367 } catch (const std::exception& e) {
369 "WindowContainer::region_to_image — crop failed for '{}': {}",
370 m_window->get_create_info().title, e.what());
371 return nullptr;
372 }
373
374 if (region.start_coordinates.size() < 2 || region.end_coordinates.size() < 2) {
376 "WindowContainer::region_to_image — region must have at least 2 coordinates (SPATIAL_Y, SPATIAL_X)");
377 return nullptr;
378 }
379
380 const auto rh = static_cast<uint32_t>(
381 region.end_coordinates[0] - region.start_coordinates[0] + 1);
382 const auto rw = static_cast<uint32_t>(
383 region.end_coordinates[1] - region.start_coordinates[1] + 1);
384
386 const auto img_fmt = surface_format_to_image_format(fmt);
387
389 rw, rh, img_fmt, cropped.data());
390
391 if (!img) {
393 "WindowContainer::region_to_image — TextureLoom::create_2d failed ({}x{}) for '{}'",
394 rw, rh,
m_window->get_create_info().title);
395 }
396
397 return img;
398}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
std::shared_ptr< Core::Window > m_window
void lock() override
Acquire a lock for thread-safe access.
std::shared_mutex m_data_mutex
std::vector< DataVariant > m_processed_data
ContainerDataStructure m_structure
static TextureLoom & instance()
std::shared_ptr< Core::VKImage > create_2d(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr, uint32_t mip_levels=1)
Create a 2D texture.
@ 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...
std::vector< DataDimension > dimensions