diff --git a/esphome/components/online_image/__init__.py b/esphome/components/online_image/__init__.py index de534f3b05..be3a7ef664 100644 --- a/esphome/components/online_image/__init__.py +++ b/esphome/components/online_image/__init__.py @@ -71,6 +71,7 @@ class JPEGFormat(Format): cg.add_define("USE_ONLINE_IMAGE_JPEG_SUPPORT") cg.add_library("JPEGDEC", None, "https://github.com/bitbank2/JPEGDEC#ca1e0f2") + class WEBPFormat(Format): def __init__(self): super().__init__("WEBP") @@ -79,6 +80,7 @@ class WEBPFormat(Format): cg.add_define("USE_ONLINE_IMAGE_WEBP_SUPPORT") cg.add_library("libwebp", None, "https://github.com/acvigue/libwebp#26b0c4b") + class PNGFormat(Format): def __init__(self): super().__init__("PNG") @@ -99,7 +101,9 @@ IMAGE_FORMATS = { } IMAGE_FORMATS.update({"JPG": IMAGE_FORMATS["JPEG"]}) -OnlineImage = online_image_ns.class_("OnlineImage", cg.PollingComponent, Image_, Animation_) +OnlineImage = online_image_ns.class_( + "OnlineImage", cg.PollingComponent, Image_, Animation_ +) # Actions SetUrlAction = online_image_ns.class_( diff --git a/esphome/components/online_image/online_image.cpp b/esphome/components/online_image/online_image.cpp index 5d2b3bfc79..68e171bae2 100644 --- a/esphome/components/online_image/online_image.cpp +++ b/esphome/components/online_image/online_image.cpp @@ -267,7 +267,8 @@ void OnlineImage::draw_pixel_(int x, int y, Color color, int frame) { ESP_LOGE(TAG, "Buffer not allocated!"); return; } - if (x < 0 || y < 0 || frame < 0 || x >= this->buffer_width_ || y >= this->buffer_height_ || frame >= this->animation_frame_count_) { + if (x < 0 || y < 0 || frame < 0 || x >= this->buffer_width_ || y >= this->buffer_height_ || + frame >= this->animation_frame_count_) { ESP_LOGE(TAG, "Tried to paint a pixel (%d,%d,%d) outside the image!", x, y, frame); return; } diff --git a/esphome/components/online_image/online_image.h b/esphome/components/online_image/online_image.h index 4322a4b73c..2ae7e91093 100644 --- a/esphome/components/online_image/online_image.h +++ b/esphome/components/online_image/online_image.h @@ -97,8 +97,12 @@ class OnlineImage : public PollingComponent, RAMAllocator allocator_{}; - uint32_t get_buffer_size_() const { return get_buffer_size_(this->buffer_width_, this->buffer_height_, this->animation_frame_count_); } - int get_buffer_size_(int width, int height, int frames) const { return frames * ((this->get_bpp() * width + 7u) / 8u * height); } + uint32_t get_buffer_size_() const { + return get_buffer_size_(this->buffer_width_, this->buffer_height_, this->animation_frame_count_); + } + int get_buffer_size_(int width, int height, int frames) const { + return frames * ((this->get_bpp() * width + 7u) / 8u * height); + } int get_position_(int x, int y, int frame = 0) const { int frame_offset = this->buffer_frame_size_ * frame; diff --git a/esphome/components/online_image/webp_image.cpp b/esphome/components/online_image/webp_image.cpp index af8e499f84..6ef6fb6af2 100644 --- a/esphome/components/online_image/webp_image.cpp +++ b/esphome/components/online_image/webp_image.cpp @@ -81,10 +81,11 @@ int HOT WebpDecoder::decode(uint8_t *buffer, size_t size) { return DECODE_ERROR_UNSUPPORTED_FORMAT; } - ESP_LOGD(TAG, "WebPAnimDecode size: (%dx%d), loops: %d, frames: %d, bgcolor: #%X", animation_.canvas_width, animation_.canvas_height, animation_.loop_count, animation_.frame_count, animation_.bgcolor); + ESP_LOGD(TAG, "WebPAnimDecode size: (%dx%d), loops: %d, frames: %d, bgcolor: #%X", animation_.canvas_width, + animation_.canvas_height, animation_.loop_count, animation_.frame_count, animation_.bgcolor); if (!this->set_size(animation_.canvas_width, animation_.canvas_height, animation_.frame_count)) { - ESP_LOGE(TAG,"could not allocate enough memory"); + ESP_LOGE(TAG, "could not allocate enough memory"); WebPAnimDecoderDelete(this->decoder_); this->decoder_ = NULL; return DECODE_ERROR_OUT_OF_MEMORY; @@ -102,7 +103,7 @@ int HOT WebpDecoder::decode(uint8_t *buffer, size_t size) { uint8_t *pix; int timestamp; if (!WebPAnimDecoderGetNext(this->decoder_, &pix, ×tamp)) { - ESP_LOGE(TAG,"error parsing webp frame %u/%u", frame, animation_.frame_count); + ESP_LOGE(TAG, "error parsing webp frame %u/%u", frame, animation_.frame_count); WebPAnimDecoderDelete(this->decoder_); this->decoder_ = NULL; return DECODE_ERROR_UNSUPPORTED_FORMAT;