MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ImageReader.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Buffers {
7class VKBuffer;
8class TextureBuffer;
9}
10
11namespace MayaFlux::IO {
12
13/**
14 * @struct ImageData
15 * @brief Raw image data loaded from file
16 */
17struct ImageData {
18 std::vector<uint8_t> pixels;
19 uint32_t width;
20 uint32_t height;
21 uint32_t channels;
23};
24
25/**
26 * @class ImageReader
27 * @brief File reader for image formats (PNG, JPG, BMP, TGA, etc.)
28 *
29 * Uses STB Image library for decoding. Supports:
30 * - PNG, JPG, BMP, TGA, PSD, GIF, HDR, PIC, PNM
31 * - Automatic format detection
32 * - Channel conversion (force RGBA, etc.)
33 * - Direct GPU texture creation
34 *
35 * Implements the FileReader interface for consistency with other readers.
36 */
37class MAYAFLUX_API ImageReader : public FileReader {
38public:
40 ~ImageReader() override;
41
42 // FileReader interface implementation
43 [[nodiscard]] bool can_read(const std::string& filepath) const override;
44 bool open(const std::string& filepath, FileReadOptions options = FileReadOptions::ALL) override;
45 void close() override;
46 [[nodiscard]] bool is_open() const override;
47 [[nodiscard]] std::optional<FileMetadata> get_metadata() const override;
48 [[nodiscard]] std::vector<FileRegion> get_regions() const override;
49 std::vector<Kakshya::DataVariant> read_all() override;
50 std::vector<Kakshya::DataVariant> read_region(const FileRegion& region) override;
51 std::shared_ptr<Kakshya::SignalSourceContainer> create_container() override;
52 bool load_into_container(std::shared_ptr<Kakshya::SignalSourceContainer> container) override;
53 [[nodiscard]] std::vector<uint64_t> get_read_position() const override;
54 bool seek(const std::vector<uint64_t>& position) override;
55 [[nodiscard]] std::vector<std::string> get_supported_extensions() const override;
56 [[nodiscard]] std::type_index get_data_type() const override;
57 [[nodiscard]] std::type_index get_container_type() const override;
58 [[nodiscard]] std::string get_last_error() const override;
59 [[nodiscard]] bool supports_streaming() const override;
60 [[nodiscard]] uint64_t get_preferred_chunk_size() const override;
61 [[nodiscard]] size_t get_num_dimensions() const override;
62 [[nodiscard]] std::vector<uint64_t> get_dimension_sizes() const override;
63
64 /**
65 * @brief Load image from memory (static utility)
66 * @param data Pointer to image data in memory
67 * @param size Size of the image data in bytes
68 * @return Image data or nullopt on failure
69 */
70 static std::optional<ImageData> load_from_memory(const void* data, size_t size);
71
72 /**
73 * @brief Load image from file (static utility)
74 * @param path Image file path
75 * @param desired_channels Force channel count (0 = keep original, 4 = RGBA)
76 * @return Image data or nullopt on failure
77 */
78 static std::optional<ImageData> load(
79 const std::string& path, int desired_channels = 4);
80
81 /**
82 * @brief Load image from file (static utility)
83 * @param path Image file path
84 * @param desired_channels Force channel count (0 = keep original, 4 = RGBA)
85 * @return Image data or nullopt on failure
86 */
87 static std::optional<ImageData> load(
88 const std::filesystem::path& path, int desired_channels = 4);
89
90 /**
91 * @brief Load image directly into GPU texture (static utility)
92 * @param path Image file path
93 * @return Initialized VKImage or nullptr on failure
94 */
95 static std::shared_ptr<Core::VKImage> load_texture(
96 const std::string& path);
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:
123 std::string m_filepath;
124 std::optional<ImageData> m_image_data;
125 std::string m_last_error;
127};
128
129} // namespace MayaFlux::IO
Abstract interface for reading various file formats into containers.
std::optional< ImageData > m_image_data
File reader for image formats (PNG, JPG, BMP, TGA, etc.)
FileReadOptions
Generic options for file reading behavior.
ImageFormat
User-friendly image format enum.
auto create_container(Args &&... args) -> std::shared_ptr< ContainerType >
creates a new container of the specified type
Definition Depot.hpp:61
Generic region descriptor for any file type.
Portal::Graphics::ImageFormat format
std::vector< uint8_t > pixels
Raw image data loaded from file.