CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
working_image_gpu.cpp
Go to the documentation of this file.
1
9
10#include <spdlog/spdlog.h>
11
13
15{
17}
18
19std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError>
21{
22 if (!isValid()) {
23 spdlog::warn("[WorkingImageGPU::getFullResImage]: Invalid working image. Cannot export to CPU.");
25 }
26
27 // Download the GPU buffer to Host RAM (m_view_data_image.working_data)
28 if (!downloadDeviceToHost()) {
29 spdlog::warn("[WorkingImageGPU::getFullResImage]: Failed to download GPU buffer to Host memory.");
31 }
32
33 try {
34 // Create a deep copy of the working data into a new ImageRegion
35 auto cpu_image_copy {std::make_unique<Common::ImageRegion>()};
36
37 cpu_image_copy->m_data.assign(m_view_data_image.working_data.begin(), m_view_data_image.working_data.end());
38
39 cpu_image_copy->m_width = static_cast<int>(m_view_data_image.width);
40 cpu_image_copy->m_height = static_cast<int>(m_view_data_image.height);
41 cpu_image_copy->m_channels = static_cast<int>(m_view_data_image.channels);
42 cpu_image_copy->m_format = Common::PixelFormat::RGBA_F32;
43
44 if (!cpu_image_copy->isValid()) {
46 }
47
48 return cpu_image_copy;
49
50 } catch (const std::bad_alloc&) {
51 return std::unexpected(ErrorHandling::CoreError::AllocationFailed);
52 } catch (const std::exception& e) {
53 spdlog::error("[WorkingImageGPU::getFullResImage]: Unexpected: {}", e.what());
54 return std::unexpected(ErrorHandling::CoreError::Unexpected);
55 }
56}
57
58} // namespace CaptureMoment::Core::ImageProcessing
ImageView m_view_data_image
The image view bound to this hardware worker.
bool isValid() const override
Checks if the GPU buffer is valid and allocated.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getFullResImage() override
Exports current internal image data by downloading from the GPU device to Host memory.
virtual bool downloadDeviceToHost()=0
A pure method that specific backends (Halide, Vulkan, etc.) must implement.
@ RGBA_F32
4-channel format: Red, Green, Blue, Alpha in 32-bit float.
CoreError
Enumeration of all error codes for CaptureMoment Core.
Definition core_error.h:36
@ 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.
std::span< float > working_data
Mutable span for processing.
Definition image_view.h:27
Image working buffers stored on the GPU.
CaptureMoment — footer