ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
jpeg_decoder.h
Go to the documentation of this file.
1#pragma once
2#include "image_decoder.h"
3#include "runtime_image.h"
6#ifdef USE_RUNTIME_IMAGE_JPEG
7#include <JPEGDEC.h>
8
10
14class JpegDecoder : public ImageDecoder {
15 public:
22
23 int prepare(size_t expected_size) override;
24 int HOT decode(uint8_t *buffer, size_t size) override;
25 void reset() override;
26
28 bool supports_source() const override { return true; }
29 int begin_source(DecodeSource *source) override;
32 int HOT decode_step() override;
33
35 int get_scale() const { return this->scale_; }
36 void draw_rgb565(int x, int y, int w, int h, const uint8_t *pixels);
37
38 protected:
40 int start_();
42 int scale_option_() const { return this->scale_ == 1 ? 0 : this->scale_; }
44 int fail_();
45
46 static int32_t source_read(JPEGFILE *file, uint8_t *buf, int32_t len);
47 static int32_t source_seek(JPEGFILE *file, int32_t position);
48 static void source_close(void *handle) {}
49
52 int scale_{1}; // JPEGDEC decodes at 1/scale_ of the image size
53 DecodeSource *source_{nullptr}; // Set while a begin_source() decode is in progress
54 bool source_failed_{false};
55};
56
57} // namespace esphome::runtime_image
58
59#endif // USE_RUNTIME_IMAGE_JPEG
uint8_t h
Definition bl0906.h:2
Input that a decoder reads itself as it goes, so the whole image never has to be in memory at once.
Class to abstract decoding different image formats.
Image decoder specialization for JPEG images.
RAMUniquePtr< JPEGDEC > jpeg_
About 18 KB of decoder state: PSRAM first, nullptr if out of memory.
int prepare(size_t expected_size) override
int begin_source(DecodeSource *source) override
void draw_rgb565(int x, int y, int w, int h, const uint8_t *pixels)
int start_()
Set up an opened image for decoding. Returns 0, or a DecodeError.
static int32_t source_read(JPEGFILE *file, uint8_t *buf, int32_t len)
int scale_option_() const
The JPEGDEC option for scale_: JPEG_SCALE_HALF, _QUARTER and _EIGHTH are the divisors themselves.
JpegDecoder(RuntimeImage *image)
Construct a new JPEG Decoder object.
bool supports_source() const override
The source is read as the decode needs it, through JPEGDEC's own 2 KB buffer.
int fail_()
The DecodeError for a failed read of the source or JPEGDEC's last error, closing the image.
int get_scale() const
JPEGDEC decodes the image at 1/get_scale() of its size: 1, 2, 4 or 8.
int HOT decode(uint8_t *buffer, size_t size) override
int HOT decode_step() override
Decodes one row of MCUs (8 or 16 pixel rows), or waits part way through one for more of the source.
static int32_t source_seek(JPEGFILE *file, int32_t position)
static void source_close(void *handle)
A dynamic image that can be loaded and decoded at runtime.
float position
Definition cover.h:0
uint32_t buffer
Definition gif.cpp:50
std::unique_ptr< T, RAMDeleter< T > > RAMUniquePtr
unique_ptr over RAMAllocator storage
Definition helpers.h:2385
const void size_t len
Definition hal.h:68
uint16_t size
Definition helpers.cpp:34
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6
spi_device_handle_t handle