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.
333{
334 if (region.start_coordinates.size() < 2 || region.end_coordinates.size() < 2) {
336 "WindowContainer::region_to_image — region must have at least 2 coordinates (SPATIAL_Y, SPATIAL_X)");
337 return nullptr;
338 }
339
340 std::shared_ptr<Core::VKImage> img;
343 MF_RT_WARN(Journal::Component::Kakshya, Journal::Context::ContainerProcessing,
344 "WindowContainer::region_to_image — no readback data for '{}'",
345 m_window->get_create_info().title);
346 return;
347 }
348
350 if (!src || src->empty()) {
352 "WindowContainer::region_to_image — processed_data[0] is not uint8_t or is empty for '{}'",
354 return;
355 }
356
357 std::vector<uint8_t> cropped;
358 try {
359 cropped = extract_region_data<uint8_t>(
360 std::span<const uint8_t> { src->data(), src->size() },
361 region,
363 } catch (const std::exception& e) {
365 "WindowContainer::region_to_image — crop failed for '{}': {}",
366 m_window->get_create_info().title, e.what());
367 return;
368 }
369
370 const auto rh = static_cast<uint32_t>(region.end_coordinates[0] - region.start_coordinates[0] + 1);
371 const auto rw = static_cast<uint32_t>(region.end_coordinates[1] - region.start_coordinates[1] + 1);
373
375 if (!img) {
377 "WindowContainer::region_to_image — TextureLoom::create_2d failed ({}x{}) for '{}'",
378 rw, rh,
m_window->get_create_info().title);
379 }
380 });
381
382 return img;
383}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
std::shared_ptr< Core::Window > m_window
Memory::Seqlock m_data_lock
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...
bool seqlock_read_void(const Seqlock &lock, uint32_t max_attempts, Fn &&fn)
Invoke a void read functor under a Seqlock with a bounded retry count.
std::vector< DataDimension > dimensions