This document provides a deep dive into the mathematical implementation of Smart Brightness.
graph TD
A[Camera Capture] --> B[Dominance Mapping]
B --> C[Reflection Compensation]
C --> D[Normalization]
D --> E[EMA Smoothing]
E --> F[Day/Night Adjustment]
F --> G[Brightness Mapping]
G --> H[Smooth Transition]
H --> I[Sysfs Write]
Smart Brightness uses a Dominance-Coverage model to estimate perceived lighting.
Implementation:
- Weighted Histogram: Pixels are binned (0-255) and weighted by spatial position (center-priority).
-
85th Percentile (
$L_{85}$ ): We find the luminance level that 85% of the environment is at or below. This represents the "dominant luminance field." -
Final Estimation:
$$L_{raw} = \frac{0.9 \times L_{85} + 0.1 \times L_{mean}}{255}$$ This ensures that pinpoint light sources (like a desk lamp) don't overpower the global environmental light.
To prevent screen light reflecting off the user's face from keeping the brightness high in dark rooms:
Compensated luma is normalized against the calibrated range:
An Exponential Moving Average (EMA) filters out noise:
smoothing parameter.
If day_night_mode is enabled, the light level is scaled by a time-of-day multiplier (e.g., 1.05 during the day).
Adjusted light levels are mapped to hardware values:
To avoid jarring snaps, brightness is moved in steps:
| File | Responsibility |
|---|---|
src/main.rs |
Coordination, mapping, and compensation. |
src/camera.rs |
V4L2 capture and Dominance Histogram. |
src/backlight.rs |
Sysfs hardware interaction. |
src/config.rs |
Simplified TOML management. |
src/smoothing.rs |
EMA noise reduction. |
src/smooth_transition.rs |
Incremental step logic. |
src/time_adjust.rs |
Day/Night scheduling. |
src/tui.rs |
Terminal configuration tool. |