ESPHome  2024.5.0
image.h
Go to the documentation of this file.
1 #pragma once
2 #include "esphome/core/color.h"
4 
5 namespace esphome {
6 namespace image {
7 
8 enum ImageType {
14 };
15 
17  switch (type) {
18  case IMAGE_TYPE_BINARY:
19  return 1;
21  return 8;
22  case IMAGE_TYPE_RGB565:
23  return 16;
24  case IMAGE_TYPE_RGB24:
25  return 24;
26  case IMAGE_TYPE_RGBA:
27  return 32;
28  }
29  return 0;
30 }
31 
32 inline int image_type_to_width_stride(int width, ImageType type) { return (width * image_type_to_bpp(type) + 7u) / 8u; }
33 
34 class Image : public display::BaseImage {
35  public:
36  Image(const uint8_t *data_start, int width, int height, ImageType type);
37  Color get_pixel(int x, int y, Color color_on = display::COLOR_ON, Color color_off = display::COLOR_OFF) const;
38  int get_width() const override;
39  int get_height() const override;
40  const uint8_t *get_data_start() { return this->data_start_; }
41  ImageType get_type() const;
42 
43  void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override;
44 
45  void set_transparency(bool transparent) { transparent_ = transparent; }
46  bool has_transparency() const { return transparent_; }
47 
48  protected:
49  bool get_binary_pixel_(int x, int y) const;
50  Color get_rgb24_pixel_(int x, int y) const;
51  Color get_rgba_pixel_(int x, int y) const;
52  Color get_rgb565_pixel_(int x, int y) const;
53  Color get_grayscale_pixel_(int x, int y) const;
54 
55  int width_;
56  int height_;
58  const uint8_t *data_start_;
60 };
61 
62 } // namespace image
63 } // namespace esphome
bool has_transparency() const
Definition: image.h:46
int image_type_to_width_stride(int width, ImageType type)
Definition: image.h:32
ImageType get_type() const
Definition: image.cpp:129
Color get_rgb24_pixel_(int x, int y) const
Definition: image.cpp:92
uint16_t x
Definition: tt21100.cpp:17
const Color COLOR_OFF(0, 0, 0, 0)
Turn the pixel OFF.
Definition: display.h:190
bool get_binary_pixel_(int x, int y) const
Definition: image.cpp:82
Color get_pixel(int x, int y, Color color_on=display::COLOR_ON, Color color_off=display::COLOR_OFF) const
Definition: image.cpp:64
Color get_grayscale_pixel_(int x, int y) const
Definition: image.cpp:121
uint16_t y
Definition: tt21100.cpp:18
ImageType type_
Definition: image.h:57
int get_width() const override
Definition: image.cpp:127
void set_transparency(bool transparent)
Definition: image.h:45
const uint8_t * get_data_start()
Definition: image.h:40
Color get_rgb565_pixel_(int x, int y) const
Definition: image.cpp:105
uint8_t type
int image_type_to_bpp(ImageType type)
Definition: image.h:16
const uint8_t * data_start_
Definition: image.h:58
const Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
Definition: display.h:192
int get_height() const override
Definition: image.cpp:128
void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override
Definition: image.cpp:8
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
Image(const uint8_t *data_start, int width, int height, ImageType type)
Definition: image.cpp:130
Color get_rgba_pixel_(int x, int y) const
Definition: image.cpp:87