1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 07:08:20 +00:00

fmt fixes

This commit is contained in:
Ian Foster 2025-02-19 21:14:12 -08:00
parent c5fcbb9404
commit 68b4c16fd4
4 changed files with 17 additions and 7 deletions

View File

@ -71,6 +71,7 @@ class JPEGFormat(Format):
cg.add_define("USE_ONLINE_IMAGE_JPEG_SUPPORT") cg.add_define("USE_ONLINE_IMAGE_JPEG_SUPPORT")
cg.add_library("JPEGDEC", None, "https://github.com/bitbank2/JPEGDEC#ca1e0f2") cg.add_library("JPEGDEC", None, "https://github.com/bitbank2/JPEGDEC#ca1e0f2")
class WEBPFormat(Format): class WEBPFormat(Format):
def __init__(self): def __init__(self):
super().__init__("WEBP") super().__init__("WEBP")
@ -79,6 +80,7 @@ class WEBPFormat(Format):
cg.add_define("USE_ONLINE_IMAGE_WEBP_SUPPORT") cg.add_define("USE_ONLINE_IMAGE_WEBP_SUPPORT")
cg.add_library("libwebp", None, "https://github.com/acvigue/libwebp#26b0c4b") cg.add_library("libwebp", None, "https://github.com/acvigue/libwebp#26b0c4b")
class PNGFormat(Format): class PNGFormat(Format):
def __init__(self): def __init__(self):
super().__init__("PNG") super().__init__("PNG")
@ -99,7 +101,9 @@ IMAGE_FORMATS = {
} }
IMAGE_FORMATS.update({"JPG": IMAGE_FORMATS["JPEG"]}) 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 # Actions
SetUrlAction = online_image_ns.class_( SetUrlAction = online_image_ns.class_(

View File

@ -267,7 +267,8 @@ void OnlineImage::draw_pixel_(int x, int y, Color color, int frame) {
ESP_LOGE(TAG, "Buffer not allocated!"); ESP_LOGE(TAG, "Buffer not allocated!");
return; 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); ESP_LOGE(TAG, "Tried to paint a pixel (%d,%d,%d) outside the image!", x, y, frame);
return; return;
} }

View File

@ -97,8 +97,12 @@ class OnlineImage : public PollingComponent,
RAMAllocator<uint8_t> allocator_{}; RAMAllocator<uint8_t> allocator_{};
uint32_t get_buffer_size_() const { return get_buffer_size_(this->buffer_width_, this->buffer_height_, this->animation_frame_count_); } uint32_t get_buffer_size_() const {
int get_buffer_size_(int width, int height, int frames) const { return frames * ((this->get_bpp() * width + 7u) / 8u * height); } 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 get_position_(int x, int y, int frame = 0) const {
int frame_offset = this->buffer_frame_size_ * frame; int frame_offset = this->buffer_frame_size_ * frame;

View File

@ -81,10 +81,11 @@ int HOT WebpDecoder::decode(uint8_t *buffer, size_t size) {
return DECODE_ERROR_UNSUPPORTED_FORMAT; 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)) { 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_); WebPAnimDecoderDelete(this->decoder_);
this->decoder_ = NULL; this->decoder_ = NULL;
return DECODE_ERROR_OUT_OF_MEMORY; return DECODE_ERROR_OUT_OF_MEMORY;
@ -102,7 +103,7 @@ int HOT WebpDecoder::decode(uint8_t *buffer, size_t size) {
uint8_t *pix; uint8_t *pix;
int timestamp; int timestamp;
if (!WebPAnimDecoderGetNext(this->decoder_, &pix, &timestamp)) { if (!WebPAnimDecoderGetNext(this->decoder_, &pix, &timestamp)) {
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_); WebPAnimDecoderDelete(this->decoder_);
this->decoder_ = NULL; this->decoder_ = NULL;
return DECODE_ERROR_UNSUPPORTED_FORMAT; return DECODE_ERROR_UNSUPPORTED_FORMAT;