mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 14:16:40 +00:00
[online_image] Allocate pngle manually to potentially use psram (#8354)
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
parent
a5f85b4437
commit
5c54f75b7a
@ -75,7 +75,7 @@ class PNGFormat(Format):
|
||||
|
||||
def actions(self):
|
||||
cg.add_define("USE_ONLINE_IMAGE_PNG_SUPPORT")
|
||||
cg.add_library("pngle", "1.0.2")
|
||||
cg.add_library("pngle", "1.1.0")
|
||||
|
||||
|
||||
IMAGE_FORMATS = {
|
||||
|
@ -34,12 +34,32 @@ static void init_callback(pngle_t *pngle, uint32_t w, uint32_t h) {
|
||||
* @param h The height of the rectangle to draw.
|
||||
* @param rgba The color to paint the rectangle in.
|
||||
*/
|
||||
static void draw_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t rgba[4]) {
|
||||
static void draw_callback(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint8_t rgba[4]) {
|
||||
PngDecoder *decoder = (PngDecoder *) pngle_get_user_data(pngle);
|
||||
Color color(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
decoder->draw(x, y, w, h, color);
|
||||
}
|
||||
|
||||
PngDecoder::PngDecoder(OnlineImage *image) : ImageDecoder(image) {
|
||||
{
|
||||
pngle_t *pngle = this->allocator_.allocate(1, PNGLE_T_SIZE);
|
||||
if (!pngle) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for PNGLE engine!");
|
||||
return;
|
||||
}
|
||||
memset(pngle, 0, PNGLE_T_SIZE);
|
||||
pngle_reset(pngle);
|
||||
this->pngle_ = pngle;
|
||||
}
|
||||
}
|
||||
|
||||
PngDecoder::~PngDecoder() {
|
||||
if (this->pngle_) {
|
||||
pngle_reset(this->pngle_);
|
||||
this->allocator_.deallocate(this->pngle_, PNGLE_T_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
int PngDecoder::prepare(size_t download_size) {
|
||||
ImageDecoder::prepare(download_size);
|
||||
if (!this->pngle_) {
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
|
@ -40,7 +40,7 @@ lib_deps =
|
||||
wjtje/qr-code-generator-library@1.7.0 ; qr_code
|
||||
functionpointer/arduino-MLX90393@1.0.2 ; mlx90393
|
||||
pavlodn/HaierProtocol@0.9.31 ; haier
|
||||
kikuchan98/pngle@1.0.2 ; online_image
|
||||
kikuchan98/pngle@1.1.0 ; online_image
|
||||
; Using the repository directly, otherwise ESP-IDF can't use the library
|
||||
https://github.com/bitbank2/JPEGDEC.git#ca1e0f2 ; online_image
|
||||
; This is using the repository until a new release is published to PlatformIO
|
||||
|
Loading…
x
Reference in New Issue
Block a user