diff --git a/examples/xdisplay_mirror.py b/examples/xdisplay_mirror.py index f251639..1f78c05 100644 --- a/examples/xdisplay_mirror.py +++ b/examples/xdisplay_mirror.py @@ -20,12 +20,19 @@ import click import numpy as np -from PIL import ImageEnhance, ImageGrab +from PIL import Image, ImageEnhance, ImageGrab import adafruit_blinka_raspberry_pi5_piomatter as piomatter import adafruit_blinka_raspberry_pi5_piomatter.click as piomatter_click from adafruit_blinka_raspberry_pi5_piomatter.pixelmappers import simple_multilane_mapper +RESAMPLE_MAP = { + "nearest": Image.NEAREST, + "bilinear": Image.BILINEAR, + "lanczos": Image.LANCZOS, + "bicubic": Image.BICUBIC +} + @click.command @click.option("--mirror-region", help="Region of X display to mirror. Comma seperated x,y,w,h. " @@ -33,9 +40,12 @@ @click.option("--x-display", help="The X display to mirror. Default is :0", default=":0") @click.option("--brightness", help="The brightness factor of the image output to the matrix", default=1.0, type=click.FloatRange(min=0.1, max=1.0)) +@click.option("--resample-method", type=click.Choice(RESAMPLE_MAP), default="nearest", + help="The resample method for PIL to use when resizing the screen image. Default is nearest") @piomatter_click.standard_options(n_lanes=2, n_temporal_planes=0) def main(width, height, serpentine, rotation, pinout, n_planes, - n_temporal_planes, n_addr_lines, n_lanes, mirror_region, x_display, brightness): + n_temporal_planes, n_addr_lines, n_lanes, mirror_region, x_display, resample_method, brightness): + if n_lanes != 2: pixelmap = simple_multilane_mapper(width, height, n_addr_lines, n_lanes) geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, @@ -64,7 +74,7 @@ def main(width, height, serpentine, rotation, pinout, n_planes, if brightness != 1.0: darkener = ImageEnhance.Brightness(img) img = darkener.enhance(brightness) - img = img.resize((width, height)) + img = img.resize((width, height), RESAMPLE_MAP[resample_method]) framebuffer[:, :] = np.array(img) matrix.show()