MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ImageReader.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace MayaFlux::Buffers {
8class VKBuffer;
9class TextureBuffer;
10}
11
12namespace MayaFlux::IO {
13
14using ImageData = Kakshya::ImageData;
15
16/**
17 * @class ImageReader
18 * @brief File reader for image formats (PNG, JPG, BMP, TGA, etc.)
19 *
20 * Uses STB Image library for decoding. Supports:
21 * - PNG, JPG, BMP, TGA, PSD, GIF, HDR, PIC, PNM
22 * - Automatic format detection
23 * - Channel conversion (force RGBA, etc.)
24 * - Direct GPU texture creation
25 *
26 * Implements the FileReader interface for consistency with other readers.
27 */
28class MAYAFLUX_API ImageReader : public FileReader {
29public:
30 /** @brief Configure channel conversion and an optional source-pixel crop for open(). */
31 ImageReader(int desired_channels = 4,
32 std::optional<Kakshya::Region> region = std::nullopt);
33 ~ImageReader() override;
34
35 // FileReader interface implementation
36 [[nodiscard]] bool can_read(const std::string& filepath) const override;
37 bool open(const std::string& filepath, FileReadOptions options = FileReadOptions::ALL) override;
38 void close() override;
39 [[nodiscard]] bool is_open() const override;
40 [[nodiscard]] std::optional<FileMetadata> get_metadata() const override;
41 [[nodiscard]] std::vector<FileRegion> get_regions() const override;
42 std::vector<Kakshya::DataVariant> read_all() override;
43 std::vector<Kakshya::DataVariant> read_region(const FileRegion& region) override;
44 std::shared_ptr<Kakshya::SignalSourceContainer> create_container() override;
45 bool load_into_container(std::shared_ptr<Kakshya::SignalSourceContainer> container) override;
46 [[nodiscard]] std::vector<uint64_t> get_read_position() const override;
47 bool seek(const std::vector<uint64_t>& position) override;
48 [[nodiscard]] std::vector<std::string> get_supported_extensions() const override;
49 [[nodiscard]] std::type_index get_data_type() const override;
50 [[nodiscard]] std::type_index get_container_type() const override;
51 [[nodiscard]] std::string get_last_error() const override;
52 [[nodiscard]] bool supports_streaming() const override;
53 [[nodiscard]] uint64_t get_preferred_chunk_size() const override;
54 [[nodiscard]] size_t get_num_dimensions() const override;
55 [[nodiscard]] std::vector<uint64_t> get_dimension_sizes() const override;
56
57 /**
58 * @brief Load image from memory (static utility)
59 * @param data Pointer to image data in memory
60 * @param size Size of the image data in bytes
61 * @return Image data or nullopt on failure
62 */
63 static std::optional<ImageData> load_from_memory(const void* data, size_t size);
64
65 /**
66 * @brief Load image from file (static utility)
67 * @param path Image file path
68 * @param desired_channels Force channel count (0 = keep original, 4 = RGBA)
69 * @param region Optional source-pixel rectangle with inclusive end coordinates
70 * @return Image data or nullopt on failure
71 */
72 static std::optional<ImageData> load(
73 const std::string& path, int desired_channels = 4,
74 std::optional<Kakshya::Region> region = std::nullopt);
75
76 /**
77 * @brief Load image from file (static utility)
78 * @param path Image file path
79 * @param desired_channels Force channel count (0 = keep original, 4 = RGBA)
80 * @param region Optional source-pixel rectangle with inclusive end coordinates
81 * @return Image data or nullopt on failure
82 */
83 static std::optional<ImageData> load(
84 const std::filesystem::path& path, int desired_channels = 4,
85 std::optional<Kakshya::Region> region = std::nullopt);
86
87 /**
88 * @brief Load image directly into GPU texture (static utility)
89 * @param path Image file path
90 * @param desired_channels Force channel count (0 = keep original, 4 = RGBA)
91 * @param region Optional source-pixel rectangle with inclusive end coordinates
92 * @return Initialized VKImage or nullptr on failure
93 */
94 static std::shared_ptr<Core::VKImage> load_texture(
95 const std::string& path, int desired_channels = 4,
96 std::optional<Kakshya::Region> region = std::nullopt);
97
98 /**
99 * @brief Get the loaded image data
100 * @return Image data or nullopt if no file open
101 */
102 [[nodiscard]] std::optional<ImageData> get_image_data() const;
103
104 /**
105 * @brief Create a VKBuffer containing the loaded image pixel data
106 * @return VKBuffer with pixel data ready for GPU processing
107 *
108 * Creates a buffer suitable for:
109 * - Transfer operations (upload to VKImage)
110 * - Direct compute shader processing
111 * - Buffer processor chains (treat pixels as samples)
112 */
113 std::shared_ptr<Buffers::TextureBuffer> create_texture_buffer();
114
115 /**
116 * @brief Load image directly into an existing VKBuffer
117 * @param buffer Target buffer (must be large enough)
118 * @return True if load succeeded
119 */
120 bool load_into_buffer(const std::shared_ptr<Buffers::VKBuffer>& buffer);
121
122private:
124 std::optional<Kakshya::Region> m_region;
125 std::string m_filepath;
126 std::optional<ImageData> m_image_data;
127 std::string m_last_error;
129};
130
131} // namespace MayaFlux::IO
std::optional< glm::vec3 > position
Definition Decoder.cpp:93
bool size
std::shared_ptr< NetworkGeometryBuffer > buffer
Abstract interface for reading various file formats into containers.
std::optional< ImageData > m_image_data
std::optional< Kakshya::Region > m_region
File reader for image formats (PNG, JPG, BMP, TGA, etc.)
FileReadOptions
Generic options for file reading behavior.
Kakshya::ImageData ImageData
auto create_container(Args &&... args) -> std::shared_ptr< ContainerType >
creates a new container of the specified type
Definition Depot.hpp:67
Generic region descriptor for any file type.