ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
image_decoder.h
Go to the documentation of this file.
1#pragma once
3
5
12
13constexpr const char *decode_error_to_string(int error) {
14 switch (error) {
16 return "Invalid type";
18 return "Unsupported format";
20 return "Out of memory";
22 return "Internal decoder error";
23 default:
24 return "Unknown error";
25 }
26}
27
28class RuntimeImage;
29
34 public:
40 ImageDecoder(RuntimeImage *image) : image_(image) {}
41 virtual ~ImageDecoder() = default;
42
49 virtual int prepare(size_t expected_size) {
50 this->expected_size_ = expected_size;
51 return 0;
52 }
53
65 virtual int decode(uint8_t *buffer, size_t size) = 0;
66
75 bool set_size(int width, int height);
76
89 void draw(int x, int y, int w, int h, const Color &color);
90
97 virtual bool is_finished() const {
98 if (this->expected_size_ > 0) {
99 return this->decoded_bytes_ >= this->expected_size_;
100 }
101 // If size is unknown, derived classes should override this
102 return false;
103 }
104
105 protected:
107 size_t expected_size_ = 0; // Expected data size (0 if unknown)
108 size_t decoded_bytes_ = 0; // Bytes processed so far
109 double x_scale_ = 1.0;
110 double y_scale_ = 1.0;
111 bool size_valid_ = true; // Last set_size() result; draw() no-ops while false
112};
113
114} // namespace esphome::runtime_image
uint8_t h
Definition bl0906.h:2
Class to abstract decoding different image formats.
virtual bool is_finished() const
Check if the decoder has finished processing.
virtual int decode(uint8_t *buffer, size_t size)=0
Decode a part of the image.
void draw(int x, int y, int w, int h, const Color &color)
Fill a rectangle on the display_buffer using the defined color.
ImageDecoder(RuntimeImage *image)
Construct a new Image Decoder object.
bool set_size(int width, int height)
Request the image to be resized once the actual dimensions are known.
virtual int prepare(size_t expected_size)
Initialize the decoder.
A dynamic image that can be loaded and decoded at runtime.
constexpr const char * decode_error_to_string(int error)
uint16_t size
Definition helpers.cpp:25
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6