mirror of
https://github.com/esphome/esphome.git
synced 2025-09-12 00:02:21 +01:00
Support simple transparent pngs for display (#3035)
This commit is contained in:
@@ -24,6 +24,7 @@ IMAGE_TYPE = {
|
||||
"BINARY": ImageType.IMAGE_TYPE_BINARY,
|
||||
"GRAYSCALE": ImageType.IMAGE_TYPE_GRAYSCALE,
|
||||
"RGB24": ImageType.IMAGE_TYPE_RGB24,
|
||||
"TRANSPARENT_BINARY": ImageType.IMAGE_TYPE_TRANSPARENT_BINARY,
|
||||
}
|
||||
|
||||
Image_ = display.display_ns.class_("Image")
|
||||
@@ -99,6 +100,17 @@ async def to_code(config):
|
||||
pos = x + y * width8
|
||||
data[pos // 8] |= 0x80 >> (pos % 8)
|
||||
|
||||
elif config[CONF_TYPE] == "TRANSPARENT_BINARY":
|
||||
image = image.convert("RGBA")
|
||||
width8 = ((width + 7) // 8) * 8
|
||||
data = [0 for _ in range(height * width8 // 8)]
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if not image.getpixel((x, y))[3]:
|
||||
continue
|
||||
pos = x + y * width8
|
||||
data[pos // 8] |= 0x80 >> (pos % 8)
|
||||
|
||||
rhs = [HexInt(x) for x in data]
|
||||
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
||||
cg.new_Pvariable(
|
||||
|
Reference in New Issue
Block a user