ESPHome 2025.5.0
Loading...
Searching...
No Matches
image_decoder.h
Go to the documentation of this file.
1#pragma once
3
4namespace esphome {
5namespace online_image {
6
12
13class OnlineImage;
14
19 public:
25 ImageDecoder(OnlineImage *image) : image_(image) {}
26 virtual ~ImageDecoder() = default;
27
34 virtual int prepare(size_t download_size) {
35 this->download_size_ = download_size;
36 return 0;
37 }
38
50 virtual int decode(uint8_t *buffer, size_t size) = 0;
51
60 bool set_size(int width, int height);
61
74 void draw(int x, int y, int w, int h, const Color &color);
75
76 bool is_finished() const { return this->decoded_bytes_ == this->download_size_; }
77
78 protected:
80 // Initializing to 1, to ensure it is distinguishable from initial "decoded_bytes_".
81 // Will be overwritten anyway once the download size is known.
82 size_t download_size_ = 1;
83 size_t decoded_bytes_ = 0;
84 double x_scale_ = 1.0;
85 double y_scale_ = 1.0;
86};
87
89 public:
90 DownloadBuffer(size_t size);
91
92 virtual ~DownloadBuffer() { this->allocator_.deallocate(this->buffer_, this->size_); }
93
94 uint8_t *data(size_t offset = 0);
95
96 uint8_t *append() { return this->data(this->unread_); }
97
98 size_t unread() const { return this->unread_; }
99 size_t size() const { return this->size_; }
100 size_t free_capacity() const { return this->size_ - this->unread_; }
101
102 size_t read(size_t len);
103 size_t write(size_t len) {
104 this->unread_ += len;
105 return this->unread_;
106 }
107
108 void reset() { this->unread_ = 0; }
109
110 size_t resize(size_t size);
111
112 protected:
114 uint8_t *buffer_;
115 size_t size_;
117 size_t unread_;
118};
119
120} // namespace online_image
121} // namespace esphome
uint8_t h
Definition bl0906.h:2
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:683
void deallocate(T *p, size_t n)
Definition helpers.h:741
size_t unread_
Total number of downloaded bytes not yet read.
uint8_t * data(size_t offset=0)
Class to abstract decoding different image formats.
void draw(int x, int y, int w, int h, const Color &color)
Fill a rectangle on the display_buffer using the defined color.
virtual int prepare(size_t download_size)
Initialize the decoder.
ImageDecoder(OnlineImage *image)
Construct a new Image Decoder object.
virtual int decode(uint8_t *buffer, size_t size)=0
Decode a part of the image.
bool set_size(int width, int height)
Request the image to be resized once the actual dimensions are known.
Download an image from a given URL, and decode it using the specified decoder.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6