Add brightness control to Key Colors targets with HAOS integration
Adds brightness (0.0-1.0) to KeyColorsSettings, applies scaling in the KC processing pipeline after smoothing, exposes a slider on the WebUI target card, and creates a HA number entity for KC target brightness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,7 @@ KC_WORK_SIZE = (160, 90) # (width, height) — small enough for fast color calc
|
||||
# CPU-bound frame processing (runs in thread pool via asyncio.to_thread)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _process_kc_frame(capture, rect_names, rect_bounds, calc_fn, prev_colors_arr, smoothing):
|
||||
def _process_kc_frame(capture, rect_names, rect_bounds, calc_fn, prev_colors_arr, smoothing, brightness):
|
||||
"""All CPU-bound work for one KC frame.
|
||||
|
||||
Returns (colors, colors_arr, timing_ms) where:
|
||||
@@ -59,7 +59,13 @@ def _process_kc_frame(capture, rect_names, rect_bounds, calc_fn, prev_colors_arr
|
||||
if prev_colors_arr is not None and smoothing > 0:
|
||||
colors_arr = colors_arr * (1 - smoothing) + prev_colors_arr * smoothing
|
||||
|
||||
colors_u8 = np.clip(colors_arr, 0, 255).astype(np.uint8)
|
||||
# Apply brightness scaling
|
||||
if brightness < 1.0:
|
||||
output_arr = colors_arr * brightness
|
||||
else:
|
||||
output_arr = colors_arr
|
||||
|
||||
colors_u8 = np.clip(output_arr, 0, 255).astype(np.uint8)
|
||||
t2 = time.perf_counter()
|
||||
|
||||
# Build output dict
|
||||
@@ -256,6 +262,7 @@ class KCTargetProcessor(TargetProcessor):
|
||||
|
||||
target_fps = settings.fps
|
||||
smoothing = settings.smoothing
|
||||
brightness = settings.brightness
|
||||
|
||||
# Select color calculation function
|
||||
calc_fns = {
|
||||
@@ -328,7 +335,7 @@ class KCTargetProcessor(TargetProcessor):
|
||||
colors, colors_arr, frame_timing = await asyncio.to_thread(
|
||||
_process_kc_frame,
|
||||
capture, rect_names, rect_bounds, calc_fn,
|
||||
prev_colors_arr, smoothing,
|
||||
prev_colors_arr, smoothing, brightness,
|
||||
)
|
||||
|
||||
prev_colors_arr = colors_arr
|
||||
|
||||
Reference in New Issue
Block a user