16template<
bool ROWS_OUTER,
typename F>
17static void for_each_pixel(
int x_start,
int x_end,
int y_start,
int y_end,
int width, F &&f) {
18 const int outer_start = ROWS_OUTER ? y_start : x_start;
19 const int outer_end = ROWS_OUTER ? y_end : x_end;
20 const int inner_start = ROWS_OUTER ? x_start : y_start;
21 const int inner_end = ROWS_OUTER ? x_end : y_end;
22 for (
int outer = outer_start; outer < outer_end; outer++) {
23 const int outer_pos = ROWS_OUTER ? outer * width : outer;
24 for (
int inner = inner_start; inner < inner_end; inner++) {
25 f(ROWS_OUTER ? inner : outer, ROWS_OUTER ? outer : inner,
26 ROWS_OUTER ? outer_pos + inner : outer_pos + inner * width);
38 if (clipping.is_set()) {
40 x_start += clipping.x -
x;
42 y_start += clipping.y -
y;
43 if (x_end > clipping.x2() -
x)
44 x_end = clipping.x2() -
x;
45 if (y_end > clipping.y2() -
y)
46 y_end = clipping.y2() -
y;
55 x_start = std::max(x_start, -
x);
56 y_start = std::max(y_start, -
y);
57 x_end = std::min(x_end, display->
get_width() -
x);
59 if (x_end <= x_start || y_end <= y_start)
64 x_start, y_start, this->
width_ - x_end);
73 this->
draw_<false>(x,
y, display, color_on, color_off, x_start, x_end, y_start, y_end);
78 this->
draw_<true>(x,
y, display, color_on, color_off, x_start, x_end, y_start, y_end);
81template<
bool ROWS_OUTER>
83 int y_start,
int y_end) {
86 const int width = this->
width_;
87 switch (this->
type_) {
89 for_each_pixel<ROWS_OUTER>(x_start, x_end, y_start, y_end, width,
90 [&](
int img_x,
int img_y,
int pos) ESPHOME_ALWAYS_INLINE {
99 for_each_pixel<ROWS_OUTER>(x_start, x_end, y_start, y_end, width,
100 [&](
int img_x,
int img_y,
int pos) ESPHOME_ALWAYS_INLINE {
102 if (color.w >= 0x80) {
109 for_each_pixel<ROWS_OUTER>(x_start, x_end, y_start, y_end, width,
110 [&](
int img_x,
int img_y,
int pos) ESPHOME_ALWAYS_INLINE {
128 for_each_pixel<ROWS_OUTER>(x_start, x_end, y_start, y_end, width,
129 [&](
int img_x,
int img_y,
int pos) ESPHOME_ALWAYS_INLINE {
131 if (color.w >= 0x80) {
137 for_each_pixel<ROWS_OUTER>(x_start, x_end, y_start, y_end, width,
138 [&](
int img_x,
int img_y,
int pos) ESPHOME_ALWAYS_INLINE {
140 if (color.w >= 0x80) {
150 switch (this->
type_) {
171 static constexpr uint8_t TRANSPARENT_PIXEL = 0;
173 if (this->
dsc_.data != &TRANSPARENT_PIXEL) {
174 memset(&this->
dsc_, 0,
sizeof(this->
dsc_));
175 this->
dsc_.header.cf = LV_COLOR_FORMAT_A8;
176 this->
dsc_.header.w = 1;
177 this->
dsc_.header.h = 1;
178 this->
dsc_.header.stride = 1;
179 this->
dsc_.data_size = 1;
180 this->
dsc_.data = &TRANSPARENT_PIXEL;
185 if (this->
dsc_.data != this->data_start_) {
187 this->
dsc_.header.reserved_2 = 0;
194 this->
dsc_.header.cf = LV_COLOR_FORMAT_A1;
198 this->
dsc_.header.cf = LV_COLOR_FORMAT_A8;
203 ESP_LOGE(TAG,
"RGB111 images are not supported in LVGL.");
208 this->
dsc_.header.cf = LV_COLOR_FORMAT_ARGB8888;
212 this->
dsc_.header.cf = LV_COLOR_FORMAT_RGB888;
220 this->
dsc_.header.cf = LV_COLOR_FORMAT_RGB565A8;
223 this->
dsc_.header.cf = LV_COLOR_FORMAT_RGB565;
239 const uint8_t *
byte = this->
data_start_ + bitpos / 8;
240 const uint8_t shift = bitpos % 8;
243 if (shift + this->bpp_ > 8)
245 const uint8_t bits = (window >> (16 - this->bpp_ - shift)) & ((1u << this->bpp_) - 1);
246 const uint8_t rgb = this->bpp_ == 4 ? bits >> 1 : bits;
247 const bool opaque = this->bpp_ == 3 || (bits & 1);
248 return Color(rgb & 4 ? 0xFF : 0x00, rgb & 2 ? 0xFF : 0x00, rgb & 1 ? 0xFF : 0x00, opaque ? 0xFF : 0x00);
257 if (color.
g == 1 && color.
r == 0 && color.
b == 0) {
275 auto r = (rgb565 & 0xF800) >> 11;
276 auto g = (rgb565 & 0x07E0) >> 5;
277 auto b = rgb565 & 0x001F;
284 if (rgb565 == 0x0020)
290 return Color((r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2), a);
299 return Color(0, 0, 0, 0);
300 return Color(gray, gray, gray, 0xFF);
302 return Color(0, 0, 0, gray);
304 return Color(gray, gray, gray, 0xFF);
315 data_start_(data_start),
316 transparency_(transparency),
317 big_endian_(big_endian) {
318 switch (this->
type_) {
virtual bool pixel_axes_swapped() const
True when draw_pixel_at() swaps x and y before writing, so pixels that are neighbours along x land a ...
virtual int get_height()
Get the calculated height of the display in pixels with rotation applied.
virtual int get_width()
Get the calculated width of the display in pixels with rotation applied.
void draw_pixel_at(int x, int y)
Set a single pixel at the specified coordinates to default color.
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Given an array of pixels encoded in the nominated format, draw these into the display's buffer.
Rect get_clipping() const
Get the current the clipping rectangle.
Color get_rgb565_pixel_(int x, int y) const
const uint8_t * data_start_
Color get_rgb_pixel_(int x, int y) const
size_t get_width_stride() const
Return the stride of the image in bytes, that is, the distance in bytes between two consecutive rows ...
Color get_pixel(int x, int y, Color color_on=display::COLOR_ON, Color color_off=display::COLOR_OFF) const
int get_height() const override
ImageType get_type() const
bool get_binary_pixel_(int x, int y) const
Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency, bool big_endian=false)
big_endian is the RGB565 byte order; codegen writes little endian unless configured otherwise.
void draw_(int x, int y, display::Display *display, Color color_on, Color color_off, int x_start, int x_end, int y_start, int y_end)
Per-pixel draw of the clipped range, rows (true) or columns (false) outer.
Transparency transparency_
Color get_rgb111_pixel_(int x, int y) const
virtual lv_image_dsc_t * get_lv_image_dsc()
void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override
int get_width() const override
Color get_grayscale_pixel_(int x, int y) const
ESPHOME_LOG_TAG(TAG, "image")
@ TRANSPARENCY_ALPHA_CHANNEL
@ TRANSPARENCY_CHROMA_KEY
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
uint8_t progmem_read_byte(const uint8_t *addr)
static uint8_t blend_channel(uint8_t from, uint8_t to, uint8_t amnt) ESPHOME_ALWAYS_INLINE
One channel of gradient(): from at amnt 0 to to at amnt 255.