Face unlock: screen fill-light for low light; fix Quad-Bayer AE ramp
CI / test (push) Failing after 51s
CI / test (push) Failing after 51s
- Boost the backlight to 90% while enrolling with the light on or while sign-in is scanning, then restore the previous level when that ends or the window closes. - Add a Light: On/Off toggle (L key) to the Face window; the backdrop turns soft white while the light is on. - Quad-Bayer AE: compute the low-light gain once and cap it by the highlight limit, so ramp-up and highlight back-off agree. - Tests: backlight round-trip through the Face window, Quad-Bayer debayer color/low-light/dark-frame cases, and the AE ramp, back-off and restore order.
This commit is contained in:
1 parent
c5b96e2c70
commit
40c5d6722c
8 files changed
+266
-12
No files matched your search
@@ -136,7 +136,17 @@ fn ChandraCompositor::auth_ops(self : ChandraCompositor) -> Array[@scene.DrawOp]
|
||||
let rad = self.theme.radius + 2
|
||||
let sw = self.output_w
|
||||
let sh = self.output_h
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), @scene.Rgba::new(0, 0, 0, 150), 0))
|
||||
ops.push(
|
||||
@scene.DrawOp::FillRect(
|
||||
@scene.Rect::new(0, 0, sw, sh),
|
||||
if d.face == Scanning {
|
||||
@scene.Rgba::new(255, 250, 242, 235)
|
||||
} else {
|
||||
@scene.Rgba::new(0, 0, 0, 150)
|
||||
},
|
||||
0,
|
||||
),
|
||||
)
|
||||
let w = (sw - 32).min(460)
|
||||
let pad = 24
|
||||
let inner = w - pad * 2
|
||||
|
||||
@@ -298,6 +298,7 @@ pub(all) struct ChandraCompositor {
|
||||
/// it last drawn.
|
||||
face_hits : Array[(@scene.Rect, FaceHit)]
|
||||
mut face_rev : Int
|
||||
mut face_saved_brightness : Int
|
||||
/// The keymap the dialog types through (parsed from the one clients get).
|
||||
mut keymap : (Bytes, @polkit.Keymap)?
|
||||
/// Another polkit agent was started (the Settings switch for Chandra's dialog is off).
|
||||
@@ -373,6 +374,7 @@ pub fn ChandraCompositor::new(
|
||||
auth_slow_said: false,
|
||||
face_hits: [],
|
||||
face_rev: -1,
|
||||
face_saved_brightness: -1,
|
||||
keymap: None,
|
||||
fallback_agent_started: false,
|
||||
mods_latched: 0U,
|
||||
@@ -622,6 +624,11 @@ pub fn ChandraCompositor::resize(self : ChandraCompositor, w : Int, h : Int) ->
|
||||
///|
|
||||
pub fn ChandraCompositor::close(self : ChandraCompositor) -> Unit {
|
||||
self.stop_recording()
|
||||
if self.face_saved_brightness >= 0 {
|
||||
let prev = self.face_saved_brightness
|
||||
self.face_saved_brightness = -1
|
||||
ignore(self.shell.set_brightness(prev))
|
||||
}
|
||||
for _, win in self.windows {
|
||||
release_snapshot(win.surface)
|
||||
}
|
||||
|
||||
@@ -230,3 +230,39 @@ test "face unlock status lines" {
|
||||
assert_eq(@shell.face_progress("error couldn't see a face clearly"), Some("Couldn't see a face clearly"))
|
||||
assert_eq(@shell.face_progress("face 1\tDesk\t2026-11-20"), None)
|
||||
}
|
||||
|
||||
///|
|
||||
test "the Face unlock window: screen fill-light boosts backlight and restores on close" {
|
||||
let root = "/tmp/chandra-test-face-backlight-" + @sys.getpid().to_string()
|
||||
let dev = root + "/ae94000.dsi.0"
|
||||
ignore(@sys.mkdir_p(dev))
|
||||
assert_eq(@sys.write_file_bytes(dev + "/max_brightness", @utf8.encode("1000\n")), 0)
|
||||
assert_eq(@sys.write_file_bytes(dev + "/brightness", @utf8.encode("500\n")), 0)
|
||||
@shell.set_backlight_root(root)
|
||||
let dir = "/tmp/chandra-face-light-" + @sys.getpid().to_string()
|
||||
let tool = fake_face_tool(dir)
|
||||
let comp = new_comp("facelight")
|
||||
comp.shell.set_face_tool(["/bin/sh", tool])
|
||||
assert_true(comp.shell.open_settings(Session))
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Desk") }))
|
||||
face_click(comp, "Add or remove faces…", 10U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
|
||||
let w = comp.shell.face.window.unwrap()
|
||||
assert_true(w.fill_light)
|
||||
assert_eq(@shell.read_backlight_percent(), 90)
|
||||
// Pressing L toggles fill-light off and restores previous backlight immediately.
|
||||
face_key(comp, 38U, 20U)
|
||||
assert_false(w.fill_light)
|
||||
assert_eq(@shell.read_backlight_percent(), 50)
|
||||
// Pressing L again boosts back to 90.
|
||||
face_key(comp, 38U, 30U)
|
||||
assert_true(w.fill_light)
|
||||
assert_eq(@shell.read_backlight_percent(), 90)
|
||||
// Esc closes window and restores backlight cleanly.
|
||||
face_key(comp, 1U, 40U)
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.shell.face.window is None)
|
||||
assert_eq(@shell.read_backlight_percent(), 50)
|
||||
comp.close()
|
||||
@shell.set_backlight_root("/sys/class/backlight")
|
||||
}
|
||||
@@ -17,14 +17,42 @@ pub(all) enum FaceHit {
|
||||
DropSnap(Int)
|
||||
ToggleFace(String)
|
||||
UseCamera(String)
|
||||
ToggleLight
|
||||
Apply
|
||||
Cancel
|
||||
} derive(Eq)
|
||||
|
||||
///| Boost display backlight while the screen acts as a face fill-light, and restore it when done.
|
||||
fn ChandraCompositor::sync_face_fill_light(self : ChandraCompositor) -> Unit {
|
||||
let enroll_light = match self.shell.face.window {
|
||||
Some(w) => !w.applying && !w.ended && w.fill_light
|
||||
None => false
|
||||
}
|
||||
let auth_light = match self.auth {
|
||||
Some(u) => u.view.face == Scanning
|
||||
None => false
|
||||
}
|
||||
let want_boost = enroll_light || auth_light
|
||||
if want_boost {
|
||||
if self.face_saved_brightness < 0 {
|
||||
let cur = @shell.read_backlight_percent()
|
||||
if cur >= 0 && cur < 90 {
|
||||
self.face_saved_brightness = cur
|
||||
ignore(self.shell.set_brightness(90))
|
||||
}
|
||||
}
|
||||
} else if self.face_saved_brightness >= 0 {
|
||||
let prev = self.face_saved_brightness
|
||||
self.face_saved_brightness = -1
|
||||
ignore(self.shell.set_brightness(prev))
|
||||
}
|
||||
}
|
||||
|
||||
///| Follow the camera process and redraw when the window changed.
|
||||
fn ChandraCompositor::face_window_tick(self : ChandraCompositor) -> Unit {
|
||||
let f = self.shell.face
|
||||
f.poll_window()
|
||||
self.sync_face_fill_light()
|
||||
if f.window_rev != self.face_rev {
|
||||
self.face_rev = f.window_rev
|
||||
self.damage.mark_full()
|
||||
@@ -52,6 +80,7 @@ fn ChandraCompositor::face_window_activate(self : ChandraCompositor, h : FaceHit
|
||||
DropSnap(i) => f.drop_snap(i)
|
||||
ToggleFace(id) => f.toggle_remove(id)
|
||||
UseCamera(path) => f.use_camera(path)
|
||||
ToggleLight => f.toggle_fill_light()
|
||||
Apply => f.apply()
|
||||
Cancel => f.cancel_window()
|
||||
}
|
||||
@@ -79,6 +108,8 @@ fn ChandraCompositor::face_window_input(self : ChandraCompositor, ev : @nested.I
|
||||
self.face_window_activate(Apply)
|
||||
} else if code == key_space {
|
||||
self.face_window_activate(Snap)
|
||||
} else if code == key_l {
|
||||
self.face_window_activate(ToggleLight)
|
||||
}
|
||||
}
|
||||
true
|
||||
@@ -106,8 +137,12 @@ fn ChandraCompositor::face_window_input(self : ChandraCompositor, ev : @nested.I
|
||||
///|
|
||||
let key_space : UInt = 57
|
||||
|
||||
///|
|
||||
let key_l : UInt = 38
|
||||
|
||||
///| The window, when it is open.
|
||||
fn ChandraCompositor::face_window_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
|
||||
self.sync_face_fill_light()
|
||||
let ops : Array[@scene.DrawOp] = []
|
||||
let f = self.shell.face
|
||||
let win = match f.window {
|
||||
@@ -136,7 +171,12 @@ fn ChandraCompositor::face_window_ops(self : ChandraCompositor) -> Array[@scene.
|
||||
let rad = self.theme.radius + 2
|
||||
let sw = self.output_w
|
||||
let sh = self.output_h
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), @scene.Rgba::new(0, 0, 0, 150), 0))
|
||||
let backdrop = if win.fill_light && !win.ended {
|
||||
@scene.Rgba::new(255, 250, 242, 245)
|
||||
} else {
|
||||
@scene.Rgba::new(0, 0, 0, 150)
|
||||
}
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), backdrop, 0))
|
||||
let w = (sw - 32).min(560)
|
||||
let pad = 24
|
||||
let inner = w - pad * 2
|
||||
@@ -145,6 +185,13 @@ fn ChandraCompositor::face_window_ops(self : ChandraCompositor) -> Array[@scene.
|
||||
let hits : Array[(@scene.Rect, FaceHit)] = []
|
||||
let mut y = pad
|
||||
body.push(@scene.DrawOp::Text(pad, y + 7, "FACE UNLOCK", fs - 3, p.accent, @scene.TextAlign::Left, true))
|
||||
if !win.ended {
|
||||
let light_label = if win.fill_light { "Light: On" } else { "Light: Off" }
|
||||
let light_w = @renderer.text_width("Light: Off", fs - 2, false, false) + 22
|
||||
let lr = @scene.Rect::new(pad + inner - light_w, pad, light_w, 28)
|
||||
auth_button(lr, light_label, false, false, hover == Some(ToggleLight), true, p, fs - 2, rad, body)
|
||||
hits.push((lr, ToggleLight))
|
||||
}
|
||||
y = y + 18
|
||||
body.push(@scene.DrawOp::Text(pad, y + (fs + 8) / 2, "Add or remove faces", fs + 3, p.foreground, @scene.TextAlign::Left, true))
|
||||
y = y + fs + 10
|
||||
|
||||
@@ -77,6 +77,8 @@ pub(all) struct FaceWindow {
|
||||
mut applying : Bool
|
||||
/// When the camera process ended without a picture: the window shows why.
|
||||
mut ended : Bool
|
||||
/// Soft white surround fill-light for low-light enrollment.
|
||||
mut fill_light : Bool
|
||||
/// The cameras chandra-face found when the configured one can't be used: (path, name, why
|
||||
/// not; empty when it takes pictures). The window offers the usable ones.
|
||||
cameras : Array[(String, String, String)]
|
||||
@@ -375,6 +377,7 @@ pub fn FaceUnlock::open_window(self : FaceUnlock, mark : String?) -> Unit {
|
||||
error: false,
|
||||
applying: false,
|
||||
ended: fd < 0,
|
||||
fill_light: true,
|
||||
cameras: [],
|
||||
}
|
||||
if fd < 0 {
|
||||
@@ -406,6 +409,17 @@ pub fn FaceUnlock::snap(self : FaceUnlock) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///| Toggle the soft screen fill-light while taking enrollment pictures.
|
||||
pub fn FaceUnlock::toggle_fill_light(self : FaceUnlock) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if !w.applying && !w.ended => {
|
||||
w.fill_light = !w.fill_light
|
||||
self.touch()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Forget snap `i`.
|
||||
pub fn FaceUnlock::drop_snap(self : FaceUnlock, i : Int) -> Unit {
|
||||
match self.window {
|
||||
|
||||
Reference in new issue
Block a user