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.
228{
230
233 "WindowContainer::region_to_image — no readback data for '{}'",
235 return nullptr;
236 }
237
239 if (!src || src->empty()) {
241 "WindowContainer::region_to_image — processed_data[0] is not uint8_t or is empty for '{}'",
243 return nullptr;
244 }
245
246 std::vector<uint8_t> cropped;
247 try {
248 cropped = extract_region_data<uint8_t>(
249 std::span<const uint8_t> { src->data(), src->size() },
250 region,
252 } catch (const std::exception& e) {
254 "WindowContainer::region_to_image — crop failed for '{}': {}",
255 m_window->get_create_info().title, e.what());
256 return nullptr;
257 }
258
259 if (region.start_coordinates.size() < 2 || region.end_coordinates.size() < 2) {
261 "WindowContainer::region_to_image — region must have at least 2 coordinates (SPATIAL_Y, SPATIAL_X)");
262 return nullptr;
263 }
264
265 const auto rh = static_cast<uint32_t>(
266 region.end_coordinates[0] - region.start_coordinates[0] + 1);
267 const auto rw = static_cast<uint32_t>(
268 region.end_coordinates[1] - region.start_coordinates[1] + 1);
269
271 const auto img_fmt = surface_format_to_image_format(fmt);
272
274 rw, rh, img_fmt, cropped.data());
275
276 if (!img) {
278 "WindowContainer::region_to_image — TextureLoom::create_2d failed ({}x{}) for '{}'",
279 rw, rh,
m_window->get_create_info().title);
280 }
281
282 return img;
283}
#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