ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
esphome::runtime_image::JpegDecoder Class Reference

Image decoder specialization for JPEG images. More...

#include <jpeg_decoder.h>

Inheritance diagram for esphome::runtime_image::JpegDecoder:
esphome::runtime_image::ImageDecoder

Public Member Functions

 JpegDecoder (RuntimeImage *image)
 Construct a new JPEG Decoder object.
 
int prepare (size_t expected_size) override
 
int HOT decode (uint8_t *buffer, size_t size) override
 
void reset () override
 
bool supports_source () const override
 The source is read as the decode needs it, through JPEGDEC's own 2 KB buffer.
 
int begin_source (DecodeSource *source) 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.
 
int get_scale () const
 JPEGDEC decodes the image at 1/get_scale() of its size: 1, 2, 4 or 8.
 
void draw_rgb565 (int x, int y, int w, int h, const uint8_t *pixels)
 
- Public Member Functions inherited from esphome::runtime_image::ImageDecoder
 ImageDecoder (RuntimeImage *image, ImageFormat format)
 Construct a new Image Decoder object.
 
virtual ~ImageDecoder ()=default
 
ImageFormat get_format () const
 Get the image format handled by this decoder.
 
bool is_active () const
 Check if a decoding session is in progress (prepare() called, reset() not yet).
 
bool set_size (int width, int height)
 Request the image to be resized once the actual dimensions are known.
 
void draw (int x, int y, int w, int h, const Color &color)
 Fill a rectangle on the display_buffer using the defined color.
 
size_t get_decoded_bytes () const
 Bytes of the image the decoder has used so far.
 
virtual bool is_finished () const
 Check if the decoder has finished processing.
 
virtual bool knows_end () const
 Whether is_finished() can tell a complete image from a cut-off one.
 
bool uses_direct_rgb565 () const
 The image is opaque RGB565, so draw() writes it straight into the buffer.
 

Protected Member Functions

int start_ ()
 Set up an opened image for decoding. Returns 0, or a DecodeError.
 
int scale_option_ () const
 The JPEGDEC option for scale_: JPEG_SCALE_HALF, _QUARTER and _EIGHTH are the divisors themselves.
 
int fail_ ()
 The DecodeError for a failed read of the source or JPEGDEC's last error, closing the image.
 
- Protected Member Functions inherited from esphome::runtime_image::ImageDecoder
bool resize_image_ (int width, int height)
 Resize the image for a width x height source, without preparing to draw. prepare_draw_() must follow.
 
void prepare_draw_ (int width, int height)
 Draw a source of width x height over the whole buffer from now on.
 
void draw_rgb565_ (int x, int y, int w, int h, uint16_t rgb565)
 Paint a block of source pixels in one color straight into the buffer. Only while uses_direct_rgb565().
 
uint8_t * image_buffer_ () const
 The image's pixel buffer, for decoders that write their output straight into it.
 
bool image_is_big_endian_ () const
 

Static Protected Member Functions

static int32_t source_read (JPEGFILE *file, uint8_t *buf, int32_t len)
 
static int32_t source_seek (JPEGFILE *file, int32_t position)
 
static void source_close (void *handle)
 

Protected Attributes

RAMUniquePtr< JPEGDEC > jpeg_
 About 18 KB of decoder state: PSRAM first, nullptr if out of memory.
 
int scale_ {1}
 
DecodeSource * source_ {nullptr}
 
bool source_failed_ {false}
 
- Protected Attributes inherited from esphome::runtime_image::ImageDecoder
int draw_width_ = 0
 
int draw_height_ = 0
 
FixedVector< uint16_t > x_boundaries_ {}
 
FixedVector< uint16_t > y_boundaries_ {}
 
RuntimeImage * image_
 
size_t expected_size_ = 0
 
size_t decoded_bytes_ = 0
 
const ImageFormat format_
 
bool active_ = false
 
bool size_valid_ = true
 
bool direct_rgb565_ = false
 

Detailed Description

Image decoder specialization for JPEG images.

Definition at line 14 of file jpeg_decoder.h.

Constructor & Destructor Documentation

◆ JpegDecoder()

esphome::runtime_image::JpegDecoder::JpegDecoder ( RuntimeImage * image)

Construct a new JPEG Decoder object.

Parameters
imageThe RuntimeImage to decode the stream into.

Definition at line 101 of file jpeg_decoder.cpp.

Member Function Documentation

◆ begin_source()

int esphome::runtime_image::JpegDecoder::begin_source ( DecodeSource * source)
overridevirtual

Reimplemented from esphome::runtime_image::ImageDecoder.

Definition at line 248 of file jpeg_decoder.cpp.

◆ decode()

int HOT esphome::runtime_image::JpegDecoder::decode ( uint8_t * buffer,
size_t size )
overridevirtual

Implements esphome::runtime_image::ImageDecoder.

Definition at line 117 of file jpeg_decoder.cpp.

◆ decode_step()

int HOT esphome::runtime_image::JpegDecoder::decode_step ( )
overridevirtual

Decodes one row of MCUs (8 or 16 pixel rows), or waits part way through one for more of the source.

A progressive image is decoded one row of one scan per step, and drawn in the steps after its last scan.

Reimplemented from esphome::runtime_image::ImageDecoder.

Definition at line 280 of file jpeg_decoder.cpp.

◆ draw_rgb565()

void esphome::runtime_image::JpegDecoder::draw_rgb565 ( int x,
int y,
int w,
int h,
const uint8_t * pixels )

Definition at line 19 of file jpeg_decoder.cpp.

◆ fail_()

int esphome::runtime_image::JpegDecoder::fail_ ( )
protected

The DecodeError for a failed read of the source or JPEGDEC's last error, closing the image.

Definition at line 193 of file jpeg_decoder.cpp.

◆ get_scale()

int esphome::runtime_image::JpegDecoder::get_scale ( ) const
inline

JPEGDEC decodes the image at 1/get_scale() of its size: 1, 2, 4 or 8.

Definition at line 35 of file jpeg_decoder.h.

◆ prepare()

int esphome::runtime_image::JpegDecoder::prepare ( size_t expected_size)
overridevirtual

Reimplemented from esphome::runtime_image::ImageDecoder.

Definition at line 108 of file jpeg_decoder.cpp.

◆ reset()

void esphome::runtime_image::JpegDecoder::reset ( )
overridevirtual

Reimplemented from esphome::runtime_image::ImageDecoder.

Definition at line 217 of file jpeg_decoder.cpp.

◆ scale_option_()

int esphome::runtime_image::JpegDecoder::scale_option_ ( ) const
inlineprotected

The JPEGDEC option for scale_: JPEG_SCALE_HALF, _QUARTER and _EIGHTH are the divisors themselves.

Definition at line 42 of file jpeg_decoder.h.

◆ source_close()

static void esphome::runtime_image::JpegDecoder::source_close ( void * handle)
inlinestaticprotected

Definition at line 48 of file jpeg_decoder.h.

◆ source_read()

int32_t esphome::runtime_image::JpegDecoder::source_read ( JPEGFILE * file,
uint8_t * buf,
int32_t len )
staticprotected

Definition at line 226 of file jpeg_decoder.cpp.

◆ source_seek()

int32_t esphome::runtime_image::JpegDecoder::source_seek ( JPEGFILE * file,
int32_t position )
staticprotected

Definition at line 238 of file jpeg_decoder.cpp.

◆ start_()

int esphome::runtime_image::JpegDecoder::start_ ( )
protected

Set up an opened image for decoding. Returns 0, or a DecodeError.

Definition at line 152 of file jpeg_decoder.cpp.

◆ supports_source()

bool esphome::runtime_image::JpegDecoder::supports_source ( ) const
inlineoverridevirtual

The source is read as the decode needs it, through JPEGDEC's own 2 KB buffer.

Reimplemented from esphome::runtime_image::ImageDecoder.

Definition at line 28 of file jpeg_decoder.h.

Field Documentation

◆ jpeg_

RAMUniquePtr<JPEGDEC> esphome::runtime_image::JpegDecoder::jpeg_
protected

About 18 KB of decoder state: PSRAM first, nullptr if out of memory.

Definition at line 51 of file jpeg_decoder.h.

◆ scale_

int esphome::runtime_image::JpegDecoder::scale_ {1}
protected

Definition at line 52 of file jpeg_decoder.h.

◆ source_

DecodeSource* esphome::runtime_image::JpegDecoder::source_ {nullptr}
protected

Definition at line 53 of file jpeg_decoder.h.

◆ source_failed_

bool esphome::runtime_image::JpegDecoder::source_failed_ {false}
protected

Definition at line 54 of file jpeg_decoder.h.


The documentation for this class was generated from the following files: