[online_image] Allocate pngle manually to potentially use psram

This commit is contained in:
Jesse Hills 2025-03-03 07:47:09 +13:00
parent 23687b2afd
commit 2d76b153bf
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
2 changed files with 23 additions and 3 deletions

View File

@ -40,6 +40,24 @@ static void draw_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, ui
decoder->draw(x, y, w, h, color);
}
PngDecoder::PngDecoder(OnlineImage *image) : ImageDecoder(image) {
{
pngle_t *pngle = this->allocator_.allocate(1);
if (!pngle) {
ESP_LOGE(TAG, "Failed to allocate memory for PNGLE engine!");
return;
}
this->pngle_ = pngle;
}
}
PngDecoder::~PngDecoder() {
if (this->pngle_) {
pngle_reset(this->pngle_);
this->allocator_.deallocate(this->pngle_, 1);
}
}
int PngDecoder::prepare(size_t download_size) {
ImageDecoder::prepare(download_size);
if (!this->pngle_) {

View File

@ -1,7 +1,8 @@
#pragma once
#include "image_decoder.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "image_decoder.h"
#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
#include <pngle.h>
@ -18,13 +19,14 @@ class PngDecoder : public ImageDecoder {
*
* @param display The image to decode the stream into.
*/
PngDecoder(OnlineImage *image) : ImageDecoder(image), pngle_(pngle_new()) {}
~PngDecoder() override { pngle_destroy(this->pngle_); }
PngDecoder(OnlineImage *image);
~PngDecoder() override;
int prepare(size_t download_size) override;
int HOT decode(uint8_t *buffer, size_t size) override;
protected:
RAMAllocator<pngle_t> allocator_;
pngle_t *pngle_;
};