diff --git a/esphome/components/image/__init__.py b/esphome/components/image/__init__.py index dfe387afd190..3558d9660e11 100644 --- a/esphome/components/image/__init__.py +++ b/esphome/components/image/__init__.py @@ -4,14 +4,14 @@ from esphome.components import display, font import esphome.config_validation as cv import esphome.codegen as cg -from esphome.const import CONF_FILE, CONF_ID, CONF_TYPE, CONF_RESIZE +from esphome.const import CONF_FILE, CONF_ID, CONF_TYPE, CONF_RESIZE, CONF_DITHER from esphome.core import CORE, HexInt + _LOGGER = logging.getLogger(__name__) DEPENDENCIES = ['display'] MULTI_CONF = True - ImageType = display.display_ns.enum('ImageType') IMAGE_TYPE = { 'BINARY': ImageType.IMAGE_TYPE_BINARY, @@ -28,6 +28,7 @@ cv.Required(CONF_FILE): cv.file_, cv.Optional(CONF_RESIZE): cv.dimensions, cv.Optional(CONF_TYPE, default='BINARY'): cv.enum(IMAGE_TYPE, upper=True), + cv.Optional(CONF_DITHER, default='NONE'): cv.one_of("NONE", "FLOYDSTEINBERG", upper=True), cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_id(cg.uint8), }) @@ -53,8 +54,9 @@ def to_code(config): _LOGGER.warning("The image you requested is very big. Please consider using" " the resize parameter.") + dither = Image.NONE if config[CONF_DITHER] == 'NONE' else Image.FLOYDSTEINBERG if config[CONF_TYPE] == 'GRAYSCALE': - image = image.convert('L', dither=Image.NONE) + image = image.convert('L', dither=dither) pixels = list(image.getdata()) data = [0 for _ in range(height * width)] pos = 0 @@ -76,7 +78,7 @@ def to_code(config): pos += 1 elif config[CONF_TYPE] == 'BINARY': - image = image.convert('1', dither=Image.NONE) + image = image.convert('1', dither=dither) width8 = ((width + 7) // 8) * 8 data = [0 for _ in range(height * width8 // 8)] for y in range(height): diff --git a/esphome/const.py b/esphome/const.py index e42da2e178ef..764d5c72bdad 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -159,6 +159,7 @@ CONF_DISCOVERY_PREFIX = 'discovery_prefix' CONF_DISCOVERY_RETAIN = 'discovery_retain' CONF_DISTANCE = 'distance' +CONF_DITHER = 'dither' CONF_DIV_RATIO = 'div_ratio' CONF_DNS1 = 'dns1' CONF_DNS2 = 'dns2'