ESPHome  2025.2.0
Public Member Functions | Protected Attributes
esphome::online_image::ImageDecoder Class Referenceabstract

Class to abstract decoding different image formats. More...

#include <image_decoder.h>

Inheritance diagram for esphome::online_image::ImageDecoder:
esphome::online_image::BmpDecoder esphome::online_image::JpegDecoder esphome::online_image::PngDecoder

Public Member Functions

 ImageDecoder (OnlineImage *image)
 Construct a new Image Decoder object. More...
 
virtual ~ImageDecoder ()=default
 
virtual int prepare (size_t download_size)
 Initialize the decoder. More...
 
virtual int decode (uint8_t *buffer, size_t size)=0
 Decode a part of the image. More...
 
bool set_size (int width, int height)
 Request the image to be resized once the actual dimensions are known. More...
 
void draw (int x, int y, int w, int h, const Color &color)
 Fill a rectangle on the display_buffer using the defined color. More...
 
bool is_finished () const
 

Protected Attributes

OnlineImageimage_
 
size_t download_size_ = 1
 
size_t decoded_bytes_ = 0
 
double x_scale_ = 1.0
 
double y_scale_ = 1.0
 

Detailed Description

Class to abstract decoding different image formats.

Definition at line 18 of file image_decoder.h.

Constructor & Destructor Documentation

◆ ImageDecoder()

esphome::online_image::ImageDecoder::ImageDecoder ( OnlineImage image)
inline

Construct a new Image Decoder object.

Parameters
imageThe image to decode the stream into.

Definition at line 25 of file image_decoder.h.

◆ ~ImageDecoder()

virtual esphome::online_image::ImageDecoder::~ImageDecoder ( )
virtualdefault

Member Function Documentation

◆ decode()

virtual int esphome::online_image::ImageDecoder::decode ( uint8_t *  buffer,
size_t  size 
)
pure virtual

Decode a part of the image.

It will try reading from the buffer. There is no guarantee that the whole available buffer will be read/decoded; the method will return the amount of bytes actually decoded, so that the unread content can be moved to the beginning.

Parameters
bufferThe buffer to read from.
sizeThe maximum amount of bytes that can be read from the buffer.
Returns
int The amount of bytes read. It can be 0 if the buffer does not have enough content to meaningfully decode anything, or negative in case of a decoding error.

Implemented in esphome::online_image::JpegDecoder, esphome::online_image::PngDecoder, and esphome::online_image::BmpDecoder.

◆ draw()

void esphome::online_image::ImageDecoder::draw ( int  x,
int  y,
int  w,
int  h,
const Color color 
)

Fill a rectangle on the display_buffer using the defined color.

Will check the given coordinates for out-of-bounds, and clip the rectangle accordingly. In case of binary displays, the color will be converted to binary as well. Called by the callback functions, to be able to access the parent Image class.

Parameters
xThe left-most coordinate of the rectangle.
yThe top-most coordinate of the rectangle.
wThe width of the rectangle.
hThe height of the rectangle.
colorThe fill color

Definition at line 18 of file image_decoder.cpp.

◆ is_finished()

bool esphome::online_image::ImageDecoder::is_finished ( ) const
inline

Definition at line 76 of file image_decoder.h.

◆ prepare()

virtual int esphome::online_image::ImageDecoder::prepare ( size_t  download_size)
inlinevirtual

Initialize the decoder.

Parameters
download_sizeThe total number of bytes that need to be downloaded for the image.
Returns
int Returns 0 on success, a {
See also
DecodeError} value in case of an error.

Reimplemented in esphome::online_image::JpegDecoder, and esphome::online_image::PngDecoder.

Definition at line 34 of file image_decoder.h.

◆ set_size()

bool esphome::online_image::ImageDecoder::set_size ( int  width,
int  height 
)

Request the image to be resized once the actual dimensions are known.

Called by the callback functions, to be able to access the parent Image class.

Parameters
widthThe image's width.
heightThe image's height.
Returns
true if the image was resized, false otherwise.

Definition at line 11 of file image_decoder.cpp.

Field Documentation

◆ decoded_bytes_

size_t esphome::online_image::ImageDecoder::decoded_bytes_ = 0
protected

Definition at line 83 of file image_decoder.h.

◆ download_size_

size_t esphome::online_image::ImageDecoder::download_size_ = 1
protected

Definition at line 82 of file image_decoder.h.

◆ image_

OnlineImage* esphome::online_image::ImageDecoder::image_
protected

Definition at line 79 of file image_decoder.h.

◆ x_scale_

double esphome::online_image::ImageDecoder::x_scale_ = 1.0
protected

Definition at line 84 of file image_decoder.h.

◆ y_scale_

double esphome::online_image::ImageDecoder::y_scale_ = 1.0
protected

Definition at line 85 of file image_decoder.h.


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