Camera: C ISP pipeline, contrast autofocus, and VFR video
CI / test (push) Canceled after 0s

- Add chandra-camera-isp.c (C/OpenMP) for Quad-Bayer unpack, CCM, and tone mapping, with a NumPy fallback when it is not built
- Add non-blocking contrast-detection VCM autofocus, with lens subdev discovery on the sensor's I2C bus
- Tune Quad-Bayer AE: a video-mode vblank cap, damped steps, and full analog gain before extending blanking
- Record variable-frame-rate video through a streaming Matroska muxer, and count dropped frames
- Ship libcamera IPA tuning files for imx376, imx519, and uncalibrated sensors
- Map camera buffers by fd and sync them with dma-buf ioctls
This commit is contained in:
nandi committed 2026-11-28 19:25:43 -08:00
1 parent 851c39d827
commit 52b42890d6
34 files changed
+2851 -364

No files matched your search

+74 -17
View File
@@ -42,9 +42,6 @@ fn nat(s : String, dflt : Int) -> Int {
///| Space kept free around the grid, in pixels.
let margin : Int = 20
///| A drag starts once the pointer has moved this far from the press.
let drag_threshold : Int = 5
///| What the module asks of the host after an event.
#derive(Eq, Debug)
pub(all) enum Action {
@@ -58,6 +55,9 @@ pub(all) struct Desk {
mut size : String
/// Where icons were put: app id -> (column, row).
places : Map[String, (Int, Int)]
/// First-seen order of shown app ids, so recents reordering never shuffles unplaced icons.
seen : Map[String, Int]
mut next_seen : Int
mut w : Int
mut h : Int
/// Kept free at the bottom (the panel).
@@ -82,6 +82,8 @@ pub fn Desk::new() -> Desk {
count: "12",
size: "Medium",
places: {},
seen: {},
next_seen: 0,
w: 0,
h: 0,
bottom: 40,
@@ -106,6 +108,13 @@ pub fn Desk::cell(self : Desk) -> (Int, Int, Int) {
}
}
///| A drag starts once the pointer has moved this far from the press.
fn Desk::drag_threshold(self : Desk) -> Int {
let (cw, _, _) = self.cell()
let t = cw / 3
if t < 24 { 24 } else { t }
}
///| Columns and rows that fit on the desktop (at least one of each).
pub fn Desk::grid(self : Desk) -> (Int, Int) {
let (cw, ch, _) = self.cell()
@@ -129,9 +138,15 @@ pub fn Desk::shown(self : Desk, apps : Array[@types.AppEntry]) -> Array[@types.A
}
///| Each shown app's cell, in `shown` order: its saved place when that is on the grid and free,
/// else the first free cell, a column at a time. (-1, -1) when the grid is full.
/// else the first free cell, a column at a time, in first-seen order. (-1, -1) when full.
pub fn Desk::layout(self : Desk, apps : Array[@types.AppEntry]) -> Array[(Int, Int)] {
let shown = self.shown(apps)
for a in shown {
if !self.seen.contains(a.id) {
self.seen.set(a.id, self.next_seen)
self.next_seen = self.next_seen + 1
}
}
let (cols, rows) = self.grid()
let taken : Map[(Int, Int), Bool] = {}
let out : Array[(Int, Int)] = Array::make(shown.length(), (-1, -1))
@@ -144,11 +159,19 @@ pub fn Desk::layout(self : Desk, apps : Array[@types.AppEntry]) -> Array[(Int, I
_ => ()
}
}
let mut next = 0
let unplaced : Array[Int] = []
for i = 0; i < shown.length(); i = i + 1 {
if out[i] != (-1, -1) {
continue
if out[i] == (-1, -1) {
unplaced.push(i)
}
}
unplaced.sort_by(fn(a, b) {
let sa = self.seen.get(shown[a].id).unwrap_or(a)
let sb = self.seen.get(shown[b].id).unwrap_or(b)
if sa != sb { sa - sb } else { a - b }
})
let mut next = 0
for i in unplaced {
while next < cols * rows && taken.contains((next / rows, next % rows)) {
next = next + 1
}
@@ -192,6 +215,20 @@ pub fn Desk::app_at(self : Desk, apps : Array[@types.AppEntry], x : Int, y : Int
""
}
///| Pin every unplaced shown icon at its current grid cell without overwriting existing places.
fn Desk::pin_unplaced(self : Desk, apps : Array[@types.AppEntry]) -> Unit {
if self.w <= 0 || self.h <= 0 {
return
}
let shown = self.shown(apps)
let cells = self.layout(apps)
for i, a in shown {
if cells[i] != (-1, -1) && !self.places.contains(a.id) {
self.places.set(a.id, cells[i])
}
}
}
///| Remember every shown icon where it is now, then put `id` at `to`, swapping with the icon
/// there (which takes `id`'s old cell).
fn Desk::move_to(self : Desk, apps : Array[@types.AppEntry], id : String, to : (Int, Int)) -> Unit {
@@ -199,13 +236,18 @@ fn Desk::move_to(self : Desk, apps : Array[@types.AppEntry], id : String, to : (
let cells = self.layout(apps)
let mut from = (-1, -1)
for i, a in shown {
if cells[i] != (-1, -1) {
self.places.set(a.id, cells[i])
}
if a.id == id {
from = cells[i]
}
}
if from == (-1, -1) || from == to {
return
}
for i, a in shown {
if cells[i] != (-1, -1) {
self.places.set(a.id, cells[i])
}
}
for i, a in shown {
if a.id != id && cells[i] == to {
self.places.set(a.id, from)
@@ -315,9 +357,13 @@ pub fn Desk::handle(self : Desk, apps : Array[@types.AppEntry], ev : @types.Inpu
PointerMove(p) => {
self.ptr_x = p.x
self.ptr_y = p.y
if self.press_id != "" && !self.dragging &&
((p.x - self.press_x).abs() > drag_threshold || (p.y - self.press_y).abs() > drag_threshold) {
self.dragging = true
if self.press_id != "" && !self.dragging {
let dx = p.x - self.press_x
let dy = p.y - self.press_y
let t = self.drag_threshold()
if dx * dx + dy * dy > t * t {
self.dragging = true
}
}
if self.dragging {
return (true, NoAction)
@@ -355,10 +401,16 @@ pub fn Desk::handle(self : Desk, apps : Array[@types.AppEntry], ev : @types.Inpu
self.move_to(apps, id, self.cell_at(p.x, p.y))
self.hover = self.app_at(apps, p.x, p.y)
(true, NoAction)
} else if self.app_at(apps, p.x, p.y) == id {
(true, Launch(id))
} else {
(true, NoAction)
let dx = p.x - self.press_x
let dy = p.y - self.press_y
let t = self.drag_threshold()
if self.app_at(apps, p.x, p.y) == id || dx * dx + dy * dy <= t * t {
self.pin_unplaced(apps)
(true, Launch(id))
} else {
(true, NoAction)
}
}
}
FocusLost => {
@@ -375,7 +427,12 @@ pub fn Desk::handle(self : Desk, apps : Array[@types.AppEntry], ev : @types.Inpu
"ArrowUp" | "Up" => self.step_selection(apps, 0, -1)
"ArrowDown" | "Down" => self.step_selection(apps, 0, 1)
"Enter" | " " =>
return (false, if self.selected != "" { Launch(self.selected) } else { NoAction })
if self.selected != "" {
self.pin_unplaced(apps)
return (false, Launch(self.selected))
} else {
return (false, NoAction)
}
"Escape" => self.selected = ""
_ => if k.length() == 1 { ignore(self.jump_to(apps, k)) } else { return (false, NoAction) }
}
+83
View File
@@ -85,3 +85,86 @@ test "keyboard moves the selection and launches" {
ignore(d.handle(a, FocusLost))
assert_false(d.focused)
}
///|
test "tapping with finger-roll drift launches without dragging or moving icons" {
let d = desk()
let a = apps(12)
let before = d.layout(a)
// 20 px drift inside cell (0,0): stays below the 32 px medium-cell drag threshold.
ignore(d.handle(a, PointerDown({ x: 60, y: 60 })))
ignore(d.handle(a, PointerMove({ x: 80, y: 64 })))
assert_false(d.dragging)
assert_eq(d.handle(a, PointerUp({ x: 80, y: 64 })), (true, Launch("app0")))
assert_eq(d.layout(a), before)
// 15 px drift starting near the right edge of cell (0,0) and crossing into cell (1,0) still
// launches app0 without moving any icon.
ignore(d.handle(a, PointerDown({ x: 110, y: 60 })))
ignore(d.handle(a, PointerMove({ x: 125, y: 60 })))
assert_false(d.dragging)
assert_eq(d.handle(a, PointerUp({ x: 125, y: 60 })), (true, Launch("app0")))
assert_eq(d.layout(a), before)
}
///|
test "launching and reordering apps by recency keeps every icon in its cell" {
let a = apps(12)
// Simulate an app launched from elsewhere (places empty): first-seen order keeps cells stable.
let d_unpinned = desk()
let expected_by_id : Map[String, (Int, Int)] = {}
let initial = d_unpinned.layout(a)
for i, app in a {
expected_by_id.set(app.id, initial[i])
}
let reordered = [a[0], a[1], a[2], a[3], a[4], a[7], a[5], a[6], a[8], a[9], a[10], a[11]]
let after_unpinned = d_unpinned.layout(reordered)
for i, app in reordered {
assert_eq(after_unpinned[i], expected_by_id.get(app.id).unwrap())
}
// Launching app7 on the desktop pins existing cells and keeps stability across recents reorder,
// off-grid rotation/resize fallback, and reload into a fresh Desk.
let d = desk()
ignore(d.layout(a))
// app7 is at cell (1, 2): x = 20 + 96 + 40 = 156, y = 20 + 2 * 96 + 40 = 252.
ignore(d.handle(a, PointerDown({ x: 156, y: 252 })))
assert_eq(d.handle(a, PointerUp({ x: 156, y: 252 })), (true, Launch("app7")))
let after_launch = d.layout(reordered)
for i, app in reordered {
assert_eq(after_launch[i], expected_by_id.get(app.id).unwrap())
}
// Portrait resize where column >= 1 falls off-grid: off-grid apps fall back in seen order,
// not recents order (app5 before app6 before app7).
d.w = 220
d.h = 1200
let portrait = d.layout(reordered)
let p_by_id : Map[String, (Int, Int)] = {}
for i, app in reordered {
p_by_id.set(app.id, portrait[i])
}
assert_true(p_by_id.get("app5").unwrap().1 < p_by_id.get("app6").unwrap().1)
assert_true(p_by_id.get("app6").unwrap().1 < p_by_id.get("app7").unwrap().1)
// Saved places round-trip into a fresh Desk with the reordered catalog.
let saved = d.config_items().filter(c => c.key == "places")[0]
let d2 = desk()
ignore(d2.set_config("places", saved.value))
let reloaded = d2.layout(reordered)
for i, app in reordered {
assert_eq(reloaded[i], expected_by_id.get(app.id).unwrap())
}
}
///|
test "dragging past threshold and dropping on the same cell cancels cleanly" {
let d = desk()
let a = apps(12)
let before = d.layout(a)
let places_val = fn(x : @icondesk.Desk) { x.config_items().filter(c => c.key == "places")[0].value }
assert_eq(places_val(d), "")
// Move 45 px (> 32 px threshold) while staying inside cell (0,0) (20..116).
ignore(d.handle(a, PointerDown({ x: 60, y: 60 })))
ignore(d.handle(a, PointerMove({ x: 105, y: 60 })))
assert_true(d.dragging)
assert_eq(d.handle(a, PointerUp({ x: 105, y: 60 })), (true, NoAction))
assert_eq(d.layout(a), before)
assert_eq(places_val(d), "")
}