- 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:
1 parent
851c39d827
commit
52b42890d6
34 files changed
+2851
-364
No files matched your search
@@ -20,14 +20,18 @@ pub fn encode_png_compressed(Pixmap) -> Bytes
|
||||
|
||||
pub fn encode_ppm(Pixmap) -> Bytes
|
||||
|
||||
pub fn inline_emoji_px(Int32) -> Int32
|
||||
|
||||
pub fn render_scene(@scene.SceneGraph) -> Pixmap
|
||||
|
||||
pub fn scale_pixmap(Pixmap, Int32, Int32) -> Pixmap
|
||||
|
||||
pub fn set_image(UInt32, Pixmap) -> UInt32
|
||||
pub fn set_emoji_source((Array[Char], Int32, Bool, Bool) -> (Int32, String)?, (String, Int32) -> UInt32) -> Unit
|
||||
|
||||
pub fn set_glyph_source((Int32, Int32, Bool, Bool) -> Glyph) -> Unit
|
||||
|
||||
pub fn set_image(UInt32, Pixmap) -> UInt32
|
||||
|
||||
pub fn shm_thumbnail(@scene.ShmBufferSnapshot, Int32, Int32) -> Pixmap?
|
||||
|
||||
pub fn text_width(String, Int32, Bool, Bool) -> Int32
|
||||
|
||||
@@ -496,10 +496,99 @@ pub fn set_glyph_source(f : (Int, Int, Bool, Bool) -> Glyph) -> Unit {
|
||||
glyph_source.val = Some(f)
|
||||
}
|
||||
|
||||
///| Pixel square size for inline colour emoji at font `size` (~1.2em, matching UI line height).
|
||||
pub fn inline_emoji_px(size : Int) -> Int {
|
||||
if size <= 0 {
|
||||
0
|
||||
} else {
|
||||
(size * 6 + 4) / 5
|
||||
}
|
||||
}
|
||||
|
||||
///| Optional inline emoji matcher and image provider for general UI text.
|
||||
let emoji_match_source : Ref[((Array[Char], Int, Bool, Bool) -> (Int, String)?)?] = {
|
||||
val: None,
|
||||
}
|
||||
|
||||
///|
|
||||
let emoji_image_source : Ref[((String, Int) -> UInt)?] = { val: None }
|
||||
|
||||
///| Register inline colour emoji lookup (`match_at`) and image rasteriser (`image`).
|
||||
pub fn set_emoji_source(
|
||||
match_at : (Array[Char], Int, Bool, Bool) -> (Int, String)?,
|
||||
image : (String, Int) -> UInt,
|
||||
) -> Unit {
|
||||
emoji_match_source.val = Some(match_at)
|
||||
emoji_image_source.val = Some(image)
|
||||
}
|
||||
|
||||
///|
|
||||
priv enum TextPiece {
|
||||
TextGlyph(Glyph)
|
||||
TextEmoji(String)
|
||||
}
|
||||
|
||||
///|
|
||||
fn renderer_may_have_emoji(text : String) -> Bool {
|
||||
for ch in text {
|
||||
if ch.to_int() >= 0x203C {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
///|
|
||||
fn renderer_ignorable_mod(cp : Int) -> Bool {
|
||||
cp == 0xFE0E || cp == 0xFE0F || cp == 0x200D
|
||||
}
|
||||
|
||||
///| Segment `text` into text glyphs and inline emoji clusters, returning `(pieces, total_w)`.
|
||||
fn layout_text(
|
||||
src : (Int, Int, Bool, Bool) -> Glyph,
|
||||
match_at : (Array[Char], Int, Bool, Bool) -> (Int, String)?,
|
||||
text : String,
|
||||
size : Int,
|
||||
bold : Bool,
|
||||
mono : Bool,
|
||||
) -> (Array[TextPiece], Int) {
|
||||
let chars = text.to_array()
|
||||
let epx = inline_emoji_px(size)
|
||||
let pieces : Array[TextPiece] = []
|
||||
let mut total_w = 0
|
||||
let mut i = 0
|
||||
while i < chars.length() {
|
||||
match match_at(chars, i, bold, mono) {
|
||||
Some((next, seq)) => {
|
||||
pieces.push(TextEmoji(seq))
|
||||
total_w = total_w + epx
|
||||
i = next
|
||||
}
|
||||
None => {
|
||||
let cp = chars[i].to_int()
|
||||
if !renderer_ignorable_mod(cp) {
|
||||
let g = src(cp, size, bold, mono)
|
||||
pieces.push(TextGlyph(g))
|
||||
total_w = total_w + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
(pieces, total_w)
|
||||
}
|
||||
|
||||
///| Pixel width `text` would occupy when drawn with the given face.
|
||||
pub fn text_width(text : String, size : Int, bold : Bool, mono : Bool) -> Int {
|
||||
match glyph_source.val {
|
||||
Some(src) => {
|
||||
match emoji_match_source.val {
|
||||
Some(match_at) if renderer_may_have_emoji(text) => {
|
||||
let (_, w) = layout_text(src, match_at, text, size, bold, mono)
|
||||
return w
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
let mut w = 0
|
||||
for ch in text {
|
||||
let g = src(ch.to_int(), size, bold, mono)
|
||||
@@ -525,12 +614,20 @@ fn draw_text_font(
|
||||
bold : Bool,
|
||||
clip : @scene.Rect?,
|
||||
) -> Unit {
|
||||
let glyphs : Array[Glyph] = []
|
||||
let mut total_w = 0
|
||||
for ch in text {
|
||||
let g = src(ch.to_int(), size, bold, mono)
|
||||
glyphs.push(g)
|
||||
total_w = total_w + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
let epx = inline_emoji_px(size)
|
||||
let (pieces, total_w) = match (emoji_match_source.val, emoji_image_source.val) {
|
||||
(Some(match_at), Some(_)) if renderer_may_have_emoji(text) =>
|
||||
layout_text(src, match_at, text, size, bold, mono)
|
||||
_ => {
|
||||
let pieces : Array[TextPiece] = []
|
||||
let mut total_w = 0
|
||||
for ch in text {
|
||||
let g = src(ch.to_int(), size, bold, mono)
|
||||
pieces.push(TextGlyph(g))
|
||||
total_w = total_w + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
(pieces, total_w)
|
||||
}
|
||||
}
|
||||
let start_x = match align {
|
||||
Left => x
|
||||
@@ -545,21 +642,37 @@ fn draw_text_font(
|
||||
let cb = color.b.to_int()
|
||||
let ca = color.a.to_int()
|
||||
let mut pen = start_x
|
||||
for g in glyphs {
|
||||
for row = 0; row < g.h; row = row + 1 {
|
||||
for col = 0; col < g.w; col = col + 1 {
|
||||
let cov = g.coverage[row * g.w + col].to_int()
|
||||
if cov > 0 {
|
||||
let px = pen + g.xoff + col
|
||||
let py = baseline + g.yoff + row
|
||||
blend_pixel(dst, px, py, cr, cg, cb, ca * cov / 255, clip)
|
||||
if g.embolden {
|
||||
blend_pixel(dst, px + 1, py, cr, cg, cb, ca * cov / 255, clip)
|
||||
for piece in pieces {
|
||||
match piece {
|
||||
TextGlyph(g) => {
|
||||
for row = 0; row < g.h; row = row + 1 {
|
||||
for col = 0; col < g.w; col = col + 1 {
|
||||
let cov = g.coverage[row * g.w + col].to_int()
|
||||
if cov > 0 {
|
||||
let px = pen + g.xoff + col
|
||||
let py = baseline + g.yoff + row
|
||||
blend_pixel(dst, px, py, cr, cg, cb, ca * cov / 255, clip)
|
||||
if g.embolden {
|
||||
blend_pixel(dst, px + 1, py, cr, cg, cb, ca * cov / 255, clip)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pen = pen + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
TextEmoji(seq) => {
|
||||
match emoji_image_source.val {
|
||||
Some(img_fn) if epx > 0 => {
|
||||
let h = img_fn(seq, epx)
|
||||
if h != 0U {
|
||||
draw_image(dst, h, @scene.Rect::new(pen, y - epx / 2, epx, epx), clip)
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
pen = pen + epx
|
||||
}
|
||||
}
|
||||
pen = pen + g.advance + (if g.embolden { 1 } else { 0 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,3 +137,58 @@ test "shm_thumbnail scales a client buffer; set_image swaps an image in place" {
|
||||
@renderer.draw_ops(dst, [@scene.DrawOp::Image(@scene.Rect::new(0, 0, 2, 1), h)], 0, 0)
|
||||
assert_eq(dst.pixel(0, 0), Some(@scene.Rgba::new(0, 0, 255, 255)))
|
||||
}
|
||||
|
||||
///|
|
||||
test "inline emoji source integrates into text_width and draw_ops" {
|
||||
assert_eq(@renderer.inline_emoji_px(0), 0)
|
||||
assert_eq(@renderer.inline_emoji_px(12), 15)
|
||||
assert_eq(@renderer.inline_emoji_px(13), 16)
|
||||
assert_eq(@renderer.inline_emoji_px(14), 17)
|
||||
|
||||
let epx = @renderer.inline_emoji_px(13)
|
||||
let turtle = @renderer.Pixmap::new(epx, epx)
|
||||
for y = 0; y < epx; y = y + 1 {
|
||||
for x = 0; x < epx; x = x + 1 {
|
||||
let o = (y * epx + x) * 4
|
||||
turtle.data[o] = (110).to_byte()
|
||||
turtle.data[o + 1] = (130).to_byte()
|
||||
turtle.data[o + 2] = (58).to_byte()
|
||||
turtle.data[o + 3] = b'\xff'
|
||||
}
|
||||
}
|
||||
let th = @renderer.add_image(turtle)
|
||||
let block = Bytes::make(4 * 8, b'\xff')
|
||||
@renderer.set_glyph_source(fn(cp, _size, _bold, _mono) {
|
||||
if cp == 0x1F422 {
|
||||
{ w: 0, h: 0, xoff: 0, yoff: 0, advance: 6, coverage: b"", embolden: false }
|
||||
} else if cp == 32 {
|
||||
{ w: 0, h: 0, xoff: 0, yoff: 0, advance: 6, coverage: b"", embolden: false }
|
||||
} else {
|
||||
{ w: 4, h: 8, xoff: 0, yoff: -8, advance: 6, coverage: block, embolden: false }
|
||||
}
|
||||
})
|
||||
@renderer.set_emoji_source(
|
||||
fn(chars, start, _bold, _mono) {
|
||||
if start < chars.length() && chars[start].to_int() == 0x1F422 {
|
||||
Some((start + 1, "🐢"))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
fn(seq, _px) { if seq == "🐢" { th } else { 0U } },
|
||||
)
|
||||
|
||||
assert_eq(@renderer.text_width("Hi 🐢", 13, false, false), 18 + epx)
|
||||
assert_eq(@renderer.text_width("Hi \u{200D}🐢\u{FE0F}", 13, false, false), 18 + epx)
|
||||
|
||||
let pm = @renderer.Pixmap::new(64, 40)
|
||||
@renderer.draw_ops(
|
||||
pm,
|
||||
[@scene.DrawOp::Text(10, 20, "Hi 🐢", 13, @scene.Rgba::new(255, 255, 255, 255), Left, false)],
|
||||
0,
|
||||
0,
|
||||
)
|
||||
// 'H' at x=10..13, y=(20 + 8/2) - 8 .. = 16..23 is white; inline turtle at x=28..28+epx-1 is olive-green.
|
||||
assert_eq(pm.pixel(11, 20), Some(@scene.Rgba::new(255, 255, 255, 255)))
|
||||
assert_eq(pm.pixel(28 + epx / 2, 20), Some(@scene.Rgba::new(110, 130, 58, 255)))
|
||||
}
|
||||
Reference in new issue
Block a user