2#ifdef USE_RUNTIME_IMAGE_JPEG
11#include "esp_task_wdt.h"
14static const char *
const TAG =
"image_decoder.jpeg";
24static int draw_callback(JPEGDRAW *jpeg) {
25 ImageDecoder *decoder = (ImageDecoder *) jpeg->pUser;
30 if (esp_task_wdt_status(
nullptr) == ESP_OK) {
37 size_t height =
static_cast<size_t>(jpeg->iHeight);
38 size_t width =
static_cast<size_t>(jpeg->iWidth);
39 for (
size_t y = 0;
y < height;
y++) {
40 for (
size_t x = 0;
x < width;
x++) {
43 Color color(rg[1], rg[0], ba[1], ba[0]);
46 ESP_LOGE(TAG,
"Decoder pointer is null!");
49 decoder->draw(jpeg->x +
x, jpeg->y +
y, 1, 1, color);
65 ESP_LOGV(TAG,
"Download not complete. Size: %zu/%zu",
size, this->expected_size_);
72 if (!this->
jpeg_.openRAM(buffer,
size, draw_callback)) {
73 ESP_LOGE(TAG,
"Could not open image for decoding: %d", this->
jpeg_.getLastError());
76 auto jpeg_type = this->
jpeg_.getJPEGType();
77 if (jpeg_type == JPEG_MODE_INVALID) {
78 ESP_LOGE(TAG,
"Unsupported JPEG image");
80 }
else if (jpeg_type == JPEG_MODE_PROGRESSIVE) {
81 ESP_LOGE(TAG,
"Progressive JPEG images not supported");
84 ESP_LOGD(TAG,
"Image size: %d x %d, bpp: %d", this->
jpeg_.getWidth(), this->jpeg_.getHeight(), this->jpeg_.getBpp());
86 this->
jpeg_.setUserPointer(
this);
87 this->
jpeg_.setPixelType(RGB8888);
88 if (!this->
set_size(this->
jpeg_.getWidth(), this->jpeg_.getHeight())) {
91 if (!this->
jpeg_.decode(0, 0, 0)) {
92 ESP_LOGE(TAG,
"Error while decoding.");
void feed_wdt(uint32_t time=0)
bool set_size(int width, int height)
Request the image to be resized once the actual dimensions are known.
virtual int prepare(size_t expected_size)
Initialize the decoder.
int prepare(size_t expected_size) override
int HOT decode(uint8_t *buffer, size_t size) override
@ DECODE_ERROR_OUT_OF_MEMORY
@ DECODE_ERROR_UNSUPPORTED_FORMAT
@ DECODE_ERROR_INVALID_TYPE
constexpr std::array< uint8_t, sizeof(T)> decode_value(T val)
Decode a value into its constituent bytes (from most to least significant).
Application App
Global storage of Application pointer - only one Application can exist.