Open Wuestengecko opened 5 months ago
When drawing a GRAYSCALE image on an ssd1327_i2c display, a white rectangle appears instead.
ssd1327_i2c
2024.5.5
pip
No response
ESP32-IDF
image: - file: ota-download.48.png id: img_ota_download_48 type: GRAYSCALE display: # {{{2 id: my_display platform: ssd1327_i2c model: "SSD1327 128x128" address: 0x3C reset_pin: $pin_disp_reset brightness: 1.0 update_interval: 5s pages: - id: ota_page lambda: |- it.image(40, 24, id(img_ota_download_48)); it.print(64, 24+48+8, id(font_small), TextAlign::TOP_CENTER, "Downloading");
The issue is that an Image in GRAYSCALE mode treats the "white" component as one-bit alpha channel, while ColorUtil::color_to_grayscale4, which ssd1327_base uses in draw_absolute_pixel_internal, instead treats it as the brightness value:
Image
GRAYSCALE
ColorUtil::color_to_grayscale4
draw_absolute_pixel_internal
Color Image::get_grayscale_pixel_(int x, int y) const { const uint32_t pos = (x + y * this->width_); const uint8_t gray = progmem_read_byte(this->data_start_ + pos); uint8_t alpha = (gray == 1 && transparent_) ? 0 : 0xFF; return Color(gray, gray, gray, alpha); } class ColorUtil { static uint32_t color_to_grayscale4(Color color) { uint32_t gs4 = esp_scale8(color.white, 15); return gs4; } };
As a workaround / quick fix, changing get_grayscale_pixel to pass gray again instead of alpha makes the images render correctly.
get_grayscale_pixel
gray
alpha
(Another workaround is to only use BINARY images, which work fine.)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The problem
When drawing a GRAYSCALE image on an
ssd1327_i2c
display, a white rectangle appears instead.Which version of ESPHome has the issue?
2024.5.5
What type of installation are you using?
pip
Which version of Home Assistant has the issue?
No response
What platform are you using?
ESP32-IDF
Board
No response
Component causing the issue
ssd1327_i2c
Example YAML snippet
Anything in the logs that might be useful for us?
No response
Additional information
The issue is that an
Image
inGRAYSCALE
mode treats the "white" component as one-bit alpha channel, whileColorUtil::color_to_grayscale4
, which ssd1327_base uses indraw_absolute_pixel_internal
, instead treats it as the brightness value:As a workaround / quick fix, changing
get_grayscale_pixel
to passgray
again instead ofalpha
makes the images render correctly.(Another workaround is to only use BINARY images, which work fine.)