M13.10: web frame workers fed by project diffs, offloaded Roto Brush propagation, non-blocking wait jobs, browser Media Browser

Viewer frames render in long-lived Web Workers holding a project replica
(engine::remote: structural JSON diff/patch, Mirror, FrameServer); the
frame cache hands jobs to a RemoteFrames renderer (UI-thread fallback).
Roto Brush propagation runs in a job worker and streams segmentations
back (FrameSeg binary form), relayed to frame workers. Control-channel
wait:true commands whose job is offloaded reply when it ends. The Media
Browser browses a pluggable Browser: the file system on the desktop;
browser storage and File System Access folders on the web.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 08:36:00 -04:00
co-authored by Claude Opus 5.5
parent 0f591e0856
commit 5bb6768766
23 changed files with 2197 additions and 79 deletions
+55
View File
@@ -230,6 +230,61 @@ impl FrameSeg {
}
(n > 0.0).then(|| [sx / n, sy / n])
}
/// A compact binary form (to ship a segmentation between engine instances, e.g. from a Web
/// Worker to the page): `ECSG`, width, height (u32 LE), the colour models as JSON (length
/// prefixed), then the matte and the Refine Edge band run-length encoded (u16 LE run, byte).
pub fn to_bytes(&self) -> Vec<u8> {
let models = serde_json::to_vec(&(&self.fg, &self.bg)).unwrap_or_default();
let mut out = Vec::with_capacity(16 + models.len() + 64);
out.extend_from_slice(b"ECSG");
out.extend_from_slice(&(self.w as u32).to_le_bytes());
out.extend_from_slice(&(self.h as u32).to_le_bytes());
out.extend_from_slice(&(models.len() as u32).to_le_bytes());
out.extend_from_slice(&models);
for plane in [&self.matte, &self.refine] {
let mut i = 0;
while i < plane.len() {
let v = plane[i];
let mut n = 1;
while i + n < plane.len() && plane[i + n] == v && n < u16::MAX as usize {
n += 1;
}
out.extend_from_slice(&(n as u16).to_le_bytes());
out.push(v);
i += n;
}
}
out
}
/// Inverse of [`FrameSeg::to_bytes`] (`None` for malformed input).
pub fn from_bytes(b: &[u8]) -> Option<FrameSeg> {
if b.len() < 16 || &b[..4] != b"ECSG" {
return None;
}
let u = |i: usize| u32::from_le_bytes([b[i], b[i + 1], b[i + 2], b[i + 3]]) as usize;
let (w, h, ml) = (u(4), u(8), u(12));
let n = w.checked_mul(h)?;
let models = b.get(16..16 + ml)?;
let (fg, bg): (Gmm, Gmm) = serde_json::from_slice(models).ok()?;
let mut rest = &b[16 + ml..];
let mut plane = || -> Option<Vec<u8>> {
let mut v = Vec::with_capacity(n);
while v.len() < n {
if rest.len() < 3 {
return None;
}
let run = u16::from_le_bytes([rest[0], rest[1]]) as usize;
v.resize(v.len() + run, rest[2]);
rest = &rest[3..];
}
(v.len() == n).then_some(v)
};
let matte = plane()?;
let refine = plane()?;
Some(FrameSeg { w, h, matte, refine, fg, bg })
}
}
/// Straight RGB of an image (transparent pixels are black).
+6
View File
@@ -89,6 +89,12 @@ fn strokes_segment_the_base_frame() {
// Deterministic.
let again = segment(&img, &refs, None, &SegOpts::default(), 0.0);
assert_eq!(seg, again);
// The binary form round-trips exactly and is compact (run-length encoded planes).
let bytes = seg.to_bytes();
assert_eq!(FrameSeg::from_bytes(&bytes).as_ref(), Some(&seg));
assert!(bytes.len() < seg.w * seg.h / 4, "{} bytes", bytes.len());
assert!(FrameSeg::from_bytes(&bytes[..bytes.len() - 1]).is_none());
assert!(FrameSeg::from_bytes(b"nope").is_none());
}
#[test]