esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 35 forks source link

SSD1327: Grayscale images render as all-white rectangles #5918

Open Wuestengecko opened 4 months ago

Wuestengecko commented 4 months ago

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

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");

Anything in the logs that might be useful for us?

No response

Additional information

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:

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.

(Another workaround is to only use BINARY images, which work fine.)

github-actions[bot] commented 1 day ago

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.