diff --git a/esphome/components/animation/__init__.py b/esphome/components/animation/__init__.py index 87d72254e8..ce9f057496 100644 --- a/esphome/components/animation/__init__.py +++ b/esphome/components/animation/__init__.py @@ -117,7 +117,7 @@ async def to_code(config): data[pos] = rgb & 255 pos += 1 - elif config[CONF_TYPE] == "BINARY": + elif config[CONF_TYPE] in ["BINARY", "TRANSPARENT_BINARY"]: width8 = ((width + 7) // 8) * 8 data = [0 for _ in range((height * width8 // 8) * frames)] for frameIndex in range(frames): diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index 97c08dae24..cfd73509ea 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -452,7 +452,7 @@ int Font::match_next_glyph(const char *str, int *match_length) { } void Font::measure(const char *str, int *width, int *x_offset, int *baseline, int *height) { *baseline = this->baseline_; - *height = this->bottom_; + *height = this->height_; int i = 0; int min_x = 0; bool has_char = false; @@ -483,7 +483,7 @@ void Font::measure(const char *str, int *width, int *x_offset, int *baseline, in *width = x - min_x; } const std::vector &Font::get_glyphs() const { return this->glyphs_; } -Font::Font(const GlyphData *data, int data_nr, int baseline, int bottom) : baseline_(baseline), bottom_(bottom) { +Font::Font(const GlyphData *data, int data_nr, int baseline, int height) : baseline_(baseline), height_(height) { for (int i = 0; i < data_nr; ++i) glyphs_.emplace_back(data + i); } @@ -527,6 +527,7 @@ int Image::get_height() const { return this->height_; } ImageType Image::get_type() const { return this->type_; } Image::Image(const uint8_t *data_start, int width, int height, ImageType type) : width_(width), height_(height), type_(type), data_start_(data_start) {} +int Image::get_current_frame() const { return 0; } bool Animation::get_pixel(int x, int y) const { if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_) diff --git a/esphome/components/display/display_buffer.h b/esphome/components/display/display_buffer.h index 41052b3ffd..b652989067 100644 --- a/esphome/components/display/display_buffer.h +++ b/esphome/components/display/display_buffer.h @@ -448,18 +448,20 @@ class Font { * @param baseline The y-offset from the top of the text to the baseline. * @param bottom The y-offset from the top of the text to the bottom (i.e. height). */ - Font(const GlyphData *data, int data_nr, int baseline, int bottom); + Font(const GlyphData *data, int data_nr, int baseline, int height); int match_next_glyph(const char *str, int *match_length); void measure(const char *str, int *width, int *x_offset, int *baseline, int *height); + inline int get_baseline() { return this->baseline_; } + inline int get_height() { return this->height_; } const std::vector &get_glyphs() const; protected: std::vector glyphs_; int baseline_; - int bottom_; + int height_; }; class Image { @@ -473,6 +475,8 @@ class Image { int get_height() const; ImageType get_type() const; + virtual int get_current_frame() const; + protected: int width_; int height_; @@ -489,7 +493,7 @@ class Animation : public Image { Color get_grayscale_pixel(int x, int y) const override; int get_animation_frame_count() const; - int get_current_frame() const; + int get_current_frame() const override; void next_frame(); void prev_frame(); diff --git a/esphome/components/image/__init__.py b/esphome/components/image/__init__.py index 0004391f20..88c625961b 100644 --- a/esphome/components/image/__init__.py +++ b/esphome/components/image/__init__.py @@ -26,6 +26,7 @@ IMAGE_TYPE = { "RGB24": ImageType.IMAGE_TYPE_RGB24, "TRANSPARENT_BINARY": ImageType.IMAGE_TYPE_TRANSPARENT_BINARY, "RGB565": ImageType.IMAGE_TYPE_RGB565, + "TRANSPARENT_IMAGE": ImageType.IMAGE_TYPE_TRANSPARENT_BINARY, } Image_ = display.display_ns.class_("Image") @@ -105,7 +106,7 @@ async def to_code(config): data[pos] = rgb & 255 pos += 1 - elif config[CONF_TYPE] == "BINARY": + elif (config[CONF_TYPE] == "BINARY") or (config[CONF_TYPE] == "TRANSPARENT_BINARY"): image = image.convert("1", dither=dither) width8 = ((width + 7) // 8) * 8 data = [0 for _ in range(height * width8 // 8)] @@ -116,7 +117,7 @@ async def to_code(config): pos = x + y * width8 data[pos // 8] |= 0x80 >> (pos % 8) - elif config[CONF_TYPE] == "TRANSPARENT_BINARY": + elif config[CONF_TYPE] == "TRANSPARENT_IMAGE": image = image.convert("RGBA") width8 = ((width + 7) // 8) * 8 data = [0 for _ in range(height * width8 // 8)]