ESPHome 2025.5.0
Loading...
Searching...
No Matches
png_image.cpp
Go to the documentation of this file.
1#include "png_image.h"
2#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
3
6#include "esphome/core/log.h"
7
8static const char *const TAG = "online_image.png";
9
10namespace esphome {
11namespace online_image {
12
21static void init_callback(pngle_t *pngle, uint32_t w, uint32_t h) {
22 PngDecoder *decoder = (PngDecoder *) pngle_get_user_data(pngle);
23 decoder->set_size(w, h);
24}
25
37static void draw_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t rgba[4]) {
38 PngDecoder *decoder = (PngDecoder *) pngle_get_user_data(pngle);
39 Color color(rgba[0], rgba[1], rgba[2], rgba[3]);
40 decoder->draw(x, y, w, h, color);
41}
42
43int PngDecoder::prepare(size_t download_size) {
44 ImageDecoder::prepare(download_size);
45 if (!this->pngle_) {
46 ESP_LOGE(TAG, "PNG decoder engine not initialized!");
48 }
49 pngle_set_user_data(this->pngle_, this);
50 pngle_set_init_callback(this->pngle_, init_callback);
51 pngle_set_draw_callback(this->pngle_, draw_callback);
52 return 0;
53}
54
55int HOT PngDecoder::decode(uint8_t *buffer, size_t size) {
56 if (!this->pngle_) {
57 ESP_LOGE(TAG, "PNG decoder engine not initialized!");
59 }
60 if (size < 256 && size < this->download_size_ - this->decoded_bytes_) {
61 ESP_LOGD(TAG, "Waiting for data");
62 return 0;
63 }
64 auto fed = pngle_feed(this->pngle_, buffer, size);
65 if (fed < 0) {
66 ESP_LOGE(TAG, "Error decoding image: %s", pngle_error(this->pngle_));
67 } else {
68 this->decoded_bytes_ += fed;
69 }
70 return fed;
71}
72
73} // namespace online_image
74} // namespace esphome
75
76#endif // USE_ONLINE_IMAGE_PNG_SUPPORT
uint8_t h
Definition bl0906.h:2
virtual int prepare(size_t download_size)
Initialize the decoder.
int HOT decode(uint8_t *buffer, size_t size) override
Definition png_image.cpp:55
int prepare(size_t download_size) override
Definition png_image.cpp:43
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6