CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
source_manager.h
Go to the documentation of this file.
1
18#pragma once
19
21
22#include <OpenImageIO/imagebuf.h>
23#include <OpenImageIO/imagecache.h>
24
25#include <mutex>
26#include <string>
27#include <memory>
28
29namespace CaptureMoment::Core {
30
31namespace Managers {
32
41public:
43 ~SourceManager() override;
44
45 // -----------------------------------------------------------------
46 // ISourceManager Implementation
47 // -----------------------------------------------------------------
48
49 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> loadFile(std::string_view path) override;
50 void unload() override;
51 [[nodiscard]] bool isLoaded() const override;
52 [[nodiscard]] Common::ImageDim width() const noexcept override;
53 [[nodiscard]] Common::ImageDim height() const noexcept override;
54 [[nodiscard]] Common::ImageChan channels() const noexcept override;
55
56 [[nodiscard]] std::expected<std::unique_ptr<Common::ImageRegion>, ErrorHandling::CoreError> getTile(
58 ) override;
59
60 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> setTile(const Common::ImageRegion& tile) override;
61
62 [[nodiscard]] std::optional<std::string> getMetadata(std::string_view key) const override;
63
64 [[nodiscard]] std::string getImageSourcePath() const override;
65
66private:
71 std::unique_ptr<OIIO::ImageBuf> m_image_buf;
72
77 mutable std::mutex m_mutex;
78
83 OIIO::ImageCache* m_cache;
84
88 std::string m_current_path;
89
93 static OIIO::ImageCache* getGlobalCache();
94
99 void unloadInternal();
100
105 [[nodiscard]] bool isLoaded_unsafe() const;
106
107
114 [[nodiscard]] std::expected<OIIO::ImageBuf, ErrorHandling::CoreError>
115 loadImageBuffer(std::string_view path, const OIIO::ImageSpec* config = nullptr);
116
117 // ============================================================
118 // RAW File Handling
119 // ============================================================
120
131 [[nodiscard]] bool isRawFile(std::string_view path) const;
132
143 [[nodiscard]] bool isHeicFile(std::string_view path) const;
144
159 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> loadRawFile(std::string_view path);
160
172 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> loadHeicFile(std::string_view path);
173
183 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> loadStandardFile(std::string_view path);
184
191 [[nodiscard]] std::expected<void, ErrorHandling::CoreError> convertToRgbaInternal(OIIO::ImageBuf&& src_buf);
192};
193
194} // namespace Managers
195
196} // namespace CaptureMoment::Core
Abstract interface for managing image sources.
Concrete implementation of ISourceManager using OIIO.
std::expected< std::unique_ptr< Common::ImageRegion >, ErrorHandling::CoreError > getTile(Common::ImageDim x, Common::ImageDim y, Common::ImageDim width, Common::ImageDim height) override
Extracts a rectangular region (tile) of pixels from the image.
Common::ImageDim width() const noexcept override
Retrieves the width (in pixels) of the source image.
bool isLoaded() const override
Checks if an image is currently loaded.
Common::ImageDim height() const noexcept override
Retrieves the height (in pixels) of the source image.
std::expected< void, ErrorHandling::CoreError > setTile(const Common::ImageRegion &tile) override
Writes pixel data from a tile back into the image buffer.
void unload() override
Unloads the currently loaded image and frees resources.
std::string getImageSourcePath() const override
Gets the path of the image source.
std::expected< void, ErrorHandling::CoreError > loadFile(std::string_view path) override
Loads an image file from the specified path.
Common::ImageChan channels() const noexcept override
Gets the number of channels of the internal buffer.
std::optional< std::string > getMetadata(std::string_view key) const override
Retrieves a specific metadata field from the source image.
Abstract interface for managing image sources.
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
Manages the lifecycle of a single IWorkingImage instance.
Represents a rectangular region of an image and its pixel data.
CaptureMoment — footer