mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
[online_image] Fix some large PNGs causing watchdog timeout (#12025)
Co-authored-by: guillempages <guillempages@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
|
#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
|
||||||
|
|
||||||
#include "esphome/components/display/display_buffer.h"
|
#include "esphome/components/display/display_buffer.h"
|
||||||
|
#include "esphome/core/application.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
@@ -38,6 +39,14 @@ static void draw_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, ui
|
|||||||
PngDecoder *decoder = (PngDecoder *) pngle_get_user_data(pngle);
|
PngDecoder *decoder = (PngDecoder *) pngle_get_user_data(pngle);
|
||||||
Color color(rgba[0], rgba[1], rgba[2], rgba[3]);
|
Color color(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||||
decoder->draw(x, y, w, h, color);
|
decoder->draw(x, y, w, h, color);
|
||||||
|
|
||||||
|
// Feed watchdog periodically to avoid triggering during long decode operations.
|
||||||
|
// Feed every 1024 pixels to balance efficiency and responsiveness.
|
||||||
|
uint32_t pixels = w * h;
|
||||||
|
decoder->increment_pixels_decoded(pixels);
|
||||||
|
if ((decoder->get_pixels_decoded() % 1024) < pixels) {
|
||||||
|
App.feed_wdt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PngDecoder::PngDecoder(OnlineImage *image) : ImageDecoder(image) {
|
PngDecoder::PngDecoder(OnlineImage *image) : ImageDecoder(image) {
|
||||||
|
|||||||
@@ -25,9 +25,13 @@ class PngDecoder : public ImageDecoder {
|
|||||||
int prepare(size_t download_size) override;
|
int prepare(size_t download_size) override;
|
||||||
int HOT decode(uint8_t *buffer, size_t size) override;
|
int HOT decode(uint8_t *buffer, size_t size) override;
|
||||||
|
|
||||||
|
void increment_pixels_decoded(uint32_t count) { this->pixels_decoded_ += count; }
|
||||||
|
uint32_t get_pixels_decoded() const { return this->pixels_decoded_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RAMAllocator<pngle_t> allocator_;
|
RAMAllocator<pngle_t> allocator_;
|
||||||
pngle_t *pngle_;
|
pngle_t *pngle_;
|
||||||
|
uint32_t pixels_decoded_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace online_image
|
} // namespace online_image
|
||||||
|
|||||||
Reference in New Issue
Block a user