Skip to content

Commit 9465e13

Browse files
committed
add brightness argument to virtualdisplay and xdisplay_mirror
1 parent 0a9e578 commit 9465e13

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

examples/virtualdisplay.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import click
2727
import numpy as np
28+
from PIL import ImageEnhance
2829
from pyvirtualdisplay.smartdisplay import SmartDisplay
2930

3031
import adafruit_blinka_raspberry_pi5_piomatter as piomatter
@@ -37,10 +38,12 @@
3738
@click.option("--backend", help="The pyvirtualdisplay backend to use", default="xvfb")
3839
@click.option("--extra-args", help="Extra arguments to pass to the backend server", default="")
3940
@click.option("--rfbport", help="The port number for the --backend xvnc", default=None, type=int)
41+
@click.option("--brightness", help="The brightness factor of the image output to the matrix",
42+
default=1.0, type=click.FloatRange(min=0.1, max=1.0))
4043
@click.option("--use-xauth/--no-use-xauth", help="If a Xauthority file should be created", default=False)
4144
@piomatter_click.standard_options
4245
@click.argument("command", nargs=-1)
43-
def main(scale, backend, use_xauth, extra_args, rfbport, width, height, serpentine, rotation, pinout,
46+
def main(scale, backend, use_xauth, extra_args, rfbport, brightness, width, height, serpentine, rotation, pinout,
4447
n_planes, n_temporal_planes, n_addr_lines, n_lanes, command):
4548
kwargs = {}
4649
if backend == "xvnc":
@@ -61,8 +64,12 @@ def main(scale, backend, use_xauth, extra_args, rfbport, width, height, serpenti
6164
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:
6265
while proc.poll() is None:
6366
img = disp.grab(autocrop=False)
67+
6468
if img is None:
6569
continue
70+
if brightness != 1.0:
71+
darkener = ImageEnhance.Brightness(img)
72+
img = darkener.enhance(brightness)
6673
img = img.resize((width, height))
6774
framebuffer[:, :] = np.array(img)
6875
matrix.show()

examples/xdisplay_mirror.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import click
2222
import numpy as np
23-
from PIL import ImageGrab
23+
from PIL import ImageEnhance, ImageGrab
2424

2525
import adafruit_blinka_raspberry_pi5_piomatter as piomatter
2626
import adafruit_blinka_raspberry_pi5_piomatter.click as piomatter_click
@@ -31,9 +31,11 @@
3131
@click.option("--mirror-region", help="Region of X display to mirror. Comma seperated x,y,w,h. "
3232
"Default will mirror entire display.", default="")
3333
@click.option("--x-display", help="The X display to mirror. Default is :0", default=":0")
34+
@click.option("--brightness", help="The brightness factor of the image output to the matrix",
35+
default=1.0, type=click.FloatRange(min=0.1, max=1.0))
3436
@piomatter_click.standard_options(n_lanes=2, n_temporal_planes=0)
3537
def main(width, height, serpentine, rotation, pinout, n_planes,
36-
n_temporal_planes, n_addr_lines, n_lanes, mirror_region, x_display):
38+
n_temporal_planes, n_addr_lines, n_lanes, mirror_region, x_display, brightness):
3739
if n_lanes != 2:
3840
pixelmap = simple_multilane_mapper(width, height, n_addr_lines, n_lanes)
3941
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,
5961
img = img.crop((mirror_region[0], mirror_region[1], # left,top
6062
mirror_region[0] + mirror_region[2], # right
6163
mirror_region[1] + mirror_region[3])) # bottom
64+
if brightness != 1.0:
65+
darkener = ImageEnhance.Brightness(img)
66+
img = darkener.enhance(brightness)
6267
img = img.resize((width, height))
6368

6469
framebuffer[:, :] = np.array(img)

0 commit comments

Comments
 (0)