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

◆ region_to_image()

std::shared_ptr< Core::VKImage > MayaFlux::Kakshya::WindowContainer::region_to_image ( const Region &  region) const

Crop a region from the last readback and refresh its cached VKImage.

Performs a CPU-side crop via extract_region_data and uploads it. Region coordinates follow IMAGE_COLOR convention: [SPATIAL_Y, SPATIAL_X]. The returned image dimensions are derived from the region extent. The image is retained by the container and refreshed for any later region with the same width and height.

Parameters
regionPixel rectangle. Must have at least 2 coordinates.
Returns
VKImage sized to the region, or nullptr on failure.

Definition at line 277 of file WindowContainer.cpp.

278{
279 if (region.start_coordinates.size() < 2 || region.end_coordinates.size() < 2) {
281 "WindowContainer::region_to_image — region must have at least 2 coordinates (SPATIAL_Y, SPATIAL_X)");
282 return nullptr;
283 }
284
285 if (region.start_coordinates[0] > region.end_coordinates[0]
286 || region.start_coordinates[1] > region.end_coordinates[1]) {
288 "WindowContainer::region_to_image : inverted region");
289 return nullptr;
290 }
291
292 auto pixels = snapshot_pixels();
293 if (!pixels)
294 return nullptr;
295
296 std::vector<uint8_t> cropped;
297 try {
298 cropped = extract_region_data<uint8_t>(
299 std::span<const uint8_t> { pixels->pixels.data(), pixels->pixels.size() },
300 region,
301 pixels->dimensions);
302 } catch (const std::exception& e) {
304 "WindowContainer::region_to_image : crop failed for '{}': {}",
305 m_window->get_create_info().title, e.what());
306 return nullptr;
307 }
308
309 const auto rh = static_cast<uint32_t>(region.end_coordinates[0] - region.start_coordinates[0] + 1);
310 const auto rw = static_cast<uint32_t>(region.end_coordinates[1] - region.start_coordinates[1] + 1);
311 const auto key = std::pair { rw, rh };
312 const auto format = get_image_format();
313 Memory::SerializedSeqlockWriteGuard image_guard(m_image_cache_lock);
315 m_region_images[key], sampled_image_key(rw, rh, format), cropped);
316}
#define MF_RT_ERROR(comp, ctx,...)
const std::vector< float > * pixels
Definition Decoder.cpp:48
bool format
std::optional< PixelSnapshot > snapshot_pixels(std::optional< uint32_t > frame_index=std::nullopt) const
ImageFormat get_image_format() const
Portal ImageFormat corresponding to the live swapchain surface format.
std::shared_ptr< Core::Window > m_window
std::map< std::pair< uint32_t, uint32_t >, Portal::Graphics::ImageCacheEntry > m_region_images
std::shared_ptr< Core::VKImage > refresh_cached_image(ImageCacheEntry &entry, const ImageKey &key, std::span< const uint8_t > pixels, const std::shared_ptr< Buffers::VKBuffer > &staging={})
Refresh a sampled image in an owner-held cache entry.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.

References MayaFlux::Journal::ContainerProcessing, MayaFlux::Kakshya::Region::end_coordinates, format, get_image_format(), MayaFlux::Portal::Graphics::TextureLoom::instance(), MayaFlux::Journal::Kakshya, m_image_cache_lock, m_region_images, m_window, MF_RT_ERROR, pixels, MayaFlux::Portal::Graphics::TextureLoom::refresh_cached_image(), snapshot_pixels(), and MayaFlux::Kakshya::Region::start_coordinates.

+ Here is the call graph for this function: