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

+214
View File
@@ -368,6 +368,197 @@ pub fn EmojiFont::has(self : EmojiFont, text : String) -> Bool raise EmojiFontEr
gs.length() == 1 && self.glyph_png(gs[0]) is Some(_)
}
///| Whether `cp` is an emoji skin tone modifier (Fitzpatrick Type-1-2 through Type-6).
fn is_skin_tone(cp : Int) -> Bool {
cp >= 0x1F3FB && cp <= 0x1F3FF
}
///| Whether `text` contains any code point >= U+203C (covering emoji, keycap combining
/// enclosing keycap U+20E3, and variation selector U+FE0F).
pub fn text_may_have_emoji(text : String) -> Bool {
for ch in text {
if ch.to_int() >= 0x203C {
return true
}
}
false
}
///| Default-ignorable emoji joiner / variation selectors (U+FE0E, U+FE0F, U+200D).
pub fn is_ignorable_emoji_mod(cp : Int) -> Bool {
cp == 0xFE0E || cp == 0xFE0F || cp == 0x200D
}
///| Whether a non-ASCII code point >= U+203C sits in a Unicode block that can start an emoji.
fn may_start_emoji_non_ascii(cp : Int) -> Bool {
(cp >= 0x203C && cp <= 0x21AA) ||
(cp >= 0x2300 && cp <= 0x27BF) ||
(cp >= 0x2934 && cp <= 0x2935) ||
(cp >= 0x2B00 && cp <= 0x2BFF) ||
cp == 0x3030 ||
cp == 0x303D ||
cp == 0x3297 ||
cp == 0x3299 ||
(cp >= 0x1F000 && cp <= 0x1FBFF)
}
///| Exclusive end index of the maximal candidate emoji cluster starting at `chars[start]`,
/// or `start` when `chars[start]` cannot start an emoji sequence.
pub fn candidate_end(chars : Array[Char], start : Int) -> Int {
let n = chars.length()
if start < 0 || start >= n {
return start
}
let cp = chars[start].to_int()
if is_ignorable_emoji_mod(cp) || cp == 0x20E3 {
return start
}
if cp < 0x80 {
// ASCII can only start a keycap emoji (#️⃣, *️⃣, 0️⃣..9️⃣).
let is_keycap = cp == 0x23 || cp == 0x2A || (cp >= 0x30 && cp <= 0x39)
if !is_keycap {
return start
}
if start + 1 < n && chars[start + 1].to_int() == 0x20E3 {
return start + 2
}
if start + 2 < n && chars[start + 1].to_int() == 0xFE0F && chars[start + 2].to_int() == 0x20E3 {
return start + 3
}
return start
}
if cp < 0x203C {
// Only ©️ / ®️ with explicit emoji presentation selector.
if (cp == 0xA9 || cp == 0xAE) && start + 1 < n && chars[start + 1].to_int() == 0xFE0F {
return start + 2
}
return start
}
if !may_start_emoji_non_ascii(cp) {
return start
}
if cp >= 0x1F1E6 && cp <= 0x1F1FF {
if start + 1 < n {
let next = chars[start + 1].to_int()
if next >= 0x1F1E6 && next <= 0x1F1FF {
return start + 2
}
}
return start + 1
}
let limit = if start + 16 < n { start + 16 } else { n }
if cp == 0x1F3F4 && start + 1 < limit {
let first_tag = chars[start + 1].to_int()
if first_tag >= 0xE0020 && first_tag <= 0xE007E {
let mut j = start + 1
while j < limit - 1 {
let t = chars[j].to_int()
if t >= 0xE0020 && t <= 0xE007E {
j = j + 1
} else {
break
}
}
if j < limit && chars[j].to_int() == 0xE007F {
return j + 1
}
}
}
let mut i = start + 1
if i < limit && chars[i].to_int() == 0xFE0F {
i = i + 1
}
if i < limit && is_skin_tone(chars[i].to_int()) {
i = i + 1
}
while i + 1 < limit && chars[i].to_int() == 0x200D {
let next = chars[i + 1].to_int()
if next < 0x80 || is_ignorable_emoji_mod(next) || next == 0x20E3 {
break
}
i = i + 2
if i < limit && chars[i].to_int() == 0xFE0F {
i = i + 1
}
if i < limit && is_skin_tone(chars[i].to_int()) {
i = i + 1
}
}
i
}
///| Match the longest emoji sequence starting at `chars[start]` accepted by `has_emoji`.
/// Respects U+FE0E text presentation and keeps bare BMP symbols monochrome when `has_text_glyph`
/// reports the text font has them.
pub fn match_with(
chars : Array[Char],
start : Int,
has_text_glyph : (Int) -> Bool,
has_emoji : (String) -> Bool,
) -> (Int, String)? {
let max_end = candidate_end(chars, start)
if max_end <= start {
return None
}
let cp = chars[start].to_int()
if start + 1 < chars.length() && chars[start + 1].to_int() == 0xFE0E && has_text_glyph(cp) {
return None
}
let mut end = max_end
while end > start {
if chars[end - 1].to_int() == 0x200D {
end = end - 1
continue
}
if cp < 0x80 && chars[end - 1].to_int() != 0x20E3 {
end = end - 1
continue
}
if end == start + 1 && cp < 0x1F000 && has_text_glyph(cp) {
return None
}
let sb = StringBuilder::new()
for k = start; k < end; k = k + 1 {
sb.write_char(chars[k])
}
let sub = sb.to_string()
if has_emoji(sub) {
return Some((end, sub))
}
end = end - 1
}
None
}
///| Match the longest emoji sequence starting at `chars[start]` that this font can draw.
pub fn EmojiFont::match_at(
self : EmojiFont,
chars : Array[Char],
start : Int,
has_text_glyph : (Int) -> Bool,
) -> (Int, String)? raise EmojiFontError {
if start < 0 || start >= chars.length() {
return None
}
let cp = chars[start].to_int()
if cp >= 0x80 && self.glyph(cp) == 0 {
return None
}
let mut err : EmojiFontError? = None
let res = match_with(chars, start, has_text_glyph, s => {
try self.has(s) catch {
e => {
err = Some(e)
false
}
}
})
match err {
Some(e) => raise e
None => res
}
}
///| The picture for `text`, `px` x `px` (the bitmap scaled to fit and centred), straight RGBA.
/// None when the font has no single picture for it.
pub fn EmojiFont::picture(self : EmojiFont, text : String, px : Int) -> @renderer.Pixmap? raise EmojiFontError {
@@ -515,3 +706,26 @@ pub fn EmojiSource::image(self : EmojiSource, text : String, px : Int, put : (@r
self.images.set(key, h)
h
}
///| Match the longest emoji sequence starting at `chars[start]` using the open font.
/// Opens the font lazily on first use; does not retry a failed open on every text draw call.
pub fn EmojiSource::match_at(
self : EmojiSource,
chars : Array[Char],
start : Int,
has_text_glyph : (Int) -> Bool,
) -> (Int, String)? {
if self.state is None {
ignore(self.font())
}
match self.state {
Some(Ok((_, f))) =>
try f.match_at(chars, start, has_text_glyph) catch {
EmojiFontError(why) => {
@sys.log("emoji: can't match inline emoji: " + why)
None
}
}
_ => None
}
}
+52
View File
@@ -68,3 +68,55 @@ test "a file that is not a colour emoji font is an error that says why" {
assert_true(msg.contains("no cmap table"))
assert_true(@emoji.missing_font_message("").contains("just install"))
}
///|
test "inline emoji matcher handles turtle, sequences, VS15/VS16, and BMP symbols" {
assert_false(@emoji.text_may_have_emoji("Regency 215-223 WiFi"))
assert_false(@emoji.text_may_have_emoji("Café • … — ©"))
assert_true(@emoji.text_may_have_emoji("🐢"))
assert_true(@emoji.text_may_have_emoji("Connected to 🐢 (72%)"))
assert_true(@emoji.text_may_have_emoji("#️⃣"))
assert_true(@emoji.text_may_have_emoji("©️"))
let f = open_font()
let all_have = fn(_cp : Int) { true }
let none_have = fn(_cp : Int) { false }
assert_eq(f.match_at("🐢".to_array(), 0, all_have), Some((1, "🐢")))
assert_eq(f.match_at("Connected to 🐢 (72%)".to_array(), 13, all_have), Some((14, "🐢")))
assert_eq(f.match_at("👍🏽!".to_array(), 0, all_have), Some((2, "👍🏽")))
assert_eq(f.match_at("#️⃣x".to_array(), 0, all_have), Some((3, "#️⃣")))
assert_eq(f.match_at("🇺🇸x".to_array(), 0, all_have), Some((2, "🇺🇸")))
assert_eq(f.match_at("👨‍👩‍👧‍👦x".to_array(), 0, all_have), Some((7, "👨‍👩‍👧‍👦")))
// Bare BMP symbols stay monochrome when the UI text font has them; VS16 switches to colour, VS15 keeps text.
assert_eq(f.match_at("▶".to_array(), 0, all_have), None)
assert_eq(f.match_at("▶️".to_array(), 0, all_have), Some((2, "▶️")))
assert_eq(f.match_at("▶\u{FE0E}".to_array(), 0, all_have), None)
assert_eq(f.match_at("☀".to_array(), 0, none_have), Some((1, "☀")))
// Non-emoji ASCII / CJK / unsupported Emoji 18.0 characters do not match.
assert_eq(f.match_at("#1".to_array(), 0, all_have), None)
assert_eq(f.match_at("日本語".to_array(), 0, none_have), None)
let cracking = @emoji.all().filter(e => e.name == "cracking face")[0]
assert_eq(f.match_at(cracking.text.to_array(), 0, none_have), None)
// Noto Color Emoji's turtle renders olive-green opaque pixels at inline size.
let p = f.picture("🐢", 16).unwrap()
assert_eq((p.width, p.height), (16, 16))
let mut green = 0
for i = 0; i < p.width * p.height; i = i + 1 {
let o = i * 4
let r = p.data[o].to_int()
let g = p.data[o + 1].to_int()
let b = p.data[o + 2].to_int()
let a = p.data[o + 3].to_int()
if a > 200 && g > r && g > b + 40 {
green = green + 1
}
}
assert_true(green > 10)
let src = @emoji.EmojiSource::new()
assert_eq(src.match_at("🐢".to_array(), 0, all_have), Some((1, "🐢")))
}