13#include <spdlog/spdlog.h>
27 m_image_data = std::make_unique<WorkingImageData>(std::move(original_tile));
28 }
catch (
const std::exception& e) {
29 spdlog::error(
"[WorkingImageContext::prepare]: Exception creating data: {}", e.what());
33 if (!m_image_data->isValid()) {
34 spdlog::error(
"[WorkingImageContext::prepare]: Data is invalid after initialization.");
42 spdlog::error(
"[WorkingImageContext::prepare]: Failed to create Hardware backend.");
48 .working_data = m_image_data->getWorkingDataSpan(),
49 .original_data = m_image_data->getOriginalDataSpan(),
50 .width = m_image_data->getWidth(),
51 .height = m_image_data->getHeight(),
52 .channels = m_image_data->getChannels()
56 if (!new_hardware->bindView(view_data_image)) {
57 spdlog::error(
"[WorkingImageContext::prepare]: Failed to bind data to hardware.");
61 m_working_image = std::move(new_hardware);
62 spdlog::debug(
"[WorkingImageContext::prepare]: Created and bound new WorkingImage.");
69 if (!m_image_data || !m_image_data->isValid()) {
70 spdlog::warn(
"[WorkingImageContext::resetToOriginal]: No valid data to reset.");
77 m_image_data->restoreOriginalData();
78 spdlog::debug(
"[WorkingImageContext::resetToOriginal]: Data reset to original.");
81std::shared_ptr<IWorkingImageHardware>
84 return m_working_image;
89 return m_working_image && m_working_image->isValid();
95 if (!m_working_image) {
98 return m_working_image->getFullResImage();
104 if (!m_working_image) {
108 return m_working_image->downsample(target_width, target_height);
113 m_working_image.reset();
114 m_image_data.reset();
115 spdlog::debug(
"[WorkingImageContext::release]: Released working image and data.");
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getWorkingImageAsRegion() const
Exports the WorkingImage data to CPU.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getDownsampled(Common::ImageDim target_width, Common::ImageDim target_height)
Downsamples the WorkingImage to the specified dimensions.
std::shared_ptr< IWorkingImageHardware > getWorkingImage() noexcept
Gets the WorkingImage for processing.
void release() noexcept
Releases the managed WorkingImage.
bool prepare(std::unique_ptr< Common::ImageRegion > original_tile)
Prepares the context with a new source image.
bool isReady() const noexcept
Checks if a WorkingImage is ready for use.
void resetToOriginal()
Restores the internal working buffer to the original source data.
static std::unique_ptr< IWorkingImageHardware > create()
Creates a working image using the application's global configuration.
Central error handling system for CaptureMoment Core library.
Lightweight, non-owning view over image memory and its geometry.
std::size_t ImageDim
Type for image dimensions (width, height).
CoreError
Enumeration of all error codes for CaptureMoment Core.
@ InvalidWorkingImage
The working image state is invalid or corrupted.
Represents a zero-copy window over contiguous image memory.
Manages the lifecycle of a single WorkingImage instance and its associated data.
Factory for creating IWorkingImageHardware instances using a Registry Pattern.