CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
state_image_manager.h
Go to the documentation of this file.
1
25#pragma once
26
32
33#include <vector>
34#include <memory>
35#include <mutex>
36#include <future>
37#include <string_view>
38#include <string>
39#include <optional>
40#include <thread>
41#include <atomic>
42#include <condition_variable>
43
44
45namespace CaptureMoment::Core {
46
47namespace Pipeline {
48class PipelineContext;
49}
50
51namespace Workers {
52class WorkerContext;
53}
54
55namespace ImageProcessing {
56class WorkingImageContext;
57}
58
59
60namespace Managers {
61
62
89public:
98 explicit StateImageManager();
99
104
105 // Disable copy and assignment
108
126 [[nodiscard]] std::future<bool> applyOperations(std::vector<Operations::OperationDescriptor>&& ops);
127
133 [[nodiscard]] bool loadImage(std::string_view path);
134
144 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> commitWorkingImageToSource();
145
155 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> resetToOriginal();
156
162 [[nodiscard]] std::string getImageSourcePath() const;
163
170 [[nodiscard]] Common::ImageDim getSourceWidth() const;
171
178 [[nodiscard]] Common::ImageDim getSourceHeight() const;
179
186 [[nodiscard]] Common::ImageChan getSourceChannels() const;
187
192 [[nodiscard]] std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError>
194
203 [[nodiscard]] std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError>
205
206private:
212 void workerLoop();
213
221 [[nodiscard]] bool executeProcessing(std::vector<Operations::OperationDescriptor> ops);
222
226 void waitForPendingProcessing();
227
228 // ========================================================================
229 // Worker Thread Synchronization
230 // ========================================================================
231
235 std::atomic<bool> m_stop_requested{false};
236
240 mutable std::mutex m_work_mutex;
241
245 std::condition_variable m_work_cv;
246
247 // ========================================================================
248 // State & Infrastructure
249 // ========================================================================
250
254 mutable std::mutex m_state_mutex;
255
259 std::unique_ptr<Pipeline::PipelineContext> m_pipeline_context;
260
264 std::unique_ptr<Workers::WorkerContext> m_worker_context;
265
269 std::unique_ptr<ImageProcessing::WorkingImageContext> m_working_image_context;
270
274 std::string m_original_image_path;
275
281 std::optional<std::vector<Operations::OperationDescriptor>> m_pending_work;
282
288 std::shared_ptr<std::promise<bool>> m_active_promise;
289
297 std::atomic<bool> m_is_idle{true};
298
302 std::unique_ptr<Managers::ISourceManager> m_source_manager;
303
309 std::thread m_worker_thread;
310
311
312 // ========================================================================
313 // Idle State Synchronization
314 // ========================================================================
315
320 std::mutex m_idle_mutex;
321
325 std::condition_variable m_idle_cv;
326};
327
328} // namespace Managers
329
330} // namespace CaptureMoment::Core
Manages the working image lifecycle and coordinates asynchronous processing.
bool loadImage(std::string_view path)
Loads an image file into the internal SourceManager.
Common::ImageChan getSourceChannels() const
Gets the number of channels of the original source image.
std::expected< void, ErrorHandling::CoreError > commitWorkingImageToSource()
Commits the current working image (with applied operations) back to the SourceManager.
Common::ImageDim getSourceWidth() const
Gets the width of the original source image.
Common::ImageDim getSourceHeight() const
Gets the height of the original source image.
std::expected< void, ErrorHandling::CoreError > resetToOriginal()
Resets the image to its original state (synchronous).
StateImageManager & operator=(const StateImageManager &)=delete
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getDownsampledDisplayImage(Common::ImageDim target_width, Common::ImageDim target_height)
Gets a downsampled version of the working image for display. Uses GPU-accelerated downsampling,...
StateImageManager(const StateImageManager &)=delete
std::string getImageSourcePath() const
Gets the path of the image source.
std::future< bool > applyOperations(std::vector< Operations::OperationDescriptor > &&ops)
Applies a list of operations to the current image using move semantics.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getWorkingImageAsRegion() const
Exports the current working image data to CPU memory as an ImageRegion.
Abstract interface for managing image sources.
Abstract interface representing an image used as a working buffer, abstracting hardware location.
Common type definitions for all image types in CaptureMoment.
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
@ ImageProcessing
Errors related to Image Processing, GPU, or Memory.
CoreError
Enumeration of all error codes for CaptureMoment Core.
Definition core_error.h:36
Manages the lifecycle of a single IWorkingImage instance.
Descriptor of an operation with its parameters and unique identifier.
Factory for creating operations (Dependency Injection)
CaptureMoment — footer