ESPHome  2025.2.0
image.h
Go to the documentation of this file.
1 #pragma once
2 #include "esphome/core/color.h"
4 
5 #ifdef USE_LVGL
7 #endif // USE_LVGL
8 
9 namespace esphome {
10 namespace image {
11 
12 enum ImageType {
17 };
18 
23 };
24 
25 class Image : public display::BaseImage {
26  public:
27  Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency);
28  Color get_pixel(int x, int y, Color color_on = display::COLOR_ON, Color color_off = display::COLOR_OFF) const;
29  int get_width() const override;
30  int get_height() const override;
31  const uint8_t *get_data_start() const { return this->data_start_; }
32  ImageType get_type() const;
33 
34  int get_bpp() const { return this->bpp_; }
35 
38  size_t get_width_stride() const { return (this->width_ * this->get_bpp() + 7u) / 8u; }
39  void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override;
40 
41  bool has_transparency() const { return this->transparency_ != TRANSPARENCY_OPAQUE; }
42 
43 #ifdef USE_LVGL
44  lv_img_dsc_t *get_lv_img_dsc();
45 #endif
46  protected:
47  bool get_binary_pixel_(int x, int y) const;
48  Color get_rgb_pixel_(int x, int y) const;
49  Color get_rgb565_pixel_(int x, int y) const;
50  Color get_grayscale_pixel_(int x, int y) const;
51 
52  int width_;
53  int height_;
55  const uint8_t *data_start_;
57  size_t bpp_{};
58  size_t stride_{};
59 #ifdef USE_LVGL
60  lv_img_dsc_t dsc_{};
61 #endif
62 };
63 
64 } // namespace image
65 } // namespace esphome
bool has_transparency() const
Definition: image.h:41
ImageType get_type() const
Definition: image.cpp:212
uint16_t x
Definition: tt21100.cpp:17
const Color COLOR_OFF(0, 0, 0, 0)
Turn the pixel OFF.
Definition: display.h:191
const uint8_t * get_data_start() const
Definition: image.h:31
bool get_binary_pixel_(int x, int y) const
Definition: image.cpp:150
Color get_rgb_pixel_(int x, int y) const
Definition: image.cpp:155
Color get_pixel(int x, int y, Color color_on=display::COLOR_ON, Color color_off=display::COLOR_OFF) const
Definition: image.cpp:71
int get_bpp() const
Definition: image.h:34
Color get_grayscale_pixel_(int x, int y) const
Definition: image.cpp:196
uint16_t y
Definition: tt21100.cpp:18
ImageType type_
Definition: image.h:54
int get_width() const override
Definition: image.cpp:210
size_t get_width_stride() const
Return the stride of the image in bytes, that is, the distance in bytes between two consecutive rows ...
Definition: image.h:38
Color get_rgb565_pixel_(int x, int y) const
Definition: image.cpp:175
uint8_t type
const uint8_t * data_start_
Definition: image.h:55
lv_img_dsc_t * get_lv_img_dsc()
Definition: image.cpp:90
const Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
Definition: display.h:193
Transparency transparency_
Definition: image.h:56
int get_height() const override
Definition: image.cpp:211
void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override
Definition: image.cpp:8
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
lv_img_dsc_t dsc_
Definition: image.h:60
Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency)
Definition: image.cpp:213