ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
runtime_image.h
Go to the documentation of this file.
1#pragma once
2
5
7
8// Forward declaration
9class ImageDecoder;
10
24
33class RuntimeImage : public image::Image {
34 public:
47 image::Image *placeholder = nullptr, bool is_big_endian = false, int fixed_width = 0,
48 int fixed_height = 0);
49
51
52 // Decoder interface methods
66 int resize(int width, int height);
67 void draw_pixel(int x, int y, const Color &color);
68 void map_chroma_key(Color &color);
69 int get_buffer_width() const { return this->buffer_width_; }
70 int get_buffer_height() const { return this->buffer_height_; }
71
72 // Image drawing interface
73 void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override;
74
81 bool begin_decode(size_t expected_size = 0);
82
90 int feed_data(uint8_t *data, size_t len);
91
97 bool end_decode();
98
102 bool is_decoding() const { return this->decoder_ != nullptr; }
103
110 bool is_decode_finished() const;
111
115 bool is_loaded() const { return this->buffer_ != nullptr; }
116
120 ImageFormat get_format() const { return this->format_; }
121
125 void release();
126
133 void set_progressive_display(bool progressive) { this->progressive_display_ = progressive; }
134
135 protected:
143 size_t resize_buffer_(int width, int height);
144
150 void release_buffer_();
151
155 size_t get_buffer_size_(int width, int height) const;
156
160 int get_position_(int x, int y) const;
161
165 std::unique_ptr<ImageDecoder> create_decoder_();
166
167 // Memory management
169 uint8_t *buffer_{nullptr};
170
171 // Decoder management
172 std::unique_ptr<ImageDecoder> decoder_{nullptr};
175
192
193 // Decoding state
194 size_t total_size_{0};
195 size_t decoded_bytes_{0};
196
198 const int fixed_width_{0};
200 const int fixed_height_{0};
201
204
205 // Configuration
211 bool is_big_endian_{false};
212};
213
214} // namespace esphome::runtime_image
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:1665
A dynamic image that can be loaded and decoded at runtime.
size_t get_buffer_size_(int width, int height) const
Get the buffer size in bytes for given dimensions.
bool is_loaded() const
Check if an image is currently loaded.
RAMAllocator< uint8_t > allocator_
bool is_decoding() const
Check if decoding is currently in progress.
bool is_big_endian_
Whether the image is stored in big-endian format.
void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override
int buffer_width_
Actual width of the current image.
bool end_decode()
Complete the decoding process.
void set_progressive_display(bool progressive)
Set whether to allow progressive display during decode.
int get_position_(int x, int y) const
Get the position in the buffer for a pixel.
const int fixed_height_
Fixed height requested on configuration, or 0 if not specified.
void release_buffer_()
Release only the image buffer without resetting the decoder.
int resize(int width, int height)
Resize the image buffer to the requested dimensions.
int feed_data(uint8_t *data, size_t len)
Feed data to the decoder.
const int fixed_width_
Fixed width requested on configuration, or 0 if not specified.
bool is_decode_finished() const
Check if the decoder has finished processing all data.
void release()
Release the image buffer and free memory.
image::Image * placeholder_
Placeholder image to show when the runtime image is not available.
RuntimeImage(ImageFormat format, image::ImageType type, image::Transparency transparency, image::Image *placeholder=nullptr, bool is_big_endian=false, int fixed_width=0, int fixed_height=0)
Construct a new RuntimeImage object.
ImageFormat get_format() const
Get the image format.
const ImageFormat format_
The image format this RuntimeImage is configured to decode.
size_t resize_buffer_(int width, int height)
Resize the image buffer to the requested dimensions.
std::unique_ptr< ImageDecoder > decoder_
std::unique_ptr< ImageDecoder > create_decoder_()
Create decoder instance for the image's format.
void draw_pixel(int x, int y, const Color &color)
int buffer_height_
Actual height of the current image.
bool begin_decode(size_t expected_size=0)
Begin decoding an image.
uint16_t type
ImageFormat
Image format types that can be decoded dynamically.
@ AUTO
Automatically detect from data.
std::string size_t len
Definition helpers.h:692
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6