CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
photo_engine.cpp
Go to the documentation of this file.
1
10
11#include <string_view>
12#include <memory>
13#include <spdlog/spdlog.h>
14#include <utility>
15
17
19 : m_state_manager(std::make_unique<Managers::StateImageManager>())
20{
21 spdlog::debug("PhotoEngine: Constructed with StateImageManager.");
22}
23
24std::expected<void, ErrorHandling::CoreError> PhotoEngine::loadImage(std::string_view path)
25{
26 if (!m_state_manager) {
27 spdlog::error("PhotoEngine::loadImage: StateImageManager is null.");
28 return std::unexpected(ErrorHandling::CoreError::Unexpected);
29 }
30
31 // 1. Load the image via StateImageManager (which internally uses SourceManager)
32 // This also updates the internal state and prepares the working image.
33 // The StateImageManager::loadImage method returns a boolean, so we check for success.
34 if (!m_state_manager->loadImage(path)) {
35 spdlog::error("PhotoEngine::loadImage: Failed to load image '{}'.", path);
36 return std::unexpected(ErrorHandling::CoreError::IOError);
37 }
38
39 // 2. Trigger initial processing (Reset to Original) to have a ready-to-display image.
40 auto process_result = m_state_manager->resetToOriginal();
41
42 if (!process_result) {
43 return std::unexpected(process_result.error());
44 }
45
46 spdlog::info("PhotoEngine: Loaded image '{}' successfully.", path);
47 return {};
48}
49
50std::expected<void, ErrorHandling::CoreError> PhotoEngine::commitWorkingImageToSource()
51{
52 if (!m_state_manager) {
53 return std::unexpected(ErrorHandling::CoreError::Unexpected);
54 }
55 return m_state_manager->commitWorkingImageToSource();
56}
57
59{
60 if (!m_state_manager) return;
61
62 spdlog::debug("PhotoEngine: Resetting working image.");
63 (void) m_state_manager->resetToOriginal();
64}
65
67{
68 return m_state_manager->getSourceWidth();
69}
70
72{
73 return m_state_manager->getSourceHeight();
74}
75
77{
78 return m_state_manager->getSourceChannels();
79}
80
81std::future<bool> PhotoEngine::applyOperations(std::vector<Operations::OperationDescriptor>&& ops)
82{
83 if (!m_state_manager) {
84 spdlog::error("PhotoEngine::applyOperations: StateImageManager is null.");
85 return std::async(std::launch::deferred, []() { return false; });
86 }
87
88 spdlog::info("PhotoEngine::applyOperations: Received {} operations.", ops.size());
89 return m_state_manager->applyOperations(std::move(ops));
90}
91
92std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError> PhotoEngine::getWorkingImageAsRegion() const
93{
94 if (!m_state_manager) {
95 spdlog::error("[PhotoEngine::getWorkingImageAsRegion]: StateManager is null.");
96 return std::unexpected(ErrorHandling::CoreError::Unexpected);
97 }
98
99 auto result = m_state_manager->getWorkingImageAsRegion();
100
101 if (!result) {
102 spdlog::error("[PhotoEngine::getWorkingImageAsRegion]: Failed to get working image.");
103 return std::unexpected(result.error());
104 }
105
106 return result;
107}
108
109std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError>
111{
112 if (!m_state_manager) {
113 return std::unexpected(ErrorHandling::CoreError::Unexpected);
114 }
115 return m_state_manager->getDownsampledDisplayImage(width, height);
116}
117
118} // namespace CaptureMoment::Core::Engine
Common::ImageDim width() const noexcept
Gets the width of the loaded image.
std::expected< void, ErrorHandling::CoreError > loadImage(std::string_view path)
Loads an image file and initializes the processing pipeline.
Common::ImageDim height() const noexcept
Gets the height of the loaded image.
void resetWorkingImage()
Resets the working image to the original state.
Common::ImageChan channels() const noexcept
Gets the number of color channels.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getDownsampledDisplayImage(Common::ImageDim width, Common::ImageDim height)
std::expected< void, ErrorHandling::CoreError > commitWorkingImageToSource()
Commits the processed working image back to the source manager.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getWorkingImageAsRegion() const
Gets the working image as a CPU-based copy.
PhotoEngine()
Constructs a PhotoEngine instance.
std::future< bool > applyOperations(std::vector< Operations::OperationDescriptor > &&ops)
Applies a cumulative list of operations.
std::uint8_t ImageChan
Type for channel count.
Definition image_types.h:26
std::size_t ImageDim
Type for image dimensions (width, height).
Definition image_types.h:20
CoreError
Enumeration of all error codes for CaptureMoment Core.
Definition core_error.h:36
@ Unexpected
An unexpected error occurred.
Declaration of PhotoEngine class.
Declaration of StateImageManager class.
CaptureMoment — footer