11#include <OpenImageIO/imagebuf.h>
12#include <OpenImageIO/imagebufalgo.h>
13#include <spdlog/spdlog.h>
26 spdlog::warn(
"[WorkingImageCPU::downsample]: Image view is invalid");
30 if (target_width == 0 || target_height == 0) {
31 spdlog::error(
"[WorkingImageCPU::downsample]: Target dimensions are invalid ({}x{})", target_width, target_height);
37 spdlog::debug(
"[WorkingImageCPU::downsample]: Start downsample.");
42 spdlog::debug(
"[WorkingImageCPU::downsample]: No downsample required.");
44 return std::make_unique<Common::ImageRegion>(
55 OIIO::ImageSpec src_spec(
69 OIIO::ImageSpec dst_spec(
70 static_cast<int>(target_width),
71 static_cast<int>(target_height),
75 OIIO::ImageBuf dst_buf(dst_spec, result_data.data());
77 if (!OIIO::ImageBufAlgo::resample(dst_buf, src_buf,
false)) {
78 spdlog::error(
"[WorkingImageCPU::downsample]: OIIO resample failed: {}", OIIO::geterror());
86 spdlog::debug(
"WorkingImageCPU::downsample]: Downsample successful, creating ImageRegion from {}x{} to {}x{}.",
88 return std::make_unique<Common::ImageRegion>(
89 std::move(result_data),
90 static_cast<int>(target_width),
91 static_cast<int>(target_height),
95 catch (
const std::bad_alloc& e) {
96 spdlog::critical(
"[WorkingImageCPU::downsample]: Allocation failed: {}", e.what());
99 catch (
const std::exception& e) {
100 spdlog::critical(
"[WorkingImageCPU::downsample]: Exception: {}", e.what());
109 spdlog::warn(
"[WorkingImageCPU::getFullResImage]: Current image is invalid, cannot export");
114 auto cpu_image_copy { std::make_unique<Common::ImageRegion>() };
124 if (!cpu_image_copy->isValid()) {
128 spdlog::debug(
"[WorkingImageCPU::getFullResImage]: Exported ImageRegion ({}x{}, {} ch)",
129 cpu_image_copy->m_width, cpu_image_copy->m_height, cpu_image_copy->m_channels);
131 return cpu_image_copy;
133 }
catch (
const std::bad_alloc& e) {
134 spdlog::critical(
"[WorkingImageCPU::getFullResImage]: Allocation failed: {}", e.what());
136 }
catch (
const std::exception& e) {
137 spdlog::critical(
"[WorkingImageCPU::getFullResImage]: Exception: {}", e.what());
ImageView m_view_data_image
The image view bound to this hardware worker.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getFullResImage() override
Exports current internal image data to a new CPU-based ImageRegion..
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > downsample(Common::ImageDim target_width, Common::ImageDim target_height) override
Exports a downscaled version of the image directly from GPU.
bool isValid() const override
Checks if the image data is valid.
Central error handling system for CaptureMoment Core library.
@ RGBA_F32
4-channel format: Red, Green, Blue, Alpha in 32-bit float.
std::size_t ImageDim
Type for image dimensions (width, height).
CoreError
Enumeration of all error codes for CaptureMoment Core.
@ InvalidImageRegion
The provided ImageRegion dimensions or data are invalid.
@ InvalidWorkingImage
The working image state is invalid or corrupted.
@ AllocationFailed
Memory allocation failed.
@ Unexpected
An unexpected error occurred.
Common::ImageChan channels
std::span< float > working_data
Mutable span for processing.
Image working buffers stored on the CPU.