diff --git a/examples/virtualdisplay.py b/examples/virtualdisplay.py index 5e16438..be3aed8 100644 --- a/examples/virtualdisplay.py +++ b/examples/virtualdisplay.py @@ -25,6 +25,7 @@ import click import numpy as np +from PIL import ImageEnhance from pyvirtualdisplay.smartdisplay import SmartDisplay import adafruit_blinka_raspberry_pi5_piomatter as piomatter @@ -37,10 +38,12 @@ @click.option("--backend", help="The pyvirtualdisplay backend to use", default="xvfb") @click.option("--extra-args", help="Extra arguments to pass to the backend server", default="") @click.option("--rfbport", help="The port number for the --backend xvnc", default=None, type=int) +@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("--use-xauth/--no-use-xauth", help="If a Xauthority file should be created", default=False) @piomatter_click.standard_options @click.argument("command", nargs=-1) -def main(scale, backend, use_xauth, extra_args, rfbport, width, height, serpentine, rotation, pinout, +def main(scale, backend, use_xauth, extra_args, rfbport, brightness, width, height, serpentine, rotation, pinout, n_planes, n_temporal_planes, n_addr_lines, n_lanes, command): kwargs = {} if backend == "xvnc": @@ -61,8 +64,12 @@ def main(scale, backend, use_xauth, extra_args, rfbport, width, height, serpenti with SmartDisplay(backend=backend, use_xauth=use_xauth, size=(round(width*scale),round(height*scale)), manage_global_env=False, **kwargs) as disp, Popen(command, env=disp.env()) as proc: while proc.poll() is None: img = disp.grab(autocrop=False) + if img is None: continue + if brightness != 1.0: + darkener = ImageEnhance.Brightness(img) + img = darkener.enhance(brightness) img = img.resize((width, height)) framebuffer[:, :] = np.array(img) matrix.show() diff --git a/examples/xdisplay_mirror.py b/examples/xdisplay_mirror.py index 45a4f84..f251639 100644 --- a/examples/xdisplay_mirror.py +++ b/examples/xdisplay_mirror.py @@ -20,7 +20,7 @@ import click import numpy as np -from PIL import ImageGrab +from PIL import ImageEnhance, ImageGrab import adafruit_blinka_raspberry_pi5_piomatter as piomatter import adafruit_blinka_raspberry_pi5_piomatter.click as piomatter_click @@ -31,9 +31,11 @@ @click.option("--mirror-region", help="Region of X display to mirror. Comma seperated x,y,w,h. " "Default will mirror entire display.", default="") @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)) @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): + n_temporal_planes, n_addr_lines, n_lanes, mirror_region, x_display, 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, @@ -59,6 +61,9 @@ def main(width, height, serpentine, rotation, pinout, n_planes, img = img.crop((mirror_region[0], mirror_region[1], # left,top mirror_region[0] + mirror_region[2], # right mirror_region[1] + mirror_region[3])) # bottom + if brightness != 1.0: + darkener = ImageEnhance.Brightness(img) + img = darkener.enhance(brightness) img = img.resize((width, height)) framebuffer[:, :] = np.array(img)