Improve perceived display brightness (#21884)

* tweak light sensor function

* CIE 1931 compensation

* before filter

* C3 scaling

* C2 is also linear

* whitespace

* scaling and min brightness
peanut-butter-jelly-time^2
Willem Melching 4 years ago committed by GitHub
parent 3616602cd2
commit 358cdaaefd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      selfdrive/ui/ui.cc

@ -185,15 +185,18 @@ static void update_state(UIState *s) {
if (sm.updated("roadCameraState")) {
auto camera_state = sm["roadCameraState"].getRoadCameraState();
float max_lines = Hardware::EON() ? 5408 : 1757;
float gain = camera_state.getGain();
float max_lines = Hardware::EON() ? 5408 : 1904;
float max_gain = Hardware::EON() ? 1.0: 10.0;
float max_ev = max_lines * max_gain;
if (Hardware::TICI()) {
// Max gain is 4 * 2.5 (High Conversion Gain)
gain /= 10.0;
// C3 camera only uses about 10% of available gain at night
if (Hardware::TICI) {
max_ev /= 10;
}
scene.light_sensor = std::clamp<float>((1023.0 / max_lines) * (max_lines - camera_state.getIntegLines() * gain), 0.0, 1023.0);
float ev = camera_state.getGain() * float(camera_state.getIntegLines());
scene.light_sensor = std::clamp<float>(1.0 - (ev / max_ev), 0.0, 1.0);
}
scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition;
}
@ -335,9 +338,19 @@ void Device::setAwake(bool on, bool reset) {
}
void Device::updateBrightness(const UIState &s) {
float brightness_b = 10;
float brightness_m = 0.1;
float clipped_brightness = std::min(100.0f, (s.scene.light_sensor * brightness_m) + brightness_b);
// Scale to 0% to 100%
float clipped_brightness = 100.0 * s.scene.light_sensor;
// CIE 1931 - https://www.photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm
if (clipped_brightness <= 8) {
clipped_brightness = (clipped_brightness / 903.3);
} else {
clipped_brightness = std::pow((clipped_brightness + 16.0) / 116.0, 3.0);
}
// Scale back to 10% to 100%
clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f);
if (!s.scene.started) {
clipped_brightness = BACKLIGHT_OFFROAD;
}

Loading…
Cancel
Save