From 7c5b0da99b0ea6c3a3202925d22061ea1bdea997 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Wed, 21 Oct 2026 21:37:31 +0530 Subject: [PATCH 01/99] Close, New and Open Project free the closed project's memory `Session::replace_project` (`crates/engine/src/lib.rs`), shared by Close, New, Open and the demo project: - forgets the decoded frames and decoders of the closed project's footage, as well as the new project's (the existing #1070 behaviour); - emits `Event::PurgeCaches` after the swap, so the viewers drop the RAM preview of the closed project. Its comp ids can also collide with the new project's. Cache budgets and LRU order are unchanged; only the release path changes. --- crates/engine/src/lib.rs | 10 +++-- crates/engine/src/tests_menu_cmds.rs | 58 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index cdfc7468e..4d8706bff 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1160,9 +1160,10 @@ impl Session { self.script_ui.project_epoch = self.script_ui.project_epoch.wrapping_add(1); p.fix_next_id(); upgrade_effects(&mut p); - // The media layer keys decoded frames by path: files of the new project may have changed - // since an earlier project decoded them (#1070). - for it in p.items.values() { + // Let go of what the closed project decoded (frames, decoders, models), and of what the + // new project's files decoded under an earlier project: the media layer keys them by + // path, and the files may have changed since (#1070). + for it in self.project.items.values().chain(p.items.values()) { if let effectcraft_project::ItemKind::Footage(f) = &it.kind { self.forget_decoded(f); } @@ -1174,6 +1175,9 @@ impl Session { self.path = path; self.bump(); self.mark_saved(); + // The viewers' RAM preview shows the closed project's frames, whose comp ids can collide + // with the new project's. + self.events.push(Event::PurgeCaches); let first = self.project.comps().next().map(|(id, _)| *id); if let Some(c) = first { self.open_comp(c); diff --git a/crates/engine/src/tests_menu_cmds.rs b/crates/engine/src/tests_menu_cmds.rs index 6da07dd40..83f3b609c 100644 --- a/crates/engine/src/tests_menu_cmds.rs +++ b/crates/engine/src/tests_menu_cmds.rs @@ -1767,3 +1767,61 @@ fn old_guides_load_as_pixel_guides_and_percent_round_trips() { // A zero-sized comp never divides by zero. assert!(g.px(0, 0).is_finite()); } + +#[test] +fn replacing_project_releases_old_footage() { + // A footage source that records the paths it is told to forget. + struct Recording(std::sync::Mutex>); + impl crate::render::FootageSource for Recording { + fn frame( + &self, + _: effectcraft_project::ItemId, + _: &effectcraft_project::Footage, + _: effectcraft_time::Tick, + ) -> Option> { + None + } + fn forget(&self, path: &str) { + self.0.lock().unwrap().push(path.to_string()); + } + } + let mut s = comp(); + let src = std::sync::Arc::new(Recording(Default::default())); + s.footage = src.clone(); + let recorded = || src.0.lock().unwrap().clone(); + let with_old = |s: &Session| { + let mut p = (*s.project).clone(); + p.add_item("old", Default::default(), None, ItemKind::Footage(effectcraft_project::Footage { path: "/old.mp4".into(), ..Default::default() })); + p + }; + let old = with_old(&s); + s.replace_project(old, None); + s.drain_events(); + src.0.lock().unwrap().clear(); + + // Close Project lets go of the closed project's footage and clears the RAM preview. + s.execute("file.closeProject", json!({})).unwrap(); + assert!(recorded().contains(&"/old.mp4".to_string()), "{:?}", recorded()); + assert!(s.drain_events().contains(&Event::PurgeCaches)); + + // Opening a project forgets the old project's files and the new project's. + let old = with_old(&s); + s.replace_project(old, None); + s.drain_events(); + src.0.lock().unwrap().clear(); + let mut new = effectcraft_project::Project::default(); + new.add_item("new", Default::default(), None, ItemKind::Footage(effectcraft_project::Footage { path: "/new.mp4".into(), ..Default::default() })); + s.replace_project(new, None); + let paths = recorded(); + assert!(paths.contains(&"/old.mp4".to_string()) && paths.contains(&"/new.mp4".to_string()), "{paths:?}"); + assert!(s.drain_events().contains(&Event::PurgeCaches)); + + // New Project does the same. + let old = with_old(&s); + s.replace_project(old, None); + s.drain_events(); + src.0.lock().unwrap().clear(); + s.execute("file.newProject", json!({})).unwrap(); + assert!(recorded().contains(&"/old.mp4".to_string()), "{:?}", recorded()); + assert!(s.drain_events().contains(&Event::PurgeCaches)); +} From 1dcb8273a45ac0bd9a4a3d05f78f53522e00d585 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Wed, 21 Oct 2026 21:47:06 +0530 Subject: [PATCH 02/99] Fast Previews: Adaptive Resolution applies while dragging in the Timeline `timeline::show` keeps a per-frame `dragging` flag. While the primary button is down, it sets the existing `property_interacting` for: - dragging the playhead or the timecode; - moving layer bars, or their in and out points; - dragging keys, and the key alt-scale. A click without movement doesn't set it. The existing clear at the start of each frame handles the release, so the first frame after it is sharp. With Fast Previews off (the default) or a fixed resolution, nothing changes. 9 lines of production code. --- crates/ui-egui/src/panels/timeline.rs | 9 +- crates/ui-egui/src/state.rs | 1 + .../ui-egui/tests/ui_timeline_interacting.rs | 115 ++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/tests/ui_timeline_interacting.rs diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index b34fbd9d3..1d9703ddb 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1468,6 +1468,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.line_segment([pos2(graph_x0 - 1.0, top), pos2(graph_x0 - 1.0, rect.max.y)], Stroke::new(1.0, t.app_bg)); let mut actions: Vec<(String, serde_json::Value)> = Vec::new(); + let mut dragging = false; // A drag that moves the frame on screen (Fast Previews). if !ui.input(|i| i.pointer.primary_down()) { ctx.data_mut(|d| d.remove::(switch_drag_id())); } @@ -1495,6 +1496,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.auto.add("timeline.timecode", tc_rect, &tc); super::toggle_time_display(app, &tc_resp); if tc_resp.dragged() { + dragging = true; let d = tc_resp.drag_delta().x as f64; let f = fr.frame_at(time) + (d * 0.5).round() as i64; let _ = app.session.execute("time.set", json!({"frame": f.max(0)})); @@ -1730,6 +1732,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { if ((rresp.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down())) || rresp.clicked()) && let Some(pt) = rresp.interact_pointer_pos() { + dragging |= rresp.dragged(); let mut x = pt.x; // Zoomed in, a scrub held past either end of the ruler scrolls the timeline that way // (faster the further), with the CTI at the edge (After Effects). @@ -2360,6 +2363,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { continue; } if resp.dragged() { + dragging = true; let acc_id = egui::Id::new(("bar-acc", layer.id.0, kind)); let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0)); acc += resp.drag_delta().x; @@ -3149,6 +3153,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { let (down, ptr) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos())); match ptr.filter(|_| down) { Some(ptr) => { + dragging = true; let frames = (((ptr.x - q.origin_x) as f64 / pps) / fd).round() as i64; if frames != q.applied { q.applied = frames; @@ -3171,6 +3176,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { let (down, ptr, shift) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos(), i.modifiers.shift)); match ptr.filter(|_| down) { Some(ptr) => { + dragging = true; let mut target = kd.anchor + (ptr.x - kd.origin_x) as f64 / pps; if shift { // The current time and whatever it snaps to (keys, layer ends, markers), but @@ -3474,7 +3480,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { } } } - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { + dragging |= super::graph_tools::alt_scale_active(&ctx); + if ui.input(|i| i.pointer.primary_down()) && (dragging || actions.iter().any(|(id, _)| id == "prop.set")) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 1e2f57204..206c70cf3 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -264,6 +264,7 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, + /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus diff --git a/crates/ui-egui/tests/ui_timeline_interacting.rs b/crates/ui-egui/tests/ui_timeline_interacting.rs new file mode 100644 index 000000000..29f86b6ff --- /dev/null +++ b/crates/ui-egui/tests/ui_timeline_interacting.rs @@ -0,0 +1,115 @@ +use effectcraft_engine::Session; +use effectcraft_engine::project::LayerId; +use effectcraft_ui_egui::EffectcraftApp; +use egui::{Event, Pos2, pos2, vec2}; +use egui_kittest::Harness; +use serde_json::json; + +fn harness() -> (Harness<'static, EffectcraftApp>, LayerId, u64) { + let mut session = Session::default(); + session.execute("comp.new", json!({"name": "Keys", "width": 320, "height": 180, "frameRate": 30, "duration": 4})).unwrap(); + session.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap(); + let id = session.active_comp().unwrap().layers[0].id; + for (time, value) in [(0.0, 0.0), (1.0, 100.0)] { + session.execute("prop.addKey", json!({"layer": id.0, "path": "transform/opacity", "time": time, "value": value})).unwrap(); + } + let uid = session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().uid; + session.execute("layer.select", json!({"layers": [id.0]})).unwrap(); + session.execute("view.fastPreviewMode", json!({"mode": "adaptive"})).unwrap(); + let mut harness = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session)); + harness.run_steps(3); + let context = harness.ctx.clone(); + effectcraft_ui_egui::menus::invoke(harness.state_mut(), &context, "timeline.reveal.opacity", json!({})).unwrap(); + harness.run_steps(4); + (harness, id, uid) +} + +fn rect(harness: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { + let entry = harness.state().auto.find(id).expect("timeline element"); + egui::Rect::from_min_size(pos2(entry.rect[0], entry.rect[1]), vec2(entry.rect[2], entry.rect[3])) +} + +fn keys(harness: &Harness<'_, EffectcraftApp>, uid: u64) -> Vec { + let mut positions: Vec = harness + .state() + .auto + .query(&format!("timeline.key.{uid}.")) + .iter() + .map(|entry| pos2(entry.rect[0] + entry.rect[2] / 2.0, entry.rect[1] + entry.rect[3] / 2.0)) + .collect(); + positions.sort_by(|left, right| left.x.total_cmp(&right.x)); + positions +} + +fn hold(harness: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { + harness.input_mut().events.push(Event::PointerMoved(from)); + harness.step(); + harness.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + harness.step(); + for step in 1..=10 { + harness.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); + harness.step(); + } +} + +fn release(harness: &mut Harness<'_, EffectcraftApp>, at: Pos2) { + harness.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + harness.run_steps(2); +} + +fn assert_adaptive_during_drag(harness: &Harness<'_, EffectcraftApp>) { + assert!(harness.state().ui.viewer.property_interacting); + assert!(harness.state().viewer_scale(1.0, 1.0) < 1.0); +} + +fn assert_full_resolution_after_release(harness: &Harness<'_, EffectcraftApp>) { + assert!(!harness.state().ui.viewer.property_interacting); + assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); +} + +#[test] +fn playhead_drag_uses_adaptive_resolution() { + let (mut harness, _, _) = harness(); + let ruler = rect(&harness, "timeline.ruler"); + let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); + let to = from + vec2(200.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn layer_bar_drag_uses_adaptive_resolution() { + let (mut harness, layer, _) = harness(); + let from = rect(&harness, &format!("timeline.layer.{}.bar", layer.0)).center(); + let to = from + vec2(60.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn key_drag_uses_adaptive_resolution() { + let (mut harness, _, uid) = harness(); + let from = keys(&harness, uid)[0]; + let to = from + vec2(60.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn timeline_click_keeps_full_resolution() { + let (mut harness, _, _) = harness(); + let point = rect(&harness, "timeline.ruler").center(); + harness.input_mut().events.push(Event::PointerMoved(point)); + harness.step(); + harness.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + harness.step(); + assert!(!harness.state().ui.viewer.property_interacting); + assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); + release(&mut harness, point); +} From 55dc4a6d9e57a470e20da45f3d21a2cd7fbf5e3d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 20:38:37 -0800 Subject: [PATCH 03/99] Plug-in Library: a file URL cannot name a network path A local catalog's file:// URLs were decoded into a path without checking how the path starts. A URL such as file:////server/share/x.wasm, or one whose path holds a backslash or a percent-encoded / or \, could become a network path on Windows, so reading the catalog or a release named in it contacted that host. file_url_path now refuses a decoded path that starts with two separators or holds a backslash, and a percent-encoded / or \, with an error that names the reason. Local paths and drive-letter paths are read as before. The library.refresh params text, docs/plugins.md and docs/publishing-plugins.md say so. --- crates/engine/src/system/library.rs | 80 ++++++++++++++++++++++++----- docs/plugins.md | 3 +- docs/publishing-plugins.md | 4 +- 3 files changed, 72 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 750ed600a..23063957f 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -324,27 +324,44 @@ enum Source { File(PathBuf), } -/// `file:///C:/x` or `file:///home/x` as a path (percent-decoded; no remote hosts). -fn file_url_path(url: &str) -> Option { - let rest = url.strip_prefix("file://")?; +/// `file:///C:/x` or `file:///home/x` as a path (percent-decoded; no remote hosts). A path that +/// starts with two separators or holds a `\` (raw or percent-encoded), or a percent-encoded `/`, +/// is refused: on Windows such a path can name a network share, and reading it contacts that host. +fn file_url_path(url: &str) -> std::result::Result { + let bad = |why: &str| format!("bad file URL `{url}`: {why}"); + let rest = url.strip_prefix("file://").ok_or_else(|| bad("it doesn't start with file://"))?; let rest = rest.strip_prefix("localhost").unwrap_or(rest); if !rest.starts_with('/') { - return None; + return Err(bad("only local files can be read (file:///path)")); } let b = rest.as_bytes(); // `/C:/…` on Windows. - let rest = if b.len() > 2 && b.get(2) == Some(&b':') { rest.get(1..)? } else { rest }; + let rest = + if b.get(1).is_some_and(u8::is_ascii_alphabetic) && b.get(2) == Some(&b':') { rest.get(1..).ok_or_else(|| bad("bad drive letter"))? } else { rest }; let mut out = Vec::with_capacity(rest.len()); let mut bytes = rest.bytes(); while let Some(c) = bytes.next() { if c == b'%' { - let hex = [bytes.next()?, bytes.next()?]; - out.push(u8::from_str_radix(std::str::from_utf8(&hex).ok()?, 16).ok()?); + let hex = [bytes.next(), bytes.next()]; + let [Some(hi), Some(lo)] = hex else { return Err(bad("a % isn't followed by two hex digits")) }; + let byte = + std::str::from_utf8(&[hi, lo]).ok().and_then(|h| u8::from_str_radix(h, 16).ok()).ok_or_else(|| bad("a % isn't followed by two hex digits"))?; + if matches!(byte, b'/' | b'\\') { + return Err(bad("a percent-encoded / or \\ isn't allowed")); + } + out.push(byte); } else { out.push(c); } } - String::from_utf8(out).ok().map(PathBuf::from) + let path = String::from_utf8(out).map_err(|_| bad("the path isn't UTF-8"))?; + if path.contains('\\') { + return Err(bad("use / between folders, not \\")); + } + if path.starts_with("//") { + return Err(bad("network paths can't be read, only local files")); + } + Ok(PathBuf::from(path)) } /// Check `url` against the rules: `https://` on GitHub's hosts; `file://` when the catalog @@ -359,7 +376,7 @@ fn source(url: &str, catalog: Option<&str>) -> std::result::Result Vec { "Refresh Plug-in Catalog", [], None, - "{catalog?: https:// or file:// URL of an index.json (default: the community catalog), wait?}", + "{catalog?: https:// or file:// URL of an index.json (default: the community catalog; file:// takes a local path, not a network path such as //server/share), wait?}", always, refresh ), @@ -1177,10 +1194,47 @@ mod tests { assert_eq!(source("file:///C:/p/x.wasm", None), Ok(Source::File(PathBuf::from("C:/p/x.wasm")))); assert!(source("file://", None).is_err()); // Percent-decoded; no remote hosts. - assert_eq!(file_url_path("file:///C:/My%20Plug-ins/Jos%C3%A9%23.wasm"), Some(PathBuf::from("C:/My Plug-ins/José#.wasm"))); - assert_eq!(file_url_path("file://localhost/home/x.wasm"), Some(PathBuf::from("/home/x.wasm"))); + assert_eq!(file_url_path("file:///C:/My%20Plug-ins/Jos%C3%A9%23.wasm"), Ok(PathBuf::from("C:/My Plug-ins/José#.wasm"))); + assert_eq!(file_url_path("file://localhost/home/x.wasm"), Ok(PathBuf::from("/home/x.wasm"))); for no in ["file://server/share/x.wasm", "file:///bad%2", "file:///bad%zz"] { - assert_eq!(file_url_path(no), None, "{no}"); + assert!(file_url_path(no).is_err(), "{no}"); + } + } + + #[test] + fn file_urls_cannot_name_a_network_path() { + for ok in [ + ("file:///C:/p/x.wasm", "C:/p/x.wasm"), + ("file:///c:/p/x.wasm", "c:/p/x.wasm"), + ("file:///home/me/x.wasm", "/home/me/x.wasm"), + ("file://localhost/C:/p/x.wasm", "C:/p/x.wasm"), + ("file:///home/me/a%20b/x.wasm", "/home/me/a b/x.wasm"), + ("file:///C:/p//x.wasm", "C:/p//x.wasm"), + ] { + assert_eq!(file_url_path(ok.0), Ok(PathBuf::from(ok.1)), "{}", ok.0); + } + for no in [ + // Two separators at the start: `//server/share/…`. + "file:////server/share/x.wasm", + "file://localhost//server/share/x.wasm", + "file://///server/share/x.wasm", + "file:////:x.wasm", + // Backslashes, raw or percent-encoded. + "file:///\\\\server\\share\\x.wasm", + "file:///\\server/share/x.wasm", + "file:///C:\\p\\x.wasm", + "file:///%5C%5Cserver/share/x.wasm", + "file:///%5c%5cserver/share/x.wasm", + "file:///C:/p%5Cx.wasm", + // Percent-encoded slashes. + "file:///%2F%2Fserver/share/x.wasm", + "file:///%2fserver/share/x.wasm", + "file:///C:/p%2Fx.wasm", + ] { + let e = file_url_path(no).expect_err(no); + assert!(e.starts_with("bad file URL"), "{no}: {e}"); + assert!(source(no, None).is_err(), "{no}"); + assert!(source(no, Some("file:///tmp/index.json")).is_err(), "{no}"); } } diff --git a/docs/plugins.md b/docs/plugins.md index 3fd8cf944..d7df3d8b1 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -369,7 +369,8 @@ package can't read files, open the network or crash the app. [`storytold/effectcraft-plugins`](https://github.com/storytold/effectcraft-plugins) repository; packages are added by pull request and reviewed there. The app has no field for another catalog; `library.refresh {catalog}` (for plug-in authors testing an entry) takes an `index.json` - on GitHub or a local file, and the page then says it shows a test catalog until Refresh. + on GitHub or a local file, and the page then says it shows a test catalog until Refresh. A file + URL that names a network path (`file:////server/share/…`) is refused. * **Nothing is downloaded until you ask.** Fetch Catalog (`library.refresh`) reads the catalog; Install (`library.install`) downloads the package's `.wasm`, checks its SHA-256 (and its size, when the catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index bd76c3ab5..0083293b6 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -226,7 +226,9 @@ Make a folder with an `index.json` that holds only your package: ``` File URLs are absolute: `file:///home/me/glow-rings/index.json` on Linux and macOS, -`file:///C:/Users/me/glow-rings/index.json` on Windows. Write a space as `%20`. +`file:///C:/Users/me/glow-rings/index.json` on Windows. Write a space as `%20`. Separate folders +with `/`: a file URL that holds a `\` or a percent-encoded `/` or `\`, or names a network path +(`file:////server/share/…`), is refused. Use a separate settings folder, so the test doesn't touch your real installation: From 75fed052e3dcb5cd876729863bc5e292aaca022c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 21:51:04 -0800 Subject: [PATCH 04/99] Plug-in Library: a package downloads only release assets of its repository A catalog release's url was checked only for its host: any https:// URL on GitHub's hosts was downloaded, from any repository and any path, including a raw file on a branch or a path with dot segments that curl resolves to another repository. library.install, library.update and library.preview now refuse a url that isn't https://github.com///releases/download//. When the package's repo is a https://github.com// URL, the asset must be in that repository (owner and name compared without case). Dot segments, also percent-encoded, empty segments, backslashes, queries and fragments are refused. file:// releases from a local catalog are read as before, and the SHA-256 and size checks are unchanged. A catalog other than the community one is still read only when library.refresh names it (https:// on GitHub's hosts, or a local file://). docs/plugins.md, docs/publishing-plugins.md and the library.install params text describe the rules. --- crates/engine/src/system/library.rs | 98 ++++++++++++++++++++++++++++- crates/host/tests/it/library.rs | 32 ++++++++++ docs/plugins.md | 6 +- docs/publishing-plugins.md | 2 +- 4 files changed, 134 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 750ed600a..0e55c8acb 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -255,6 +255,58 @@ fn release_problem(r: &Release) -> Option { None } +/// An owner or repository name on GitHub: letters, digits, `.`, `-`, `_`, and not `.` or `..`. +fn valid_repo_part(p: &str) -> bool { + !p.is_empty() && p != "." && p != ".." && p.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-".contains(&b)) +} + +/// The rest of `s` after `prefix`, ignoring ASCII case. +fn strip_prefix_ignore_case<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { + let head = s.get(..prefix.len())?; + head.eq_ignore_ascii_case(prefix).then(|| s.get(prefix.len()..)).flatten() +} + +/// `(owner, name)` in lower case of a `https://github.com//` repository URL (an +/// optional trailing `/` or `.git`); `None` for anything else. +fn github_repo(repo: &str) -> Option<(String, String)> { + let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; + let rest = rest.strip_suffix('/').unwrap_or(rest); + let rest = rest.strip_suffix(".git").unwrap_or(rest); + let mut parts = rest.split('/'); + let (owner, name) = (parts.next()?, parts.next()?); + (parts.next().is_none() && valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) +} + +/// Why an `https://` release URL can't be used, if it can't: it must be a release asset, +/// `https://github.com///releases/download//`, and when the package's +/// `repo` is a GitHub repository URL, `/` must be that repository. +fn release_url_problem(repo: &str, url: &str) -> Option { + let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); + let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; + if rest.contains(['?', '#', '\\']) { + return not_asset(); + } + let parts: Vec<&str> = rest.split('/').collect(); + // `.` and `..` (also percent-encoded) would move the download to another path. + let dot_segment = |p: &&str| { + let p = p.to_ascii_lowercase().replace("%2e", "."); + p == "." || p == ".." + }; + if parts.len() < 6 || parts.iter().any(|p| p.is_empty() || dot_segment(p)) { + return not_asset(); + } + let (Some(owner), Some(name), Some(releases), Some(download)) = (parts.first(), parts.get(1), parts.get(2), parts.get(3)) else { return not_asset() }; + if !valid_repo_part(owner) || !valid_repo_part(name) || *releases != "releases" || *download != "download" { + return not_asset(); + } + match github_repo(repo) { + Some((o, n)) if o != owner.to_ascii_lowercase() || n != name.to_ascii_lowercase() => { + Some(format!("`{url}` isn't a release asset of the package's repository {}", repo.trim())) + } + _ => None, + } +} + /// Read a catalog: packages and releases that are malformed are left out (and reported), so one /// bad entry doesn't hide the others. pub fn parse_catalog(bytes: &[u8]) -> std::result::Result<(Catalog, Vec), String> { @@ -799,7 +851,11 @@ fn pick(s: &Session, c: &str, p: &Value) -> Result<(String, Package, Release)> { ), )); } - source(&rel.url, Some(&url)).map_err(|e| bad(c, e))?; + if let Source::Https(u) = source(&rel.url, Some(&url)).map_err(|e| bad(c, e))? + && let Some(why) = release_url_problem(&pkg.repo, &u) + { + return Err(bad(c, why)); + } Ok((url, pkg, rel)) } @@ -1049,7 +1105,7 @@ pub fn specs() -> Vec { "Install Plug-in", [], None, - "{id, version?, wait?} — downloads the release, checks its SHA-256 against the catalog, loads it", + "{id, version?, wait?} — downloads the release (a GitHub release asset, in the package's repo when it names one), checks its SHA-256 against the catalog, loads it", always, install ), @@ -1132,6 +1188,44 @@ mod tests { assert!(latest_compatible(&Package::default()).is_none()); } + #[test] + fn release_urls_are_assets_of_the_declared_repository() { + let asset = "https://github.com/Me/Glow/releases/download/v1.0.0/glow.wasm"; + for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", "", "https://gitlab.com/me/glow"] { + assert_eq!(release_url_problem(repo, asset), None, "{repo}"); + } + assert_eq!(release_url_problem("", "https://github.com/a/b/releases/download/tags/v1/x.wasm"), None, "a tag with a slash"); + assert!( + release_url_problem("https://github.com/me/glow", "https://github.com/me/other/releases/download/v1/x.wasm") + .unwrap() + .contains("package's repository") + ); + assert!(release_url_problem("https://github.com/me/glow", "https://github.com/you/glow/releases/download/v1/x.wasm").is_some()); + for no in [ + "https://raw.githubusercontent.com/me/glow/main/x.wasm", + "https://objects.githubusercontent.com/x.wasm", + "https://github.com/me/glow/blob/main/x.wasm", + "https://github.com/me/glow/releases/download/v1", + "https://github.com/me/glow/releases/download//x.wasm", + "https://github.com/me/glow/releases/download/v1/x.wasm?x=1", + "https://github.com/me/glow/releases/download/v1/x.wasm#x", + "https://github.com/me/glow/releases/download/../../../you/evil/releases/download/v1/x.wasm", + "https://github.com/me/glow/releases/download/%2e%2e/%2E./x/y/x.wasm", + "https://github.com/me/glow/releases/download/./v1/x.wasm", + "https://github.com/me/glow/releases/download/v1\\x.wasm", + "https://github.com/m e/glow/releases/download/v1/x.wasm", + "https://github.com/../glow/releases/download/v1/x.wasm", + "https://github.com.evil.com/me/glow/releases/download/v1/x.wasm", + ] { + assert!(release_url_problem("https://github.com/me/glow", no).is_some(), "{no}"); + assert!(release_url_problem("", no).is_some(), "{no}"); + } + assert_eq!(github_repo("https://github.com/Me/Glow.git"), Some(("me".into(), "glow".into()))); + for no in ["https://github.com/me", "https://github.com/me/glow/tree/main", "http://github.com/me/glow", "me/glow"] { + assert_eq!(github_repo(no), None, "{no}"); + } + } + #[test] fn catalogs_leave_out_bad_entries() { let good = "a".repeat(64); diff --git a/crates/host/tests/it/library.rs b/crates/host/tests/it/library.rs index 4cd94ecdd..f5bd613cc 100644 --- a/crates/host/tests/it/library.rs +++ b/crates/host/tests/it/library.rs @@ -156,6 +156,38 @@ fn a_wrong_checksum_or_a_bad_module_installs_nothing() { let _ = std::fs::remove_dir_all(&dir); } +#[test] +fn downloads_are_release_assets_of_the_package_repository() { + let dir = tmp("assets"); + let sum = "0".repeat(64); + let pkg = + |id: &str, repo: &str, url: &str| json!({"id": id, "name": id, "repo": repo, "versions": [{"version": "1", "api": 1, "url": url, "sha256": sum}]}); + let catalog = write_catalog( + &dir, + json!([ + pkg("org.test.other", "https://github.com/me/glow", "https://github.com/someone/else/releases/download/v1/glow.wasm"), + pkg("org.test.raw", "https://github.com/me/glow", "https://raw.githubusercontent.com/me/glow/main/glow.wasm"), + pkg("org.test.page", "", "https://github.com/me/glow/blob/main/glow.wasm"), + pkg("org.test.dots", "https://github.com/me/glow", "https://github.com/me/glow/releases/download/%2e%2e/%2E%2E/x/y/glow.wasm"), + ]), + ); + let mut s = session(&dir); + s.execute("library.refresh", json!({"catalog": catalog, "wait": true})).unwrap(); + for (id, why) in [ + ("org.test.other", "isn't a release asset of the package's repository https://github.com/me/glow"), + ("org.test.raw", "isn't a release asset"), + ("org.test.page", "isn't a release asset"), + ("org.test.dots", "isn't a release asset"), + ] { + for c in ["library.install", "library.preview"] { + let e = s.execute(c, json!({"id": id, "wait": true})).unwrap_err().to_string(); + assert!(e.contains(why), "{c} {id}: {e}"); + } + } + assert!(!dir.join("Plug-ins").join("Library").join("installed.json").exists()); + let _ = std::fs::remove_dir_all(&dir); +} + #[test] fn installed_packages_load_at_start_and_changed_files_are_refused() { let dir = tmp("startup"); diff --git a/docs/plugins.md b/docs/plugins.md index 3fd8cf944..99b91874f 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -374,7 +374,11 @@ package can't read files, open the network or crash the app. Install (`library.install`) downloads the package's `.wasm`, checks its SHA-256 (and its size, when the catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, `https://` only and starting on GitHub's hosts (redirects stay on `https://`; the SHA-256 check - is what guarantees the file). + is what guarantees the file). A package's `url` must be a release asset + (`https://github.com///releases/download/…`), in the package's `repo` when that is + a GitHub repository URL. A catalog other than the community one is read only when + `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a + local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to the settings), listed in `Library/installed.json`. Installed packages load at start-up, each checked against the SHA-256 it was installed with. The catalog last fetched is kept as diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index bd76c3ab5..c94f9e2a8 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -193,7 +193,7 @@ Release fields (one per entry in `versions`): | `version` | yes | Dotted numbers only, at most 32 characters: `1.0.0`, `1.2`. No `v` and no suffixes such as `-beta`. | | `api` | yes | The plug-in API the module implements: `1`. | | `minApp` | no | The oldest EffectCraft version the release needs (`0.17.0`). Leave it out if any version with this API works. | -| `url` | yes | The release asset's `https://` URL on GitHub. | +| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When `repo` is a `https://github.com//` URL, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | | `sha256` | yes | The file's SHA-256, 64 hex digits. | | `size` | no, but reviewed | The file's size in bytes. When it is given, a download of another size is refused. | | `effects` | yes | The effect ids the module registers (its manifest's `id`). EffectCraft uses them to find the package that provides an effect a project needs. | From 5dfcadd09bbca14eb53ec52694995eac4199f1be Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 23:24:20 -0800 Subject: [PATCH 05/99] Plug-in Library: a package with an unreadable repo URL downloads nothing When a package names a `repo` that isn't a GitHub repository URL (`https://github.com//`, a trailing `/` or `.git` allowed, or a folder in one, `.../tree//`), Install, Update and Preview now refuse its release URLs with an error naming the package. Before, such a `repo` skipped the repository check and any GitHub release asset was downloaded. A package without a `repo` keeps any repository's release asset. The example catalog's schema now holds `repo` and release `url` to the same forms, and `scripts/validate.sh` checks that every release is an asset of the package's `repo` before it downloads anything. --- crates/engine/src/system/library.rs | 100 ++++++++++++++++---- crates/host/tests/it/library.rs | 6 ++ docs/plugins.md | 6 +- docs/publishing-plugins.md | 4 +- examples/plugin-catalog/schema.json | 8 +- examples/plugin-catalog/scripts/validate.sh | 22 ++++- 6 files changed, 117 insertions(+), 29 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 0e55c8acb..d1eaaf0bd 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -266,20 +266,33 @@ fn strip_prefix_ignore_case<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { head.eq_ignore_ascii_case(prefix).then(|| s.get(prefix.len()..)).flatten() } +/// A `.` or `..` path segment, also percent-encoded. +fn dot_segment(p: &str) -> bool { + let p = p.to_ascii_lowercase().replace("%2e", "."); + p == "." || p == ".." +} + /// `(owner, name)` in lower case of a `https://github.com//` repository URL (an -/// optional trailing `/` or `.git`); `None` for anything else. +/// optional trailing `/` or `.git`) or of a folder in one, `https://github.com///tree//`; +/// `None` for anything else. fn github_repo(repo: &str) -> Option<(String, String)> { let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; + if rest.contains(['?', '#', '\\']) { + return None; + } let rest = rest.strip_suffix('/').unwrap_or(rest); - let rest = rest.strip_suffix(".git").unwrap_or(rest); - let mut parts = rest.split('/'); - let (owner, name) = (parts.next()?, parts.next()?); - (parts.next().is_none() && valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) + let parts: Vec<&str> = rest.split('/').collect(); + let (owner, name) = match parts.as_slice() { + [owner, name] => (*owner, name.strip_suffix(".git").unwrap_or(name)), + [owner, name, "tree", folder @ ..] if !folder.is_empty() && folder.iter().all(|p| !p.is_empty() && !dot_segment(p)) => (*owner, *name), + _ => return None, + }; + (valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) } /// Why an `https://` release URL can't be used, if it can't: it must be a release asset, -/// `https://github.com///releases/download//`, and when the package's -/// `repo` is a GitHub repository URL, `/` must be that repository. +/// `https://github.com///releases/download//`, and when the package +/// names a `repo`, that must be a GitHub repository URL (see [`github_repo`]) of `/`. fn release_url_problem(repo: &str, url: &str) -> Option { let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; @@ -287,11 +300,9 @@ fn release_url_problem(repo: &str, url: &str) -> Option { return not_asset(); } let parts: Vec<&str> = rest.split('/').collect(); - // `.` and `..` (also percent-encoded) would move the download to another path. - let dot_segment = |p: &&str| { - let p = p.to_ascii_lowercase().replace("%2e", "."); - p == "." || p == ".." - }; + // At least six segments, not exactly six: a tag may contain `/` (`release/v1`), and its assets are + // then at `releases/download/release/v1/`. `.` and `..` (also percent-encoded) would move + // the download to another path. if parts.len() < 6 || parts.iter().any(|p| p.is_empty() || dot_segment(p)) { return not_asset(); } @@ -299,11 +310,16 @@ fn release_url_problem(repo: &str, url: &str) -> Option { if !valid_repo_part(owner) || !valid_repo_part(name) || *releases != "releases" || *download != "download" { return not_asset(); } + let repo = repo.trim(); + if repo.is_empty() { + return None; + } match github_repo(repo) { - Some((o, n)) if o != owner.to_ascii_lowercase() || n != name.to_ascii_lowercase() => { - Some(format!("`{url}` isn't a release asset of the package's repository {}", repo.trim())) - } - _ => None, + Some((o, n)) if o == owner.to_ascii_lowercase() && n == name.to_ascii_lowercase() => None, + Some(_) => Some(format!("`{url}` isn't a release asset of the package's repository {repo}")), + None => Some(format!( + "the package's `repo` {repo} isn't a GitHub repository URL (https://github.com//), so `{url}` can't be checked against it" + )), } } @@ -854,7 +870,7 @@ fn pick(s: &Session, c: &str, p: &Value) -> Result<(String, Package, Release)> { if let Source::Https(u) = source(&rel.url, Some(&url)).map_err(|e| bad(c, e))? && let Some(why) = release_url_problem(&pkg.repo, &u) { - return Err(bad(c, why)); + return Err(bad(c, format!("{}: {why}", pkg.name))); } Ok((url, pkg, rel)) } @@ -1191,7 +1207,7 @@ mod tests { #[test] fn release_urls_are_assets_of_the_declared_repository() { let asset = "https://github.com/Me/Glow/releases/download/v1.0.0/glow.wasm"; - for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", "", "https://gitlab.com/me/glow"] { + for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", ""] { assert_eq!(release_url_problem(repo, asset), None, "{repo}"); } assert_eq!(release_url_problem("", "https://github.com/a/b/releases/download/tags/v1/x.wasm"), None, "a tag with a slash"); @@ -1221,11 +1237,57 @@ mod tests { assert!(release_url_problem("", no).is_some(), "{no}"); } assert_eq!(github_repo("https://github.com/Me/Glow.git"), Some(("me".into(), "glow".into()))); - for no in ["https://github.com/me", "https://github.com/me/glow/tree/main", "http://github.com/me/glow", "me/glow"] { + assert_eq!(github_repo("https://github.com/Me/Glow/tree/main/plugins/glow"), Some(("me".into(), "glow".into()))); + for no in ["https://github.com/me", "https://github.com/me/glow/tree", "http://github.com/me/glow", "me/glow"] { assert_eq!(github_repo(no), None, "{no}"); } } + #[test] + fn a_repo_that_isnt_a_github_repository_url_refuses_every_release() { + let asset = "https://github.com/me/glow/releases/download/v1/glow.wasm"; + for repo in [ + "https://github.com/me/glow", + "https://github.com/me/glow/", + "https://github.com/me/glow.git", + "https://github.com/me/glow.git/", + " https://github.com/ME/glow ", + "https://github.com/me/glow/tree/main", + "https://github.com/me/glow/tree/main/plugins/glow/", + "", + " ", + ] { + assert_eq!(release_url_problem(repo, asset), None, "{repo:?}"); + } + let elsewhere = release_url_problem("https://github.com/me/glow/tree/main", "https://github.com/you/evil/releases/download/v1/glow.wasm"); + assert!(elsewhere.as_deref().is_some_and(|w| w.contains("package's repository")), "{elsewhere:?}"); + for repo in [ + "https://github.com/me/glow/tree", + "https://github.com/me/glow/tree/", + "https://github.com/me/glow/tree//x", + "https://github.com/me/glow/tree/main/../../you/evil", + "https://github.com/me/glow/tree/main/%2e%2e", + "https://github.com/me/glow/blob/main/README.md", + "https://github.com/me/glow.git/x", + "https://github.com/me/glow/releases", + "https://github.com/me/glow//", + "https://github.com/me", + "https://github.com/me/", + "http://github.com/me/glow", + "github.com/me/glow", + "me/glow", + "https://www.github.com/me/glow", + "https://gitlab.com/me/glow", + "https://github.com/me/glow?tab=readme", + "https://github.com/me/glow#readme", + "https://github.com/me/gl ow", + "https://github.com/me/..", + ] { + let why = release_url_problem(repo, asset); + assert!(why.as_deref().is_some_and(|w| w.contains("isn't a GitHub repository URL")), "{repo:?}: {why:?}"); + } + } + #[test] fn catalogs_leave_out_bad_entries() { let good = "a".repeat(64); diff --git a/crates/host/tests/it/library.rs b/crates/host/tests/it/library.rs index f5bd613cc..35cbf74a7 100644 --- a/crates/host/tests/it/library.rs +++ b/crates/host/tests/it/library.rs @@ -169,6 +169,9 @@ fn downloads_are_release_assets_of_the_package_repository() { pkg("org.test.raw", "https://github.com/me/glow", "https://raw.githubusercontent.com/me/glow/main/glow.wasm"), pkg("org.test.page", "", "https://github.com/me/glow/blob/main/glow.wasm"), pkg("org.test.dots", "https://github.com/me/glow", "https://github.com/me/glow/releases/download/%2e%2e/%2E%2E/x/y/glow.wasm"), + pkg("org.test.tree", "https://github.com/me/glow/tree/main", "https://github.com/someone/else/releases/download/v1/glow.wasm"), + pkg("org.test.http", "http://github.com/me/glow", "https://github.com/me/glow/releases/download/v1/glow.wasm"), + pkg("org.test.blob", "https://github.com/me/glow/blob/main/README.md", "https://github.com/me/glow/releases/download/v1/glow.wasm"), ]), ); let mut s = session(&dir); @@ -178,6 +181,9 @@ fn downloads_are_release_assets_of_the_package_repository() { ("org.test.raw", "isn't a release asset"), ("org.test.page", "isn't a release asset"), ("org.test.dots", "isn't a release asset"), + ("org.test.tree", "isn't a release asset of the package's repository https://github.com/me/glow/tree/main"), + ("org.test.http", "org.test.http: the package's `repo` http://github.com/me/glow isn't a GitHub repository URL"), + ("org.test.blob", "org.test.blob: the package's `repo` https://github.com/me/glow/blob/main/README.md isn't a GitHub repository URL"), ] { for c in ["library.install", "library.preview"] { let e = s.execute(c, json!({"id": id, "wait": true})).unwrap_err().to_string(); diff --git a/docs/plugins.md b/docs/plugins.md index 99b91874f..5302b0b3c 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -375,8 +375,10 @@ package can't read files, open the network or crash the app. catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, `https://` only and starting on GitHub's hosts (redirects stay on `https://`; the SHA-256 check is what guarantees the file). A package's `url` must be a release asset - (`https://github.com///releases/download/…`), in the package's `repo` when that is - a GitHub repository URL. A catalog other than the community one is read only when + (`https://github.com///releases/download/…`). When the package names a `repo`, the + asset must be in that repository. A `repo` that isn't `https://github.com//` (with + an optional trailing `/` or `.git`) or a folder in one (`https://github.com///tree//…`) + makes Install and Preview refuse every release of the package. A catalog other than the community one is read only when `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index c94f9e2a8..c28554f14 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -181,7 +181,7 @@ Package fields: | `author` | no | You, or your group. | | `description` | no, but reviewed | One or two plain sentences that say what the effect does. | | `license` | no, but reviewed | The licence's SPDX id (`MIT`, `Apache-2.0`, `MIT OR Apache-2.0`…). | -| `repo` | no, but reviewed | The public source repository. The details' "Open on GitHub" opens it. | +| `repo` | no, but reviewed | The public source repository, as `https://github.com//` (a trailing `/` or `.git` is allowed), or a folder in it, `https://github.com///tree//`. The details' "Open on GitHub" opens it. When `repo` is given in any other form, Install and Preview refuse every release of the package. | | `tags` | no | Lower-case words for the tag filter (`blur`, `stylize`, `light`, `distort`…). Reuse tags the catalog already has. | | `preview.video` | no | An `https://` link to a short demo video on YouTube, Vimeo or GitHub. "Watch video" opens it in the browser. A link that isn't `https://` (or is longer than 500 characters) is left out. The live preview doesn't need it. | | `versions` | yes | One entry per release, newest or oldest first. | @@ -193,7 +193,7 @@ Release fields (one per entry in `versions`): | `version` | yes | Dotted numbers only, at most 32 characters: `1.0.0`, `1.2`. No `v` and no suffixes such as `-beta`. | | `api` | yes | The plug-in API the module implements: `1`. | | `minApp` | no | The oldest EffectCraft version the release needs (`0.17.0`). Leave it out if any version with this API works. | -| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When `repo` is a `https://github.com//` URL, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | +| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When the package has a `repo`, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | | `sha256` | yes | The file's SHA-256, 64 hex digits. | | `size` | no, but reviewed | The file's size in bytes. When it is given, a download of another size is refused. | | `effects` | yes | The effect ids the module registers (its manifest's `id`). EffectCraft uses them to find the package that provides an effect a project needs. | diff --git a/examples/plugin-catalog/schema.json b/examples/plugin-catalog/schema.json index a2d30676b..5fe914d86 100644 --- a/examples/plugin-catalog/schema.json +++ b/examples/plugin-catalog/schema.json @@ -12,9 +12,9 @@ }, "$defs": { "version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"}, - "github_url": { + "release_url": { "type": "string", - "pattern": "^https://(github\\.com|raw\\.githubusercontent\\.com|objects\\.githubusercontent\\.com|release-assets\\.githubusercontent\\.com)/[^\\s]+$" + "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s]+(/[^/?#\\\\\\s]+)+$" }, "package": { "type": "object", @@ -26,7 +26,7 @@ "author": {"type": "string"}, "description": {"type": "string"}, "license": {"type": "string"}, - "repo": {"type": "string", "pattern": "^https://"}, + "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s]+)+)?/?$"}, "tags": {"type": "array", "items": {"type": "string"}}, "preview": { "type": "object", @@ -44,7 +44,7 @@ "version": {"$ref": "#/$defs/version"}, "api": {"type": "integer", "minimum": 0, "maximum": 4294967295}, "minApp": {"$ref": "#/$defs/version"}, - "url": {"$ref": "#/$defs/github_url"}, + "url": {"$ref": "#/$defs/release_url"}, "sha256": {"type": "string", "pattern": "^[0-9a-fA-F]{64}$"}, "size": {"type": "integer", "minimum": 1, "maximum": 67108864}, "effects": {"type": "array", "minItems": 1, "items": {"type": "string", "pattern": "^(?!ec\\.)[A-Za-z0-9._-]+$"}} diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 40e37de7f..60686330a 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -42,7 +42,25 @@ dups=$(jq -r '.packages[].id' "$catalog" | sort | uniq -d) [ -z "$dups" ] || fail "duplicate package ids: $dups" echo "ok" -echo "== 3. downloads" +echo "== 3. release URLs" +# When a package has a `repo`, every release must be an asset of that repository, as Install and +# Preview require (the loader step installs from file:// copies, which skip this check). +bad=$(jq -r ' + # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. + def repo_of: + (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") + // capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/[^?#]+$") + | select(.h | ascii_downcase == "https://github.com") | "\(.o)/\(.n)" | ascii_downcase) // "?"; + .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo + | select($repo != "") | ($repo | repo_of) as $want + | .versions[] | select(.url | startswith("file://") | not) + | ((.url | ascii_downcase | capture("^https://github\\.com/(?[^/]+)/(?[^/]+)/releases/download/") | "\(.o)/\(.n)") // "?") as $got + | select($want == "?" or $got != $want) + | "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)"' "$catalog") +[ -z "$bad" ] || fail "release URLs outside the package's repo:"$'\n'"$bad" +echo "ok" + +echo "== 4. downloads" # The checked files are what the loader step installs: a copy of the catalog names them by file://. local_catalog=$(jq '.' "$catalog") while IFS=$'\t' read -r p r id version url sha size; do @@ -58,7 +76,7 @@ done < <(jq -r '.packages | to_entries[] | .key as $p | .value as $pkg | $pkg.ve | [$p, .key, $pkg.id, .value.version, .value.url, .value.sha256, (.value.size // "")] | @tsv' "$catalog") echo "ok" -echo "== 4. load with EffectCraft" +echo "== 5. load with EffectCraft" if [ -z "${EFFECTCRAFT_CLI:-}" ]; then echo "skipped (set EFFECTCRAFT_CLI to an effectcraft-cli build)" exit 0 From 400187f9d91b4b2e9b6995f5afb19b4bba053390 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 23:59:53 -0800 Subject: [PATCH 06/99] Plug-in Library: the catalog validator refuses dot and empty folder segments in repo `scripts/validate.sh` now reads a `repo` folder URL (`https://github.com///tree//`) as EffectCraft does: an empty, `.` or `..` segment (also percent-encoded), or a `?`, `#` or `\`, makes the `repo` unreadable, and every release of the package is reported. A `.` or `..` owner or name is refused too. The check now matches the app when the schema step is skipped. --- examples/plugin-catalog/scripts/validate.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 60686330a..6e57e05ce 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -46,11 +46,15 @@ echo "== 3. release URLs" # When a package has a `repo`, every release must be an asset of that repository, as Install and # Preview require (the loader step installs from file:// copies, which skip this check). bad=$(jq -r ' + # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). + def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. def repo_of: (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") - // capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/[^?#]+$") - | select(.h | ascii_downcase == "https://github.com") | "\(.o)/\(.n)" | ascii_downcase) // "?"; + // (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/(?[^?#\\\\]+?)/?$") + | select(.f | split("/") | any(bad_segment) | not)) + | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) + | "\(.o)/\(.n)" | ascii_downcase) // "?"; .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo | select($repo != "") | ($repo | repo_of) as $want | .versions[] | select(.url | startswith("file://") | not) From cc90ad0c3b2f36c5ade8b4d9620f6e5afba0bf32 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 6 Nov 2026 00:32:31 -0800 Subject: [PATCH 07/99] Plug-in Library: the catalog validator checks every remote release URL in full scripts/validate.sh now refuses any release URL other than a local file:// path that isn't a release asset (https://github.com///releases/download// with no query, fragment, backslash, or empty, . or .. segment), for packages without a repo too, as Install and Preview do. docs/plugins.md says the release URL rules don't apply to file:// releases from a local catalog. --- docs/plugins.md | 4 ++- examples/plugin-catalog/scripts/validate.sh | 28 +++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index 5302b0b3c..cc4f164aa 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -378,7 +378,9 @@ package can't read files, open the network or crash the app. (`https://github.com///releases/download/…`). When the package names a `repo`, the asset must be in that repository. A `repo` that isn't `https://github.com//` (with an optional trailing `/` or `.git`) or a folder in one (`https://github.com///tree//…`) - makes Install and Preview refuse every release of the package. A catalog other than the community one is read only when + makes Install and Preview refuse every `https://` release of the package. These rules don't apply + to a release whose `url` is a local `file://` path, which only a local catalog may name (to test + an entry before its release is published). A catalog other than the community one is read only when `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 6e57e05ce..4a0d196fc 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -43,11 +43,24 @@ dups=$(jq -r '.packages[].id' "$catalog" | sort | uniq -d) echo "ok" echo "== 3. release URLs" -# When a package has a `repo`, every release must be an asset of that repository, as Install and -# Preview require (the loader step installs from file:// copies, which skip this check). +# Every release that isn't a local file:// path must be a release asset, and when its package has +# a `repo`, an asset of that repository, as Install and Preview require (the loader step installs +# from file:// copies, which skip this check). bad=$(jq -r ' # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); + # "owner/name" in lower case of a release asset, + # https://github.com///releases/download// (a tag may contain `/`), with + # no query, fragment, backslash, or empty, `.` or `..` segment; "?" for anything else. + def asset_of: + if startswith("https://") and (.[8:19] | ascii_downcase) == "github.com/" then + .[19:] as $rest + | ($rest | split("/")) as $p + | if ($rest | test("[?#\\\\]")) or ($p | length) < 6 or ($p | any(bad_segment)) + or ($p[0] | test("^[A-Za-z0-9._-]+$") | not) or ($p[1] | test("^[A-Za-z0-9._-]+$") | not) + or $p[2] != "releases" or $p[3] != "download" + then "?" else "\($p[0])/\($p[1])" | ascii_downcase end + else "?" end; # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. def repo_of: (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") @@ -56,12 +69,13 @@ bad=$(jq -r ' | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) | "\(.o)/\(.n)" | ascii_downcase) // "?"; .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo - | select($repo != "") | ($repo | repo_of) as $want + | (if $repo == "" then "" else $repo | repo_of end) as $want | .versions[] | select(.url | startswith("file://") | not) - | ((.url | ascii_downcase | capture("^https://github\\.com/(?[^/]+)/(?[^/]+)/releases/download/") | "\(.o)/\(.n)") // "?") as $got - | select($want == "?" or $got != $want) - | "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)"' "$catalog") -[ -z "$bad" ] || fail "release URLs outside the package's repo:"$'\n'"$bad" + | (.url | asset_of) as $got + | if $got == "?" then "\($pkg.id) \(.version): \(.url) is not a release asset (https://github.com///releases/download//)" + elif $want != "" and ($want == "?" or $got != $want) then "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)" + else empty end' "$catalog") +[ -z "$bad" ] || fail "release URLs that Install and Preview refuse:"$'\n'"$bad" echo "ok" echo "== 4. downloads" From 36dc209badfdbab2fa99f44e130798e3c35277ef Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 6 Nov 2026 00:49:16 -0800 Subject: [PATCH 08/99] Plug-in Library: release and repo URLs with white space are refused Install and Preview, the catalog schema and scripts/validate.sh now refuse a release URL or repo folder that contains white space in any segment, the tag and file name included: any Unicode white space character, and U+FEFF. Before, the app accepted a space or tab in a tag, file name or repo folder that the schema refused. --- crates/engine/src/system/library.rs | 19 +++++++++++++++++-- examples/plugin-catalog/schema.json | 4 ++-- examples/plugin-catalog/scripts/validate.sh | 9 ++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index d1eaaf0bd..8fb147e53 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -272,12 +272,18 @@ fn dot_segment(p: &str) -> bool { p == "." || p == ".." } +/// A character a release or repository URL may not contain: `?`, `#`, `\`, Unicode white space, +/// or U+FEFF (the catalog schema's `\s` matches it too). +fn bad_url_char(c: char) -> bool { + matches!(c, '?' | '#' | '\\' | '\u{feff}') || c.is_whitespace() +} + /// `(owner, name)` in lower case of a `https://github.com//` repository URL (an /// optional trailing `/` or `.git`) or of a folder in one, `https://github.com///tree//`; /// `None` for anything else. fn github_repo(repo: &str) -> Option<(String, String)> { let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; - if rest.contains(['?', '#', '\\']) { + if rest.contains(bad_url_char) { return None; } let rest = rest.strip_suffix('/').unwrap_or(rest); @@ -296,7 +302,7 @@ fn github_repo(repo: &str) -> Option<(String, String)> { fn release_url_problem(repo: &str, url: &str) -> Option { let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; - if rest.contains(['?', '#', '\\']) { + if rest.contains(bad_url_char) { return not_asset(); } let parts: Vec<&str> = rest.split('/').collect(); @@ -1230,6 +1236,12 @@ mod tests { "https://github.com/me/glow/releases/download/./v1/x.wasm", "https://github.com/me/glow/releases/download/v1\\x.wasm", "https://github.com/m e/glow/releases/download/v1/x.wasm", + "https://github.com/me/glow/releases/download/v 1/x.wasm", + "https://github.com/me/glow/releases/download/v1/x\t.wasm", + "https://github.com/me/glow/releases/download/v1/x.wasm\n", + "https://github.com/me/glow/releases/download/v1\u{a0}/x.wasm", + "https://github.com/me/glow/releases/download/v1/\u{85}x.wasm", + "https://github.com/me/glow/releases/download/v1/x\u{feff}.wasm", "https://github.com/../glow/releases/download/v1/x.wasm", "https://github.com.evil.com/me/glow/releases/download/v1/x.wasm", ] { @@ -1281,6 +1293,9 @@ mod tests { "https://github.com/me/glow?tab=readme", "https://github.com/me/glow#readme", "https://github.com/me/gl ow", + "https://github.com/me/glow/tree/main/my plug-in", + "https://github.com/me/glow/tree/ma\tin", + "https://github.com/me/glow/tree/main/x\u{feff}", "https://github.com/me/..", ] { let why = release_url_problem(repo, asset); diff --git a/examples/plugin-catalog/schema.json b/examples/plugin-catalog/schema.json index 5fe914d86..c31d57fea 100644 --- a/examples/plugin-catalog/schema.json +++ b/examples/plugin-catalog/schema.json @@ -14,7 +14,7 @@ "version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"}, "release_url": { "type": "string", - "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s]+(/[^/?#\\\\\\s]+)+$" + "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s\\u0085]+(/[^/?#\\\\\\s\\u0085]+)+$" }, "package": { "type": "object", @@ -26,7 +26,7 @@ "author": {"type": "string"}, "description": {"type": "string"}, "license": {"type": "string"}, - "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s]+)+)?/?$"}, + "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s\\u0085]+)+)?/?$"}, "tags": {"type": "array", "items": {"type": "string"}}, "preview": { "type": "object", diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 4a0d196fc..711b69394 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -49,25 +49,28 @@ echo "== 3. release URLs" bad=$(jq -r ' # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); + # A `?`, `#`, `\` or white space character (Unicode, and U+FEFF), which EffectCraft refuses in a URL. + def bad_char: test("[?#\\\\\t\n\u000b\f\r \u0085   - 

   ]"); # "owner/name" in lower case of a release asset, # https://github.com///releases/download// (a tag may contain `/`), with - # no query, fragment, backslash, or empty, `.` or `..` segment; "?" for anything else. + # no query, fragment, backslash, white space, or empty, `.` or `..` segment; "?" for anything else. def asset_of: if startswith("https://") and (.[8:19] | ascii_downcase) == "github.com/" then .[19:] as $rest | ($rest | split("/")) as $p - | if ($rest | test("[?#\\\\]")) or ($p | length) < 6 or ($p | any(bad_segment)) + | if ($rest | bad_char) or ($p | length) < 6 or ($p | any(bad_segment)) or ($p[0] | test("^[A-Za-z0-9._-]+$") | not) or ($p[1] | test("^[A-Za-z0-9._-]+$") | not) or $p[2] != "releases" or $p[3] != "download" then "?" else "\($p[0])/\($p[1])" | ascii_downcase end else "?" end; # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. def repo_of: + if bad_char then "?" else (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") // (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/(?[^?#\\\\]+?)/?$") | select(.f | split("/") | any(bad_segment) | not)) | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) - | "\(.o)/\(.n)" | ascii_downcase) // "?"; + | "\(.o)/\(.n)" | ascii_downcase) // "?" end; .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo | (if $repo == "" then "" else $repo | repo_of end) as $want | .versions[] | select(.url | startswith("file://") | not) From 26dc7b3a5e6a40e13c83665dffaf5fc41aedf7bf Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 12:40:04 +0100 Subject: [PATCH 09/99] CC Ball Action: add Coloring, Shading, Scatter Motion, Displace and Displace Property (#3197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After Effects 24.2 reworked CC Ball Action's controls. EffectCraft now lists them in After Effects' order with its defaults: Grid Spacing (5), Ball Size (100), Coloring (Medium), Shading (-75), Scatter, Scatter Motion, Displace, Displace Property (Brightness), Twist Angle, Twist Property, Rotation Axis, Rotation. Grid Spacing and Ball Size used to default to 4 and 40; saved projects keep their values. - Shading scales the balls' light and shine. -75 is the lit sphere as before, 0 draws flat balls in the layer's colour, larger magnitudes shade more, and the sign mirrors the light's direction. The value is clamped to -100..100 (an assumed range) so huge values stay finite on the GPU. Values other than -75 and 0 use a new sprite shape (Shape::Ball), drawn the same way on the CPU and the GPU. - Coloring is an approximation: Crisp takes the nearest pixel, Medium keeps EffectCraft's earlier smooth sample (for compatibility), Smooth averages 16 samples over the ball's cell. - Scatter Motion is treated as the renamed Instability State, since 24.2 shows no Instability State. Old projects are upgraded through PARAM_ID_ALIASES. - Displace and Displace Property (Red, Green, Blue, Brightness, Saturation, RGB, Radius, Diamond, Spherize) move each ball towards or away from the camera. The scale, direction, pivot and range, and what Radius, Diamond and Spherize compute, are EffectCraft's own choice pending a comparison with After Effects. Displace is clamped to -1000..1000. With the old Grid Spacing and Ball Size, every CC Ball Action golden hash is unchanged, so the new controls at their defaults draw what was drawn before. Only the golden cases that use the default Grid Spacing and Ball Size were reblessed. CC Ball Action has no .aep mapping yet. Sources (behaviour and public descriptions only): - After Effects February 2024 (24.2) feature summary: "Ball Action: Rearranged effect controls with new controls, such as Displacement, Shading, and Coloring" https://helpx.adobe.com/ae_en/after-effects/using/whats-new/2024-2.html - The After Effects screenshot in #3197: control order and defaults. - 163.com, "Ae 效果详解:CC Ball Action": option lists, defaults, and that Shading 0 is flat https://www.163.com/dy/article/JOICG6E10536FE6V.html - Adobe community, "CC Ball Action is broken in update 24.4": the Coloring options Crisp, Medium and Smooth - Mike Murphy, "How To Use CC Ball Action": Shading 0 with Displace on Brightness https://mikemurphy.ai/tutorials/ccballaction/ Fixes #3197 --- crates/effects/src/migrate.rs | 3 + crates/effects/src/sim/sprites.rs | 22 ++++ crates/effects/src/sim2/pixels.rs | 118 +++++++++++++++++- crates/effects/src/sim2/registry.rs | 21 +++- crates/effects/src/sim2/tests.rs | 132 +++++++++++++++++++++ crates/effects/tests/it/particle_golden.rs | 42 +++---- crates/gpu/src/fx_sim.rs | 2 + crates/gpu/src/shaders/fx_sim.wgsl | 21 ++++ crates/gpu/src/tests/fx_particles.rs | 17 ++- docs/effects.md | 4 +- 10 files changed, 347 insertions(+), 35 deletions(-) diff --git a/crates/effects/src/migrate.rs b/crates/effects/src/migrate.rs index 59daca49d..6529e658d 100644 --- a/crates/effects/src/migrate.rs +++ b/crates/effects/src/migrate.rs @@ -44,6 +44,9 @@ pub const PARAM_ID_ALIASES: &[(&str, &str, &str)] = &[ ("ec.key.innerouter", "additionalBackground", "additionalBackground/background1"), // Generate: Radio Waves' growth speed was called Velocity; Velocity now moves the wave. ("ec.generate.radiowaves", "velocity", "waveMotion/expansion"), + // Simulation: CC Ball Action's Instability State is treated as the control After Effects + // 24.2 calls Scatter Motion (#3197; an assumption: 24.2 shows no Instability State). + ("ec.sim.ccballaction", "instabilityState", "scatterMotion"), ]; /// Popup option labels renamed since they were first saved: diff --git a/crates/effects/src/sim/sprites.rs b/crates/effects/src/sim/sprites.rs index 55ba594b4..031bee978 100644 --- a/crates/effects/src/sim/sprites.rs +++ b/crates/effects/src/sim/sprites.rs @@ -93,6 +93,10 @@ pub enum Shape { Disc, /// Lit sphere (upper-left light, specular). Sphere, + /// CC Ball Action's ball: [`Shape::Sphere`]'s light and shine scaled by `|shade|` (1 is the + /// sphere's look, 0 a flat disc; callers keep it finite, the GPU draws the same); a negative + /// `shade` mirrors the light's direction (lit from the lower right). + Ball { shade: f32 }, /// Disc fading linearly to its rim. Faded, /// Thin ring with a highlight. @@ -277,6 +281,24 @@ fn sprite_shade(s: &Sprite, x: f32, y: f32) -> Option { rgb = [rgb[0] * k + spec, rgb[1] * k + spec, rgb[2] * k + spec]; cv } + Shape::Ball { shade } => { + let d = (dx * dx + dy * dy).sqrt(); + let cv = aa(r - d); + if cv <= 0.0 { + return None; + } + let (nx, ny) = (dx / r, dy / r); + let nz = (1.0 - nx * nx - ny * ny).max(0.0).sqrt(); + let m = if shade < 0.0 { -1.0 } else { 1.0 }; + let (lx, ly, lz) = (-0.48 * m, -0.58 * m, 0.66); + let diff = (nx * lx + ny * ly + nz * lz).max(0.0); + let rz = 2.0 * diff * nz - lz; + let st = shade.abs(); + let spec = rz.max(0.0).powi(20) * 0.6 * st; + let k = (1.0 - st * 0.8 * (1.0 - diff)).max(0.0); + rgb = [rgb[0] * k + spec, rgb[1] * k + spec, rgb[2] * k + spec]; + cv + } Shape::Bubble => { let d = (dx * dx + dy * dy).sqrt() / r; if d > 1.0 + 1.0 / r { diff --git a/crates/effects/src/sim2/pixels.rs b/crates/effects/src/sim2/pixels.rs index 2cda428db..4fed8da59 100644 --- a/crates/effects/src/sim2/pixels.rs +++ b/crates/effects/src/sim2/pixels.rs @@ -4,10 +4,91 @@ use super::{Acc, Buf, EffectCtx, IntoParallelIterator, ParallelIterator, Post, S // ------------------------------------------------------------------ CC Ball Action +/// CC Ball Action's Coloring: how a ball takes its colour from the layer under its grid cell. +/// An approximation: After Effects' own meaning is not published beyond "how smooth the +/// balls look". Crisp takes the nearest pixel, Medium keeps EffectCraft's earlier smooth +/// sample at the cell centre (for compatibility), Smooth averages 16 samples over the cell. +pub(super) const BALL_COLORING: &[&str] = &["Crisp", "Medium", "Smooth"]; +pub(super) const BALL_COLORING_MEDIUM: u32 = 1; +/// CC Ball Action's default Shading: the lit sphere (`Shape::Sphere`); 0 draws flat discs. +pub(super) const BALL_SHADING_DEFAULT: f64 = -75.0; +/// CC Ball Action's Displace Property: what pushes a ball towards (high values) or away from +/// (low values) the camera. The option names come from public descriptions; what Radius, +/// Diamond and Spherize compute here is an assumption pending a comparison with After Effects. +pub(super) const BALL_DISPLACE_PROPERTIES: &[&str] = &["Red", "Green", "Blue", "Brightness", "Saturation", "RGB", "Radius", "Diamond", "Spherize"]; +pub(super) const BALL_DISPLACE_BRIGHTNESS: u32 = 3; + pub(super) fn ball_action(ctx: &EffectCtx, b: Buf) -> Buf { ball_action_plan(ctx, &b).finish(b) } +/// A parameter's number, or `default` when the instance does not carry it. +fn f_or(ctx: &EffectCtx, id: &str, default: f64) -> f64 { + ctx.params.values.get(id).map(|v| v.as_f64()).unwrap_or(default) +} + +/// The layer's straight colour and alpha for the ball of the grid cell centred on (`sx`, `sy`) +/// (buffer pixels, cell `cell` buffer pixels wide), by Coloring `coloring`. +fn ball_color(src: &effectcraft_raster::Image, sx: f64, sy: f64, cell: f64, coloring: u32) -> ([f32; 3], f32) { + match coloring { + // Crisp: the pixel under the cell centre. + 0 => unpremul(src.get(sx.floor() as i64, sy.floor() as i64)), + // Smooth: the cell's average (4 × 4 samples, premultiplied). + 2 => { + const N: u32 = 4; + let mut acc = [0.0f32; 4]; + for j in 0..N { + for i in 0..N { + let ox = (f64::from(i) + 0.5) / f64::from(N) - 0.5; + let oy = (f64::from(j) + 0.5) / f64::from(N) - 0.5; + let p = src.sample_bilinear(sx + ox * cell, sy + oy * cell); + for (a, v) in acc.iter_mut().zip(p) { + *a += v; + } + } + } + let n = (N * N) as f32; + unpremul([acc[0] / n, acc[1] / n, acc[2] / n, acc[3] / n]) + } + // Medium: a smooth sample at the cell centre. + _ => unpremul(src.sample_bilinear(sx, sy)), + } +} + +/// CC Ball Action's Displace Property `prop` (0..1) for a ball of straight colour `c` at +/// (`gx`, `gy`) on a `lw` × `lh` layer (`maxr`: half its diagonal). Assumed meanings (not +/// compared with After Effects yet): Radius, Diamond and Spherize are shapes that peak at the +/// layer centre. +fn ball_displace_value(prop: u32, c: [f32; 3], gx: f32, gy: f32, lw: f32, lh: f32, maxr: f32) -> f32 { + let (cx, cy) = (lw * 0.5, lh * 0.5); + let v = match prop { + 0 => c[0], + 1 => c[1], + 2 => c[2], + // Brightness: the brightest channel (HSB brightness). + 3 => c[0].max(c[1]).max(c[2]), + // Saturation: HSB saturation. + 4 => { + let mx = c[0].max(c[1]).max(c[2]); + let mn = c[0].min(c[1]).min(c[2]); + if mx > 0.0 { (mx - mn) / mx } else { 0.0 } + } + // RGB: the channels' mean. + 5 => (c[0] + c[1] + c[2]) / 3.0, + // Radius: high at the centre, low at the corners. + 6 => 1.0 - (gx - cx).hypot(gy - cy) / maxr.max(1.0), + // Diamond: high at the centre, falling linearly to the edge midpoints' diamond. + 7 => 1.0 - ((gx - cx).abs() / cx.max(0.5) + (gy - cy).abs() / cy.max(0.5)) * 0.5, + // Spherize: a hemisphere over the largest centred circle. + _ => { + let rr = cx.min(cy).max(0.5); + let d = (gx - cx).hypot(gy - cy) / rr; + (1.0 - d * d).max(0.0).sqrt() + } + }; + if v.is_finite() { v.clamp(0.0, 1.0) } else { 0.0 } +} + /// CC Ball Action's balls (far to near), coloured by the layer's pixels. fn ball_action_plan(ctx: &EffectCtx, b: &Buf) -> SpritePlan { let pr = ctx.params; @@ -18,7 +99,29 @@ fn ball_action_plan(ctx: &EffectCtx, b: &Buf) -> SpritePlan { let twist = pr.f("twistAngle").to_radians(); let spacing = pr.f("gridSpacing").max(1.0) as f32; let size = pr.f("ballSize") as f32 / 100.0; - let instab = pr.f("instabilityState").to_radians() as f32; + // Scatter Motion, treated as the renamed Instability State (an assumption: After Effects + // 24.2 shows Scatter Motion and no Instability State): turns each ball's scatter direction. + let instab = pr.f("scatterMotion").to_radians() as f32; + let coloring = pr.values.get("coloring").map(|v| v.as_enum()).unwrap_or(BALL_COLORING_MEDIUM); + let shading = f_or(ctx, "shading", BALL_SHADING_DEFAULT); + // Shading: -75 is the lit sphere as it always was, 0 flat discs; the magnitude scales the + // light and shine (strength 1 at 75) and the sign mirrors the light's direction (positive + // lights the balls from the lower right). How this compares with After Effects' sign + // (described as concave versus convex) is unverified, as is the -100..100 range. + let shape = if shading == BALL_SHADING_DEFAULT || !shading.is_finite() { + Shape::Sphere + } else if shading == 0.0 { + Shape::Disc + } else { + // Clamped: a huge value would reach the GPU as an infinite strength (and NaN colours). + Shape::Ball { shade: (-shading.clamp(-100.0, 100.0) / 75.0) as f32 } + }; + // Displace: pushes each ball along z by its Displace Property (high values towards the + // camera, pivoting at the property's middle value); 100 moves the extremes by half the + // layer's diagonal. Scale, direction, pivot and range are EffectCraft's own choice, + // pending a comparison with After Effects. Clamped so huge values stay finite. + let displace = pr.f("displace").clamp(-1000.0, 1000.0) as f32; + let displace_prop = pr.values.get("displaceProperty").map(|v| v.as_enum()).unwrap_or(BALL_DISPLACE_BRIGHTNESS); let seed = ctx.seed.wrapping_mul(0x2545f491); let (lw, lh) = (ctx.layer_size[0] as f32, ctx.layer_size[1] as f32); let s = b.scale as f32; @@ -43,7 +146,7 @@ fn ball_action_plan(ctx: &EffectCtx, b: &Buf) -> SpritePlan { let gx = (i % nx) as f32 * spacing + spacing * 0.5; let gy = (i / nx) as f32 * spacing + spacing * 0.5; let (sx, sy) = b.to_px([gx as f64, gy as f64]); - let (c, a) = unpremul(src.sample_bilinear(sx, sy)); + let (c, a) = ball_color(src, sx, sy, f64::from(spacing * s), coloring); if a <= 0.0 || size <= 0.0 { return None; } @@ -54,11 +157,16 @@ fn ball_action_plan(ctx: &EffectCtx, b: &Buf) -> SpritePlan { _ => crate::util::rgb3([c[0], c[1], c[2], 0.0]).iter().sum::() / 3.0, } as f64; let ang = rot + twist * tp; - // Scatter: random 3D offsets whose direction drifts with the instability state. + // Scatter: random 3D offsets whose direction drifts with Scatter Motion. let ph = h(i, 1, seed) * std::f32::consts::TAU + instab; let sc = scatter * h(i, 2, seed); let off = [(sc * ph.cos()) as f64, (sc * ph.sin()) as f64, (scatter * hs(i, 3, seed)) as f64]; - let p0 = [gx as f64 - cx + off[0], gy as f64 - cy + off[1], off[2]]; + let mut p0 = [gx as f64 - cx + off[0], gy as f64 - cy + off[1], off[2]]; + // Only when set, so Displace 0 leaves every depth (and the far-to-near order) as is. + if displace != 0.0 && displace.is_finite() { + let v = ball_displace_value(displace_prop, c, gx, gy, lw, lh, maxr); + p0[2] -= f64::from(displace / 100.0 * (v - 0.5) * 2.0 * maxr); + } let m = rot_axis(ax, ang); let q: [f64; 3] = std::array::from_fn(|k| m[k][0] * p0[0] + m[k][1] * p0[1] + m[k][2] * p0[2]); if d + q[2] <= d * 0.05 { @@ -67,7 +175,7 @@ fn ball_action_plan(ctx: &EffectCtx, b: &Buf) -> SpritePlan { let persp = d / (d + q[2]); let (bx, by) = b.to_px([cx + q[0] * persp, cy + q[1] * persp]); let r = spacing * 0.5 * size * persp as f32 * s; - Some((q[2], Sprite::new(bx as f32, by as f32, r, [c[0], c[1], c[2], a], Shape::Sphere))) + Some((q[2], Sprite::new(bx as f32, by as f32, r, [c[0], c[1], c[2], a], shape))) }) .collect(); balls.sort_by(|a, b| b.0.total_cmp(&a.0)); diff --git a/crates/effects/src/sim2/registry.rs b/crates/effects/src/sim2/registry.rs index 333916a16..28eb8e808 100644 --- a/crates/effects/src/sim2/registry.rs +++ b/crates/effects/src/sim2/registry.rs @@ -1,5 +1,7 @@ use super::foam::{FOAM_TEXTURES, foam}; -use super::pixels::{ball_action, pixel_polly, scatterize}; +use super::pixels::{ + BALL_COLORING, BALL_COLORING_MEDIUM, BALL_DISPLACE_BRIGHTNESS, BALL_DISPLACE_PROPERTIES, BALL_SHADING_DEFAULT, ball_action, pixel_polly, scatterize, +}; use super::shatter::{CD_PROPS, CD_SOURCES, SHATTER_PATTERNS, SHATTER_TEXTURE_MODES, card_dance, shatter}; use super::surfaces::{caustics, wave_world}; use super::{EffectSpec, ParamUi, Value, col, num, p, pct, popup, pt, slider, spec}; @@ -80,15 +82,22 @@ pub fn specs() -> Vec { spec( "ec.sim.ccballaction", "CC Ball Action", + // After Effects' order and defaults since 24.2 (#3197). Scatter Motion is treated as + // the renamed Instability State (an assumption, `migrate::PARAM_ID_ALIASES`). The + // Shading range is not published; -100..100 is an assumption. vec![ + p("gridSpacing", "Grid Spacing", num(5.0), slider(1.0, 200.0, 1.0, 50.0, 0)), + p("ballSize", "Ball Size", num(100.0), slider(0.0, 400.0, 0.0, 200.0, 1)), + p("coloring", "Coloring", Value::Enum(BALL_COLORING_MEDIUM), popup(BALL_COLORING)), + p("shading", "Shading", num(BALL_SHADING_DEFAULT), slider(-100.0, 100.0, -100.0, 100.0, 1)), p("scatter", "Scatter", num(0.0), slider(0.0, 2000.0, 0.0, 300.0, 1)), + p("scatterMotion", "Scatter Motion", num(0.0), ParamUi::Angle), + p("displace", "Displace", num(0.0), slider(-1000.0, 1000.0, 0.0, 100.0, 1)), + p("displaceProperty", "Displace Property", Value::Enum(BALL_DISPLACE_BRIGHTNESS), popup(BALL_DISPLACE_PROPERTIES)), + p("twistAngle", "Twist Angle", num(0.0), ParamUi::Angle), + p("twistProperty", "Twist Property", Value::Enum(0), popup(&["X Axis", "Y Axis", "Radius", "Brightness"])), p("rotationAxis", "Rotation Axis", Value::Enum(0), popup(&["X Axis", "Y Axis", "Z Axis", "XY Axis", "XZ Axis", "YZ Axis", "XYZ Axis"])), p("rotation", "Rotation", num(0.0), ParamUi::Angle), - p("twistProperty", "Twist Property", Value::Enum(0), popup(&["X Axis", "Y Axis", "Radius", "Brightness"])), - p("twistAngle", "Twist Angle", num(0.0), ParamUi::Angle), - p("gridSpacing", "Grid Spacing", num(4.0), slider(1.0, 200.0, 1.0, 50.0, 0)), - p("ballSize", "Ball Size", num(40.0), slider(0.0, 400.0, 0.0, 200.0, 1)), - p("instabilityState", "Instability State", num(0.0), ParamUi::Angle), ], ball_action, ), diff --git a/crates/effects/src/sim2/tests.rs b/crates/effects/src/sim2/tests.rs index 2ef35b122..6ad6eb21c 100644 --- a/crates/effects/src/sim2/tests.rs +++ b/crates/effects/src/sim2/tests.rs @@ -46,6 +46,138 @@ fn ball_action_draws_balls() { assert!(sum_diff(&a, &sc) > 1.0); } +/// #3197: CC Ball Action has After Effects' controls (since 24.2), in its order, with its +/// defaults: Coloring, Shading, Scatter Motion (formerly Instability State), Displace and +/// Displace Property were missing. +#[test] +fn ball_action_has_after_effects_controls() { + let spec = crate::find("ec.sim.ccballaction").unwrap(); + let names: Vec<&str> = spec.params.iter().map(|p| p.name).collect(); + assert_eq!( + names, + [ + "Grid Spacing", + "Ball Size", + "Coloring", + "Shading", + "Scatter", + "Scatter Motion", + "Displace", + "Displace Property", + "Twist Angle", + "Twist Property", + "Rotation Axis", + "Rotation" + ] + ); + let sp = |id: &str| spec.params.iter().find(|p| p.id == id).unwrap_or_else(|| panic!("no {id}")); + assert_eq!(sp("gridSpacing").default, num(5.0)); + assert_eq!(sp("ballSize").default, num(100.0)); + assert_eq!(sp("coloring").default, Value::Enum(1)); + assert_eq!(sp("coloring").ui, ParamUi::Popup { options: vec!["Crisp".into(), "Medium".into(), "Smooth".into()] }); + assert_eq!(sp("shading").default, num(-75.0)); + assert!(matches!(sp("shading").ui, ParamUi::Slider { min, max, .. } if min <= -100.0 && max >= 100.0)); + assert_eq!(sp("scatterMotion").default, num(0.0)); + assert_eq!(sp("scatterMotion").ui, ParamUi::Angle); + assert_eq!(sp("displace").default, num(0.0)); + let ParamUi::Popup { options } = &sp("displaceProperty").ui else { panic!("Displace Property is a popup") }; + let Value::Enum(d) = sp("displaceProperty").default else { panic!("Displace Property defaults to an option") }; + assert_eq!(options.get(d as usize).map(String::as_str), Some("Brightness")); + // Old projects' Instability State becomes Scatter Motion through `PARAM_ID_ALIASES`; the + // engine test `opening_an_old_project_upgrades_effect_instances` covers every alias. +} + +/// #3197: the new controls at After Effects' defaults draw exactly what CC Ball Action drew +/// before (the lit sphere, a smooth colour sample, no displacement). +#[test] +fn ball_action_new_controls_at_defaults_keep_the_render() { + let base = [("ballSize", num(80.0)), ("scatter", num(6.0)), ("rotationAxis", Value::Enum(1)), ("rotation", num(25.0))]; + let a = run("ec.sim.ccballaction", &base, ramp(32, 32), 0.0); + let mut explicit = base.to_vec(); + explicit.extend([ + ("coloring", Value::Enum(1)), + ("shading", num(-75.0)), + ("scatterMotion", num(0.0)), + ("displace", num(0.0)), + ("displaceProperty", Value::Enum(3)), + ]); + assert_eq!(a, run("ec.sim.ccballaction", &explicit, ramp(32, 32), 0.0)); +} + +/// #3197: Shading 0 removes the built-in light: every ball is the layer's flat colour. The +/// default (-75) shades it; a smaller magnitude shades less, a positive value lights the balls +/// from the other side. +#[test] +fn ball_action_shading_zero_is_flat() { + let c = [0.6, 0.3, 0.2, 1.0]; + let shade = |v: f64| run("ec.sim.ccballaction", &[("ballSize", num(100.0)), ("gridSpacing", num(8.0)), ("shading", num(v))], Image::filled(32, 32, c), 0.0); + let flat = shade(0.0); + let covered: Vec<&[f32; 4]> = flat.data.iter().filter(|p| p[3] > 0.999).collect(); + assert!(!covered.is_empty(), "balls drawn"); + for p in &covered { + for k in 0..3 { + assert!((p[k] / p[3] - c[k]).abs() < 1e-4, "flat colour: {p:?}"); + } + } + let lit = shade(-75.0); + assert!(lit.data.iter().any(|p| p[3] > 0.999 && (0..3).any(|k| (p[k] / p[3] - c[k]).abs() > 0.05)), "the default shading lights and darkens the balls"); + let soft = shade(-30.0); + assert!(sum_diff(&flat, &soft) > 0.1 && sum_diff(&flat, &soft) < sum_diff(&flat, &lit), "less shading, closer to flat"); + assert!(sum_diff(&shade(75.0), &lit) > 1.0, "the sign moves the light"); +} + +/// #3197: Coloring Crisp takes the pixel under each ball's cell centre; Medium samples +/// smoothly between pixels. Grid Spacing 4 puts the cell centres on pixel corners (with the +/// default 5 they fall on pixel centres, where Medium's sample equals Crisp's). +#[test] +fn ball_action_coloring_crisp_takes_the_pixel() { + let mut src = Image::new(32, 32); + for y in 0..32u32 { + for x in 0..32u32 { + src.set(x, y, [x as f32 / 32.0, y as f32 / 32.0, ((x * 7 + y * 3) % 5) as f32 / 4.0, 1.0]); + } + } + let col = |m: u32| { + let v = [("gridSpacing", num(4.0)), ("ballSize", num(100.0)), ("shading", num(0.0)), ("coloring", Value::Enum(m))]; + run("ec.sim.ccballaction", &v, src.clone(), 0.0) + }; + let crisp = col(0); + // Flat, opaque balls of radius 2 centred on (4i + 2, 4j + 2): the pixel to the lower right + // of each centre is fully covered by its ball alone. + for j in 0..8i64 { + for i in 0..8i64 { + let (x, y) = (4 * i + 2, 4 * j + 2); + let (got, want) = (crisp.get(x, y), src.get(x, y)); + assert!((0..4).all(|k| (got[k] - want[k]).abs() < 1e-5), "ball ({i}, {j}): {got:?} vs the pixel {want:?}"); + } + } + assert!(sum_diff(&crisp, &col(1)) > 1.0, "medium blends the pixels"); +} + +/// #3197: a huge Shading (typed or from an expression) is clamped, so the balls stay finite. +#[test] +fn ball_action_huge_shading_stays_finite() { + for v in [1e45, -1e45, f64::MAX] { + let o = run("ec.sim.ccballaction", &[("gridSpacing", num(8.0)), ("shading", num(v))], ramp(32, 32), 0.0); + assert!(o.data.iter().all(|p| p.iter().all(|c| c.is_finite())), "shading {v}"); + assert!(o.data.iter().any(|p| p[3] > 0.0), "shading {v}: balls drawn"); + } +} + +/// #3197: Displace pushes the balls along z by the chosen property (Radius: the centre comes +/// towards the camera and grows); 0 leaves them in the layer's plane. +#[test] +fn ball_action_displace_moves_balls_in_depth() { + let flat = run("ec.sim.ccballaction", &[("ballSize", num(80.0))], ramp(32, 32), 0.0); + let d = run("ec.sim.ccballaction", &[("ballSize", num(80.0)), ("displace", num(60.0)), ("displaceProperty", Value::Enum(6))], ramp(32, 32), 0.0); + assert_eq!(d, run("ec.sim.ccballaction", &[("ballSize", num(80.0)), ("displace", num(60.0)), ("displaceProperty", Value::Enum(6))], ramp(32, 32), 0.0)); + assert!(sum_diff(&flat, &d) > 1.0); + for prop in 0..9 { + let o = run("ec.sim.ccballaction", &[("ballSize", num(80.0)), ("displace", num(400.0)), ("displaceProperty", Value::Enum(prop))], ramp(32, 32), 0.0); + assert!(o.data.iter().all(|p| p.iter().all(|v| v.is_finite())), "property {prop}"); + } +} + #[test] fn pixel_polly_breaks_after_start() { let v = [("forceCenter", pt(16.0, 16.0)), ("gridSpacing", num(4.0))]; diff --git a/crates/effects/tests/it/particle_golden.rs b/crates/effects/tests/it/particle_golden.rs index 0dbf19d76..5d0b255b1 100644 --- a/crates/effects/tests/it/particle_golden.rs +++ b/crates/effects/tests/it/particle_golden.rs @@ -192,7 +192,7 @@ fn cases() -> Vec<(&'static str, Vec)> { vec![ vec![], vec![("scatter", n(20.0)), ("rotationAxis", e(6)), ("rotation", n(40.0)), ("twistProperty", e(3)), ("twistAngle", n(90.0))], - vec![("gridSpacing", n(2.0)), ("ballSize", n(80.0)), ("instabilityState", n(45.0)), ("twistProperty", e(2)), ("twistAngle", n(30.0))], + vec![("gridSpacing", n(2.0)), ("ballSize", n(80.0)), ("scatterMotion", n(45.0)), ("twistProperty", e(2)), ("twistAngle", n(30.0))], ], ), ( @@ -538,26 +538,26 @@ const GOLDEN: &[(&str, u64)] = &[ ("ec.sim.particleplayground/8/32bpc/t1.5", 0xb5b7f0281f26baad), ("ec.sim.particleplayground/8/32bpc/t0.8", 0x8b6934363ef4dcfd), ("ec.sim.particleplayground/8/32bpc/t2.2", 0x0a31c17e8e34b9f5), - ("ec.sim.ccballaction/0/8bpc/t0.5", 0x12698ec8353be38c), - ("ec.sim.ccballaction/0/8bpc/t1.5", 0x12698ec8353be38c), - ("ec.sim.ccballaction/0/8bpc/t0.8", 0x12698ec8353be38c), - ("ec.sim.ccballaction/0/8bpc/t2.2", 0x12698ec8353be38c), - ("ec.sim.ccballaction/0/32bpc/t0.5", 0x3fb733487e120261), - ("ec.sim.ccballaction/0/32bpc/t1.5", 0x3fb733487e120261), - ("ec.sim.ccballaction/0/32bpc/t0.8", 0x3fb733487e120261), - ("ec.sim.ccballaction/0/32bpc/t2.2", 0x3fb733487e120261), - ("ec.sim.ccballaction/0/8bpc/half/t0.5", 0x4946070917cc0945), - ("ec.sim.ccballaction/0/8bpc/half/t1.5", 0x4946070917cc0945), - ("ec.sim.ccballaction/0/8bpc/half/t0.8", 0x4946070917cc0945), - ("ec.sim.ccballaction/0/8bpc/half/t2.2", 0x4946070917cc0945), - ("ec.sim.ccballaction/1/8bpc/t0.5", 0xf34b3be38a4dd468), - ("ec.sim.ccballaction/1/8bpc/t1.5", 0xf34b3be38a4dd468), - ("ec.sim.ccballaction/1/8bpc/t0.8", 0xf34b3be38a4dd468), - ("ec.sim.ccballaction/1/8bpc/t2.2", 0xf34b3be38a4dd468), - ("ec.sim.ccballaction/1/32bpc/t0.5", 0x503b7238edf2912c), - ("ec.sim.ccballaction/1/32bpc/t1.5", 0x503b7238edf2912c), - ("ec.sim.ccballaction/1/32bpc/t0.8", 0x503b7238edf2912c), - ("ec.sim.ccballaction/1/32bpc/t2.2", 0x503b7238edf2912c), + ("ec.sim.ccballaction/0/8bpc/t0.5", 0x5f7401d3d1e5a513), + ("ec.sim.ccballaction/0/8bpc/t1.5", 0x5f7401d3d1e5a513), + ("ec.sim.ccballaction/0/8bpc/t0.8", 0x5f7401d3d1e5a513), + ("ec.sim.ccballaction/0/8bpc/t2.2", 0x5f7401d3d1e5a513), + ("ec.sim.ccballaction/0/32bpc/t0.5", 0x9cf15a7756ab88ed), + ("ec.sim.ccballaction/0/32bpc/t1.5", 0x9cf15a7756ab88ed), + ("ec.sim.ccballaction/0/32bpc/t0.8", 0x9cf15a7756ab88ed), + ("ec.sim.ccballaction/0/32bpc/t2.2", 0x9cf15a7756ab88ed), + ("ec.sim.ccballaction/0/8bpc/half/t0.5", 0xe2e3a624434f8e88), + ("ec.sim.ccballaction/0/8bpc/half/t1.5", 0xe2e3a624434f8e88), + ("ec.sim.ccballaction/0/8bpc/half/t0.8", 0xe2e3a624434f8e88), + ("ec.sim.ccballaction/0/8bpc/half/t2.2", 0xe2e3a624434f8e88), + ("ec.sim.ccballaction/1/8bpc/t0.5", 0x07382912d068a625), + ("ec.sim.ccballaction/1/8bpc/t1.5", 0x07382912d068a625), + ("ec.sim.ccballaction/1/8bpc/t0.8", 0x07382912d068a625), + ("ec.sim.ccballaction/1/8bpc/t2.2", 0x07382912d068a625), + ("ec.sim.ccballaction/1/32bpc/t0.5", 0xa1e843936e72815f), + ("ec.sim.ccballaction/1/32bpc/t1.5", 0xa1e843936e72815f), + ("ec.sim.ccballaction/1/32bpc/t0.8", 0xa1e843936e72815f), + ("ec.sim.ccballaction/1/32bpc/t2.2", 0xa1e843936e72815f), ("ec.sim.ccballaction/2/8bpc/t0.5", 0x0b6bf26753ee4582), ("ec.sim.ccballaction/2/8bpc/t1.5", 0x0b6bf26753ee4582), ("ec.sim.ccballaction/2/8bpc/t0.8", 0x0b6bf26753ee4582), diff --git a/crates/gpu/src/fx_sim.rs b/crates/gpu/src/fx_sim.rs index 944ca6c07..a3f0f7a0c 100644 --- a/crates/gpu/src/fx_sim.rs +++ b/crates/gpu/src/fx_sim.rs @@ -228,6 +228,8 @@ pub(crate) fn sprite_layer(e: &mut Enc, src: &GpuImage, plan: &SpritePlan) -> Op Shape::Square => (6.0, 0.0, 0.0), Shape::Tri => (7.0, 0.0, 0.0), Shape::Line { dx, dy } => (8.0, dx, dy), + // The strength rides in the (otherwise unused) first segment slot. + Shape::Ball { shade } => (9.0, shade, 0.0), }; let mut rec = [kind, s.x, s.y, s.r, s.c[0], s.c[1], s.c[2], s.c[3], s.rot, dx, dy, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]; match plan.tints.get(i).copied().unwrap_or(Tint::Fixed) { diff --git a/crates/gpu/src/shaders/fx_sim.wgsl b/crates/gpu/src/shaders/fx_sim.wgsl index 7deeac048..cf4a14a03 100644 --- a/crates/gpu/src/shaders/fx_sim.wgsl +++ b/crates/gpu/src/shaders/fx_sim.wgsl @@ -145,6 +145,27 @@ fn fxm_sprite(at: u32, x: f32, y: f32) -> FxmShade { } cov = fxm_aa(m); } + // sim::Shape::Ball (CC Ball Action's Shading): the sphere's light and shine scaled by + // |shade| (data[at + 9]), lit from the lower right when shade < 0. + case 9u: { + let d = sqrt(dx * dx + dy * dy); + let cv = fxm_aa(r - d); + if (cv <= 0.0) { + return fxm_none(); + } + let shade = data[at + 9u]; + let nx = dx / r; + let ny = dy / r; + let nz = sqrt(max(1.0 - nx * nx - ny * ny, 0.0)); + let m = select(1.0, -1.0, shade < 0.0); + let diff = max(nx * (-0.48 * m) + ny * (-0.58 * m) + nz * 0.66, 0.0); + let rz = 2.0 * diff * nz - 0.66; + let st = abs(shade); + let spec = powz(max(rz, 0.0), 20.0) * 0.6 * st; + let k = max(1.0 - st * 0.8 * (1.0 - diff), 0.0); + rgb = rgb * k + spec; + cov = cv; + } default: { let lx = data[at + 9u]; let ly = data[at + 10u]; diff --git a/crates/gpu/src/tests/fx_particles.rs b/crates/gpu/src/tests/fx_particles.rs index e8c3a7ce6..a4d531a37 100644 --- a/crates/gpu/src/tests/fx_particles.rs +++ b/crates/gpu/src/tests/fx_particles.rs @@ -141,7 +141,22 @@ fn ball_action_pixel_polly_scatterize() { 0.0, 0.0, ); - case("ec.sim.ccballaction", &[("gridSpacing", n(2.0)), ("ballSize", n(80.0)), ("instabilityState", n(45.0)), ("twistProperty", e(2))], 0.0, 0.0); + case("ec.sim.ccballaction", &[("gridSpacing", n(2.0)), ("ballSize", n(80.0)), ("scatterMotion", n(45.0)), ("twistProperty", e(2))], 0.0, 0.0); + // #3197: Shading (flat, weaker, stronger, lit from the other side), Coloring, Displace. + for shading in [0.0, -30.0, -100.0, 60.0, 1e45] { + case("ec.sim.ccballaction", &[("ballSize", n(80.0)), ("shading", n(shading))], 0.0, 0.0); + } + for coloring in [0, 2] { + case("ec.sim.ccballaction", &[("ballSize", n(80.0)), ("coloring", e(coloring))], 0.0, 0.0); + } + for prop in [3, 6, 8] { + case( + "ec.sim.ccballaction", + &[("ballSize", n(80.0)), ("rotationAxis", e(1)), ("rotation", n(30.0)), ("displace", n(40.0)), ("displaceProperty", e(prop))], + 0.0, + 0.0, + ); + } for object in 0..4 { case("ec.sim.ccpixelpolly", &[("object", e(object)), ("gridSpacing", n(6.0))], 0.6, 0.0); } diff --git a/docs/effects.md b/docs/effects.md index d9f726481..130d00a90 100644 --- a/docs/effects.md +++ b/docs/effects.md @@ -3,7 +3,7 @@ -EffectCraft ships 308 effects with 2988 parameters in total, grouped into the same categories as the Effects & Presets panel. Every effect is our own implementation, written from public behaviour descriptions and standard image-processing literature. Parameter names, order, popup options, units, defaults and ranges follow the reference application so that projects, expressions and muscle memory carry over. +EffectCraft ships 308 effects with 2992 parameters in total, grouped into the same categories as the Effects & Presets panel. Every effect is our own implementation, written from public behaviour descriptions and standard image-processing literature. Parameter names, order, popup options, units, defaults and ranges follow the reference application so that projects, expressions and muscle memory carry over. - **GPU**: 280 effects also run on the GPU compositor with identical results. - **32**: 308 effects process 32-bit float (HDR, overbright) pixels without clamping. @@ -319,7 +319,7 @@ Effects are addressed by id (`ec..`) or display name in commands | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| -| CC Ball Action | `ec.sim.ccballaction` | 8 | GPU | 32 | Implemented | +| CC Ball Action | `ec.sim.ccballaction` | 12 | GPU | 32 | Implemented | | CC Bubbles | `ec.sim.ccbubbles` | 7 | GPU | 32 | Implemented | | CC Drizzle | `ec.sim.ccdrizzle` | 14 | GPU | 32 | Implemented | | CC Hair | `ec.sim.cchair` | 20 | GPU | 32 | Implemented | From 1c47f233ea9b18bd74a4eb4a178f406f2896b716 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 12:57:53 +0100 Subject: [PATCH 10/99] Graph Editor: the value curve passes through every key and draws Hold steps vertically Refs #2720 The curve was sampled on an even grid every 2 px, blind to key times. Zoomed out, keys one frame apart sit closer than a sample step, so the polyline cut across the jump instead of passing through the key squares, and a Hold step was drawn as a slope across one step. The samples now also include every visible key time and both sides of the key after a Hold key (so a stretched layer's one-tick rounding or a reversed layer still gives a vertical step). Keys denser than the grid add no samples, so the work stays bounded. This does not change the slanted spans in the issue's screenshot: their key squares sit at different values (about 0.36 vs 0.40, 0.01 vs 0.00), so the curve draws the stored values as they are. --- crates/ui-egui/src/panels/graph.rs | 142 ++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/graph.rs b/crates/ui-egui/src/panels/graph.rs index be18999d4..8a4401d97 100644 --- a/crates/ui-egui/src/panels/graph.rs +++ b/crates/ui-egui/src/panels/graph.rs @@ -130,6 +130,45 @@ fn speed_at(pr: &Property, spatial: bool, d: usize, lt: Tick) -> f64 { } } +/// How far either side of the key after a Hold key the step is sampled (seconds; far below a +/// pixel, far above the tick a stretched layer's time conversion can be off by). +const HOLD_EDGE: f64 = 1e-6; + +/// The comp times (seconds) a curve is sampled at between `t0` and `t1`: `n` evenly spaced +/// times, plus every key time `keys` puts inside the span, and around the key after a key that +/// holds (its out side is Hold) the instants just before and after it. `keys` are the active +/// keys in key order, as (comp seconds, holds); on a reversed layer their comp times descend. +/// Without the key times the polyline only passes near the keys: keys closer together than a +/// sample step (a one-frame jump zoomed out) got cut across, missing their squares, and a Hold +/// step was drawn as a slope across one step instead of a vertical edge (#2720). With no keys +/// this is the plain even grid. Keys denser than the grid (baked keys zoomed out) add nothing +/// visible and would multiply the evaluations, so past `2 * n` key samples only the grid is used. +fn sample_times(t0: f64, t1: f64, n: usize, keys: &[(f64, bool)]) -> Vec { + let n = n.max(2); + let mut ts: Vec = (0..n).map(|i| t0 + (t1 - t0) * i as f64 / (n - 1) as f64).collect(); + let (lo, hi) = (t0.min(t1), t0.max(t1)); + let inside = |t: f64| t > lo && t < hi; + let max_extra = n.saturating_mul(2); + let mut extra = vec![]; + for (i, &(kt, holds)) in keys.iter().enumerate() { + if inside(kt) { + extra.push(kt); + } + if holds && let Some(&(next, _)) = keys.get(i + 1) { + extra.extend([next - HOLD_EDGE, next + HOLD_EDGE].into_iter().filter(|&t| inside(t))); + } + if extra.len() > max_extra { + extra.clear(); + break; + } + } + ts.extend(extra); + ts.retain(|t| t.is_finite()); + ts.sort_by(f64::total_cmp); + ts.dedup(); + ts +} + /// Build the curves for the visible time span. fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, plot: Rect, speed: bool) -> Vec> { let sel = &app.session.state.selected_keys; @@ -140,12 +179,14 @@ fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, pl let Some(pr) = l.props.find(uid) else { continue }; let spatial = pr.spatial && matches!(pr.value, Value::Vec2(_) | Value::Vec3(_)); let dims = if speed && spatial { 1 } else { shown_dims(l, pr) }; + // The active keys (muted ones are skipped by evaluation) in comp seconds, and whether each + // holds its value up to the next one. + let active: Vec<(f64, bool)> = pr.keys.iter().filter(|k| !k.muted).map(|k| (l.comp_time(k.time).seconds(), k.out_interp == Interp::Hold)).collect(); + let times = sample_times(tm.t(plot.min.x), tm.t(plot.max.x), n, &active); for d in 0..dims { let color = if dims > 1 { DIM_COLORS[d % 4] } else { PROP_COLORS[pi % PROP_COLORS.len()] }; - let mut pts = Vec::with_capacity(n); - for i in 0..n { - let x = plot.min.x + plot.width() * i as f32 / (n - 1) as f32; - let ct = tm.t(x); + let mut pts = Vec::with_capacity(times.len()); + for &ct in × { let tt = Tick::from_seconds_f64(ct); let v = if speed { speed_at(pr, spatial, d, l.layer_time(tt)) } else { ectx.at(tt).value(l, pr).components().get(d).copied().unwrap_or(0.0) }; pts.push((ct, v)); @@ -892,7 +933,98 @@ fn shift_axes(shift: bool, dx: f32, dy: f32) -> (bool, bool) { #[cfg(test)] mod tests { - use super::shift_axes; + use super::{HOLD_EDGE, sample_times, shift_axes}; + use effectcraft_engine::keyframe::{Keyframe, Value, evaluate}; + use effectcraft_engine::time::Tick; + + /// The value-graph polyline of `keys` (layer time = comp time) sampled at `times`. + fn polyline(keys: &[Keyframe], times: &[f64]) -> Vec<(f64, f64)> { + times + .iter() + .map(|&t| { + let v = evaluate(keys, Tick::from_seconds_f64(t), false).map(|v| v.components().first().copied().unwrap_or(f64::NAN)).unwrap_or(f64::NAN); + (t, v) + }) + .collect() + } + + fn active(keys: &[Keyframe]) -> Vec<(f64, bool)> { + keys.iter().map(|k| (k.time.seconds(), k.out_interp == effectcraft_engine::keyframe::Interp::Hold)).collect() + } + + /// #2720: a step one frame wide, zoomed out so it is narrower than a sample step. The curve + /// has to pass through every key square: the old even grid (`sample_times` with no keys) + /// never sampled 0.2 s or 0.2 s + 1 frame and drew a slope from 0 to 1 across the step. + #[test] + fn value_graph_passes_through_keys_narrower_than_a_sample_step() { + let keys = [ + Keyframe::new(Tick::from_seconds_f64(0.0), Value::Scalar(0.0)), + Keyframe::new(Tick::from_seconds_f64(0.2), Value::Scalar(0.0)), + Keyframe::new(Tick::from_seconds_f64(0.2 + 1.0 / 30.0), Value::Scalar(1.0)), + Keyframe::new(Tick::from_seconds_f64(0.9), Value::Scalar(1.0)), + ]; + let times = sample_times(0.0, 1.0, 4, &active(&keys)); + let pts = polyline(&keys, ×); + for k in &keys { + let (t, v) = (k.time.seconds(), k.value.components()[0]); + assert!(pts.iter().any(|p| p.0 == t && (p.1 - v).abs() < 1e-12), "no curve point on the key at {t} s ({v}): {pts:?}"); + } + // The spans between equal keys are flat: no sample between 0 and 0.2 s leaves 0, none + // between 0.2 s + 1 frame and 0.9 s leaves 1. + for &(t, v) in &pts { + if t <= 0.2 { + assert!(v.abs() < 1e-12, "{t} s: {v}"); + } else if (0.2 + 1.0 / 30.0..=0.9).contains(&t) { + assert!((v - 1.0).abs() < 1e-12, "{t} s: {v}"); + } + } + // Times are sorted and unique, the even grid is still there. + assert!(times.windows(2).all(|w| w[0] < w[1]), "{times:?}"); + assert!([0.0, 1.0 / 3.0, 2.0 / 3.0, 1.0].iter().all(|g| times.iter().any(|t| (t - g).abs() < 1e-12)), "{times:?}"); + } + + /// #2720: a Hold key draws a vertical step at the next key, not a slope across a sample step. + #[test] + fn hold_step_is_vertical() { + let keys = [Keyframe::new(Tick::from_seconds_f64(0.1), Value::Scalar(0.0)).hold(), Keyframe::new(Tick::from_seconds_f64(0.5), Value::Scalar(1.0))]; + let pts = polyline(&keys, &sample_times(0.0, 1.0, 4, &active(&keys))); + let at = pts.iter().position(|p| p.0 == 0.5).unwrap_or_else(|| panic!("no sample on the key at 0.5 s: {pts:?}")); + let before = pts[at - 1]; + assert!((0.5 - before.0 - HOLD_EDGE).abs() < 1e-12 && before.1.abs() < 1e-12, "the held value ends right before the next key: {pts:?}"); + assert!((pts[at].1 - 1.0).abs() < 1e-12, "{pts:?}"); + } + + #[test] + fn sample_times_keep_keys_inside_the_span_only() { + let times = sample_times(1.0, 2.0, 3, &[(0.5, true), (1.25, false), (2.5, false)]); + // 0.5 s and 2.5 s are off screen; the hold from 0.5 s ends at 1.25 s, inside it. + assert_eq!(times, vec![1.0, 1.25 - HOLD_EDGE, 1.25, 1.25 + HOLD_EDGE, 1.5, 2.0]); + // Degenerate input never panics: an empty span is one point, a NaN span has no points. + assert_eq!(sample_times(0.0, 0.0, 0, &[]), vec![0.0]); + assert!(sample_times(f64::NAN, 1.0, 4, &[(0.5, true)]).iter().all(|t| t.is_finite())); + } + + /// A reversed layer: its keys run backwards in comp time, and both sides of each step after + /// a Hold key are still sampled. + #[test] + fn sample_times_cover_hold_steps_on_a_reversed_layer() { + let times = sample_times(1.0, 2.0, 10, &[(1.8, true), (1.4, true), (1.1, false)]); + for t in [1.8, 1.4 - HOLD_EDGE, 1.4, 1.4 + HOLD_EDGE, 1.1 - HOLD_EDGE, 1.1, 1.1 + HOLD_EDGE] { + assert!(times.contains(&t), "{t} missing: {times:?}"); + } + assert!(times.windows(2).all(|w| w[0] < w[1]), "{times:?}"); + } + + /// Dense keys zoomed out (100 000 in one second, half of them Hold) don't multiply the samples. + #[test] + fn sample_times_stay_bounded_with_dense_keys() { + let keys: Vec<(f64, bool)> = (0..100_000).map(|i| (i as f64 / 100_000.0, i % 2 == 0)).collect(); + let times = sample_times(0.0, 1.0, 100, &keys); + assert!(times.len() <= 300, "{} samples", times.len()); + // A few keys inside the span are still all sampled. + let few = sample_times(0.0, 1.0, 100, &keys[..50]); + assert!(keys[1..50].iter().all(|(t, _)| few.contains(t)), "{few:?}"); + } #[test] fn shift_locks_drag_to_dominant_axis() { From 36854318db1bbd8a2d1eafacb1efc5611fba8422 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 14:02:20 +0100 Subject: [PATCH 11/99] Viewer: the Rotation tool counts the turn from the press The Rotation gesture seeded its angle from the pointer where egui registered the drag, past the drag threshold, so the sweep round the anchor before that was lost; near the anchor that is a large angle. Count from where the button went down, as After Effects does and as the Create and Pan Behind gestures already do. A press within 3 points of the anchor, or with no anchor on screen, has no direction and still counts from where the drag registered, so the first move doesn't jump. The layer under the press is the one picked. The issue's main cause, a pivot far off for child and 3D layers, was fixed by #2887. Refs #2769 --- crates/ui-egui/src/panels/viewer.rs | 13 ++++-- crates/ui-egui/tests/it/ui_viewer.rs | 61 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/viewer.rs b/crates/ui-egui/src/panels/viewer.rs index b1899e1f8..f17d11795 100644 --- a/crates/ui-egui/src/panels/viewer.rs +++ b/crates/ui-egui/src/panels/viewer.rs @@ -1193,16 +1193,23 @@ fn phase_dragstart(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, }) } Tool::MaskFeather => ov::begin_feather(app, ectx, &paths, &map, press).map(Gesture::Overlay), - Tool::Rotate => pick(app, ectx, cpt, mods.shift).map(|l| { + // The layer under the press is the one that turns. + Tool::Rotate => pick(app, ectx, map.to_comp(press), mods.shift).map(|l| { let layer = comp.layer(l).cloned(); let sign = layer.as_ref().map_or(1.0, |l| rotation_sign(ectx, l)); let others = selected_others(app, comp, l) .into_iter() .filter_map(|o| Some((o.id, ectx.f(o, o.transform()?, "rotation", 0.0), rotation_sign(ectx, o) * sign))) .collect(); - let pivot = layer.as_ref().and_then(|l| anchor_in_comp(ectx, l)).unwrap_or(cpt); + let anchor = layer.as_ref().and_then(|l| anchor_in_comp(ectx, l)); + let pivot = anchor.unwrap_or(cpt); let rot = layer.as_ref().and_then(|l| l.transform().map(|tr| ectx.f(l, tr, "rotation", 0.0))).unwrap_or(0.0); - let last_angle = (cpt[1] - pivot[1]).atan2(cpt[0] - pivot[0]).to_degrees(); + // The turn counts from where the button went down, as in After Effects: by the + // time the drag registers the pointer has already swept some way round the anchor. + // A press on the anchor (or with no anchor to turn about) has no direction, so + // the turn then counts from where the drag registered. + let seed = if anchor.is_some() && press.distance(map.to_screen(pivot)) > 3.0 { map.to_comp(press) } else { cpt }; + let last_angle = (seed[1] - pivot[1]).atan2(seed[0] - pivot[0]).to_degrees(); Gesture::Rotate { layer: l, pivot, sign, last_angle, turned: 0.0, start_rot: rot, others } }), Tool::PanBehind => pick(app, ectx, cpt, false).and_then(|l| { diff --git a/crates/ui-egui/tests/it/ui_viewer.rs b/crates/ui-egui/tests/it/ui_viewer.rs index 7b32fa2ec..bd047088b 100644 --- a/crates/ui-egui/tests/it/ui_viewer.rs +++ b/crates/ui-egui/tests/it/ui_viewer.rs @@ -3022,6 +3022,67 @@ fn rotate_tool_counts_revolutions_both_ways() { assert_eq!(h.state().session.history.undo.len(), undo_before + 1, "one drag, one undo step"); } +/// #2769: the Rotation tool counts the turn from where the button went down, as in After Effects, +/// not from where the drag registered: a first move that sweeps 60° round the anchor turns the +/// layer 60° (it used to drop that sweep, so near the anchor the tool lagged behind the pointer). +#[test] +fn rotate_tool_counts_the_turn_from_the_press() { + let mut h = harness(); + let box_id = h.state().session.active_comp().unwrap().layers[0].id; + h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap(); + h.state_mut().ui.tool = Tool::Rotate; + h.run_steps(2); + let center = screen(&h, [320.0, 180.0]); + let r = (screen(&h, [350.0, 180.0]) - center).x; + // Press on the box right of its anchor (0°), then one move to 60° clockwise, still on the box. + let press = center + vec2(r * 0.3, 0.0); + let to = center + vec2(r * 60f32.to_radians().cos(), r * 60f32.to_radians().sin()); + h.input_mut().events.push(Event::PointerMoved(press)); + h.input_mut().events.push(Event::PointerButton { pos: press, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); + h.input_mut().events.push(Event::PointerMoved(to)); + h.step(); + // The gesture applies the previous frame's pointer: hold a frame. + h.step(); + h.input_mut().events.push(Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(2); + let rot = h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/rotation").unwrap().value.as_f64(); + assert!((rot - 60.0).abs() < 1.0, "the whole sweep from the press turns the layer: {rot}"); +} + +/// #2769: a press right on the anchor point has no direction to count the turn from, so the layer +/// doesn't jump on the first move; the turn counts from where the drag registered. +#[test] +fn rotate_tool_pressed_on_the_anchor_does_not_jump() { + let mut h = harness(); + let box_id = h.state().session.active_comp().unwrap().layers[0].id; + h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap(); + h.state_mut().ui.tool = Tool::Rotate; + h.run_steps(2); + let rotation = |h: &Harness<'_, EffectcraftApp>| { + h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/rotation").unwrap().value.as_f64() + }; + let center = screen(&h, [320.0, 180.0]); + let r = (screen(&h, [350.0, 180.0]) - center).x; + let at = |deg: f32| center + vec2(r * deg.to_radians().cos(), r * deg.to_radians().sin()); + h.input_mut().events.push(Event::PointerMoved(center)); + h.input_mut().events.push(Event::PointerButton { pos: center, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); + h.input_mut().events.push(Event::PointerMoved(at(60.0))); + h.step(); + // The gesture applies the previous frame's pointer: hold a frame. + h.step(); + let first = rotation(&h); + assert!(first.abs() < 1.0, "no jump on the first move: {first}"); + h.input_mut().events.push(Event::PointerMoved(at(90.0))); + h.step(); + h.step(); + let next = rotation(&h); + assert!((next - 30.0).abs() < 1.0, "then turns with the pointer: {next}"); + h.input_mut().events.push(Event::PointerButton { pos: at(90.0), button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(2); +} + /// A harness whose Box is a child of Plate (anchor 320,180) with `plate` set on Plate first, at /// parent-space position (200, 120). Returns the two layers' ids. fn rotate_child_harness(plate: serde_json::Value) -> (Harness<'static, EffectcraftApp>, u64, u64) { From e109fa6b95310ac84955bef6b272c0c76aa2e2c3 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 15:20:11 +0100 Subject: [PATCH 12/99] Graph Editor: a dense key cluster only thins its own grid steps Refs #2720 When the key samples passed the budget, sample_times dropped all of them, so a sparse Hold step elsewhere in view went back to a slope. Key samples are now kept per grid step: up to four as they are, past that only the earliest and latest of that step. Sparse keys keep every sample and a curve still has at most 5 * n samples. --- crates/ui-egui/src/panels/graph.rs | 87 +++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/panels/graph.rs b/crates/ui-egui/src/panels/graph.rs index 8a4401d97..397d9cab3 100644 --- a/crates/ui-egui/src/panels/graph.rs +++ b/crates/ui-egui/src/panels/graph.rs @@ -134,6 +134,42 @@ fn speed_at(pr: &Property, spatial: bool, d: usize, lt: Tick) -> f64 { /// pixel, far above the tick a stretched layer's time conversion can be off by). const HOLD_EDGE: f64 = 1e-6; +/// How many key samples one grid step of [`sample_times`] keeps as they are (a key and both +/// sides of a Hold step fit); past that only its earliest and latest are kept. +const BUCKET_KEEP: usize = 4; + +/// The key samples falling in one grid step of [`sample_times`]. +#[derive(Clone)] +struct Bucket { + few: Vec, + first: f64, + last: f64, + /// More than [`BUCKET_KEEP`] samples fell here. + full: bool, +} + +impl Default for Bucket { + fn default() -> Self { + Bucket { few: Vec::new(), first: f64::INFINITY, last: f64::NEG_INFINITY, full: false } + } +} + +impl Bucket { + fn add(&mut self, t: f64) { + self.first = self.first.min(t); + self.last = self.last.max(t); + if self.full { + return; + } + if self.few.len() < BUCKET_KEEP { + self.few.push(t); + } else { + self.full = true; + self.few = Vec::new(); + } + } +} + /// The comp times (seconds) a curve is sampled at between `t0` and `t1`: `n` evenly spaced /// times, plus every key time `keys` puts inside the span, and around the key after a key that /// holds (its out side is Hold) the instants just before and after it. `keys` are the active @@ -142,27 +178,40 @@ const HOLD_EDGE: f64 = 1e-6; /// sample step (a one-frame jump zoomed out) got cut across, missing their squares, and a Hold /// step was drawn as a slope across one step instead of a vertical edge (#2720). With no keys /// this is the plain even grid. Keys denser than the grid (baked keys zoomed out) add nothing -/// visible and would multiply the evaluations, so past `2 * n` key samples only the grid is used. +/// visible and would multiply the evaluations: in a grid step with more than [`BUCKET_KEEP`] +/// key samples only the earliest and latest are kept, so a curve has at most `5 * n` samples +/// and sparse keys elsewhere in view keep every sample. fn sample_times(t0: f64, t1: f64, n: usize, keys: &[(f64, bool)]) -> Vec { let n = n.max(2); let mut ts: Vec = (0..n).map(|i| t0 + (t1 - t0) * i as f64 / (n - 1) as f64).collect(); let (lo, hi) = (t0.min(t1), t0.max(t1)); let inside = |t: f64| t > lo && t < hi; - let max_extra = n.saturating_mul(2); - let mut extra = vec![]; + // One bucket per grid step. + let steps = n - 1; + let mut buckets = vec![Bucket::default(); steps]; + let mut add = |t: f64| { + if !inside(t) { + return; + } + let b = (((t - lo) / (hi - lo) * steps as f64) as usize).min(steps - 1); + if let Some(bucket) = buckets.get_mut(b) { + bucket.add(t); + } + }; for (i, &(kt, holds)) in keys.iter().enumerate() { - if inside(kt) { - extra.push(kt); - } + add(kt); if holds && let Some(&(next, _)) = keys.get(i + 1) { - extra.extend([next - HOLD_EDGE, next + HOLD_EDGE].into_iter().filter(|&t| inside(t))); + add(next - HOLD_EDGE); + add(next + HOLD_EDGE); } - if extra.len() > max_extra { - extra.clear(); - break; + } + for b in &buckets { + if b.full { + ts.extend([b.first, b.last]); + } else { + ts.extend_from_slice(&b.few); } } - ts.extend(extra); ts.retain(|t| t.is_finite()); ts.sort_by(f64::total_cmp); ts.dedup(); @@ -1021,9 +1070,19 @@ mod tests { let keys: Vec<(f64, bool)> = (0..100_000).map(|i| (i as f64 / 100_000.0, i % 2 == 0)).collect(); let times = sample_times(0.0, 1.0, 100, &keys); assert!(times.len() <= 300, "{} samples", times.len()); - // A few keys inside the span are still all sampled. - let few = sample_times(0.0, 1.0, 100, &keys[..50]); - assert!(keys[1..50].iter().all(|(t, _)| few.contains(t)), "{few:?}"); + } + + /// A dense cluster of keys only thins its own grid steps: a Hold step elsewhere in view keeps + /// its key and both sides of the step. + #[test] + fn sample_times_keep_sparse_keys_beside_a_dense_cluster() { + let mut keys: Vec<(f64, bool)> = (0..100_000).map(|i| (0.1 * i as f64 / 100_000.0, i % 2 == 0)).collect(); + keys.extend([(0.5, true), (0.8, false)]); + let times = sample_times(0.0, 1.0, 100, &keys); + assert!(times.len() <= 500, "{} samples", times.len()); + for t in [0.5, 0.8 - HOLD_EDGE, 0.8, 0.8 + HOLD_EDGE] { + assert!(times.contains(&t), "{t} missing"); + } } #[test] From a2728fbf094d79ef92d164b2769228dc938487b2 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 15:29:46 +0100 Subject: [PATCH 13/99] Timeline waveform: draw what the mix plays for reversed layers and Backwards (#3238) A time-reversed layer (negative stretch) is silent in the audio mix, but the Timeline drew its waveform; with the Backwards audio effect the mix plays the layer's [in, out) span reversed, but the waveform was drawn forwards. The render crate now exposes the mix's rules as stretch_is_mixed and plays_backwards, and the mix uses them. The waveform uses the same rules, decided once per layer: only the baselines for a layer the mix leaves silent, and comp time mirrored over [in, out) under Backwards, as the mix maps it. Columns are limited to [in, out) so an edge column draws no audio past the out point. Fixes #3238 --- crates/render/src/audio.rs | 15 ++- crates/ui-egui/src/panels/waveform.rs | 177 ++++++++++++++++++++++++-- 2 files changed, 180 insertions(+), 12 deletions(-) diff --git a/crates/render/src/audio.rs b/crates/render/src/audio.rs index e2861340c..b715c5efe 100644 --- a/crates/render/src/audio.rs +++ b/crates/render/src/audio.rs @@ -66,6 +66,17 @@ fn generates(l: &Layer) -> bool { audio_effect_groups(l).any(|(id, _)| audio_fx::generates_audio(id)) } +/// Does the mix play the layer at its time stretch? Reversed layers (negative stretch) are +/// silent for now; the Timeline waveform shares this rule so it draws what is heard. +pub fn stretch_is_mixed(l: &Layer) -> bool { + l.stretch > 0.0 +} + +/// Does an enabled audio effect (Backwards) play the layer's [in, out) span reversed? +pub fn plays_backwards(l: &Layer) -> bool { + audio_effect_groups(l).any(|(id, _)| audio_fx::reverses(id)) +} + /// Does the layer contribute to the mix (Audio switch on and something to hear)? pub fn audible(project: &Project, l: &Layer) -> bool { l.switches.audio @@ -210,7 +221,7 @@ impl MixEnv<'_> { if fx.is_empty() { return self.layer_raw(l, i0, n, false); } - let reversed = fx.iter().any(|(id, _, _)| audio_fx::reverses(id)); + let reversed = plays_backwards(l); let pre_s: f64 = fx.iter().map(|(id, _, p)| audio_fx::preroll(id, p)).sum(); let pre = (pre_s * self.rate as f64).ceil() as usize; let b0 = i0 - pre as i64; @@ -291,7 +302,7 @@ fn mix_into(sources: &AudioSources<'_>, comp_id: ItemId, start: Tick, out: &mut let any_solo = comp.layers.iter().any(|l| l.switches.solo && audible(project, l)); let s0 = start.to_units_floor(rate as i64); for l in &comp.layers { - if !audible(project, l) || (any_solo && !l.switches.solo) || l.stretch <= 0.0 { + if !audible(project, l) || (any_solo && !l.switches.solo) || !stretch_is_mixed(l) { continue; } // Sample range of the block that falls inside the layer's [in, out). diff --git a/crates/ui-egui/src/panels/waveform.rs b/crates/ui-egui/src/panels/waveform.rs index 4e355f951..aa4c218e5 100644 --- a/crates/ui-egui/src/panels/waveform.rs +++ b/crates/ui-egui/src/panels/waveform.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; use std::sync::{Arc, Mutex}; use effectcraft_engine::project::{ItemId, ItemKind, Layer, LayerSource, Project, Property}; -use effectcraft_engine::render::audio::db_to_gain; +use effectcraft_engine::render::audio::{self, db_to_gain}; use effectcraft_engine::time::Tick; use egui::{Color32, Painter, Rect, Stroke, pos2}; @@ -39,6 +39,39 @@ pub fn audio_item(project: &Project, l: &Layer) -> Option { } } +/// How the layer plays its audio, as far as its waveform goes: `None` when it is silent +/// (reversed, see [`audio::stretch_is_mixed`]), else whether the Backwards effect plays its +/// [in, out) span mirrored ([`audio::plays_backwards`]). The Audio switch and solo are not +/// followed: a muted layer still shows its waveform. +fn played(layer: &Layer) -> Option { + audio::stretch_is_mixed(layer).then(|| audio::plays_backwards(layer)) +} + +/// The summary bins under the Timeline column for comp times `ta .. tb` (seconds, limited to +/// the layer's [in, out) span), as the layer plays them: mirrored over that span when `mirror` +/// (see [`played`]), so the first column shows the last samples. +fn column_bins<'a>(layer: &Layer, s: &'a Summary, ta: f64, tb: f64, mirror: bool) -> Option<&'a [[f32; 4]]> { + let (i, o) = (layer.in_point.seconds(), layer.out_point.seconds()); + let (ta, tb) = (ta.max(i).min(o), tb.max(i).min(o)); + if tb <= ta { + return None; + } + let span = i + o; + let src = |t: f64| { + let t = if mirror { span - t } else { t }; + layer.layer_time(Tick::from_seconds_f64(t)).seconds() * s.bins_per_sec as f64 + }; + let (u, v) = (src(ta), src(tb)); + let n = s.peaks.len() as i64; + let ba = u.min(v).floor() as i64; + let bb = (u.max(v).ceil() as i64).max(ba.saturating_add(1)); + let (ba, bb) = (ba.clamp(0, n), bb.clamp(0, n)); + if ba >= bb { + return None; + } + s.peaks.get(ba as usize..bb as usize) +} + /// The summary for `item`, starting its computation on first request. pub fn summary(app: &EffectcraftApp, ctx: &egui::Context, item: ItemId) -> Option> { let mut m = app.waveforms.map.lock().ok()?; @@ -88,27 +121,23 @@ fn level_gains(levels: Option<&Property>, t: Tick) -> [f32; 2] { } /// Draw `layer`'s waveform in `rect` (left channel above right), columns mapped through the -/// timeline's time map and the layer's time mapping, limited to its [in, out) span. +/// timeline's time map and the layer's time mapping, limited to its [in, out) span and drawn as +/// the layer plays (see [`played`]): only the baselines for a silent layer. pub(crate) fn draw(p: &Painter, rect: Rect, tm: &TMap, layer: &Layer, s: &Summary, color: Color32) { let mid = [rect.min.y + rect.height() * 0.25, rect.min.y + rect.height() * 0.75]; let half = rect.height() * 0.25 - 1.0; let x0 = tm.x(layer.in_point.seconds()).max(rect.min.x).floor() as i32; let x1 = tm.x(layer.out_point.seconds()).min(rect.max.x).ceil() as i32; - let n = s.peaks.len() as i64; let levels = layer.props.sub("audio").and_then(|g| g.get("levels")); for c in 0..2 { p.line_segment([pos2(x0 as f32, mid[c]), pos2(x1 as f32, mid[c])], Stroke::new(1.0, color.gamma_multiply(0.5))); } + let Some(mirror) = played(layer) else { return }; for x in x0..x1 { let (ta, tb) = (tm.t(x as f32), tm.t(x as f32 + 1.0)); - let src = |t: f64| layer.layer_time(Tick::from_seconds_f64(t)).seconds() * s.bins_per_sec as f64; - let (ba, bb) = (src(ta).floor() as i64, src(tb).ceil() as i64); - let (ba, bb) = (ba.min(bb).clamp(0, n), ba.max(bb).max(ba + 1).clamp(0, n)); - if ba >= bb { - continue; - } + let Some(bins) = column_bins(layer, s, ta, tb, mirror) else { continue }; let mut agg = [0.0f32; 4]; - for b in &s.peaks[ba as usize..bb as usize] { + for b in bins { agg[0] = agg[0].min(b[0]); agg[1] = agg[1].max(b[1]); agg[2] = agg[2].min(b[2]); @@ -137,3 +166,131 @@ mod tests { assert_eq!(level_gains(None, Tick::ZERO), [1.0, 1.0]); } } + +#[cfg(test)] +mod played_tests { + use super::*; + use effectcraft_engine::color::Label; + use effectcraft_engine::project::{Comp, Footage, FootageKind, GroupKind, build}; + use effectcraft_engine::render::audio::{footage_peaks, mix_comp}; + use effectcraft_engine::render::{FootageSource, Image}; + use effectcraft_engine::time::FrameRate; + + /// Footage audio equal to its source time (seconds) on both channels over [0, 2) s. + struct Ramp; + impl FootageSource for Ramp { + fn frame(&self, _: ItemId, _: &Footage, _: Tick) -> Option> { + None + } + fn audio(&self, _: ItemId, _: &Footage, start: Tick, frames: usize, rate: u32) -> Option> { + let t0 = start.seconds(); + Some( + (0..frames) + .flat_map(|k| { + let t = t0 + k as f64 / rate as f64; + let v = if (0.0..2.0).contains(&t) { t as f32 } else { 0.0 }; + [v, v] + }) + .collect(), + ) + } + } + + /// A project with a 2 s ramp clip and a comp holding one layer of it (start and in 0 s, + /// out 1 s) changed by `edit`, and the clip's peak summary. + fn setup(edit: &dyn Fn(&mut Layer)) -> (Project, ItemId, Layer, Summary) { + let mut p = Project::default(); + let f = Footage { + path: "ramp.wav".into(), + kind: FootageKind::Audio, + has_audio: true, + frame_rate: FrameRate::new(25, 1), + duration: Tick::from_seconds_f64(2.0), + ..Default::default() + }; + let fid = p.add_item("ramp.wav", Label::SeaFoam, None, ItemKind::Footage(f.clone())); + let mut comp = Comp::new(64, 64, FrameRate::new(25, 1), Tick::from_seconds_f64(2.0)); + let mut l = build::layer(&mut p, &comp, "a", LayerSource::Footage { item: fid }, (0, 0), None); + (l.start_time, l.in_point, l.out_point) = (Tick::ZERO, Tick::ZERO, Tick::from_seconds_f64(1.0)); + edit(&mut l); + comp.layers = vec![l.clone()].into(); + let cid = p.add_item("C", Label::Sandstone, None, ItemKind::Comp(comp.into())); + let peaks = footage_peaks(&Ramp, fid, &f, f.duration, BINS_PER_SEC); + (p, cid, l, Summary { bins_per_sec: BINS_PER_SEC, peaks }) + } + + fn add_backwards(l: &mut Layer, enabled: bool) { + let mut n = 1_000_000; + let mut g = build::Ids(&mut n).group("backwards", "Backwards"); + g.kind = GroupKind::Effect { effect: "ec.audio.backwards".into() }; + g.enabled = enabled; + l.props.group_mut("effects").expect("effects group").children.push(g.into()); + } + + /// The loudest left-channel peak drawn in the column for comp times `ta .. tb`. + fn drawn(l: &Layer, s: &Summary, ta: f64, tb: f64) -> Option { + played(l).and_then(|mirror| column_bins(l, s, ta, tb, mirror)).map(|bins| bins.iter().fold(f32::MIN, |m, b| m.max(b[1]))) + } + + /// The left-channel sample the mix plays at comp time `t`. + fn heard(p: &Project, cid: ItemId, t: f64) -> f32 { + mix_comp(p, &Ramp, None, cid, Tick::from_seconds_f64(t), 1, 8000).first().copied().unwrap_or(f32::NAN) + } + + /// #3238: a time-reversed layer (Time-Reverse Layer: stretch -100 %, start time at its out + /// point) is silent in the mix, so the Timeline draws no waveform columns for it. + #[test] + fn a_reversed_layer_draws_no_waveform_as_the_mix_is_silent() { + let (p, cid, l, s) = setup(&|l| { + l.stretch = -100.0; + l.start_time = Tick::from_seconds_f64(1.0); + }); + for k in 0..200 { + let (ta, tb) = (k as f64 / 200.0, (k + 1) as f64 / 200.0); + assert_eq!(drawn(&l, &s, ta, tb), None, "column at {ta} s"); + } + for t in [0.1, 0.5, 0.9] { + assert_eq!(heard(&p, cid, t), 0.0, "the mix plays the reversed layer at {t} s"); + } + } + + /// #3238: with the Backwards audio effect the first column shows the clip's last samples + /// and the last column its first, matching what the mix plays there. + #[test] + fn backwards_draws_the_waveform_mirrored_as_the_mix_plays_it() { + let (p, cid, l, s) = setup(&|l| add_backwards(l, true)); + let first = drawn(&l, &s, 0.0, 0.005).expect("first column"); + let h = heard(&p, cid, 0.0); + assert!(first > 0.98, "first column draws {first}, not the clip's last samples"); + assert!((first - h).abs() < 0.01, "first column {first}, heard {h}"); + let last = drawn(&l, &s, 0.995, 1.0).expect("last column"); + let h = heard(&p, cid, 0.995); + assert!(last < 0.02, "last column draws {last}, not the clip's first samples"); + assert!((last - h).abs() < 0.01, "last column {last}, heard {h}"); + } + + /// No Backwards effect, a disabled one, or the layer's Effects switch off: the mix plays + /// forwards, and so the waveform is drawn. + #[test] + fn without_an_active_backwards_effect_the_waveform_runs_forwards() { + let edits: [(&str, &dyn Fn(&mut Layer)); 3] = [ + ("no effect", &|_| {}), + ("effect disabled", &|l| add_backwards(l, false)), + ("effects switch off", &|l| { + add_backwards(l, true); + l.switches.effects = false; + }), + ]; + for (name, edit) in edits { + let (p, cid, l, s) = setup(edit); + let first = drawn(&l, &s, 0.0, 0.005).expect("first column"); + let h = heard(&p, cid, 0.004); + assert!(first < 0.02, "{name}: first column draws {first}"); + assert!((first - h).abs() < 0.01, "{name}: first column {first}, heard {h}"); + // A column reaching past the out point draws only up to it. + let edge = drawn(&l, &s, 0.998, 1.003).expect("edge column"); + assert!(edge < 1.001, "{name}: the edge column draws {edge}, past the out point"); + assert_eq!(drawn(&l, &s, 1.0, 1.005), None, "{name}: a column after the out point"); + } + } +} From 2d547200c02dc612ce6b125f3ea395430bdb55f7 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 16:13:20 +0100 Subject: [PATCH 14/99] Effect Controls: Alt-click on a stopwatch adds an expression and edits it in the Timeline Refs #1460. As in After Effects, Alt-click (Option-click) on a stopwatch in Effect Controls adds an expression (it toggled keyframing instead) and Alt-click again removes it. Effect Controls has no expression field, so the property is revealed in the Timeline (the same reveal as a double-click on its name, #1497) and the new expression's editor takes the keyboard with the expression selected. The Timeline's stopwatch and Effect Controls share one helper for that focus request (expression_toggled). The editor takes a request from the pass after the one it was made in: drawn in the same pass as the Alt-click in another panel, its text field gave the keyboard straight back as a click elsewhere. --- .../src/panels/effect_controls/rows.rs | 30 +++++++++--- crates/ui-egui/src/panels/timeline.rs | 33 +++++++++---- crates/ui-egui/tests/it/ui_inline_edit.rs | 48 +++++++++++++++++++ 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/panels/effect_controls/rows.rs b/crates/ui-egui/src/panels/effect_controls/rows.rs index c14630af4..e7f1bfee5 100644 --- a/crates/ui-egui/src/panels/effect_controls/rows.rs +++ b/crates/ui-egui/src/panels/effect_controls/rows.rs @@ -128,6 +128,18 @@ impl PropCx<'_> { } } +/// Shows property `uid` of layer `layer` in the Timeline: its layer and groups twirled open, the +/// property scrolled to and the Timeline brought forward (After Effects' Reveal in Timeline, +/// which a double-click on the property's name does; #1497). +fn reveal_in_timeline(app: &mut EffectcraftApp, ctx: &egui::Context, layer: u64, uid: u64) { + app.ui.timeline.search.clear(); + app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid)); + if let Err(e) = crate::menus::frontend(app, ctx, "timeline.revealProps", json!({"props": [{"layer": layer, "prop": uid}]})) { + app.ui.status = e; + } + app.show_panel(crate::dock::PanelKind::Timeline); +} + /// One property row: stopwatch, name, value control (and the keyframe navigator). Returns the /// value fields of a vector, one per dimension, for the pick whip. #[allow(clippy::too_many_arguments)] @@ -167,7 +179,16 @@ fn prop_row( }, ); app.auto.add(&format!("effectControls.prop.{uid}.stopwatch"), swr, &prop.name); - if resp.clicked() { + if resp.clicked() && ui.input(|i| i.modifiers.alt) { + // Alt+click adds an expression (or removes it), as in the Timeline. Effect Controls + // has no expression field: the property shows in the Timeline with its new + // expression's editor taking the keyboard, as After Effects does (#1460). + actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid}))); + if prop.expr.is_none() { + reveal_in_timeline(app, ui.ctx(), layer.id.0, uid); + } + crate::panels::timeline::expression_toggled(app, ui.ctx(), prop); + } else if resp.clicked() { actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "selected": true}))); } } @@ -201,12 +222,7 @@ fn prop_row( p.with_clip_rect(name_clip.intersect(p.clip_rect())).text(pos2(swr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text); let name_response = ui.interact(name_clip, egui::Id::unique(("ec-prop-name", uid)), Sense::click()); if name_response.double_clicked() { - app.ui.timeline.search.clear(); - app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid)); - if let Err(e) = crate::menus::frontend(app, ui.ctx(), "timeline.revealProps", json!({"props": [{"layer": layer.id.0, "prop": uid}]})) { - app.ui.status = e; - } - app.show_panel(crate::dock::PanelKind::Timeline); + reveal_in_timeline(app, ui.ctx(), layer.id.0, uid); } app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name); // With several layers selected the edit applies to the same effect property of each (#491). diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 038dcc9b9..e7f8311c0 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -323,9 +323,27 @@ fn expr_focus_id() -> egui::Id { egui::Id::unique("tl-expr-focus") } +/// Asks the expression editor of property `prop` to take the keyboard when the Timeline next +/// draws it, selecting `select` (counts of characters before the end). fn focus_expression(ctx: &egui::Context, prop: u64, select: [usize; 2]) { let pass = ctx.cumulative_pass_nr(); ctx.data_mut(|d| d.insert_temp(expr_focus_id(), ExprFocus { prop, select, pass })); + // The editor takes it in a later pass: make sure one comes without waiting for input. + ctx.request_repaint(); +} + +/// After a `prop.setExpression` toggle of `prop` was queued (an Alt-click on its stopwatch, in the +/// Timeline or in Effect Controls): adding one, its editor opens, comes into view and takes the +/// keyboard with the new expression selected (#1072, #1460); removing it, a pending request for +/// its editor goes, as nothing is left to take the keyboard. +pub(crate) fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) { + let uid = prop.uid; + if prop.expr.is_none() { + app.ui.timeline.expr_closed.remove(&uid); + focus_expression(ctx, uid, [usize::MAX, 0]); + } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == uid) { + ctx.data_mut(|d| d.remove::(expr_focus_id())); + } } #[derive(Clone, Debug)] @@ -3927,7 +3945,10 @@ fn expr_editor_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.expr_bg); let er = Rect::from_min_max(pos2(graph_x0 + 8.0, r.min.y + 3.0), pos2(rect.max.x - 14.0, r.max.y - 3.0)); let mut buf: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone()); - if let Some(f) = ctx.data(|d| d.get_temp::(expr_focus_id())).filter(|f| f.prop == *uid) { + // Not in the pass it was asked for in: a click that asked for it from another panel (an + // Alt-click on a stopwatch in Effect Controls, drawn before the Timeline) would take the + // keyboard straight back as a click elsewhere (#1460). + if let Some(f) = ctx.data(|d| d.get_temp::(expr_focus_id())).filter(|f| f.prop == *uid && ctx.cumulative_pass_nr() > f.pass) { // Asked for once (a pick whip put a reference in, or an Alt-click added the // expression): editing starts in the expression as it is now. ctx.data_mut(|d| d.remove::(expr_focus_id())); @@ -4079,15 +4100,7 @@ fn prop_stopwatch(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: & if ui.input(|i| i.modifiers.alt) { if resp.clicked() { actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid}))); - if prop.expr.is_none() { - // Adding one: its editor opens, comes into view and takes the - // keyboard with the new expression selected (#1072). - app.ui.timeline.expr_closed.remove(uid); - focus_expression(&ctx, *uid, [usize::MAX, 0]); - } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == *uid) { - // Removing it: nothing is left to take the keyboard. - ctx.data_mut(|d| d.remove::(expr_focus_id())); - } + expression_toggled(app, &ctx, prop); } } else if let Some((value, merge)) = switch_gesture(ui, &resp, r, "stopwatch", prop.is_animated()) { actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "value": value, "merge": merge}))); diff --git a/crates/ui-egui/tests/it/ui_inline_edit.rs b/crates/ui-egui/tests/it/ui_inline_edit.rs index 6c29045bb..8271e2f9e 100644 --- a/crates/ui-egui/tests/it/ui_inline_edit.rs +++ b/crates/ui-egui/tests/it/ui_inline_edit.rs @@ -634,6 +634,54 @@ fn an_expression_added_at_the_bottom_of_the_timeline_comes_into_view() { assert_eq!(expression(&h, layer, opacity).as_deref(), Some("25")); } +/// #1460: Alt-clicking an effect property's stopwatch in Effect Controls adds an expression, as in +/// the Timeline (it toggled the animation instead). Effect Controls has no expression field, so, +/// as in After Effects, the property shows in the Timeline (its layer and effect twirled open, +/// scrolled into view) with the new expression's editor taking the keyboard: typing replaces +/// it. Another Alt-click removes it and leaves nothing holding the keyboard. +#[test] +fn alt_clicking_a_stopwatch_in_effect_controls_edits_the_expression_in_the_timeline() { + let (mut h, _) = harness(); + let (layer, slider) = { + let s = &mut h.state_mut().session; + let l = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("effect.apply", json!({"layers": [l], "effect": "Slider Control"})).unwrap(); + // Layers above push it below the bottom of the Timeline. + for i in 0..40 { + s.execute("layer.newSolid", json!({"name": format!("Layer {i}"), "color": "#204060"})).unwrap(); + } + s.execute("layer.select", json!({"layers": [l]})).unwrap(); + let slider = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(l)).unwrap().props.prop("effects/#1/slider").unwrap().uid; + (l, slider) + }; + h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::EffectControls); + h.run_steps(3); + let editor = format!("timeline.prop.{slider}.expression"); + assert!(h.state().auto.find(&format!("timeline.prop.{slider}.row")).is_none(), "the property is not in the Timeline yet"); + let alt = Modifiers { alt: true, ..Modifiers::NONE }; + let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch")); + click_with(&mut h, at, alt); + assert!(expression(&h, layer, slider).is_some(), "an expression was added"); + let key = h.state().session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(layer)).unwrap().props.find(slider).unwrap().is_animated(); + assert!(!key, "Alt-click doesn't turn on keyframing"); + assert!(h.state().ui.timeline.reveal_props.contains(&slider), "the property is revealed in the Timeline"); + let rows = h.state().auto.find("timeline.scroll").expect("the Timeline is shown").rect; + let e = h.state().auto.find(&editor).expect("the Timeline draws the expression editor").rect; + assert!(e[1] >= rows[1] - 0.5 && e[1] + e[3] <= rows[1] + rows[3] + 0.5, "the editor is in view: {e:?} in {rows:?}"); + type_text(&mut h, "42"); + commit_expression(&mut h); + assert_eq!(expression(&h, layer, slider).as_deref(), Some("42"), "typing replaced the new expression"); + // Alt-click again removes the expression and its editor with it (the keyboard stays free; + // the editor's focus request was taken when it was added, so this doesn't exercise the + // cancel path). + let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch")); + click_with(&mut h, at, alt); + h.run_steps(5); + assert_eq!(expression(&h, layer, slider), None); + assert!(h.state().auto.find(&editor).is_none(), "the expression editor is gone"); + assert!(!h.ctx.egui_wants_keyboard_input(), "nothing has the keyboard"); +} + /// A primary-button drag from `from` to `to` with `modifiers` held from the press to the release. fn drag_with(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2, modifiers: Modifiers) { h.input_mut().events.push(Event::PointerMoved(from)); From 932326ced681040605017ee064fdbef0d4805fe1 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 19:50:44 +0100 Subject: [PATCH 15/99] Doc comments for the functions this PR touches --- crates/ui-egui/src/panels/viewer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/src/panels/viewer.rs b/crates/ui-egui/src/panels/viewer.rs index f17d11795..cc3666d6a 100644 --- a/crates/ui-egui/src/panels/viewer.rs +++ b/crates/ui-egui/src/panels/viewer.rs @@ -1130,6 +1130,7 @@ fn led_by_a_moved_ancestor(comp: &Comp, layers: &[MoveLayer]) -> Vec { layers.iter().map(|l| led(l.0)).collect() } +/// Starts the viewer drag gesture for the active tool from the press point, picking the layer, vertex or handle under it. fn phase_dragstart(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, resp: &egui::Response, v: &mut Vw<'_>) { let comp_rect = v.comp_rect; let zoom = v.zoom; From ca4d8470beeab3e2ca2221514790f03f9bb9c56f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 8 Nov 2026 23:54:01 -0800 Subject: [PATCH 16/99] Updates: the first start after an update shows how it ended The check at start sets the status to Updated or InstallFailed, and the result dialog showed only after a Help > Check for Updates request. A failed installation was not reported at start when no newer release was found, and a later manual check replaced the status. The dialog now shows whenever the updater's status is not idle. --- crates/ui-egui/src/lifecycle_tests.rs | 23 +++++++++++++++++++++++ crates/ui-egui/src/updates_ui.rs | 14 ++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/lifecycle_tests.rs b/crates/ui-egui/src/lifecycle_tests.rs index 6c9eb85d2..a6c8115bf 100644 --- a/crates/ui-egui/src/lifecycle_tests.rs +++ b/crates/ui-egui/src/lifecycle_tests.rs @@ -239,6 +239,29 @@ fn the_close_guard_answers_a_close_request_without_a_pass() { assert_eq!(app.ui_passes(), 0); } +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn the_update_result_dialog_shows_every_status_but_idle() { + use craft_update::updater::Status; + let shown = [ + Status::Checking, + Status::UpToDate, + Status::Failed("offline".into()), + Status::Installing, + Status::Ready, + Status::Managed, + Status::Updated("1.2.3".into()), + Status::InstallFailed("access denied".into()), + ]; + for status in &shown { + assert!(updates_ui::result_window_open(false, status, false), "{status:?} opens the dialog without a requested check"); + } + assert!(!updates_ui::result_window_open(false, &Status::Idle, false)); + assert!(!updates_ui::result_window_open(true, &Status::Idle, false), "a check that found a release closes it"); + assert!(updates_ui::result_window_open(true, &Status::Idle, true), "a queued check keeps it open"); + assert!(!updates_ui::result_window_open(false, &Status::Idle, true), "a queued check does not open it"); +} + // ---------------------------------------------------------------- screenshots fn screenshot_request(app: &mut EffectcraftApp, ctx: &egui::Context, path: Option<&str>, target: ShotTarget) -> std::sync::mpsc::Receiver { diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 316e34ac4..e1c4c2eac 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -72,6 +72,15 @@ pub(crate) fn tick(app: &mut EffectcraftApp, ctx: &egui::Context) { let _ = (app, ctx); } +/// Whether the check result dialog shows this frame. It answers Help ▸ Check for Updates until the +/// requested check ends, and it shows whenever the status is not idle: at the first start after an +/// update, the check at start leaves `Updated` or `InstallFailed`. A check that finds a release +/// leaves the status idle and the startup prompt takes over, so the dialog closes then. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn result_window_open(open: bool, status: &Status, check_requested: bool) -> bool { + !matches!(status, Status::Idle) || (open && check_requested) +} + pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { #[cfg(not(target_arch = "wasm32"))] { @@ -83,6 +92,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { Action::None => {} } let rt = &mut app.updates_rt; + rt.manual_window_open = result_window_open(rt.manual_window_open, rt.updater.status(), rt.check_requested); if rt.manual_window_open { match CheckResultDialog::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).show(ctx, rt.updater.status()) { CheckResultResponse::None => {} @@ -93,10 +103,6 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), } - // A check that found a release leaves the status idle and the startup prompt takes over. - if matches!(rt.updater.status(), Status::Idle) && !rt.check_requested { - rt.manual_window_open = false; - } } } From a31af8b4233d796adb608065d4e4b3ef2f2f689c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 9 Nov 2026 00:08:40 -0800 Subject: [PATCH 17/99] Updates: Restart to Update with unsaved changes opens the save prompt The updater closes the app only when nothing is unsaved, and the result dialog is modal, so with a dirty project Restart to Update did nothing the user could see and the project could not be saved behind the dialog. With unsaved changes the button now closes the result dialog and asks the window to close, which opens the unsaved-changes prompt. Cancel leaves the update ready and a later save does not close the app. When the startup prompt is open, the result dialog closes and the prompt keeps its own Restart to Update. --- crates/ui-egui/src/lifecycle_tests.rs | 54 +++++++++++++++++++++++++++ crates/ui-egui/src/updates_ui.rs | 24 +++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/lifecycle_tests.rs b/crates/ui-egui/src/lifecycle_tests.rs index 6c9eb85d2..ce230f54c 100644 --- a/crates/ui-egui/src/lifecycle_tests.rs +++ b/crates/ui-egui/src/lifecycle_tests.rs @@ -224,6 +224,60 @@ fn workspace_layout_autosave_writes_on_a_hidden_tick() { assert_eq!(app.ui_passes(), 0); } +/// Whether a frame running `f` asked the root window to close. +#[cfg(not(target_arch = "wasm32"))] +fn asks_to_close(ctx: &egui::Context, mut f: impl FnMut(&egui::Context)) -> bool { + let mut out = ctx.run_ui(raw(egui::vec2(800.0, 480.0)), |ui| f(ui.ctx())); + out.textures_delta.clear(); + out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|v| v.commands.contains(&egui::ViewportCommand::Close)) +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() { + let ctx = egui::Context::default(); + let frame = eframe::Frame::_new_kittest(); + let mut app = app_with_comp(); + assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes"); + app.updates_rt.manual_window_open = true; + assert!(asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the window is asked to close"); + assert!(!app.updates_rt.manual_window_open, "the modal result dialog closes"); + let mut raw = raw(egui::vec2(800.0, 480.0)); + raw.viewports.insert(egui::ViewportId::ROOT, egui::ViewportInfo { events: vec![egui::ViewportEvent::Close], ..Default::default() }); + let out = tick_with(&mut app, &ctx, &frame, &raw); + assert!(app.dialog.is_some(), "the close opens the unsaved-changes prompt"); + assert!(out.viewport_commands.values().flatten().any(|c| matches!(c, egui::ViewportCommand::CancelClose))); +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() { + let ctx = egui::Context::default(); + let mut app = app_with_comp(); + app.updates_rt.manual_window_open = true; + assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, true))); + assert!(app.updates_rt.manual_window_open, "the result dialog stays until the updater closes the app"); +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() { + let ctx = egui::Context::default(); + let mut app = app_with_comp(); + app.updates_rt.updater.offer(craft_update::Release { + tag: "v99.0.0".into(), + version: craft_update::parse_version("99.0.0"), + name: "EffectCraft 99.0.0".into(), + html_url: "https://github.com/storytold/effectcraft/releases/tag/v99.0.0".into(), + ..Default::default() + }); + assert!(app.updates_rt.updater.prompt_open()); + app.updates_rt.manual_window_open = true; + assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the prompt carries the restart"); + assert!(!app.updates_rt.manual_window_open, "the result dialog closes"); + assert!(app.updates_rt.updater.prompt_open(), "the prompt stays"); +} + #[test] fn the_close_guard_answers_a_close_request_without_a_pass() { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 316e34ac4..a4dba938a 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -9,7 +9,7 @@ use craft_update::updater::{Action, Status, Updater}; pub(crate) struct Runtime { #[cfg(not(target_arch = "wasm32"))] - updater: Updater, + pub(crate) updater: Updater, /// The desktop app turns the check at start on; tests and the web build leave it off. #[cfg(not(target_arch = "wasm32"))] startup_check: bool, @@ -44,6 +44,26 @@ impl EffectcraftApp { } } +/// Restart to Update. With unsaved changes the result dialog closes and the window is asked to +/// close, so the unsaved-changes prompt opens. Cancel there leaves the update ready. An open +/// startup prompt keeps its own Restart to Update and save-first note, so the window stays open. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn restart_to_update(rt: &mut Runtime, ctx: &egui::Context, clean: bool) { + if clean { + rt.updater.restart_to_update(); + return; + } + rt.manual_window_open = false; + rt.updater.dismiss_status(); + if rt.updater.prompt_open() { + return; + } + // Without a prompt this only takes the close a finished installation queued, so a save after + // Cancel does not close the app. + let _ = rt.updater.show_if(ctx, true); + ctx.send_viewport_cmd(egui::ViewportCommand::Close); +} + pub(crate) fn check(app: &mut EffectcraftApp) { #[cfg(not(target_arch = "wasm32"))] { @@ -91,7 +111,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { rt.updater.dismiss_status(); } CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), - CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), + CheckResultResponse::RestartToUpdate => restart_to_update(rt, ctx, clean), } // A check that found a release leaves the status idle and the startup prompt takes over. if matches!(rt.updater.status(), Status::Idle) && !rt.check_requested { From f0ab5f107fb671146f5b68242dbe6d7f1d759843 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Mon, 9 Nov 2026 22:16:24 +0100 Subject: [PATCH 18/99] Opening an old project: a renamed effect parameter keeps its place among the parameters (#3197) Ball Grid's Instability State becomes Scatter Motion; it used to move to the end, after the new controls, so an expression reading the parameter by index (the 8th) read Coloring afterwards. A parameter renamed within its own group is now renamed where it is; new parameters are still added after it. --- crates/effects/src/migrate.rs | 43 +++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/effects/src/migrate.rs b/crates/effects/src/migrate.rs index 6529e658d..ccd3d11b1 100644 --- a/crates/effects/src/migrate.rs +++ b/crates/effects/src/migrate.rs @@ -192,6 +192,14 @@ fn take_at(g: &mut PropGroup, id: &str) -> Option { } } +/// The position of the property at spec id `id` (`a/b/param`) among its siblings. +fn index_at(g: &PropGroup, id: &str) -> Option { + match id.split_once('/') { + None => g.children.iter().position(|c| matches!(c, Node::Prop(p) if p.match_id == id)), + Some((first, rest)) => index_at(g.sub(first)?, rest), + } +} + fn prop_at<'a>(g: &'a mut PropGroup, id: &str) -> Option<&'a mut Property> { match id.split_once('/') { None => g.get_mut(id), @@ -279,6 +287,12 @@ pub fn upgrade_instance(spec: &EffectSpec, g: &mut PropGroup, ids: &mut Ids, lay // before it moved into a twirl-down group. let found = prop_at(g, ps.id).is_some(); if !found { + // A parameter renamed within its group keeps its place, so expressions that address + // it by index still read it. + let slot = PARAM_ID_ALIASES + .iter() + .filter(|(e, old, new)| *e == spec.id && *new == ps.id && old.rsplit_once('/').map(|(p, _)| p) == new.rsplit_once('/').map(|(p, _)| p)) + .find_map(|(_, old, _)| index_at(g, old)); let moved = PARAM_ID_ALIASES.iter().filter(|(e, _, new)| *e == spec.id && *new == ps.id).find_map(|(_, old, _)| take_at(g, old)).or_else(|| { let leaf = ps.id.rsplit('/').next().unwrap_or(ps.id); // Not when the top-level leaf is an old id of another parameter (Radio @@ -300,9 +314,13 @@ pub fn upgrade_instance(spec: &EffectSpec, g: &mut PropGroup, ids: &mut Ids, lay pr } }; + let at = |sub: &mut PropGroup| match slot { + Some(i) if i <= sub.children.len() => sub.children.insert(i, pr.into()), + _ => sub.children.push(pr.into()), + }; match path.and_then(|path| group_at(g, ids, path)) { - Some(sub) => sub.children.push(pr.into()), - None => g.children.push(pr.into()), + Some(sub) => at(sub), + None => at(g), } } if let Some(pr) = prop_at(g, ps.id) { @@ -584,6 +602,27 @@ mod tests { assert_eq!((&pr.ui, &pr.value), (&ParamUi::Point, &Value::Vec2([20.0, -5.0]))); } + /// #3197 review: an old CC Ball Action saved Instability State as its 8th property; renamed to + /// Scatter Motion it keeps that place, so an expression that reads `effect(..)(8)` still gets + /// the same control (new controls are appended after it). + #[test] + fn upgrade_renames_a_param_in_place_and_keeps_its_index() { + let spec = find("ec.sim.ccballaction").unwrap(); + let mut next = 1; + let mut g = instantiate(spec, &mut Ids(&mut next), "Ball Grid", [100.0, 50.0]); + // The layout an earlier version saved: eight parameters, Instability State last. + let old = ["scatter", "rotationAxis", "rotation", "twistProperty", "twistAngle", "gridSpacing", "ballSize", "scatterMotion"]; + let mut kept: Vec = old.iter().map(|id| take_prop(&mut g, id).unwrap()).collect(); + g.children.clear(); + kept[7].match_id = "instabilityState".into(); + kept[7].value = Value::Scalar(33.0); + g.children.extend(kept.into_iter().map(Node::from)); + assert!(upgrade_instance(spec, &mut g, &mut Ids(&mut next), [100.0, 50.0])); + let ids: Vec<&str> = g.children.iter().take(8).map(|c| c.match_id()).collect(); + assert_eq!(ids, ["scatter", "rotationAxis", "rotation", "twistProperty", "twistAngle", "gridSpacing", "ballSize", "scatterMotion"]); + assert_eq!(g.get("scatterMotion").unwrap().value, Value::Scalar(33.0)); + } + #[test] fn upgrade_moves_params_into_twirl_down_groups() { let spec = find(crate::warp_stab::ID).unwrap(); From ff245aabc74885ac58260ee6e99470dba7762276 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Tue, 10 Nov 2026 22:12:13 +0100 Subject: [PATCH 19/99] Expressions: a renamed effect parameter keeps answering to its old name (#3197) Old projects can name CC Ball Action's Instability State in an expression. The name now resolves to Scatter Motion, through the same alias table the project migration uses, and only after every current name has been tried. --- crates/effects/src/catalog.rs | 2 +- crates/expr/Cargo.toml | 2 +- crates/expr/src/host.rs | 17 ++++++- crates/expr/src/tests.rs | 83 +++++++++++++++++++++++++++++++++++ docs/effects.md | 2 +- 5 files changed, 102 insertions(+), 4 deletions(-) diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index 7fcb024bf..c7eecaaf3 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -147,7 +147,7 @@ pub fn effects_markdown() -> String { - **Status**: {} implemented in full, {partial} partial (what is missing is listed).\n\n", r.len() - partial )); - s.push_str("Effects are addressed by id (`ec..`) or display name in commands, scripts and the control channel, and every parameter by its id (`effects/#1/blurriness`).\n\n"); + s.push_str("Effects are addressed by id (`ec..`) or display name in commands, scripts and the control channel, and every parameter by its id (`effects/#1/blurriness`). A parameter that was renamed keeps its old name working in expressions of older projects: `effect(\"CC Ball Action\")(\"Instability State\")` still reads Scatter Motion.\n\n"); for cat in CATEGORIES { let list: Vec<_> = r.iter().filter(|e| e.category == *cat).collect(); if list.is_empty() { diff --git a/crates/expr/Cargo.toml b/crates/expr/Cargo.toml index 6f157698b..a0cb29945 100644 --- a/crates/expr/Cargo.toml +++ b/crates/expr/Cargo.toml @@ -11,6 +11,7 @@ workspace = true [dependencies] effectcraft-time = { workspace = true } +effectcraft-effects = { workspace = true } effectcraft-geom = { workspace = true } effectcraft-keyframe = { workspace = true } serde_json = { workspace = true } @@ -25,5 +26,4 @@ boa_engine = { workspace = true, features = ["js"] } [dev-dependencies] effectcraft-color = { workspace = true } -effectcraft-effects = { workspace = true } effectcraft-text = { workspace = true } diff --git a/crates/expr/src/host.rs b/crates/expr/src/host.rs index 43400ea1d..52dca5823 100644 --- a/crates/expr/src/host.rs +++ b/crates/expr/src/host.rs @@ -7,9 +7,10 @@ //! the answers and runs the script again. Expressions are pure functions of these answers, so //! re-running is exact, and the runtime stays free of borrowed state. +use effectcraft_effects::migrate::PARAM_ID_ALIASES; use effectcraft_geom::{Mat3, Mat4}; use effectcraft_keyframe::Value; -use effectcraft_project::{Comp, ItemId, ItemKind, Layer, LayerId, LayerSource, Node, PropGroup, Property}; +use effectcraft_project::{Comp, GroupKind, ItemId, ItemKind, Layer, LayerId, LayerSource, Node, PropGroup, Property}; use effectcraft_render::EvalCtx; use effectcraft_time::Tick; @@ -283,10 +284,24 @@ fn find_child<'g>(g: &'g PropGroup, key: &Key) -> Option<&'g Node> { .find(|n| n.match_id() == m) .or_else(|| g.children.iter().find(|n| n.name().eq_ignore_ascii_case(name))) .or_else(|| g.children.iter().find(|n| compact(n.name()) == c || compact(n.match_id()) == c)) + // Last, so a legacy name never shadows a current one. + .or_else(|| legacy_effect_child(g, &c)) } } } +/// A parameter of an effect instance addressed by a name it had when the project was saved +/// ([`PARAM_ID_ALIASES`]): `effect("CC Ball Action")("Instability State")` keeps reading the +/// parameter that is now Scatter Motion. `c` is the compacted (lowercase, no spaces) name. Only +/// renames inside the instance's own top-level group count; moves into twirl-downs do not. +fn legacy_effect_child<'g>(g: &'g PropGroup, c: &str) -> Option<&'g Node> { + let GroupKind::Effect { effect } = &g.kind else { return None }; + PARAM_ID_ALIASES + .iter() + .filter(|(e, old, new)| e == effect && !old.contains('/') && !new.contains('/') && compact(old) == c) + .find_map(|(_, _, new)| g.children.iter().find(|n| n.match_id() == *new)) +} + impl<'a> Resolver<'a> { fn comp(&self, c: u64) -> Option<&'a Comp> { if c == self.ctx.comp_id.0 { Some(self.ctx.comp) } else { self.ctx.project.comp(ItemId(c)) } diff --git a/crates/expr/src/tests.rs b/crates/expr/src/tests.rs index 050a5a550..22ce60ca0 100644 --- a/crates/expr/src/tests.rs +++ b/crates/expr/src/tests.rs @@ -2070,3 +2070,86 @@ fn bench_evaluation() { println!("BENCH {best:>9} ns/eval {label} (min of 3 x {iters})"); } } + +/// Layer A with an old-format CC Ball Action: Scatter Motion saved as `instabilityState` +/// ("Instability State"), opened through the migration (#3197). Scatter Motion is 37 and keyed +/// 10 at 0 s, 50 at 2 s. +fn old_ball_action() -> Fx { + let mut f = fx(); + let spec = effectcraft_effects::find("ec.sim.ccballaction").unwrap(); + let mut g = group_push(&mut f.p, |ids| effectcraft_effects::instantiate(spec, ids, "CC Ball Action", [20.0, 20.0])); + let sm = g.prop_mut("scatterMotion").unwrap(); + sm.value = Value::Scalar(37.0); + sm.keys = vec![Keyframe::new(Tick::ZERO, Value::Scalar(10.0)), Keyframe::new(secs(2.0), Value::Scalar(50.0))]; + sm.match_id = "instabilityState".into(); + sm.name = "Instability State".into(); + let mut next = f.p.next_id; + assert!(effectcraft_effects::migrate::upgrade_instance(spec, &mut g, &mut Ids(&mut next), [20.0, 20.0])); + f.p.next_id = next; + assert!(g.prop("scatterMotion").is_some(), "the migration renamed the parameter"); + f.p.comp_mut(f.cid).unwrap().layers[0].props.sub_mut("effects").unwrap().children.push(g.into()); + f +} + +#[test] +fn old_parameter_names_still_resolve_in_expressions() { + let f = old_ball_action(); + for name in ["Instability State", "instabilityState", "instability state", "InstabilityState"] { + // Keyframes still apply: the keyed value at 0 s, not the stored 37. + assert_close!(f.num(&format!("effect('CC Ball Action')('{name}')"), 0.0), 10.0); + assert_close!(f.num(&format!("effect('CC Ball Action')('{name}')"), 2.0), 50.0); + assert_close!(f.num(&format!("effect('CC Ball Action')('{name}').valueAtTime(2)"), 0.0), 50.0); + } + // Current names read the same property, unchanged. + for name in ["Scatter Motion", "scatterMotion"] { + assert_close!(f.num(&format!("effect('CC Ball Action')('{name}')"), 0.0), 10.0); + } +} + +#[test] +fn old_parameter_name_follows_the_parameter_expression() { + let mut f = old_ball_action(); + let p = f.p.comp_mut(f.cid).unwrap().layers[0].props.prop_mut("effects/#2/scatterMotion"); + let p = match p { + Some(p) => p, + None => panic!("scatterMotion at effects/#2"), + }; + p.expr = Some(Expression { text: "123".into(), enabled: true }); + assert_close!(f.num("effect('CC Ball Action')('Instability State')", 0.0), 123.0); +} + +#[test] +fn unknown_parameter_names_still_fail() { + let f = old_ball_action(); + assert!(f.ev(f.a, ROT, "effect('CC Ball Action')('No Such Thing')", 0.0).is_err()); + // Old names only exist on the effect they were renamed on. + assert!(f.ev(f.a, ROT, "effect('Slider Control')('Instability State')", 0.0).is_err()); +} + +/// Every in-group rename in the alias table keeps resolving by its old id and display name. +#[test] +fn every_in_group_alias_resolves_by_its_old_name() { + let mut n = 0; + for (effect, old, new) in effectcraft_effects::migrate::PARAM_ID_ALIASES { + if old.contains('/') || new.contains('/') { + continue; + } + let Some(spec) = effectcraft_effects::find(effect) else { continue }; + let mut f = fx(); + let g = group_push(&mut f.p, |ids| effectcraft_effects::instantiate(spec, ids, "Probe", [20.0, 20.0])); + f.p.comp_mut(f.cid).unwrap().layers[0].props.sub_mut("effects").unwrap().children.push(g.into()); + let (new_name, kind) = { + let l = &f.p.comp(f.cid).unwrap().layers[0]; + let p = l.props.prop(&format!("effects/#2/{new}")).unwrap(); + (p.name.clone(), p.value.clone()) + }; + if !matches!(kind, Value::Scalar(_)) { + continue; + } + let a = f.ev(f.a, ROT, &format!("effect('Probe')('{old}')"), 0.0).unwrap(); + let b = f.ev(f.a, ROT, &format!("effect('Probe')('{new_name}')"), 0.0).unwrap(); + assert_eq!(a, b, "{effect}: {old}"); + n += 1; + } + assert!(n >= 1); +} diff --git a/docs/effects.md b/docs/effects.md index 83ee80223..903d26113 100644 --- a/docs/effects.md +++ b/docs/effects.md @@ -9,7 +9,7 @@ EffectCraft ships 308 effects with 2992 parameters in total, grouped into the sa - **32**: 308 effects process 32-bit float (HDR, overbright) pixels without clamping. - **Status**: 308 implemented in full, 0 partial (what is missing is listed). -Effects are addressed by id (`ec..`) or display name in commands, scripts and the control channel, and every parameter by its id (`effects/#1/blurriness`). +Effects are addressed by id (`ec..`) or display name in commands, scripts and the control channel, and every parameter by its id (`effects/#1/blurriness`). A parameter that was renamed keeps its old name working in expressions of older projects: `effect("CC Ball Action")("Instability State")` still reads Scatter Motion. ## 3D Channel From 131e4b325258021a6b7902641797c353497fdb94 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 14:43:58 -0800 Subject: [PATCH 20/99] Fonts: substitute test checks whether the original family is installed microsoft_families_resolve_to_metric_compatible_substitutes took resolve's own answer as the sign that Calibri or Cambria is installed, so it passed when an installed original lost to its substitute. It now looks for the family among the registered faces and, when it is there, requires resolve to pick it and report it as not missing. --- crates/text/src/fonts/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/text/src/fonts/tests.rs b/crates/text/src/fonts/tests.rs index 2e04e5f0e..d0cb53ea5 100644 --- a/crates/text/src/fonts/tests.rs +++ b/crates/text/src/fonts/tests.rs @@ -459,7 +459,9 @@ fn microsoft_families_resolve_to_metric_compatible_substitutes() { let resolved = resolve(requested, style); let family = &face(resolved.face).info.family; - if family.eq_ignore_ascii_case(requested) { + let installed = all_faces().iter().any(|f| f.info.family.eq_ignore_ascii_case(requested)); + if installed { + assert!(family.eq_ignore_ascii_case(requested), "an installed {requested} wins over {family}"); assert!(!resolved.missing, "an installed original family is available"); } else { assert_eq!(family, substitute); From c48abd7964982e916e3ae007f6a2dbc31ced9f9d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 15:07:52 -0800 Subject: [PATCH 21/99] Fonts: test that an installed Microsoft family wins over its substitute --- crates/text/src/fonts/tests.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/text/src/fonts/tests.rs b/crates/text/src/fonts/tests.rs index d0cb53ea5..ba1e33b25 100644 --- a/crates/text/src/fonts/tests.rs +++ b/crates/text/src/fonts/tests.rs @@ -473,6 +473,24 @@ fn microsoft_families_resolve_to_metric_compatible_substitutes() { assert!(unknown.missing); } +/// An installed Microsoft family is used as is and not reported missing, even when its +/// substitute is also available (#1677). It runs in a child process so the Calibri fixture does +/// not reach the substitute test above. +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn an_installed_microsoft_family_wins_over_its_substitute() { + const CHILD: &str = "EFFECTCRAFT_TEST_ISOLATED_CALIBRI"; + if std::env::var_os(CHILD).is_none() { + run_in_child(CHILD, "fonts::tests::an_installed_microsoft_family_wins_over_its_substitute"); + return; + } + add_font_data(test_font("Carlito")); + add_font_data(test_font("Calibri")); + let resolved = resolve("Calibri", "Regular"); + assert_eq!(face(resolved.face).info.family, "Calibri"); + assert!(!resolved.missing, "the installed family is available"); +} + #[test] fn the_han_order_follows_the_cjk_locale() { // Chinese first for any Chinese tag, whether or not it names a script. From 550aeb0ac9f6d36416109d6b3ccc330b3a8b7028 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:04 +0530 Subject: [PATCH 22/99] #2047: tests for Adaptive Resolution during Timeline and Properties drags Drag/release tests for the playhead, timecode, layer bar, In trim, source slip, key drag, the In/Out/Duration cells and a Properties scrub: a draft while held, Full on the first frame after release. A click, a work-area drag (same pixels) and Fast Previews off keep Full. --- .../tests/it/ui_timeline_interacting.rs | 224 ++++++++++++------ 1 file changed, 145 insertions(+), 79 deletions(-) diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index 29f86b6ff..6ed4c719a 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -1,115 +1,181 @@ +//! Fast Previews ▸ Adaptive Resolution while dragging outside the viewer (After Effects): any +//! Timeline drag that changes the frame on screen (the time, or the comp's pixels) draws a draft +//! until release, and the first frame after the release is full resolution again. A plain click, +//! or a drag that changes nothing on screen, keeps Full. use effectcraft_engine::Session; -use effectcraft_engine::project::LayerId; use effectcraft_ui_egui::EffectcraftApp; use egui::{Event, Pos2, pos2, vec2}; use egui_kittest::Harness; use serde_json::json; -fn harness() -> (Harness<'static, EffectcraftApp>, LayerId, u64) { - let mut session = Session::default(); - session.execute("comp.new", json!({"name": "Keys", "width": 320, "height": 180, "frameRate": 30, "duration": 4})).unwrap(); - session.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap(); - let id = session.active_comp().unwrap().layers[0].id; +/// The Timeline of a 10 s comp at 30 fps with a solid (opacity keys at 0 s and 1 s, revealed) +/// and a 20 s precomp trimmed to 3–7 s (its source runs past both ends, so it can slip), in +/// Adaptive Resolution. +struct Fixture { + h: Harness<'static, EffectcraftApp>, + solid: u64, + pre: u64, + opacity: u64, +} + +fn fixture(mode: &str) -> Fixture { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 320, "height": 180, "frameRate": 30, "duration": 20})).unwrap(); + s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "frameRate": 30, "duration": 10})).unwrap(); + let solid = s.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap()["layer"].as_u64().unwrap(); for (time, value) in [(0.0, 0.0), (1.0, 100.0)] { - session.execute("prop.addKey", json!({"layer": id.0, "path": "transform/opacity", "time": time, "value": value})).unwrap(); + s.execute("prop.addKey", json!({"layer": solid, "path": "transform/opacity", "time": time, "value": value})).unwrap(); } - let uid = session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().uid; - session.execute("layer.select", json!({"layers": [id.0]})).unwrap(); - session.execute("view.fastPreviewMode", json!({"mode": "adaptive"})).unwrap(); - let mut harness = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session)); - harness.run_steps(3); - let context = harness.ctx.clone(); - effectcraft_ui_egui::menus::invoke(harness.state_mut(), &context, "timeline.reveal.opacity", json!({})).unwrap(); - harness.run_steps(4); - (harness, id, uid) + let pre = s.execute("layer.addItem", json!({"item": "Inner"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.timing", json!({"layers": [pre], "in": 3.0, "out": 7.0})).unwrap(); + let comp = s.active_comp().unwrap(); + let opacity = comp.layers.iter().find(|l| l.id.0 == solid).unwrap().props.prop("transform/opacity").unwrap().uid; + s.execute("layer.select", json!({"layers": [solid]})).unwrap(); + s.execute("view.fastPreviewMode", json!({"mode": mode})).unwrap(); + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s)); + h.run_steps(3); + let ctx = h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "timeline.reveal.opacity", json!({})).unwrap(); + h.run_steps(4); + Fixture { h, solid, pre, opacity } } -fn rect(harness: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { - let entry = harness.state().auto.find(id).expect("timeline element"); - egui::Rect::from_min_size(pos2(entry.rect[0], entry.rect[1]), vec2(entry.rect[2], entry.rect[3])) +fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { + let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}")); + egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), vec2(e.rect[2], e.rect[3])) } -fn keys(harness: &Harness<'_, EffectcraftApp>, uid: u64) -> Vec { - let mut positions: Vec = harness - .state() - .auto - .query(&format!("timeline.key.{uid}.")) - .iter() - .map(|entry| pos2(entry.rect[0] + entry.rect[2] / 2.0, entry.rect[1] + entry.rect[3] / 2.0)) - .collect(); - positions.sort_by(|left, right| left.x.total_cmp(&right.x)); - positions +/// What a frame-changing drag must change: the project or the current time. +fn on_screen(h: &Harness<'_, EffectcraftApp>) -> (u64, effectcraft_time::Tick) { + (h.state().session.revision, h.state().session.time()) } -fn hold(harness: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { - harness.input_mut().events.push(Event::PointerMoved(from)); - harness.step(); - harness.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); - harness.step(); +/// Presses at `from` and moves to `to` in ten steps, leaving the button down. +fn hold(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { + h.input_mut().events.push(Event::PointerMoved(from)); + h.step(); + h.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); for step in 1..=10 { - harness.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); - harness.step(); + h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); + h.step(); } } -fn release(harness: &mut Harness<'_, EffectcraftApp>, at: Pos2) { - harness.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); - harness.run_steps(2); +/// Releases at `at` and runs exactly one frame: that frame must already be sharp. +fn release(h: &mut Harness<'_, EffectcraftApp>, at: Pos2) { + h.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.step(); } -fn assert_adaptive_during_drag(harness: &Harness<'_, EffectcraftApp>) { - assert!(harness.state().ui.viewer.property_interacting); - assert!(harness.state().viewer_scale(1.0, 1.0) < 1.0); +fn draft(h: &Harness<'_, EffectcraftApp>) -> bool { + h.state().viewer_scale(1.0, 1.0) < 1.0 } -fn assert_full_resolution_after_release(harness: &Harness<'_, EffectcraftApp>) { - assert!(!harness.state().ui.viewer.property_interacting); - assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); +/// Drags from `from` by `by`: a draft while held, Full on the first frame after release. +fn assert_draft_while_dragging(f: &mut Fixture, from: Pos2, by: egui::Vec2) { + let before = on_screen(&f.h); + hold(&mut f.h, from, from + by); + assert_ne!(on_screen(&f.h), before, "the drag changed nothing on screen"); + assert!(f.h.state().ui.viewer.property_interacting, "not interacting while dragging"); + assert!(draft(&f.h), "full resolution while dragging"); + release(&mut f.h, from + by); + assert!(!f.h.state().ui.viewer.property_interacting, "still interacting after release"); + assert!(!draft(&f.h), "the first frame after release is a draft"); } #[test] -fn playhead_drag_uses_adaptive_resolution() { - let (mut harness, _, _) = harness(); - let ruler = rect(&harness, "timeline.ruler"); - let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); - let to = from + vec2(200.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn playhead_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let ruler = rect(&f.h, "timeline.ruler"); + assert_draft_while_dragging(&mut f, pos2(ruler.min.x + 40.0, ruler.max.y - 3.0), vec2(200.0, 0.0)); } #[test] -fn layer_bar_drag_uses_adaptive_resolution() { - let (mut harness, layer, _) = harness(); - let from = rect(&harness, &format!("timeline.layer.{}.bar", layer.0)).center(); - let to = from + vec2(60.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn timecode_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, "timeline.timecode").center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); } #[test] -fn key_drag_uses_adaptive_resolution() { - let (mut harness, _, uid) = harness(); - let from = keys(&harness, uid)[0]; - let to = from + vec2(60.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn layer_bar_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.bar", f.solid)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn in_point_trim_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.bar.in", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn source_slip_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.sourcel", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn key_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.key.{}.0", f.opacity)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn in_out_and_duration_cell_drags_draw_a_draft() { + for kind in ["in", "out", "duration"] { + let mut f = fixture("adaptive"); + effectcraft_ui_egui::panels::timeline::set_column(&mut f.h.state_mut().ui.timeline, kind, true).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.layer.{}.{kind}", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); + } +} + +#[test] +fn properties_scrub_draws_a_draft() { + let mut f = fixture("adaptive"); + let ctx = f.h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(f.h.state_mut(), &ctx, "window.panel", json!({"panel": "properties"})).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, &format!("properties.prop.{}.value", f.opacity)).center(); + assert_draft_while_dragging(&mut f, from, vec2(40.0, 0.0)); +} + +#[test] +fn work_area_drag_keeps_full_resolution() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, "timeline.workArea.end").center(); + let before = f.h.state().session.active_comp().unwrap().work_area; + hold(&mut f.h, from, from + vec2(-80.0, 0.0)); + assert_ne!(f.h.state().session.active_comp().unwrap().work_area, before, "the work area moved"); + assert!(!draft(&f.h), "a work-area drag changes no pixels"); + release(&mut f.h, from); } #[test] fn timeline_click_keeps_full_resolution() { - let (mut harness, _, _) = harness(); - let point = rect(&harness, "timeline.ruler").center(); - harness.input_mut().events.push(Event::PointerMoved(point)); - harness.step(); - harness.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); - harness.step(); - assert!(!harness.state().ui.viewer.property_interacting); - assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); - release(&mut harness, point); + let mut f = fixture("adaptive"); + let point = rect(&f.h, "timeline.ruler").center(); + f.h.input_mut().events.push(Event::PointerMoved(point)); + f.h.step(); + f.h.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + f.h.run_steps(3); + assert!(!draft(&f.h)); + release(&mut f.h, point); +} + +#[test] +fn fast_previews_off_keeps_full_resolution() { + let mut f = fixture("off"); + let ruler = rect(&f.h, "timeline.ruler"); + let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); + hold(&mut f.h, from, from + vec2(200.0, 0.0)); + assert!(!draft(&f.h)); + release(&mut f.h, from); } From 724865e3405233eef2db75b9e09bfade30a6c11e Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:04 +0530 Subject: [PATCH 23/99] #2047: Fast Previews: any frame-changing Timeline drag draws a draft One rule instead of a flag per gesture: DragWatch snapshots the active comp and its current frame when the Timeline (and the Properties panel) starts its pass, and after the pass, while the primary button drags past a click, a new frame or a comp that no longer draws the same pixels sets property_interacting until release. This covers the playhead and timecode, layer moves and trims, slips, key drags and alt-scale, Quick Offset, the In/Out/Duration cells, property scrubs and the Graph Editor, and any gesture added later. Clicks, scrolling, zooming, the work area and selection keep Full. It replaces the prop.set-only check in apply_actions. --- crates/ui-egui/src/panels.rs | 1 + crates/ui-egui/src/panels/drag_preview.rs | 47 +++++++++++++++++++++++ crates/ui-egui/src/panels/properties.rs | 2 + crates/ui-egui/src/panels/timeline.rs | 10 ++--- crates/ui-egui/src/state.rs | 4 +- 5 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 crates/ui-egui/src/panels/drag_preview.rs diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index ccff0fdcd..8feb8c8c5 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -9,6 +9,7 @@ pub mod crypto_pick; pub mod delete_items; pub mod dialogs; pub mod dialogs_3d; +pub(crate) mod drag_preview; pub mod effect_controls; pub mod effects_presets; pub mod essential; diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs new file mode 100644 index 000000000..9d0d42f7b --- /dev/null +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -0,0 +1,47 @@ +//! Fast Previews ▸ Adaptive Resolution for drags outside the viewer: as in After Effects, a drag +//! that changes the frame on screen (scrubbing the time, moving or trimming layers, slipping, +//! dragging keys, scrubbing values) draws a draft until the button is released. + +use std::sync::Arc; + +use effectcraft_engine::project::{Comp, ItemId}; + +use crate::EffectcraftApp; + +/// The frame on screen when a panel starts its pass: the active comp and its current frame. +/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag +/// the panel handles is covered without a flag per gesture. +pub(crate) struct DragWatch { + before: Option<(ItemId, Arc, i64)>, +} + +impl DragWatch { + pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let before = app.session.active_comp_id().and_then(|id| { + let comp = app.session.project.comp_arc(id)?; + let frame = comp.frame_rate.frame_at(app.session.time()); + Some((id, comp, frame)) + }); + Self { before } + } + + /// While the primary button drags (moved past a click), a change of the current frame or of + /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays + /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { + let Some((id, comp, frame)) = self.before else { return }; + if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { + return; + } + if app.session.active_comp_id() != Some(id) { + return; + } + let Some(now) = app.session.project.comp_arc(id) else { return }; + let moved = comp.frame_rate.frame_at(app.session.time()) != frame; + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + app.ui.viewer.property_interacting = true; + ctx.request_repaint(); + } + } +} diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 4edcbb31a..74ae4daec 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -67,6 +67,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.text(rect.center(), Align2::CENTER_CENTER, crate::i18n::tr("Select a layer to see its properties"), Tokens::ui(12.0), t.text_faint); return; }; + let watch = super::drag_preview::DragWatch::begin(app); let project = app.session.project.clone(); let expr = app.session.expr.clone(); let now = app.session.time(); @@ -190,6 +191,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.ui.status = e; } } + watch.end(app, &ctx); } fn section_header(app: &mut EffectcraftApp, p: &egui::Painter, x0: f32, w: f32, y: f32, title: &str, auto: &str) { diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 4de3233e8..4d35de005 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1963,6 +1963,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { return; }; let Some(comp) = app.session.project.comp_arc(cid) else { return }; + let watch = super::drag_preview::DragWatch::begin(app); let mut tl = layout(app, ui, rect, cid, &comp); let g = &mut tl; if !ui.input(|i| i.pointer.primary_down()) { @@ -2022,7 +2023,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { drop_targets(app, ui, g); let Rw { tl, ui_actions, .. } = rw; apply_ui_acts(app, &tl.comp, ui_actions); - apply_actions(app, ui, &tl.ctx, tl.actions); + apply_actions(app, &tl.ctx, tl.actions); + watch.end(app, &tl.ctx); } /// Applies the UI-only changes the frame collected (twirls, time, ending an undo merge). @@ -2081,11 +2083,7 @@ fn apply_ui_acts(app: &mut EffectcraftApp, comp: &Comp, ui_actions: Vec) } /// Runs the commands the frame collected through [`crate::menus::invoke`]. -fn apply_actions(app: &mut EffectcraftApp, ui: &mut egui::Ui, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { - app.ui.viewer.property_interacting = true; - ctx.request_repaint(); - } +fn apply_actions(app: &mut EffectcraftApp, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { for (id, params) in actions { if id == "__endMerge" { app.session.history.merge_key = None; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ee415e36c..d71114b4d 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -265,7 +265,9 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, - /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. + /// A drag outside the viewer changed the frame on screen: a property scrub in Effect Controls, + /// or any Timeline or Properties drag ([`crate::panels::drag_preview`]). Adaptive Resolution + /// draws a draft until the primary button is up, which clears it. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus From 418a55bc4f39e21db863de2e878f69d3ec9969b2 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:15 +0530 Subject: [PATCH 24/99] #2042: test that thumbnail jobs can't refill a closed project's caches A Project panel thumbnail job made while a project is open, run after Close / New Project (held), or decoding through Close (gated), must leave nothing of the closed project's footage in the footage source or the layer cache. Both fail on the current code: the job decodes the old still again and keeps it. --- crates/engine/src/tests/project_release.rs | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/crates/engine/src/tests/project_release.rs b/crates/engine/src/tests/project_release.rs index 490bb6576..c8ba5f9ea 100644 --- a/crates/engine/src/tests/project_release.rs +++ b/crates/engine/src/tests/project_release.rs @@ -61,3 +61,83 @@ fn replacing_project_releases_old_footage() { assert!(recorded().contains(&"/old.mp4".to_string()), "{:?}", recorded()); assert!(s.drain_events().contains(&Event::PurgeCaches)); } + +/// A footage source with a memory cache, like the media pool: a frame read keeps its file's +/// entry until the file is forgotten. With a gate, the first read waits for the test. +#[derive(Default)] +struct Caching { + cached: Mutex>, + gate: Mutex, std::sync::mpsc::Receiver<()>)>>, +} + +impl FootageSource for Caching { + fn frame(&self, _: ItemId, footage: &Footage, _: Tick) -> Option> { + let gate = self.gate.lock().unwrap().take(); + if let Some((entered, go)) = gate { + entered.send(()).unwrap(); + go.recv().unwrap(); + } + self.cached.lock().unwrap().insert(footage.path.clone()); + Some(Arc::new(Image::new(footage.width, footage.height))) + } + fn forget(&self, path: &str) { + self.cached.lock().unwrap().remove(path); + } +} + +/// A session showing `/old.png` (a footage item, and a comp with a layer of it) through a +/// [`Caching`] source: (session, source, footage item, comp). +fn old_project() -> (Session, Arc, ItemId, ItemId) { + let mut s = Session::default(); + let src = Arc::new(Caching::default()); + s.footage = src.clone(); + let still = Footage { path: "/old.png".into(), has_video: true, width: 8, height: 8, ..Default::default() }; + let mut p = Project::default(); + let item = p.add_item("old", Default::default(), None, ItemKind::Footage(still)); + s.replace_project(p, None); + s.execute("comp.new", json!({"name": "Main", "width": 8, "height": 8, "frameRate": 30, "duration": 1})).unwrap(); + s.execute("layer.addItem", json!({"item": item.0})).unwrap(); + let comp = s.active_comp_id().unwrap(); + (s, src, item, comp) +} + +#[test] +fn held_thumbnail_jobs_cannot_refill_the_closed_projects_caches() { + for close in ["file.closeProject", "file.newProject"] { + let (mut s, src, item, comp) = old_project(); + // Project panel thumbnails, made while the project is open and run after it closed (a + // thread that started late). + let jobs = [s.thumbnail_job(item, Tick(0), 16).unwrap(), s.thumbnail_job(comp, Tick(0), 16).unwrap()]; + s.execute(close, json!({})).unwrap(); + let shown: Vec<_> = jobs.into_iter().map(|job| job()).collect(); + assert!(src.cached.lock().unwrap().is_empty(), "{close}: the closed project's frames came back"); + assert_eq!(s.layer_cache.stats().entries, 0, "{close}: the closed project's layers came back"); + assert!(shown.iter().all(Option::is_none), "{close}: a closed project's thumbnail isn't shown"); + } +} + +#[test] +fn a_thumbnail_reading_through_close_lets_go_of_what_it_read() { + let (mut s, src, item, _) = old_project(); + let (entered, entered_rx) = std::sync::mpsc::channel(); + let (go, go_rx) = std::sync::mpsc::channel(); + *src.gate.lock().unwrap() = Some((entered, go_rx)); + let job = s.thumbnail_job(item, Tick(0), 16).unwrap(); + let running = std::thread::spawn(job); + // The job is decoding the closed project's still when the project closes. + entered_rx.recv().unwrap(); + s.execute("file.closeProject", json!({})).unwrap(); + go.send(()).unwrap(); + let shown = running.join().unwrap(); + assert!(src.cached.lock().unwrap().is_empty(), "the frame decoded through Close was kept"); + assert!(shown.is_none(), "a closed project's thumbnail isn't shown"); +} + +#[test] +fn an_open_projects_thumbnails_still_render() { + let (s, src, item, comp) = old_project(); + let (w, h, px) = s.thumbnail_job(item, Tick(0), 16).unwrap()().unwrap(); + assert_eq!((w, h, px.len()), (8, 8, 8 * 8 * 4)); + assert!(s.thumbnail_job(comp, Tick(0), 16).unwrap()().is_some()); + assert!(src.cached.lock().unwrap().contains("/old.png")); +} From 365c472828cff8971d647302c41a7ea3311d9c27 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:02:57 +0530 Subject: [PATCH 25/99] #2042: closing a project calls off its thumbnail jobs Session::replace_project sets the closed project's flag (Session::project_closed) before it forgets the project's footage, and gives the next project a fresh one. A Project panel thumbnail job reads through it (CancellableFootage, #329): started after Close it reads nothing, a movie decode in flight stops early, and a job that read through Close forgets its files (and a comp thumbnail clears the layer cache) before answering None, so it can't refill the shared caches with the closed project's frames. replace_project also forgets the decoded proxies of the closed and new items, and drops the Cryptomatte probe for projects without footage. The thumbnail's pixel copy uses get(). --- crates/engine/src/lib.rs | 8 ++++ crates/engine/src/session/edit.rs | 16 ++++--- crates/engine/src/session/render.rs | 56 ++++++++++++++++++---- crates/engine/src/tests/project_release.rs | 15 ++++++ 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 0b7608756..380358529 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -167,6 +167,13 @@ pub struct Session { pub journal: Vec<(String, Value)>, /// Processed-layer pixels reused across frames and edits (content-keyed, never stale). pub layer_cache: Arc, + /// Set when this project closes ([`Session::replace_project`]), then replaced by a fresh flag + /// for the next one: work started for the project off the UI thread (Project panel + /// thumbnails) stops reading its footage and lets go of what it read, so it can't fill the + /// shared caches with a closed project's frames. Public only so that other crates can build a + /// `Session { .. }`. + #[doc(hidden)] + pub project_closed: Arc, /// The last Cryptomatte pick probe (see [`Session::crypto_probe_job`]). Public only so that /// other crates can build a `Session { .. }`; its type is crate-private. #[doc(hidden)] @@ -351,6 +358,7 @@ impl Default for Session { events: vec![], journal: vec![], layer_cache: Arc::new(LayerCache::default()), + project_closed: Default::default(), crypto_probe: Default::default(), disk_cache: None, pending_disk_drops: Default::default(), diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 9235dc41c..a1d994f45 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -196,6 +196,9 @@ impl Session { /// Replace the whole project (open/new), resetting history and state. pub fn replace_project(&mut self, mut p: Project, path: Option) { + // Work still running for the closed project stops reading it (see `project_closed`). + self.project_closed.store(true, std::sync::atomic::Ordering::SeqCst); + self.project_closed = Arc::default(); if self.stop_render() && let Some(mut job) = self.render_job.take() { @@ -221,14 +224,13 @@ impl Session { self.script_ui.project_epoch = self.script_ui.project_epoch.wrapping_add(1); p.fix_next_id(); upgrade_effects(&mut p); - // Let go of what the closed project decoded (frames, decoders, models), and of what the - // new project's files decoded under an earlier project: the media layer keys them by - // path, and the files may have changed since (#1070). - for it in self.project.items.values().chain(p.items.values()) { - if let effectcraft_project::ItemKind::Footage(f) = &it.kind { - self.forget_decoded(f); - } + // Let go of what the closed project's footage and proxies decoded (frames, decoders, + // models), and of what the new project's files decoded under an earlier project: the + // media layer keys them by path, and the files may have changed since (#1070). + for f in super::render::project_footage(&self.project).chain(super::render::project_footage(&p)) { + self.forget_decoded(f); } + self.drop_crypto_probe(); self.layer_cache.clear(); self.project = Arc::new(p); // The set of footage effects read the channels of is sent again, even when it is empty. diff --git a/crates/engine/src/session/render.rs b/crates/engine/src/session/render.rs index c3740196c..7e95a7bfe 100644 --- a/crates/engine/src/session/render.rs +++ b/crates/engine/src/session/render.rs @@ -1,3 +1,7 @@ +use std::sync::atomic::Ordering; + +use effectcraft_render::{CancellableFootage, FootageSource}; + use super::{EngineError, Image, ItemId, RenderOpts, Renderer, Result, Session, ThumbnailJob, Tick, Value, commands}; impl Session { @@ -77,9 +81,12 @@ impl Session { /// A Project panel thumbnail of an item (a comp at `t`, footage at its first frame), longest /// side at most `max_side`, as a job that owns everything it reads: frontends run it off the /// UI thread (a big comp takes far longer than a frame). `None` for items without pixels. + /// Once the project closes ([`Session::replace_project`]) the job reads no more and answers + /// `None`, after letting go of what it read meanwhile: a thread that started late or decoded + /// through Close can't fill the shared caches with the closed project's frames. pub fn thumbnail_job(&self, item: ItemId, t: Tick, max_side: u32) -> Option { let it = self.project.item(item)?; - let footage = self.footage.clone(); + let (footage, closed) = (self.footage.clone(), self.project_closed.clone()); match &it.kind { effectcraft_project::ItemKind::Comp(c) => { let (project, expr, cache) = (self.project.clone(), self.expr.clone(), self.layer_cache.clone()); @@ -93,21 +100,38 @@ impl Session { }; let bg = c.background; Some(Box::new(move || { - let mut r = Renderer::new(&project, footage.as_ref(), opts); + if closed.load(Ordering::SeqCst) { + return None; + } + let src = CancellableFootage { inner: footage.as_ref(), cancel: closed.clone() }; + let mut r = Renderer::new(&project, &src, opts); r.expr = expr.as_deref(); r.cache = Some(&cache); let img = r.comp_frame(item, t); + if closed.load(Ordering::SeqCst) { + project_footage(&project).for_each(|f| forget_files(footage.as_ref(), f)); + cache.clear(); + return None; + } Some((img.width, img.height, img.to_rgba8_over(bg))) })) } effectcraft_project::ItemKind::Footage(f) if f.has_video => { let f = f.clone(); Some(Box::new(move || { + if closed.load(Ordering::SeqCst) { + return None; + } // Vector footage is drawn at the thumbnail's size: its declared size can be a // 16384² canvas, gigabytes of pixels to point-sample down to a few dozen. let scale = (max_side.max(1) as f64 / f.width.max(f.height).max(1) as f64).min(1.0); - let src = footage.vector_frame(item, &f, scale).or_else(|| footage.frame(item, &f, Tick(0)))?; - let img = effectcraft_render::cineon_frame(src, &f); + let read = CancellableFootage { inner: footage.as_ref(), cancel: closed.clone() }; + let src = read.vector_frame(item, &f, scale).or_else(|| read.frame(item, &f, Tick(0))); + if closed.load(Ordering::SeqCst) { + forget_files(footage.as_ref(), &f); + return None; + } + let img = effectcraft_render::cineon_frame(src?, &f); // Point-sample down to at most `max_side` on the long side (a drawn size one // pixel over it, from rounding, is shrunk by that pixel, not halved). let (long, max) = (u64::from(img.width.max(img.height)), u64::from(max_side.max(1))); @@ -119,7 +143,7 @@ impl Session { for x in 0..w { let (sx, sy) = (u64::from(x) * u64::from(img.width) / u64::from(w), u64::from(y) * u64::from(img.height) / u64::from(h)); let i = ((sy * u64::from(img.width) + sx) * 4) as usize; - px.extend_from_slice(&full[i..i + 4]); + px.extend_from_slice(full.get(i..i + 4)?); } } Some((w, h, px)) @@ -145,9 +169,7 @@ impl Session { /// Make the media layer and the layer cache let go of what they decoded from `footage`'s /// files (it keys frames by path, so an overwritten file would keep showing its old pixels). pub(crate) fn forget_decoded(&self, footage: &effectcraft_project::Footage) { - for p in std::iter::once(&footage.path).chain(&footage.sequence) { - self.footage.forget(p); - } + forget_files(self.footage.as_ref(), footage); self.layer_cache.clear(); self.drop_crypto_probe(); } @@ -191,3 +213,21 @@ pub(crate) fn aux_footage(project: &effectcraft_project::Project) -> Vec paths.dedup(); paths } + +/// Make `src` let go of what it decoded from `footage`'s files (its file, or a sequence's). +fn forget_files(src: &dyn FootageSource, footage: &effectcraft_project::Footage) { + for p in std::iter::once(&footage.path).chain(&footage.sequence) { + src.forget(p); + } +} + +/// Every footage `project` shows: its footage items and the proxies of its items. +pub(crate) fn project_footage(project: &effectcraft_project::Project) -> impl Iterator { + project.items.values().flat_map(|it| { + let own = match &it.kind { + effectcraft_project::ItemKind::Footage(f) => Some(f), + _ => None, + }; + own.into_iter().chain(it.proxy.as_deref().map(|px| &px.footage)) + }) +} diff --git a/crates/engine/src/tests/project_release.rs b/crates/engine/src/tests/project_release.rs index c8ba5f9ea..f556b34be 100644 --- a/crates/engine/src/tests/project_release.rs +++ b/crates/engine/src/tests/project_release.rs @@ -62,6 +62,21 @@ fn replacing_project_releases_old_footage() { assert!(s.drain_events().contains(&Event::PurgeCaches)); } +#[test] +fn closing_a_project_releases_its_proxies() { + let mut s = Session::default(); + let src = Arc::new(Recording::default()); + s.footage = src.clone(); + let mut p = with_footage(&Project::default(), "old", "/old.mp4"); + let item = p.items.values_mut().next().unwrap(); + let footage = Footage { path: "/old-proxy.mov".into(), ..Default::default() }; + item.proxy = Some(Box::new(effectcraft_project::Proxy { footage, enabled: true })); + s.replace_project(p, None); + src.0.lock().unwrap().clear(); + s.execute("file.closeProject", json!({})).unwrap(); + assert!(src.0.lock().unwrap().contains(&"/old-proxy.mov".to_string()), "{:?}", src.0.lock().unwrap()); +} + /// A footage source with a memory cache, like the media pool: a frame read keeps its file's /// entry until the file is forgotten. With a gate, the first read waits for the test. #[derive(Default)] From 2da516ed84e8f1eb2bda3a9ffa3ce093ec9344c3 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:05:59 +0530 Subject: [PATCH 26/99] #2042: a decode in flight when its file is forgotten keeps nothing The media pool counts forgets and frame clears. A read-ahead (sequential playback's next frame, on its own thread) carries the count it was queued at and decodes nothing once a forget came after it; any decode keeps its frame only if no forget came while it ran. A viewer playing a movie at Close, or any reader decoding through it, can no longer bring the closed project's frames back after Session::replace_project forgot them. --- crates/media/src/pool.rs | 58 +++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 872e4fdfa..6e2e8faa4 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -208,6 +208,10 @@ struct CacheState { last: HashMap, i64>, /// Movies whose frames can't be kept as 8-bit levels (more bits, or shown turned). wide: HashSet>, + /// Counts [`MediaPool::forget`]s and frame clears: a decode keeps its frame only when none + /// came while it ran, so one in flight when a file is forgotten (a closed project's, or one + /// changed on disk) can't bring the frame back. + forgets: u64, } /// A movie/audio source by path ([`Opened`]), opened by the first caller while the others wait @@ -406,6 +410,7 @@ impl MediaPool { let mut c = lock(&self.inner.cache); c.lru = Lru::default(); c.last.clear(); + c.forgets = c.forgets.wrapping_add(1); drop(c); // Decoded GIFs sit outside the frame budget; Purge frees them too. lock(&self.inner.gifs).clear(); @@ -431,6 +436,7 @@ impl MediaPool { } c.last.remove(path); c.wide.remove(path); + c.forgets = c.forgets.wrapping_add(1); drop(c); crate::exr_channels::forget(path); } @@ -455,7 +461,7 @@ impl MediaPool { if lock(&self.inner.cache).wide.contains(footage.path.as_str()) { return None; } - match Inner::frame_px(&self.inner, footage, t, true, None, float, true) { + match Inner::frame_px(&self.inner, footage, t, true, None, float, true, None) { Ok(Pixels::Q8(f)) => Some(f), _ => None, } @@ -850,7 +856,7 @@ impl Inner { /// The frame of `footage` at `t`, resampled to `size` (see [`FootageSource::frame_at_size`]): /// a movie's made at that size directly, a still's resampled once and kept at that size. fn frame_at(self: &Arc, footage: &Footage, t: Tick, playback: bool, size: Option<(u32, u32)>, float: FloatCurve) -> Result> { - match Self::frame_px(self, footage, t, playback, size, float, false)? { + match Self::frame_px(self, footage, t, playback, size, float, false, None)? { Pixels::F32(img) => Ok(img), // (a float request's key never holds 8-bit levels) Pixels::Q8(_) => Err(MediaError::Decode(format!("{}: 8-bit frame for a float request", footage.path))), @@ -859,8 +865,20 @@ impl Inner { /// [`Self::frame_at`], kept as 8-bit levels when `q8` is set and the frame has 8 bits (a /// float frame under the float key otherwise, and the movie is remembered as `wide`). + /// `since`: the [`CacheState::forgets`] count the read was asked at (a read-ahead's, when it + /// was queued); a read that missed is not decoded once a forget came after it, and a frame + /// decoded while one came is not kept. #[allow(clippy::too_many_arguments)] - fn frame_px(self: &Arc, footage: &Footage, t: Tick, playback: bool, size: Option<(u32, u32)>, float: FloatCurve, q8: bool) -> Result { + fn frame_px( + self: &Arc, + footage: &Footage, + t: Tick, + playback: bool, + size: Option<(u32, u32)>, + float: FloatCurve, + q8: bool, + since: Option, + ) -> Result { if !footage.has_video { return Err(MediaError::Unsupported(format!("{}: no video", footage.path))); } @@ -909,6 +927,10 @@ impl Inner { } c = self.done.wait(c).unwrap_or_else(std::sync::PoisonError::into_inner); } + let since = since.unwrap_or(c.forgets); + if c.forgets != since { + return Err(MediaError::Cancelled); + } self.misses.fetch_add(1, Ordering::Relaxed); c.inflight.insert(loc.key.clone()); drop(c); @@ -917,6 +939,9 @@ impl Inner { reads::note_all(&files); let img = img?; let mut c = lock(&self.cache); + if c.forgets != since { + return Ok(img); + } if q8 && let Pixels::F32(_) = img { // not 8-bit: kept as the float frame it is, which the renderer asks for next c.wide.insert(loc.key.path.clone()); @@ -935,23 +960,23 @@ impl Inner { next.key.size = loc.key.size; next.key.q8 = loc.key.q8; if next.key != loc.key && !c.lru.map.contains_key(&next.key) && !c.inflight.contains(&next.key) { - self.prefetch(footage, next_t, size, float, loc.key.q8); + self.prefetch(footage, next_t, size, float, loc.key.q8, c.forgets); } } } #[cfg(not(target_arch = "wasm32"))] - fn prefetch(self: &Arc, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve, q8: bool) { + fn prefetch(self: &Arc, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve, q8: bool, since: u64) { let (me, f) = (self.clone(), footage.clone()); self.prefetched.fetch_add(1, Ordering::Relaxed); // A plain thread, not a rayon job: the decode below parallelises with rayon itself. std::thread::spawn(move || { - let _ = me.frame_px(&f, t, false, size, float, q8); + let _ = me.frame_px(&f, t, false, size, float, q8, Some(since)); }); } #[cfg(target_arch = "wasm32")] - fn prefetch(self: &Arc, _footage: &Footage, _t: Tick, _size: Option<(u32, u32)>, _float: FloatCurve, _q8: bool) {} + fn prefetch(self: &Arc, _footage: &Footage, _t: Tick, _size: Option<(u32, u32)>, _float: FloatCurve, _q8: bool, _since: u64) {} /// A still (image file or sequence frame) at `loc.key.size` when one is set: resampled as the /// renderer would ([`FootageSource::frame_at_size`]), so the pool keeps the reduced frame and a @@ -1203,6 +1228,25 @@ fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { mod tests { use super::*; + /// #2042: a read queued before its file was forgotten (a read-ahead of a closed project's + /// movie, started from the frame before) decodes nothing and keeps nothing; a read asked + /// after the forget decodes and keeps its frame. + #[test] + fn reads_queued_before_a_forget_keep_nothing() { + let mut png = std::io::Cursor::new(Vec::new()); + image::RgbaImage::new(2, 2).write_to(&mut png, image::ImageFormat::Png).unwrap(); + let pool = MediaPool::new(); + pool.add_bytes("/a.png", png.into_inner().into()); + let f = Footage { path: "/a.png".into(), kind: FootageKind::Still, width: 2, height: 2, has_video: true, ..Default::default() }; + let queued = lock(&pool.inner.cache).forgets; + pool.forget("/a.png"); + let read = Inner::frame_px(&pool.inner, &f, Tick::ZERO, false, None, FloatCurve::Srgb, false, Some(queued)); + assert!(matches!(read, Err(MediaError::Cancelled)), "{:?}", read.err()); + assert_eq!(pool.stats().frames, 0, "the forgotten file's frame came back"); + pool.frame_at(&f, Tick::ZERO).unwrap(); + assert_eq!(pool.stats().frames, 1); + } + /// Conforming a long file's audio reads every chunk at its own time: the sample index times /// ticks per second overflowed `i64` past 12:36 at 48 kHz, and later chunks came out silent /// (#172). From 9ed7954a9742104e8d3a6ff6bffbb23562845637 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:08:18 +0530 Subject: [PATCH 27/99] #2047: markers no expression reads don't drop the resolution Compare the comp the way the frame cache does (#1083): markers count as pixels only when an expression reads them, so dragging a marker keeps Full. Tighten the click and Fast Previews Off tests so they prove the gesture reached the app. --- crates/ui-egui/src/panels/drag_preview.rs | 17 +++++++++-------- .../tests/it/ui_timeline_interacting.rs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 9d0d42f7b..4384095c7 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -8,9 +8,9 @@ use effectcraft_engine::project::{Comp, ItemId}; use crate::EffectcraftApp; -/// The frame on screen when a panel starts its pass: the active comp and its current frame. -/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag -/// the panel handles is covered without a flag per gesture. +/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] +/// compares them with the comp and frame after the panel ran its gestures, so every drag the +/// panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { before: Option<(ItemId, Arc, i64)>, } @@ -25,10 +25,11 @@ impl DragWatch { Self { before } } - /// While the primary button drags (moved past a click), a change of the current frame or of - /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays - /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws - /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + /// While the primary button drags (moved past a click, or held past one), a change of the + /// current frame or of the active comp's pixels since [`Self::begin`] sets + /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, + /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers + /// no expression reads, as for the frame cache) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { let Some((id, comp, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { @@ -39,7 +40,7 @@ impl DragWatch { } let Some(now) = app.session.project.comp_arc(id) else { return }; let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index 6ed4c719a..e2cb2112a 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,24 +158,42 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. +#[test] +fn marker_drag_keeps_full_resolution() { + let mut f = fixture("adaptive"); + f.h.state_mut().session.execute("comp.addMarker", json!({"time": 2.0})).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, "timeline.marker.0").center(); + let before = f.h.state().session.active_comp().unwrap().markers[0].time; + hold(&mut f.h, from, from + vec2(80.0, 0.0)); + assert_ne!(f.h.state().session.active_comp().unwrap().markers[0].time, before, "the marker moved"); + assert!(!draft(&f.h), "a marker no expression reads changes no pixels"); + release(&mut f.h, from); +} + #[test] fn timeline_click_keeps_full_resolution() { let mut f = fixture("adaptive"); let point = rect(&f.h, "timeline.ruler").center(); + let before = f.h.state().session.time(); f.h.input_mut().events.push(Event::PointerMoved(point)); f.h.step(); f.h.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); f.h.run_steps(3); + assert_ne!(f.h.state().session.time(), before, "the click moved the playhead"); assert!(!draft(&f.h)); release(&mut f.h, point); } +/// The drag is still noted, but Fast Previews Off never lowers the resolution. #[test] fn fast_previews_off_keeps_full_resolution() { let mut f = fixture("off"); let ruler = rect(&f.h, "timeline.ruler"); let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); hold(&mut f.h, from, from + vec2(200.0, 0.0)); + assert!(f.h.state().ui.viewer.property_interacting); assert!(!draft(&f.h)); release(&mut f.h, from); } From 66337085711dcc32d1279188fddda77fac9e53b6 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:12:26 +0530 Subject: [PATCH 28/99] #2042: a cache purge drops the Project panel's thumbnails Event::PurgeCaches (Close / New / Open Project, Edit > Purge, footage reloads) now also removes the Project panel's thumbnail textures and the renders awaited for them. They were keyed by item id only: the closed project's textures stayed in memory, and an item of the next project with a closed one's id showed the closed project's picture until its own render landed. --- crates/ui-egui/src/app/frame.rs | 1 + crates/ui-egui/src/panels/project.rs | 47 +++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index b78c38c73..63101350d 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -153,6 +153,7 @@ impl EffectcraftApp { } effectcraft_engine::Event::PurgeCaches => { self.frames.clear(); + crate::panels::project::forget_thumbnails(ctx); // (frames made after it get keys of their own: see `Self::purge_stamp`) self.purges = self.purges.wrapping_add(1); } diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rs index 8d67fd9ee..bc03d282f 100644 --- a/crates/ui-egui/src/panels/project.rs +++ b/crates/ui-egui/src/panels/project.rs @@ -119,8 +119,22 @@ pub fn drop_folder(project: &effectcraft_engine::project::Project, row: Option)>>>>); +#[derive(Clone)] +struct PendingThumb(u64, Arc)>>>>); + +/// Let go of every Project panel thumbnail and the renders in flight for them (a cache purge, or +/// a project closed: the next project's item ids can be the closed one's). +pub fn forget_thumbnails(ctx: &egui::Context) { + ctx.data_mut(|d| { + d.remove_by_type::(); + d.remove_by_type::(); + }); +} /// Thumbnail of a comp (its current time) or footage (first frame), cached per item/revision. /// Rendered on a background thread (inline on wasm32): until the new one lands the previous @@ -129,19 +143,19 @@ fn thumbnail(app: &EffectcraftApp, ctx: &egui::Context, it: &Item) -> Option = ctx.data(|d| d.get_temp(key)); - let mut tex = cached.as_ref().map(|(_, t)| t.clone()); - let have = cached.as_ref().map(|(r, _)| *r); + let cached: Option = ctx.data(|d| d.get_temp(key)); + let mut tex = cached.as_ref().map(|Thumb(_, t)| t.clone()); + let have = cached.as_ref().map(|Thumb(r, _)| *r); // A finished render: upload it. let pending: Option = ctx.data(|d| d.get_temp(pkey)); - if let Some((prev, slot)) = &pending { + if let Some(PendingThumb(prev, slot)) = &pending { let done = slot.lock().ok().and_then(|mut s| s.take()); match done { Some(Some((w, h, px))) => { let ci = egui::ColorImage::from_rgba_unmultiplied([w as usize, h as usize], &px); let t = ctx.load_texture(format!("proj-thumb-{}", it.id.0), ci, egui::TextureOptions::LINEAR); ctx.data_mut(|d| { - d.insert_temp(key, (*prev, t.clone())); + d.insert_temp(key, Thumb(*prev, t.clone())); d.remove::(pkey); }); tex = Some(t); @@ -179,7 +193,7 @@ fn thumbnail(app: &EffectcraftApp, ctx: &egui::Context, it: &Item) -> Option(pkey, (rev, slot))); + ctx.data_mut(|d| d.insert_temp(pkey, PendingThumb(rev, slot))); ctx.request_repaint(); tex } @@ -1504,6 +1518,25 @@ mod tests { } } + /// #2042: closing the project drops the Project panel's thumbnails (and renders in flight), + /// so their textures go with it and an item of the next project with a closed one's id never + /// shows the closed project's picture. + #[test] + fn closing_the_project_forgets_its_thumbnails() { + let mut app = EffectcraftApp::new(effectcraft_engine::Session::default()); + let ctx = egui::Context::default(); + let (key, pkey) = (egui::Id::unique(("proj-thumb", 1u64)), egui::Id::unique(("proj-thumb-pending", 1u64))); + let tex = ctx.load_texture("t", egui::ColorImage::from_rgba_unmultiplied([1, 1], &[255; 4]), egui::TextureOptions::LINEAR); + ctx.data_mut(|d| { + d.insert_temp(key, Thumb(app.session.revision, tex)); + d.insert_temp(pkey, PendingThumb(app.session.revision, Arc::default())); + }); + app.session.execute("file.closeProject", serde_json::json!({})).unwrap(); + app.handle_events(&ctx); + assert!(ctx.data(|d| d.get_temp::(key)).is_none(), "the closed project's thumbnail is kept"); + assert!(ctx.data(|d| d.get_temp::(pkey)).is_none(), "a closed project's render is awaited"); + } + /// Long names show in full: the Name column fits them (it stopped at 260 points with "…") /// up to the panel's width less the Label column and, while optional columns show, room for /// them; a width the user dragged wins. From 8b481f3811ab3d276c78d331ef80d6a76dc2f676 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:18:24 +0530 Subject: [PATCH 29/99] #2047: a layer's audio counts when something draws it Compare the comp exactly as the frame cache does: a layer's Audio switch, Audio group and audio effects are pixels when a layer picks its audio or an expression reads audio, before or after the edit. Scrubbing Audio Levels read by an expression now draws a draft; with nothing drawing the audio it keeps Full. --- crates/ui-egui/src/panels/drag_preview.rs | 36 +++++++++++-------- .../tests/it/ui_timeline_interacting.rs | 30 ++++++++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 4384095c7..e0f53fb12 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -4,43 +4,49 @@ use std::sync::Arc; -use effectcraft_engine::project::{Comp, ItemId}; +use effectcraft_engine::project::{ItemId, Project}; use crate::EffectcraftApp; -/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] -/// compares them with the comp and frame after the panel ran its gestures, so every drag the -/// panel handles is covered without a flag per gesture. +/// The project, the active comp and its current frame index when a panel starts its pass. +/// [`DragWatch::end`] compares them with the comp and frame after the panel ran its gestures, so +/// every drag the panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { - before: Option<(ItemId, Arc, i64)>, + before: Option<(ItemId, Arc, i64)>, } impl DragWatch { pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let project = app.session.project.clone(); let before = app.session.active_comp_id().and_then(|id| { - let comp = app.session.project.comp_arc(id)?; - let frame = comp.frame_rate.frame_at(app.session.time()); - Some((id, comp, frame)) + let frame = project.comp_arc(id)?.frame_rate.frame_at(app.session.time()); + Some((id, project, frame)) }); Self { before } } /// While the primary button drags (moved past a click, or held past one), a change of the /// current frame or of the active comp's pixels since [`Self::begin`] sets - /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, - /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers - /// no expression reads, as for the frame cache) keeps Full. + /// `property_interacting`, which stays set until the button is up (`App::frame`). Pixels are + /// compared as the frame cache does: markers count when an expression reads them, a layer's + /// audio when something draws it, before or after the edit. A click, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { - let Some((id, comp, frame)) = self.before else { return }; + let Some((id, project, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { return; } if app.session.active_comp_id() != Some(id) { return; } - let Some(now) = app.session.project.comp_arc(id) else { return }; - let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { + let (Some(was), Some(now)) = (project.comp_arc(id), app.session.project.comp_arc(id)) else { return }; + let moved = was.frame_rate.frame_at(app.session.time()) != frame; + let edited = || { + let current = &app.session.project; + let heard = current.heard_layers().union(&project.heard_layers()); + !now.same_pixels_with(&was, current.reads_markers(), &|l| heard.contains(id, l)) + }; + if moved || (!Arc::ptr_eq(&was, &now) && edited()) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index e2cb2112a..5cf11ad0e 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,6 +158,36 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Scrubs the precomp's Audio Levels in the Timeline; `reads_audio` adds an expression that +/// reads audio. Returns whether the viewer drew a draft while held. +fn audio_levels_scrub(reads_audio: bool) -> bool { + let mut f = fixture("adaptive"); + if reads_audio { + let rotation = json!({"layer": f.solid, "path": "transform/rotation", "expression": "thisComp.layer(1).audioLevels; value"}); + f.h.state_mut().session.execute("prop.setExpression", rotation).unwrap(); + } + let uid = f.h.state().session.active_comp().unwrap().layers.iter().find(|l| l.id.0 == f.pre).unwrap().props.prop("audio/levels").unwrap().uid; + let tl = &mut f.h.state_mut().ui.timeline; + tl.open_layers.insert(f.pre); + tl.layer_reveal.insert(f.pre, vec!["props".into()]); + tl.reveal_props.insert(uid); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.prop.{uid}.value.0")).center(); + let before = on_screen(&f.h); + hold(&mut f.h, from, from + vec2(40.0, 0.0)); + assert_ne!(on_screen(&f.h), before, "the scrub changed the levels"); + let draft = draft(&f.h); + release(&mut f.h, from); + draft +} + +/// A layer's audio is pixels only when something draws it (an expression reading audio here). +#[test] +fn audio_levels_scrub_draws_a_draft_only_when_audio_is_drawn() { + assert!(audio_levels_scrub(true), "an expression reads the audio"); + assert!(!audio_levels_scrub(false), "nothing draws the audio"); +} + /// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. #[test] fn marker_drag_keeps_full_resolution() { From 0635f2496d9da71332671f3dd8522266058bd5a8 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:32:06 +0530 Subject: [PATCH 30/99] #2042: review fixes for closing a project's thumbnails - CancellableFootage calls off vector_frame too: a closed project's SVG / PDF thumbnail stops before it rasterises, like a viewer frame nobody waits for. - replace_project forgets every footage file once and clears the layer cache and the Cryptomatte probe once, instead of once per footage item. - The through-Close test covers comp thumbnails (layer cache and footage) as well as footage ones, and fails with a timeout instead of hanging. - Docs: forget is also how a closed project's files go. --- crates/engine/src/session/edit.rs | 2 +- crates/engine/src/session/render.rs | 2 +- crates/engine/src/tests/project_release.rs | 31 ++++++++++++---------- crates/media/src/pool.rs | 10 ++++--- crates/render/src/footage.rs | 8 +++--- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index a1d994f45..7d2a20949 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -228,7 +228,7 @@ impl Session { // models), and of what the new project's files decoded under an earlier project: the // media layer keys them by path, and the files may have changed since (#1070). for f in super::render::project_footage(&self.project).chain(super::render::project_footage(&p)) { - self.forget_decoded(f); + super::render::forget_files(self.footage.as_ref(), f); } self.drop_crypto_probe(); self.layer_cache.clear(); diff --git a/crates/engine/src/session/render.rs b/crates/engine/src/session/render.rs index 7e95a7bfe..fe1634945 100644 --- a/crates/engine/src/session/render.rs +++ b/crates/engine/src/session/render.rs @@ -215,7 +215,7 @@ pub(crate) fn aux_footage(project: &effectcraft_project::Project) -> Vec } /// Make `src` let go of what it decoded from `footage`'s files (its file, or a sequence's). -fn forget_files(src: &dyn FootageSource, footage: &effectcraft_project::Footage) { +pub(crate) fn forget_files(src: &dyn FootageSource, footage: &effectcraft_project::Footage) { for p in std::iter::once(&footage.path).chain(&footage.sequence) { src.forget(p); } diff --git a/crates/engine/src/tests/project_release.rs b/crates/engine/src/tests/project_release.rs index f556b34be..f7fb91b99 100644 --- a/crates/engine/src/tests/project_release.rs +++ b/crates/engine/src/tests/project_release.rs @@ -132,20 +132,23 @@ fn held_thumbnail_jobs_cannot_refill_the_closed_projects_caches() { } #[test] -fn a_thumbnail_reading_through_close_lets_go_of_what_it_read() { - let (mut s, src, item, _) = old_project(); - let (entered, entered_rx) = std::sync::mpsc::channel(); - let (go, go_rx) = std::sync::mpsc::channel(); - *src.gate.lock().unwrap() = Some((entered, go_rx)); - let job = s.thumbnail_job(item, Tick(0), 16).unwrap(); - let running = std::thread::spawn(job); - // The job is decoding the closed project's still when the project closes. - entered_rx.recv().unwrap(); - s.execute("file.closeProject", json!({})).unwrap(); - go.send(()).unwrap(); - let shown = running.join().unwrap(); - assert!(src.cached.lock().unwrap().is_empty(), "the frame decoded through Close was kept"); - assert!(shown.is_none(), "a closed project's thumbnail isn't shown"); +fn thumbnails_reading_through_close_let_go_of_what_they_read() { + for which in ["footage", "comp"] { + let (mut s, src, item, comp) = old_project(); + let (entered, entered_rx) = std::sync::mpsc::channel(); + let (go, go_rx) = std::sync::mpsc::channel(); + *src.gate.lock().unwrap() = Some((entered, go_rx)); + let job = s.thumbnail_job(if which == "comp" { comp } else { item }, Tick(0), 16).unwrap(); + let running = std::thread::spawn(job); + // The job is decoding the closed project's still when the project closes. + entered_rx.recv_timeout(std::time::Duration::from_secs(30)).unwrap(); + s.execute("file.closeProject", json!({})).unwrap(); + go.send(()).unwrap(); + let shown = running.join().unwrap(); + assert!(src.cached.lock().unwrap().is_empty(), "{which}: the frame decoded through Close was kept"); + assert_eq!(s.layer_cache.stats().entries, 0, "{which}: the closed project's layers were kept"); + assert!(shown.is_none(), "{which}: a closed project's thumbnail isn't shown"); + } } #[test] diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 6e2e8faa4..9e87c1575 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -423,7 +423,9 @@ impl MediaPool { lock(&self.inner.problems).clear(); } - /// Forget a file (after it changed on disk, or to retry a file that failed to open). + /// Forget a file (after it changed on disk or its project closed, or to retry a file that + /// failed to open). A decode of any file in flight meanwhile keeps nothing (see + /// [`CacheState::forgets`]). pub fn forget(&self, path: &str) { lock(&self.inner.sources).remove(path); lock(&self.inner.models).remove(path); @@ -1228,9 +1230,9 @@ fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { mod tests { use super::*; - /// #2042: a read queued before its file was forgotten (a read-ahead of a closed project's - /// movie, started from the frame before) decodes nothing and keeps nothing; a read asked - /// after the forget decodes and keeps its frame. + /// #2042: a read queued before its file was forgotten (as a read-ahead of a closed project's + /// movie is, by the read of the frame before) decodes nothing and keeps nothing; a read asked + /// after the forget decodes and keeps its frame. (A still stands in for the movie.) #[test] fn reads_queued_before_a_forget_keep_nothing() { let mut png = std::io::Cursor::new(Vec::new()); diff --git a/crates/render/src/footage.rs b/crates/render/src/footage.rs index c14961d0f..9c4b2527c 100644 --- a/crates/render/src/footage.rs +++ b/crates/render/src/footage.rs @@ -73,9 +73,9 @@ pub trait FootageSource: Send + Sync { /// Drop the decoded frames it keeps (Edit ▸ Purge ▸ All Memory / Image Cache Memory): the /// next reads decode again. Sources without a cache ignore it. fn purge(&self) {} - /// The file at `path` changed on disk (Reload Footage): drop what it keeps of it (decoded - /// frames, open decoders, parsed models), so the next reads see the new contents. Sources - /// without a cache ignore it. + /// The file at `path` changed on disk (Reload Footage), or the project showing it closed: + /// drop what it keeps of it (decoded frames, open decoders, parsed models), so the next reads + /// see the new contents. Sources without a cache ignore it. fn forget(&self, _path: &str) {} /// Settings ▸ Disk ▸ Conformed Audio Folder: where decoded audio is kept between reads /// (`None` = off); sources that don't decode audio ignore it. @@ -205,7 +205,7 @@ impl FootageSource for CancellableFootage<'_> { self.inner.cache_budget() } fn vector_frame(&self, item: ItemId, footage: &Footage, scale: f64) -> Option> { - self.inner.vector_frame(item, footage, scale) + self.read(|| self.inner.vector_frame(item, footage, scale)) } fn cancellable(&self, cancel: &Arc, f: &mut dyn FnMut()) { self.inner.cancellable(cancel, f) From 9046c8d39a96102bd1c8839cb109aa0e22ff71d6 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 20:03:35 +0530 Subject: [PATCH 31/99] #2042: read the Project panel thumbnail through panels::project::cached_thumbnail ui_large_project::comp_thumbnail_renders_off_the_ui_thread read the thumbnail cache by its old storage type, (u64, TextureHandle), which the purge change replaced with a private newtype, so it never saw the texture land. It now asks cached_thumbnail. --- crates/ui-egui/src/panels/project.rs | 5 +++++ crates/ui-egui/tests/it/ui_large_project.rs | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rs index bc03d282f..0d8074934 100644 --- a/crates/ui-egui/src/panels/project.rs +++ b/crates/ui-egui/src/panels/project.rs @@ -127,6 +127,11 @@ struct Thumb(u64, egui::TextureHandle); #[derive(Clone)] struct PendingThumb(u64, Arc)>>>>); +/// The Project panel's thumbnail texture of `item`, once its render has landed. +pub fn cached_thumbnail(ctx: &egui::Context, item: ItemId) -> Option { + ctx.data(|d| d.get_temp::(egui::Id::unique(("proj-thumb", item.0)))).map(|Thumb(_, t)| t) +} + /// Let go of every Project panel thumbnail and the renders in flight for them (a cache purge, or /// a project closed: the next project's item ids can be the closed one's). pub fn forget_thumbnails(ctx: &egui::Context) { diff --git a/crates/ui-egui/tests/it/ui_large_project.rs b/crates/ui-egui/tests/it/ui_large_project.rs index 4e2476269..2310087e3 100644 --- a/crates/ui-egui/tests/it/ui_large_project.rs +++ b/crates/ui-egui/tests/it/ui_large_project.rs @@ -64,9 +64,7 @@ fn comp_thumbnail_renders_off_the_ui_thread() { let mut landed = false; for _ in 0..400 { h.step(); - if h.state().auto.find("project.thumbnail").is_some() - && h.ctx.data(|d| d.get_temp::<(u64, egui::TextureHandle)>(egui::Id::unique(("proj-thumb", main.0)))).is_some() - { + if h.state().auto.find("project.thumbnail").is_some() && effectcraft_ui_egui::panels::project::cached_thumbnail(&h.ctx, main).is_some() { landed = true; break; } From 0627dd0e4b0c88e15bd2ce40e056033ecd8684b4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 15:07:00 +0000 Subject: [PATCH 32/99] Use shared ZIP codec for dotLottie imports --- Cargo.lock | 90 +++++++++++++++++--------- Cargo.toml | 42 ++++++------- crates/lottie/src/import.rs | 8 +-- crates/lottie/src/tests.rs | 18 ++++++ crates/lottie/src/zip.rs | 122 +----------------------------------- 5 files changed, 107 insertions(+), 173 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6450c078..8e4ae1211 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "serde", "serde_json", @@ -1129,12 +1129,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "serde_json", ] @@ -1142,17 +1142,17 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,8 +1175,9 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ + "craft-zip", "serde_json", "thiserror 2.0.21", ] @@ -1184,7 +1185,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "thiserror 2.0.21", ] @@ -1200,7 +1201,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1209,7 +1210,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1218,7 +1219,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "encoding_rs", "flate2", @@ -1229,7 +1230,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "dispatch2", "egui", @@ -1240,19 +1241,21 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "craft-xml", "flate2", "kurbo", "roxmltree", "thiserror 2.0.21", + "vectorcraft-geom", + "vectorcraft-pathops", ] [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1273,7 +1276,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "chrono", "dunce", @@ -1300,9 +1303,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", "rayon", "thiserror 2.0.21", ] @@ -1310,7 +1313,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "thiserror 2.0.21", ] @@ -1318,12 +1321,22 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.3", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1683,7 +1696,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1852,7 +1865,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3422,7 +3435,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "hayro-ccitt", ] @@ -3436,7 +3449,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -6683,6 +6696,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 1b80048f2..4deece869 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/lottie/src/import.rs b/crates/lottie/src/import.rs index 6534727dc..22dd8ad21 100644 --- a/crates/lottie/src/import.rs +++ b/crates/lottie/src/import.rs @@ -41,7 +41,7 @@ pub struct ImportResult { pub warnings: Vec, } -/// The Lottie document inside raw bytes (plain JSON, or a stored dotLottie archive), read into +/// The Lottie document inside raw bytes (plain JSON, or a dotLottie archive), read into /// `craft-lottie`'s model within its default limits. fn document(bytes: &[u8]) -> Result { let read = |b: &[u8]| { @@ -51,12 +51,12 @@ fn document(bytes: &[u8]) -> Result { }) }; if bytes.starts_with(b"PK") { - let entries = crate::zip::read_stored(bytes); + let entries = crate::zip::read_entries(bytes).map_err(|e| LottieError::Parse(format!("dotLottie ZIP: {e}")))?; let anim = entries .iter() .find(|(n, _)| n.starts_with("animations/") && n.ends_with(".json")) .or_else(|| entries.iter().find(|(n, _)| n.ends_with(".json") && n != "manifest.json")) - .ok_or_else(|| LottieError::Parse("dotLottie archive without an uncompressed animation".into()))?; + .ok_or_else(|| LottieError::Parse("dotLottie archive without a JSON animation".into()))?; return read(&anim.1); } read(bytes) @@ -102,7 +102,7 @@ fn external_image(stored: &str, base_dir: &str) -> Result { } } -/// Import a Lottie document (JSON or a stored `.lottie` archive) into `project` as a new +/// Import a Lottie document (JSON or a `.lottie` archive) into `project` as a new /// composition. `store` saves embedded images and returns the file path to use; /// `base_dir` resolves external image references. pub fn import( diff --git a/crates/lottie/src/tests.rs b/crates/lottie/src/tests.rs index 35c52026d..cf8543fdf 100644 --- a/crates/lottie/src/tests.rs +++ b/crates/lottie/src/tests.rs @@ -799,6 +799,24 @@ fn dotlottie_archive_roundtrip() { assert_eq!(q.comp(imp.comp).unwrap().layers.len(), 1); } +#[test] +fn deflated_dotlottie_archive_imports() { + let (mut p, cid) = setup(); + let l = solid_layer(&mut p, cid, [0.0, 1.0, 0.0], 40, 40); + push(&mut p, cid, l); + let res = export_comp(&p, cid, &ExportOptions::default(), &no_read).unwrap(); + let manifest = serde_json::to_vec(&serde_json::json!({"version":"1","animations":[{"id":"main"}]})).unwrap(); + let animation = serde_json::to_vec(&res.json).unwrap(); + let zip = craft_lottie::zip::try_store_with_compression( + &[("manifest.json".into(), manifest), ("animations/main.json".into(), animation)], + craft_lottie::zip::Compression::Deflated, + ) + .unwrap(); + let mut q = Project::default(); + let imp = import(&mut q, &zip, "compressed", "", &mut |_| None).unwrap(); + assert_eq!(q.comp(imp.comp).unwrap().layers.len(), 1); +} + // ---------------------------------------------------------------- hand-written fixtures fn fixture(name: &str) -> (Project, ItemId, Vec) { diff --git a/crates/lottie/src/zip.rs b/crates/lottie/src/zip.rs index 2a11dfa25..b47e7cab2 100644 --- a/crates/lottie/src/zip.rs +++ b/crates/lottie/src/zip.rs @@ -1,121 +1,3 @@ -//! A minimal ZIP writer (stored entries, PKWARE APPNOTE 6.3 local headers + central directory) -//! for `.lottie` (dotLottie) archives. +//! Shared stored-entry ZIP functions used by dotLottie imports and exports. -fn crc32(data: &[u8]) -> u32 { - let mut crc = 0xFFFF_FFFFu32; - for &b in data { - crc ^= b as u32; - for _ in 0..8 { - crc = if crc & 1 != 0 { (crc >> 1) ^ 0xEDB8_8320 } else { crc >> 1 }; - } - } - !crc -} - -/// Build a ZIP archive with the given (name, bytes) entries, uncompressed. -pub fn store(entries: &[(String, Vec)]) -> Vec { - let mut out = Vec::new(); - let mut central = Vec::new(); - let put16 = |v: &mut Vec, x: u16| v.extend_from_slice(&x.to_le_bytes()); - let put32 = |v: &mut Vec, x: u32| v.extend_from_slice(&x.to_le_bytes()); - for (name, data) in entries { - let offset = out.len() as u32; - let crc = crc32(data); - let n = name.as_bytes(); - // Local file header. - put32(&mut out, 0x0403_4b50); - put16(&mut out, 20); // version needed - put16(&mut out, 0x0800); // flags: UTF-8 names - put16(&mut out, 0); // stored - put16(&mut out, 0); // time - put16(&mut out, 0x21); // date (1980-01-01) - put32(&mut out, crc); - put32(&mut out, data.len() as u32); - put32(&mut out, data.len() as u32); - put16(&mut out, n.len() as u16); - put16(&mut out, 0); - out.extend_from_slice(n); - out.extend_from_slice(data); - // Central directory record. - put32(&mut central, 0x0201_4b50); - put16(&mut central, 20); // made by - put16(&mut central, 20); - put16(&mut central, 0x0800); - put16(&mut central, 0); - put16(&mut central, 0); - put16(&mut central, 0x21); - put32(&mut central, crc); - put32(&mut central, data.len() as u32); - put32(&mut central, data.len() as u32); - put16(&mut central, n.len() as u16); - put16(&mut central, 0); // extra - put16(&mut central, 0); // comment - put16(&mut central, 0); // disk - put16(&mut central, 0); // internal attrs - put32(&mut central, 0); // external attrs - put32(&mut central, offset); - central.extend_from_slice(n); - } - let cd_offset = out.len() as u32; - let cd_len = central.len() as u32; - out.extend_from_slice(¢ral); - put32(&mut out, 0x0605_4b50); - put16(&mut out, 0); - put16(&mut out, 0); - put16(&mut out, entries.len() as u16); - put16(&mut out, entries.len() as u16); - put32(&mut out, cd_len); - put32(&mut out, cd_offset); - put16(&mut out, 0); - out -} - -/// Whether an entry name is a relative path inside the archive: not absolute (`/…`, `\…`), no -/// drive (`C:…`) and no `..` component. -fn is_relative_name(name: &str) -> bool { - let drive = name.as_bytes().get(1) == Some(&b':'); - !name.starts_with(['/', '\\']) && !drive && !name.split(['/', '\\']).any(|c| c == "..") -} - -/// Read the stored (uncompressed) entries of a ZIP archive written by [`store`] or any other -/// writer that did not compress. Compressed entries and entries whose names are not relative -/// paths inside the archive are skipped. -pub fn read_stored(data: &[u8]) -> Vec<(String, Vec)> { - let mut out = vec![]; - let mut i = 0usize; - let u16_at = |p: usize| data.get(p..p + 2).map(|b| u16::from_le_bytes([b[0], b[1]]) as usize); - let u32_at = |p: usize| data.get(p..p + 4).map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]]) as usize); - while u32_at(i) == Some(0x0403_4b50) { - let (Some(method), Some(size), Some(nlen), Some(xlen)) = (u16_at(i + 8), u32_at(i + 18), u16_at(i + 26), u16_at(i + 28)) else { break }; - let name_start = i + 30; - let body = name_start + nlen + xlen; - let (Some(name), Some(bytes)) = (data.get(name_start..name_start + nlen), data.get(body..body + size)) else { break }; - let name = String::from_utf8_lossy(name).to_string(); - if method == 0 && is_relative_name(&name) { - out.push((name, bytes.to_vec())); - } - i = body + size; - } - out -} - -#[cfg(test)] -mod tests { - #[test] - fn crc_and_roundtrip() { - assert_eq!(super::crc32(b"123456789"), 0xCBF4_3926); - let z = super::store(&[("a.json".into(), b"{}".to_vec()), ("b/c.txt".into(), b"hello".to_vec())]); - let back = super::read_stored(&z); - assert_eq!(back.len(), 2); - assert_eq!(back[1].0, "b/c.txt"); - assert_eq!(back[1].1, b"hello"); - } - - #[test] - fn entries_outside_the_archive_root_are_skipped() { - let names = ["../up.txt", "a/../../up.txt", "/abs/x", "\\abs\\x", "C:\\x", "c:x", "a\\..\\x", "ok/x.txt", "ok/..x"]; - let z = super::store(&names.iter().map(|n| (n.to_string(), b"x".to_vec())).collect::>()); - let back: Vec = super::read_stored(&z).into_iter().map(|(n, _)| n).collect(); - assert_eq!(back, ["ok/x.txt", "ok/..x"]); - } -} +pub use craft_lottie::zip::{Limits, read_entries, read_entries_with_limits, read_stored, store, try_store, try_store_with_compression}; From e48c1c7c98df52a62a382e146eeb0369b34d70d3 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 15:51:49 +0000 Subject: [PATCH 33/99] chore: pin shared libraries to merged dotlottie --- Cargo.lock | 58 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 42 +++++++++++++++++++-------------------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e4ae1211..a44dcc111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "serde", "serde_json", @@ -1129,12 +1129,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "serde_json", ] @@ -1142,17 +1142,17 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,7 +1175,7 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "craft-zip", "serde_json", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "thiserror 2.0.21", ] @@ -1201,7 +1201,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1210,7 +1210,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1219,7 +1219,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "encoding_rs", "flate2", @@ -1230,7 +1230,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "dispatch2", "egui", @@ -1241,7 +1241,7 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "craft-xml", "flate2", @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1276,7 +1276,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "chrono", "dunce", @@ -1303,9 +1303,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90)", "rayon", "thiserror 2.0.21", ] @@ -1313,7 +1313,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "thiserror 2.0.21", ] @@ -1321,7 +1321,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1330,7 +1330,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "flate2", "thiserror 2.0.21", @@ -1696,7 +1696,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1865,7 +1865,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3435,7 +3435,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "hayro-ccitt", ] @@ -3449,7 +3449,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=b7b9f8eb7c016cef2680cb65230eb7273723a7ef#b7b9f8eb7c016cef2680cb65230eb7273723a7ef" +source = "git+https://github.com/storytold/craft-libs?rev=3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90#3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", diff --git a/Cargo.toml b/Cargo.toml index 4deece869..71da0b27f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "b7b9f8eb7c016cef2680cb65230eb7273723a7ef", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } From 9c94c11856fbcd5c2ff87995119563c148ce5519 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 16:25:01 +0000 Subject: [PATCH 34/99] fix ci: track merged craft pdf revision --- xtask/src/pdf_deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index a4ed9d6dd..ca376bf5d 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "47107f660191de2f0b425569506f4daa4faadac9"; +const REV: &str = "3c59a2aa520bc3b7eb17a5e1d4632dea98d7ae90"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From 9bb7b55e0d36024f1c61c4e852eed84f9923faac Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 17:11:03 +0000 Subject: [PATCH 35/99] refactor(exr): decode channels with shared craft exr --- Cargo.lock | 94 +++++--- Cargo.toml | 42 ++-- crates/media/Cargo.toml | 2 +- crates/media/src/exr_channels.rs | 367 ++++++++++++------------------- xtask/src/pdf_deps.rs | 2 +- 5 files changed, 232 insertions(+), 275 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6450c078..64214d619 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "serde", "serde_json", @@ -1129,30 +1129,34 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ + "exr", + "flate2", + "half", "serde_json", + "thiserror 2.0.21", ] [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,8 +1179,9 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ + "craft-zip", "serde_json", "thiserror 2.0.21", ] @@ -1184,7 +1189,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "thiserror 2.0.21", ] @@ -1200,7 +1205,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1209,7 +1214,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1218,7 +1223,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "encoding_rs", "flate2", @@ -1229,7 +1234,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "dispatch2", "egui", @@ -1240,19 +1245,21 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "craft-xml", "flate2", "kurbo", "roxmltree", "thiserror 2.0.21", + "vectorcraft-geom", + "vectorcraft-pathops", ] [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1273,7 +1280,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "chrono", "dunce", @@ -1300,9 +1307,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "rayon", "thiserror 2.0.21", ] @@ -1310,7 +1317,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "thiserror 2.0.21", ] @@ -1318,12 +1325,22 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.3", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1683,7 +1700,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1852,7 +1869,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3422,7 +3439,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "hayro-ccitt", ] @@ -3436,7 +3453,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -6683,6 +6700,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 1b80048f2..83af23a17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["decode"] } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index f744c684c..05e05b09c 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -32,7 +32,6 @@ filmcraft-mpegts = { workspace = true } filmcraft-frame = { workspace = true } filmcraft-color = { workspace = true } filmcraft-time = { workspace = true } -exr = { workspace = true } image = { workspace = true, features = ["gif", "webp", "tiff", "bmp", "exr", "tga", "hdr"] } rayon = { workspace = true } serde_json = { workspace = true } @@ -40,6 +39,7 @@ thiserror = { workspace = true } log = { workspace = true } [dev-dependencies] +exr = { workspace = true } # Writes the animated GIFs of the tests. gif = { workspace = true } tempfile = { workspace = true } diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index 96b0173cd..ee3cc3ed3 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -1,5 +1,5 @@ //! Auxiliary channels from multi-layer OpenEXR files (depth, object / material IDs, normals, -//! Cryptomatte, …) for the 3D Channel effects, read with the pure-Rust `exr` crate. +//! Cryptomatte, …) for the 3D Channel effects, read through the shared `craft-exr` decoder. //! //! Every channel of every layer becomes a plane named `layer.channel` (or just `channel` for //! the unnamed layer), placed in the display window (pixels outside a layer's data window are @@ -18,12 +18,6 @@ use std::sync::{Arc, Mutex, OnceLock, PoisonError}; use effectcraft_raster::channels3d::{BACKGROUND_DEPTH, split_channel}; use effectcraft_raster::{AuxChannels, Image}; use effectcraft_render::reads::{ReadFile, ReadFiles}; -use exr::block::UncompressedBlock; -use exr::block::chunk::TileCoordinates; -use exr::image::read::image::ReadImage; -use exr::image::read::layers::{ChannelsReader, ReadAllLayers, ReadChannels}; -use exr::meta::attribute::SampleType; -use exr::meta::header::Header; use crate::convert::{AlphaOp, float_to_image}; @@ -35,179 +29,20 @@ const MAX_DISPLAY_PIXELS: usize = 1 << 28; use craft_exr::channels::{is_depth, part_channel_name as channel_name}; pub use craft_exr::cryptomatte::parse_manifest; -/// The part name channels are prefixed with (`None`: unnamed). -fn part_name(header: &Header) -> Option { - header.own_attributes.layer_name.as_ref().map(|t| t.to_string()).filter(|s| !s.is_empty()) -} - /// Why an OpenEXR file's pixels can't be decoded when its headers name a compression this build /// can't decompress (HTJ2K, OpenEXR 3.4's High-Throughput JPEG 2000): the decoders only said /// "no non-deep rgb channels" or showed a transparent frame (#482). `None` for other files. pub fn unsupported_compression(bytes: &[u8]) -> Option<&'static str> { - use exr::compression::Compression; - let meta = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false).ok()?; - meta.headers + let mut limits = craft_exr::decode::Limits::default(); + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + craft_exr::decode::parts(bytes, &limits) + .ok()? .iter() - .any(|h| matches!(h.compression, Compression::HTJ2K32 | Compression::HTJ2K256)) + .any(|part| matches!(part.compression.as_str(), "HTJ2K32" | "HTJ2K256")) .then_some("OpenEXR HTJ2K compression isn't supported yet: re-save the file with ZIP, PIZ or DWAA compression") } -/// Which channels a decode keeps, by plane name, and the display window they are placed in -/// (the first part's, as the `exr` crate reports the image's). -struct Planes<'k> { - keep: &'k dyn Fn(&str) -> bool, - display: exr::meta::attribute::IntegerBounds, -} - -/// One part's kept channels while it is decoded: each line of samples goes straight into its -/// channel's display-window plane (no copy of the part's samples in their own type first). -struct PlanesReader { - /// Per channel of the part: its plane name, sample type and plane (`None`: not kept). - planes: Vec)>>, - /// The data window's position in the display window, and the data window's and display - /// window's sizes. - offset: (i64, i64), - layer: (usize, usize), - display: (usize, usize), - f16s: Vec, - u32s: Vec, - f32s: Vec, - /// The part's channel indices of exact `R`, `G`, `B` and `A`, when it has R, G and B. - rgb: Option<([usize; 3], Option)>, - /// The part's display window differs from the first part's. - own_display: bool, -} - -/// A decoded part: its kept planes (in channel order) and what [`PlanesReader`] found. -struct PartPlanes { - planes: Vec<(String, Vec)>, - /// Positions in `planes` of the part's R, G, B (and A) channels, when it has them and keeps - /// them all. - rgb: Option<([usize; 3], Option)>, - has_rgb: bool, - exact: bool, -} - -impl<'s> ReadChannels<'s> for Planes<'_> { - type Reader = PlanesReader; - - fn create_channels_reader(&'s self, header: &Header) -> exr::error::Result { - if header.deep { - return Err(exr::error::Error::NotSupported("deep data".into())); - } - let dw = self.display; - let display = (dw.size.0, dw.size.1); - // Each channel is a display-window plane: a 60000² window over a 1×1 data window was a - // multi-gigabyte allocation per channel (#2141). - let n = display.0.checked_mul(display.1).filter(|n| *n > 0 && *n <= MAX_DISPLAY_PIXELS).ok_or(exr::error::Error::Invalid("display window".into()))?; - let prefix = part_name(header); - let pos = header.own_attributes.layer_position; - let offset = (i64::from(pos.0) - i64::from(dw.position.0), i64::from(pos.1) - i64::from(dw.position.1)); - let planes = header - .channels - .list - .iter() - .map(|ch| { - let name = channel_name(prefix.as_deref(), &ch.name.to_string()); - let fill = if is_depth(&name) { BACKGROUND_DEPTH } else { 0.0 }; - (self.keep)(&name).then(|| (name, ch.sample_type, vec![fill; n])) - }) - .collect(); - let find = |c: &str| header.channels.find_index_of_channel(&exr::meta::attribute::Text::from(c)); - let rgb = match (find("R"), find("G"), find("B")) { - (Some(r), Some(g), Some(b)) => Some(([r, g, b], find("A"))), - _ => None, - }; - Ok(PlanesReader { - planes, - offset, - layer: (header.layer_size.0, header.layer_size.1), - display, - f16s: vec![], - u32s: vec![], - f32s: vec![], - rgb, - own_display: header.shared_attributes.display_window != dw, - }) - } -} - -impl ChannelsReader for PlanesReader { - type Channels = PartPlanes; - - fn filter_block(&self, tile: TileCoordinates) -> bool { - tile.is_largest_resolution_level() && self.planes.iter().any(Option::is_some) - } - - fn read_block(&mut self, header: &Header, block: UncompressedBlock) -> exr::error::UnitResult { - let ((lw, lh), (w, h)) = (self.layer, self.display); - for line in block.lines(&header.channels) { - let Some(Some((_, kind, plane))) = self.planes.get_mut(line.location.channel) else { continue }; - let (x0, y, count) = (line.location.position.0, line.location.position.1, line.location.sample_count); - // The samples of data-window row `y`, columns `x0..x0 + count`, at display row `ty` - // from display column `tx0`; clipped to the display window. - if y >= lh || x0.checked_add(count).is_none_or(|end| end > lw) { - continue; - } - let Some(ty) = usize::try_from(y as i64 + self.offset.1).ok().filter(|ty| *ty < h) else { continue }; - let tx0 = x0 as i64 + self.offset.0; - let skip = usize::try_from(-tx0).unwrap_or(0).min(count); - let tx = usize::try_from(tx0.max(0)).unwrap_or(usize::MAX); - let take = (count - skip).min(w.saturating_sub(tx)); - let start = ty.checked_mul(w).and_then(|row| row.checked_add(tx)); - let Some(dst) = start.filter(|_| take > 0).and_then(|s| plane.get_mut(s..s.checked_add(take)?)) else { continue }; - match kind { - SampleType::F16 => { - self.f16s.resize(count, exr::prelude::f16::ZERO); - line.read_samples_into_slice(&mut self.f16s)?; - for (d, s) in dst.iter_mut().zip(self.f16s.iter().skip(skip)) { - *d = s.to_f32(); - } - } - SampleType::F32 => { - self.f32s.resize(count, 0.0); - line.read_samples_into_slice(&mut self.f32s)?; - for (d, s) in dst.iter_mut().zip(self.f32s.iter().skip(skip)) { - *d = *s; - } - } - SampleType::U32 => { - self.u32s.resize(count, 0); - line.read_samples_into_slice(&mut self.u32s)?; - for (d, s) in dst.iter_mut().zip(self.u32s.iter().skip(skip)) { - *d = *s as f32; - } - } - } - } - Ok(()) - } - - fn into_channels(self) -> PartPlanes { - // Positions of the kept channels among the kept planes. - let mut at = vec![None; self.planes.len()]; - let mut planes = Vec::with_capacity(self.planes.len()); - for (i, p) in self.planes.into_iter().enumerate() { - if let Some((name, _, data)) = p { - if let Some(slot) = at.get_mut(i) { - *slot = Some(planes.len()); - } - planes.push((name, data)); - } - } - let kept = |i: usize| at.get(i).copied().flatten(); - let has_rgb = self.rgb.is_some(); - let rgb = self.rgb.and_then(|([r, g, b], a)| { - let a = match a { - Some(a) => Some(kept(a)?), - None => None, - }; - Some(([kept(r)?, kept(g)?, kept(b)?], a)) - }); - PartPlanes { planes, rgb, has_rgb, exact: !self.own_display } - } -} - /// How the `image` crate's OpenEXR decoder would show a file: the first part with exact `R`, `G` /// and `B` channels (alpha `A` when it has one, else opaque), placed in the display window with /// 0 outside the data window. @@ -253,73 +88,103 @@ enum Refused { TooLarge(String), } -/// Bytes the planes of the channels `keep` names would take (`None`: not a readable header). -fn planes_bytes(meta: &exr::meta::MetaData, keep: &dyn Fn(&str) -> bool) -> Option { - let dw = meta.headers.first()?.shared_attributes.display_window; - let n = dw.size.0.checked_mul(dw.size.1)?; - let mut kept = 0usize; - for header in meta.headers.iter() { - let prefix = part_name(header); - kept = kept.saturating_add(header.channels.list.iter().filter(|ch| keep(&channel_name(prefix.as_deref(), &ch.name.to_string()))).count()); - } - Some(n.saturating_mul(kept).saturating_mul(std::mem::size_of::())) +/// Bytes the selected channels occupy in the first part's display window. The channel cache +/// reserves this before decoding so concurrent imports cannot exceed its soft budget. +fn planes_bytes(infos: &[craft_exr::decode::PartInfo], keep: &dyn Fn(&str) -> bool) -> Option { + let display = infos.first()?.display_window; + let pixels = u64::from(display.width).checked_mul(u64::from(display.height))?; + let selected = infos.iter().try_fold(0u64, |total, part| { + let count = part.channels.iter().filter(|channel| keep(&channel_name(part.name.as_deref(), &channel.name))).count() as u64; + total.checked_add(count) + })?; + usize::try_from(pixels.checked_mul(selected)?.checked_mul(4)?).ok() } -/// Decode the channels of an EXR file's bytes that `keep` names (by plane name). +/// Decode selected EXR channels through craft-exr, which places each selected block directly +/// into its bounded display-window plane. fn decode(bytes: &[u8], keep: &dyn Fn(&str) -> bool) -> Result { - let meta = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false).map_err(|_| Refused::Unreadable)?; - let display = meta.headers.first().ok_or(Refused::Unreadable)?.shared_attributes.display_window; - let need = planes_bytes(&meta, keep).ok_or(Refused::Unreadable)?; - if need > MAX_DECODE_BYTES { - let gb = |b: usize| b as f64 / f64::from(1u32 << 30); + use craft_exr::decode::{self, Error as ExrError, Limits}; + + let mut limits = Limits::default(); + limits.max_pixels = MAX_DISPLAY_PIXELS as u64; + limits.max_bytes = MAX_DECODE_BYTES as u64; + // Header-only checks must not charge channels this caller does not decode. The shared display + // decoder independently checks the exact selected display planes before allocating them. + let mut header_limits = limits; + header_limits.max_width = u32::MAX; + header_limits.max_height = u32::MAX; + header_limits.max_pixels = u64::MAX; + header_limits.max_bytes = u64::MAX; + let infos = decode::parts(bytes, &header_limits).map_err(|e| match e { + ExrError::LimitExceeded(message) => Refused::TooLarge(message), + _ => Refused::Unreadable, + })?; + let display = infos.first().ok_or(Refused::Unreadable)?.display_window; + let needed = planes_bytes(&infos, keep).filter(|bytes| *bytes > 0).ok_or(Refused::Unreadable)?; + if needed > MAX_DECODE_BYTES { + let gb = |b: u64| b as f64 / f64::from(1u32 << 30); return Err(Refused::TooLarge(format!( "its {}×{} OpenEXR channels need {:.1} GB of memory, more than the {:.1} GB one file may use", - display.size.0, - display.size.1, - gb(need), - gb(MAX_DECODE_BYTES) + display.width, + display.height, + gb(needed as u64), + gb(MAX_DECODE_BYTES as u64), ))); } - let read = ReadImage::new(ReadAllLayers { read_channels: Planes { keep, display } }, |_| {}); - let img = read.from_buffered(std::io::Cursor::new(bytes)).map_err(|_| Refused::Unreadable)?; - let dw = img.attributes.display_window; - let mut aux = AuxChannels::new(dw.size.0 as u32, dw.size.1 as u32, 1.0); + + let mut aux = AuxChannels::new(display.width, display.height, 1.0); let mut crypto: HashMap, Option)> = HashMap::new(); - let mut collect_meta = |other: &HashMap| { - for (k, v) in other { - let key = k.to_string(); + let mut rgb = Rgb::None; + for info in infos { + for (key, value) in &info.text_attributes { let Some(rest) = key.strip_prefix("cryptomatte/") else { continue }; let Some((id, field)) = rest.split_once('/') else { continue }; - let exr::meta::attribute::AttributeValue::Text(t) = v else { continue }; - let e = crypto.entry(id.to_string()).or_default(); + let entry = crypto.entry(id.to_string()).or_default(); match field { - "name" => e.0 = Some(t.to_string()), - "manifest" => e.1 = Some(t.to_string()), + "name" => entry.0 = Some(value.clone()), + "manifest" => entry.1 = Some(value.clone()), _ => {} } } - }; - collect_meta(&img.attributes.other); - let mut rgb = Rgb::None; - for layer in img.layer_data { - collect_meta(&layer.attributes.other); - let part = layer.channel_data; - if rgb == Rgb::None && part.has_rgb { + let prefix = info.name.as_deref(); + let exact = info.display_window == display; + let rgb_indices = ["R", "G", "B"].map(|wanted| info.channels.iter().position(|channel| channel.name == wanted)); + let has_rgb = rgb_indices.iter().all(Option::is_some); + let alpha_index = info.channels.iter().position(|channel| channel.name == "A"); + let mut part = decode::decode_display_part( + bytes, + info.index, + keep, + &|name| { + if is_depth(name) { BACKGROUND_DEPTH } else { 0.0 } + }, + &limits, + ) + .map_err(|error| match error { + ExrError::LimitExceeded(message) => Refused::TooLarge(message), + _ => Refused::Unreadable, + })?; + if rgb == Rgb::None && has_rgb { let base = aux.channels.len(); - rgb = match part.rgb { - Some(([r, g, b], a)) if part.exact => { - let picked = [Some(r), Some(g), Some(b), a]; - let depth = picked.iter().flatten().any(|i| part.planes.get(*i).is_some_and(|(n, _)| is_depth(n))); - if depth { Rgb::Unsupported } else { Rgb::Planes([base + r, base + g, base + b], a.map(|a| base + a)) } + let locate = |raw: usize| { + let name = channel_name(prefix, &info.channels.get(raw)?.name); + part.channels.iter().position(|channel| channel.name == name) + }; + rgb = match (rgb_indices[0].and_then(locate), rgb_indices[1].and_then(locate), rgb_indices[2].and_then(locate)) { + (Some(r), Some(g), Some(b)) if exact => { + let a = alpha_index.and_then(locate); + let depth = + [Some(r), Some(g), Some(b), a].into_iter().flatten().any(|i| part.channels.get(i).is_some_and(|channel| is_depth(&channel.name))); + if depth { Rgb::Unsupported } else { Rgb::Planes([base + r, base + g, base + b], a.map(|i| base + i)) } } _ => Rgb::Unsupported, }; } - aux.channels.extend(part.planes); + aux.channels.extend(part.channels.drain(..).map(|channel| (channel.name, channel.samples))); } for (_, (name, manifest)) in crypto { - if let (Some(n), Some(m)) = (name, manifest) { - aux.manifests.push((n, parse_manifest(&m))); + if let (Some(name), Some(manifest)) = (name, manifest) { + aux.manifests.push((name, parse_manifest(&manifest))); } } aux.manifests.sort(); @@ -389,11 +254,16 @@ fn picture_names(aux: &AuxChannels) -> Option<([String; 3], Option)> { /// headers, then only those channels decoded; in a multi-part file the other parts' pixels are /// not even decompressed), with the names of its planes. fn picture_only(bytes: &[u8]) -> Result<(Decoded, [String; 3], Option), Refused> { - let meta = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false).map_err(|_| Refused::Unreadable)?; + let mut limits = craft_exr::decode::Limits::default(); + limits.max_width = u32::MAX; + limits.max_height = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + let meta = craft_exr::decode::parts(bytes, &limits).map_err(|_| Refused::Unreadable)?; let mut names = AuxChannels::new(0, 0, 1.0); - for header in meta.headers.iter() { - let prefix = part_name(header); - names.channels.extend(header.channels.list.iter().map(|ch| (channel_name(prefix.as_deref(), &ch.name.to_string()), vec![]))); + for part in meta { + let prefix = part.name.as_deref(); + names.channels.extend(part.channels.iter().map(|ch| (channel_name(prefix, &ch.name), vec![]))); } let (rgb, a) = picture_names(&names).ok_or(Refused::Unreadable)?; // Planes are looked up by name ignoring case, so every channel that could answer is kept. @@ -672,8 +542,13 @@ impl ChannelCache { /// Decode the file at `path` whose bytes are `bytes` for `slot` (see [`ChannelCache::get`]). fn decode_file(&self, path: &str, slot: &Slot, bytes: &[u8]) -> Option> { // The planes it will allocate count against the budget while it decodes. - if let Ok(meta) = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false) - && let Some(need) = planes_bytes(&meta, &|_| true) + let mut limits = craft_exr::decode::Limits::default(); + limits.max_width = u32::MAX; + limits.max_height = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + if let Ok(infos) = craft_exr::decode::parts(bytes, &limits) + && let Some(need) = planes_bytes(&infos, &|_| true) { self.account(slot, need.min(MAX_DECODE_BYTES)); } @@ -1242,6 +1117,50 @@ mod tests { assert!(aux.get("ViewLayer.Combined.R").is_some()); } + #[test] + fn multipart_fallback_filters_channels_and_reserves_display_planes() { + use exr::prelude::*; + let part = |name: &str, pos: (i32, i32), size: (usize, usize), channels: Vec>| { + let attrs = LayerAttributes { layer_name: Some(Text::from(name)), layer_position: Vec2(pos.0, pos.1), ..Default::default() }; + Layer::new(size, attrs, Encoding::FAST_LOSSLESS, AnyChannels::sort(channels.into())) + }; + let (w, h) = (2usize, 1usize); + let bytes = file( + vec![ + part("Depth", (0, 0), (1, 1), vec![AnyChannel::new("Z", FlatSamples::F32(vec![7.0]))]), + part( + "Beauty", + (1, 1), + (w, h), + vec![ + AnyChannel::new("R", FlatSamples::F32(vec![0.1; w * h])), + AnyChannel::new("G", FlatSamples::F32(vec![0.2; w * h])), + AnyChannel::new("B", FlatSamples::F32(vec![0.3; w * h])), + ], + ), + ], + IntegerBounds::from_dimensions((3, 2)), + ); + let mut limits = craft_exr::decode::Limits::default(); + limits.max_width = u32::MAX; + limits.max_height = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + let parts = craft_exr::decode::parts(&bytes, &limits).unwrap(); + assert_eq!(planes_bytes(&parts, &|name| name == "Beauty.R"), Some(3 * 2 * 4)); + assert_eq!(planes_bytes(&parts, &|_| false), Some(0)); + + let selected = decode(&bytes, &|name| name == "Beauty.R").unwrap(); + assert_eq!(selected.aux.channels.iter().map(|(name, _)| name.as_str()).collect::>(), ["Beauty.R"]); + assert_eq!(selected.aux.get("Beauty.R").unwrap(), [0.0, 0.0, 0.0, 0.0, 0.1, 0.1]); + + // The old app decoder selected the named beauty part when the first part was depth-only, + // and placed its data into the shared display window; retain that layered-picture result. + let image = layered_image(&bytes).unwrap().to_rgba32f(); + assert_eq!(image.get_pixel(1, 1).0, [0.1, 0.2, 0.3, 1.0]); + assert_eq!(image.get_pixel(0, 0).0, [0.0, 0.0, 0.0, 1.0]); + } + /// Straight RGBA of [`layered_image`] at pixel 0 for a file of single-value channels. fn picture>(channels: &[(S, f32)]) -> Vec { use exr::prelude::*; diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index a4ed9d6dd..d16ba14ee 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "47107f660191de2f0b425569506f4daa4faadac9"; +const REV: &str = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From b68249c47b37b048b9de90aeb21a8acea50579da Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 17:18:13 +0000 Subject: [PATCH 36/99] test(lottie): cover archive without animation --- crates/lottie/src/tests.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/lottie/src/tests.rs b/crates/lottie/src/tests.rs index cf8543fdf..19f8a4c32 100644 --- a/crates/lottie/src/tests.rs +++ b/crates/lottie/src/tests.rs @@ -12,7 +12,7 @@ use effectcraft_render::render_frame; use effectcraft_time::{FrameRate, Tick}; use serde_json::{Value as Json, json}; -use crate::{ExportOptions, export_comp, import}; +use crate::{ExportOptions, LottieError, export_comp, import}; fn s(x: f64) -> Tick { Tick::from_seconds_f64(x) @@ -799,6 +799,14 @@ fn dotlottie_archive_roundtrip() { assert_eq!(q.comp(imp.comp).unwrap().layers.len(), 1); } +#[test] +fn dotlottie_archive_without_animation_is_rejected() { + let zip = craft_lottie::zip::try_store(&[("manifest.json".into(), b"{}".to_vec())]).unwrap(); + let mut project = Project::default(); + let err = import(&mut project, &zip, "empty archive", "", &mut |_| None).unwrap_err(); + assert!(matches!(err, LottieError::Parse(message) if message.contains("without a JSON animation"))); +} + #[test] fn deflated_dotlottie_archive_imports() { let (mut p, cid) = setup(); From e8b188fdb002860737923ab8e915993ec4fced90 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 17:45:15 +0000 Subject: [PATCH 37/99] fix(gpu): sort selective color channels on llvmpipe --- crates/gpu/src/shaders/fx_color.wgsl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/gpu/src/shaders/fx_color.wgsl b/crates/gpu/src/shaders/fx_color.wgsl index f616a2d9d..8d95ee166 100644 --- a/crates/gpu/src/shaders/fx_color.wgsl +++ b/crates/gpu/src/shaders/fx_color.wgsl @@ -75,8 +75,9 @@ fn fxc_colorama_phase(c: vec3, a: f32, mode: u32) -> f32 { // Selective Color range weights (color2::sc_weights). fn fxc_sc_weights(c0: vec3) -> array { let c = clamp(c0, vec3(0.0), vec3(1.0)); - // Stable descending sort of the channel indices. - var idx = vec3(0u, 1u, 2u); + // Stable descending sort of the channel indices. Use an array because llvmpipe does not + // preserve dynamically indexed writes to vector components here. + var idx = array(0u, 1u, 2u); for (var i = 1u; i < 3u; i++) { var j = i; while (j > 0u && c[idx[j]] > c[idx[j - 1u]]) { @@ -86,14 +87,14 @@ fn fxc_sc_weights(c0: vec3) -> array { j--; } } - let mx = c[idx.x]; - let md = c[idx.y]; - let mn = c[idx.z]; + let mx = c[idx[0]]; + let md = c[idx[1]]; + let mn = c[idx[2]]; var w = array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); var prim = array(0u, 2u, 4u); var sec = array(3u, 5u, 1u); - w[prim[idx.x]] = mx - md; - w[sec[idx.z]] = md - mn; + w[prim[idx[0]]] = mx - md; + w[sec[idx[2]]] = md - mn; w[6] = max((mn - 0.5) * 2.0, 0.0); w[8] = max((0.5 - mx) * 2.0, 0.0); w[7] = clamp(1.0 - (abs(mx - 0.5) + abs(mn - 0.5)), 0.0, 1.0); From cb2cd0c5cfb3f5a6d35d375611d453dd12f124c0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 19:52:19 +0000 Subject: [PATCH 38/99] Use shared EPS embedded font scanner --- Cargo.lock | 90 +++++++++++++++++++++++++++------------- Cargo.toml | 42 +++++++++---------- crates/pdf/src/ps/eps.rs | 57 +++---------------------- xtask/src/pdf_deps.rs | 2 +- 4 files changed, 89 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a525e39c9..9de86ecd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "serde", "serde_json", @@ -1129,12 +1129,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "serde_json", ] @@ -1142,17 +1142,17 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,8 +1175,9 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ + "craft-zip", "serde_json", "thiserror 2.0.21", ] @@ -1184,7 +1185,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "thiserror 2.0.21", ] @@ -1200,7 +1201,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1209,7 +1210,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1218,7 +1219,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "encoding_rs", "flate2", @@ -1229,7 +1230,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "dispatch2", "egui", @@ -1240,19 +1241,21 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "craft-xml", "flate2", "kurbo", "roxmltree", "thiserror 2.0.21", + "vectorcraft-geom", + "vectorcraft-pathops", ] [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1273,7 +1276,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "chrono", "dunce", @@ -1300,9 +1303,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", "rayon", "thiserror 2.0.21", ] @@ -1310,7 +1313,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "thiserror 2.0.21", ] @@ -1318,12 +1321,22 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.3", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1683,7 +1696,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1852,7 +1865,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3422,7 +3435,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "hayro-ccitt", ] @@ -3436,7 +3449,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -6683,6 +6696,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 08e34d741..1a3665518 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/pdf/src/ps/eps.rs b/crates/pdf/src/ps/eps.rs index e89b1d276..af5bf93be 100644 --- a/crates/pdf/src/ps/eps.rs +++ b/crates/pdf/src/ps/eps.rs @@ -1,4 +1,4 @@ -use super::{HashMap, Rc, is_white}; +use super::{HashMap, Rc}; /// The PostScript section of an EPS file (DOS EPS binary header handled) and its bounding box /// (`%%HiResBoundingBox` preferred), read with `craft-eps`: the header comments, and the trailer @@ -12,62 +12,15 @@ pub(super) fn find_from(hay: &[u8], needle: &[u8], from: usize) -> Option hay.get(from..)?.windows(needle.len()).position(|w| w == needle).map(|p| p + from) } -/// Every position of `needle` in `hay`, in order (one pass over the file). -fn positions(hay: &[u8], needle: &[u8]) -> Vec { - let mut out = vec![]; - let mut from = 0; - while let Some(p) = find_from(hay, needle, from) { - out.push(p); - from = p + needle.len(); - } - out -} - -/// The name after `key` (`/FontName /Name`). -fn name_after(b: &[u8], key: &[u8]) -> Option { - let p = find_from(b, key, 0)? + key.len(); - let rest = &b[p..]; - let s = rest.iter().position(|c| *c == b'/')? + 1; - let e = rest[s..].iter().position(|c| is_white(*c) || matches!(c, b'/' | b'[' | b'(' | b'{')).map_or(rest.len(), |q| s + q); - (e > s).then(|| String::from_utf8_lossy(&rest[s..e]).into_owned()) -} - /// Embedded font programs of an EPS file: Type 1 fonts (`… /FontName /X … currentfile eexec /// … cleartomark`, hexadecimal or binary) and CFF font sets (`… StartData `). pub(super) fn embedded_fonts(ps: &[u8]) -> HashMap>, bool)> { let mut out = HashMap::new(); - // The headers are found once, in one pass each; every `eexec` then takes the last header - // before it that no earlier `eexec` has used, so no prefix of the file is searched again. - let mut heads = positions(ps, b"%!PS-AdobeFont"); - heads.extend(positions(ps, b"%!FontType1")); - heads.sort_unstable(); - let names = positions(ps, b"/FontName"); - let mut from = 0; - let mut used = 0; - while let Some(ee) = find_from(ps, b"eexec", from) { - from = ee + 5; - let last_before = |v: &[usize]| v[..v.partition_point(|&p| p < ee)].last().copied().filter(|&p| p >= used); - // The fallback look-back stops at the previous font's end, so it cannot pick up its header. - let start = last_before(&heads).or_else(|| last_before(&names).map(|p| p.saturating_sub(512).max(used))); - let Some(start) = start else { continue }; - let end = find_from(ps, b"cleartomark", ee).map_or(ps.len(), |p| p + 11); - if let Some(name) = name_after(&ps[start..ee], b"/FontName") { - out.insert(name, (Rc::new(ps[start..end].to_vec()), false)); + for font in craft_eps::embedded_font_programs(ps) { + let name = if font.cff { crate::cff::font_name(&font.program) } else { font.name }; + if let Some(name) = name { + out.insert(name, (Rc::new(font.program), font.cff)); } - from = end; - used = end; - } - let mut from = 0; - while let Some(sd) = find_from(ps, b"StartData", from) { - from = sd + 9; - let head = String::from_utf8_lossy(&ps[sd.saturating_sub(64)..sd]).into_owned(); - let Some(len) = head.split_whitespace().last().and_then(|t| t.parse::().ok()) else { continue }; - let s = sd + 10; - let Some(data) = ps.get(s..s.saturating_add(len)) else { continue }; - if let Some(name) = crate::cff::font_name(data) { - out.insert(name, (Rc::new(data.to_vec()), true)); - } - from = s + len; } out } diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index a4ed9d6dd..e0d8db068 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "47107f660191de2f0b425569506f4daa4faadac9"; +const REV: &str = "46478f4cf2d5879ae7ce0593f3f41eff90d98609"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From f9ffd91a3b947f52a2d71b6254942d11aa06e924 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 20:01:08 +0000 Subject: [PATCH 39/99] Run EffectCraft coverage tests in one shard --- .github/workflows/sonarcloud.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 8f1aa5ad5..7d193b610 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -20,5 +20,8 @@ jobs: uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main with: timeout-minutes: 120 + # GPU tests share a process-local lock; separate coverage shards create independent + # software Vulkan devices, bypassing that lock and potentially contending on llvmpipe. + shards: 1 fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 secrets: inherit From 47eb768ba6af57cdc25b47210152e6a21b1cdc44 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 03:37:32 +0000 Subject: [PATCH 40/99] wip: repin craft-eps dependencies --- Cargo.lock | 58 +++++++++++++++++++++---------------------- Cargo.toml | 42 +++++++++++++++---------------- xtask/src/pdf_deps.rs | 2 +- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9de86ecd1..cb3f57699 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "serde", "serde_json", @@ -1129,12 +1129,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "serde_json", ] @@ -1142,17 +1142,17 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,7 +1175,7 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "craft-zip", "serde_json", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "thiserror 2.0.21", ] @@ -1201,7 +1201,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1210,7 +1210,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1219,7 +1219,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "encoding_rs", "flate2", @@ -1230,7 +1230,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "dispatch2", "egui", @@ -1241,7 +1241,7 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "craft-xml", "flate2", @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1276,7 +1276,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "chrono", "dunce", @@ -1303,9 +1303,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", "rayon", "thiserror 2.0.21", ] @@ -1313,7 +1313,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "thiserror 2.0.21", ] @@ -1321,7 +1321,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1330,7 +1330,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "flate2", "thiserror 2.0.21", @@ -1696,7 +1696,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1865,7 +1865,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3435,7 +3435,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "hayro-ccitt", ] @@ -3449,7 +3449,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=46478f4cf2d5879ae7ce0593f3f41eff90d98609#46478f4cf2d5879ae7ce0593f3f41eff90d98609" +source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", diff --git a/Cargo.toml b/Cargo.toml index 1a3665518..2d88486d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "46478f4cf2d5879ae7ce0593f3f41eff90d98609", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index e0d8db068..32541b038 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "46478f4cf2d5879ae7ce0593f3f41eff90d98609"; +const REV: &str = "2fea4b4ce28678e30bd546885a323aaa8fa243ef"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From 501c5a70c48a5eaff7ffdc571b7a495f3d91cafc Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 03:37:33 +0000 Subject: [PATCH 41/99] wip: wire shared craft-gif animation writer in effectcraft-export --- Cargo.lock | 94 ++++++++++++++++++++--------- Cargo.toml | 42 ++++++------- crates/export/Cargo.toml | 3 +- crates/export/src/lib.rs | 53 ++++++++++------ crates/export/tests/it/roundtrip.rs | 48 +++++++++++++++ xtask/src/pdf_deps.rs | 2 +- 6 files changed, 174 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a525e39c9..aec0de6f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "serde", "serde_json", @@ -1129,12 +1129,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "serde_json", ] @@ -1142,17 +1142,20 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" +dependencies = [ + "gif", +] [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,8 +1178,9 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ + "craft-zip", "serde_json", "thiserror 2.0.21", ] @@ -1184,7 +1188,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "thiserror 2.0.21", ] @@ -1200,7 +1204,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1209,7 +1213,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1218,7 +1222,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "encoding_rs", "flate2", @@ -1229,7 +1233,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "dispatch2", "egui", @@ -1240,19 +1244,21 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "craft-xml", "flate2", "kurbo", "roxmltree", "thiserror 2.0.21", + "vectorcraft-geom", + "vectorcraft-pathops", ] [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1273,7 +1279,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "chrono", "dunce", @@ -1300,9 +1306,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7)", "rayon", "thiserror 2.0.21", ] @@ -1310,7 +1316,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "thiserror 2.0.21", ] @@ -1318,12 +1324,22 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.3", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1683,7 +1699,8 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-gif", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1852,7 +1869,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3422,7 +3439,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "hayro-ccitt", ] @@ -3436,7 +3453,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -6683,6 +6700,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 08e34d741..247ba208e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index 164b10a7f..f1579686c 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -17,16 +17,17 @@ effectcraft-render = { workspace = true } craft-video = { workspace = true } craft-audio = { workspace = true } craft-media = { workspace = true } +craft-gif = { workspace = true } effectcraft-opusenc = { workspace = true } image = { workspace = true, features = ["png", "jpeg", "tiff", "exr", "tga"] } exr = { workspace = true } -gif = { workspace = true } rayon = { workspace = true } web-time = { workspace = true } thiserror = { workspace = true } log = { workspace = true } [dev-dependencies] +gif = { workspace = true } tempfile = { workspace = true } effectcraft-media = { workspace = true } effectcraft-effects = { workspace = true } diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs index d9af7b2aa..04603e558 100644 --- a/crates/export/src/lib.rs +++ b/crates/export/src/lib.rs @@ -421,13 +421,22 @@ fn write_still(cx: &Cx, file: &mut W, img: &I } async fn gif_export(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut State<'_>) -> Result { - if w > u16::MAX as u32 || h > u16::MAX as u32 { - return Err(ExportError::Unsupported("GIF frames are limited to 65535 px".into())); - } + use craft_gif::write::{AnimationWriter, Disposal, Options, PreparedFrame}; + + validate_gif_dimensions(w, h)?; let path = job.place(job.path, 1); let mut file = job.create(&path)?; - let mut enc = gif::Encoder::new(&mut file, w as u16, h as u16, &[]).map_err(|e| ExportError::Encode(e.to_string()))?; - enc.set_repeat(if job.output.gif_loop { gif::Repeat::Infinite } else { gif::Repeat::Finite(0) }).map_err(|e| ExportError::Encode(e.to_string()))?; + let mut enc = AnimationWriter::new( + &mut file, + w, + h, + Options { + loop_forever: job.output.gif_loop, + disposal: if job.output.channels == Channels::Rgba { Disposal::Background } else { Disposal::Keep }, + speed: 10, + }, + ) + .map_err(|e| ExportError::Encode(e.to_string()))?; let rate = job.settings.rate(comp); // GIF delays are in 1/100 s: carry the rounding error so long animations keep their timing. let cs_per_frame = 100.0 * rate.den as f64 / rate.num as f64; @@ -437,30 +446,31 @@ async fn gif_export(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut State<'_ let mut i = 0; while i < st.total { let end = (i + batch).min(st.total); - let frames: Vec> = job - .frames(comp, (i..end).collect(), |_, img| { - let mut px = job.pixels_with(&img, comp, job.output.channels, w, h, false); - gif::Frame::from_rgba_speed(w as u16, h as u16, &mut px, 10) - }) + let frames: Vec> = job + .frames(comp, (i..end).collect(), |_, img| craft_gif::write::prepare_frame(w, h, job.pixels_with(&img, comp, job.output.channels, w, h, false), 10)) .await; - for mut f in frames { + for frame in frames { clock += cs_per_frame; let d = (clock.round() as u64).saturating_sub(emitted).max(1); emitted += d; - f.delay = d.min(u16::MAX as u64) as u16; - if job.output.channels == Channels::Rgba { - f.dispose = gif::DisposalMethod::Background; - } - enc.write_frame(&f).map_err(|e| ExportError::Encode(e.to_string()))?; + let frame = frame.map_err(|e| ExportError::Encode(e.to_string()))?; + enc.write_prepared_frame(frame, d.min(u16::MAX as u64) as u16).map_err(|e| ExportError::Encode(e.to_string()))?; } st.advance(end - i)?; i = end; } - drop(enc); + let _ = enc.finish().map_err(|e| ExportError::Encode(e.to_string()))?; let bytes = file.finish()?; Ok(Report { path, frames: 0, width: w, height: h, seconds: 0.0, bytes, audio: false, log: None, overflow: vec![] }) } +fn validate_gif_dimensions(w: u32, h: u32) -> Result<()> { + if w > u16::MAX as u32 || h > u16::MAX as u32 { + return Err(ExportError::Unsupported("GIF frames are limited to 65535 px".into())); + } + Ok(()) +} + #[cfg(test)] mod tests { use super::*; @@ -478,4 +488,13 @@ mod tests { assert_eq!(OutputFormat::H264.coded_size(1, 101), (2, 100)); assert_eq!(OutputFormat::Gif.coded_size(1, 101), (1, 101)); } + + #[test] + fn gif_dimension_limit_keeps_the_existing_unsupported_error() { + assert!(validate_gif_dimensions(u16::MAX as u32, u16::MAX as u32).is_ok()); + assert!(matches!( + validate_gif_dimensions(u16::MAX as u32 + 1, 1), + Err(ExportError::Unsupported(message)) if message == "GIF frames are limited to 65535 px" + )); + } } diff --git a/crates/export/tests/it/roundtrip.rs b/crates/export/tests/it/roundtrip.rs index bcf7b9d90..1abed1983 100644 --- a/crates/export/tests/it/roundtrip.rs +++ b/crates/export/tests/it/roundtrip.rs @@ -554,10 +554,12 @@ fn gif_roundtrip() { opts.set_color_output(gif::ColorOutput::RGBA); let mut dec = opts.read_info(std::fs::File::open(&path).expect("open")).expect("gif header"); assert_eq!((dec.width() as u32, dec.height() as u32), (W, H)); + assert_eq!(dec.repeat(), gif::Repeat::Infinite); let mut k = 0; let mut total_delay = 0u32; while let Some(f) = dec.read_next_frame().expect("frame") { assert_eq!((f.width as u32, f.height as u32), (W, H)); + assert_eq!(f.dispose, gif::DisposalMethod::Keep); total_delay += f.delay as u32; let img = Image::from_rgba8(W, H, &f.buffer); check_frame(&img, k, 0.06); @@ -565,11 +567,57 @@ fn gif_roundtrip() { } assert_eq!(k, FRAMES); assert_eq!(total_delay, 120, "1.2 s in centiseconds"); + + // Re-encode the same rendered RGB pixels through the former app-local gif 0.13 path. The + // shared writer must preserve the complete output bytes, including quantization and LZW data. + let reference_dir = out_dir("gif-byte-parity"); + let png_pattern = reference_dir.join("frame_[#####].png"); + let png_module = OutputModule::for_format(OutputFormat::PngSequence); + run(&p, cid, &NoFootage, &png_module, &png_pattern); + let png_pattern = png_pattern.to_string_lossy(); + let mut expected = Vec::new(); + { + let mut encoder = gif::Encoder::new(&mut expected, W as u16, H as u16, &[]).expect("reference GIF encoder"); + encoder.set_repeat(gif::Repeat::Infinite).expect("reference GIF repeat"); + for frame_number in 0..FRAMES { + let png_path = sequence_path(&png_pattern, frame_number as i64); + let mut rgba = image::open(png_path).expect("reference PNG").to_rgba8().into_raw(); + let mut frame = gif::Frame::from_rgba_speed(W as u16, H as u16, &mut rgba, 10); + frame.delay = 10; + encoder.write_frame(&frame).expect("reference GIF frame"); + } + } + let actual = std::fs::read(&path).expect("GIF bytes"); + assert_eq!(actual.len(), expected.len(), "GIF byte length differs: actual {}, reference {}", actual.len(), expected.len()); + let difference = actual.iter().zip(&expected).position(|(a, b)| a != b); + assert!( + difference.is_none(), + "GIF bytes differ at offset {:?}: actual {:#04x}, reference {:#04x}", + difference, + difference.map_or(0, |i| actual[i]), + difference.map_or(0, |i| expected[i]) + ); if let Some(s) = ffprobe(&path) { assert!(s.starts_with("gif|64|48"), "{s}"); } } +#[test] +fn gif_rgba_keeps_background_disposal_and_non_looping() { + let (p, cid) = project(None); + let d = out_dir("gif-rgba"); + let om = OutputModule { channels: Channels::Rgba, gif_loop: false, ..OutputModule::for_format(OutputFormat::Gif) }; + let path = d.join("anim.gif"); + run(&p, cid, &NoFootage, &om, &path); + + let mut opts = gif::DecodeOptions::new(); + opts.set_color_output(gif::ColorOutput::RGBA); + let mut dec = opts.read_info(std::fs::File::open(&path).expect("open")).expect("gif header"); + assert_eq!(dec.repeat(), gif::Repeat::Finite(0)); + let first = dec.read_next_frame().expect("frame").expect("first frame"); + assert_eq!(first.dispose, gif::DisposalMethod::Background); +} + #[test] fn cancel_stops_early() { let (p, cid) = project(None); diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index a4ed9d6dd..eab796342 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "47107f660191de2f0b425569506f4daa4faadac9"; +const REV: &str = "948b5c23c12dc8c87c8b1828892b1462113dd5a7"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From c3c23a9a6fd2e2eb7b6d2fcb25e197af98fb9fb1 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 15:21:46 +0000 Subject: [PATCH 42/99] refactor(pdf): use shared PostScript reader for EPS --- Cargo.lock | 232 ++++++-- Cargo.toml | 43 +- crates/pdf/Cargo.toml | 2 +- crates/pdf/src/cff.rs | 8 - crates/pdf/src/font.rs | 30 - crates/pdf/src/lib.rs | 58 +- crates/pdf/src/object.rs | 1 + crates/pdf/src/page.rs | 17 +- crates/pdf/src/ps.rs | 49 -- crates/pdf/src/ps/builtin.rs | 1076 ---------------------------------- crates/pdf/src/ps/eps.rs | 53 -- crates/pdf/src/ps/exec.rs | 182 ------ crates/pdf/src/ps/paths.rs | 187 ------ crates/pdf/src/ps/scanner.rs | 223 ------- crates/pdf/src/ps/text.rs | 329 ----------- crates/pdf/src/ps/value.rs | 88 --- crates/pdf/src/tests.rs | 24 + xtask/src/pdf_deps.rs | 10 +- 18 files changed, 314 insertions(+), 2298 deletions(-) delete mode 100644 crates/pdf/src/ps.rs delete mode 100644 crates/pdf/src/ps/builtin.rs delete mode 100644 crates/pdf/src/ps/eps.rs delete mode 100644 crates/pdf/src/ps/exec.rs delete mode 100644 crates/pdf/src/ps/paths.rs delete mode 100644 crates/pdf/src/ps/scanner.rs delete mode 100644 crates/pdf/src/ps/text.rs delete mode 100644 crates/pdf/src/ps/value.rs diff --git a/Cargo.lock b/Cargo.lock index cb3f57699..2d7940146 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,6 +138,21 @@ dependencies = [ "equator", ] +[[package]] +name = "alloc-no-stdlib" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2fb6cfd47bf496ff64095c20eaba0c201404ee38714d4142fcfa1dc334fcc7a" + +[[package]] +name = "alloc-stdlib" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5c1865780388bfa186411ab5f247819487fc4864c6e9c3106611fa347586e1" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -697,6 +712,16 @@ dependencies = [ "syn 3.0.6", ] +[[package]] +name = "brotli-decompressor" +version = "6.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75c74c9c51b9140663e196b5fb88bc94c334d7a497c8311cb759d8557874747f" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.20.3" @@ -1092,26 +1117,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1144,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "serde", "serde_json", @@ -1129,12 +1154,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "serde_json", ] @@ -1142,17 +1167,20 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +dependencies = [ + "gif", +] [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1172,10 +1200,41 @@ dependencies = [ "writeable", ] +[[package]] +name = "craft-image-codecs" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +dependencies = [ + "craft-jpeg", + "craft-metadata", + "exr", + "flate2", + "half", + "image", + "image-webp", + "jpeg-encoder", + "png", + "rayon", + "serde_json", + "thiserror 2.0.21", + "tiff", + "zune-core", + "zune-jpeg", + "zune-jpegxl", +] + +[[package]] +name = "craft-jpeg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "craft-zip", "serde_json", @@ -1185,7 +1244,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "thiserror 2.0.21", ] @@ -1201,25 +1260,50 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "miniz_oxide 0.9.1", "serde_json", ] +[[package]] +name = "craft-metadata" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +dependencies = [ + "brotli-decompressor", + "chrono", + "craft-tiff", + "quick-xml 0.41.0", + "serde", +] + [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "hayro-syntax", "thiserror 2.0.21", ] +[[package]] +name = "craft-ps" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +dependencies = [ + "craft-eps", + "kurbo", + "miniz_oxide 0.8.9", + "pdf-writer", + "skrifa 0.47.0", + "weezl", +] + [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "encoding_rs", "flate2", @@ -1230,7 +1314,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "dispatch2", "egui", @@ -1241,8 +1325,9 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ + "craft-image-codecs", "craft-xml", "flate2", "kurbo", @@ -1252,10 +1337,19 @@ dependencies = [ "vectorcraft-pathops", ] +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1267,7 +1361,7 @@ dependencies = [ "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", "serde", - "skrifa", + "skrifa 0.44.0", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -1276,7 +1370,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "chrono", "dunce", @@ -1303,9 +1397,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)", "rayon", "thiserror 2.0.21", ] @@ -1313,7 +1407,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "thiserror 2.0.21", ] @@ -1321,7 +1415,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1330,7 +1424,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "flate2", "thiserror 2.0.21", @@ -1696,7 +1790,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1865,7 +1959,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -1928,15 +2022,15 @@ dependencies = [ name = "effectcraft-pdf" version = "0.24.1" dependencies = [ - "craft-eps", "craft-pdf", + "craft-ps", "effectcraft-raster", "effectcraft-svg", "effectcraft-text", "image", "kurbo", "miniz_oxide 0.9.1", - "skrifa", + "skrifa 0.44.0", "wasm-bindgen-test", "zune-jpeg", ] @@ -2072,7 +2166,7 @@ dependencies = [ "effectcraft-keyframe", "harfrust", "kurbo", - "skrifa", + "skrifa 0.44.0", "unicode-bidi", "unicode-linebreak", ] @@ -2407,7 +2501,7 @@ dependencies = [ "parking_lot", "profiling", "self_cell", - "skrifa", + "skrifa 0.44.0", "smallvec", "unicode-bidi", "unicode-general-category", @@ -3254,7 +3348,7 @@ dependencies = [ "hashbrown 0.17.1", "log", "peniko", - "skrifa", + "skrifa 0.44.0", "smallvec", "vello_common", ] @@ -3383,7 +3477,7 @@ checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9" dependencies = [ "bitflags 2.13.2", "bytemuck", - "read-fonts", + "read-fonts 0.41.0", "smallvec", ] @@ -3435,7 +3529,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "hayro-ccitt", ] @@ -3449,7 +3543,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef" +source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -3706,6 +3800,7 @@ dependencies = [ "moxcms", "num-traits", "png", + "qoi", "tiff", "zune-core", "zune-jpeg", @@ -3836,6 +3931,12 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-encoder" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b454d911ac55068f53495488d8ccd0646eaa540c033a28ee15b07838afafb01f" + [[package]] name = "js-sys" version = "0.3.106" @@ -4812,6 +4913,18 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4" +[[package]] +name = "pdf-writer" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5e456864a7a304047bff84977dc6fb162bd956475d40ba50b2dcecaada7f753" +dependencies = [ + "bitflags 2.13.2", + "itoa", + "memchr", + "ryu", +] + [[package]] name = "peniko" version = "0.6.1" @@ -5125,6 +5238,15 @@ version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5311,6 +5433,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "read-fonts" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5a0cf4bb6cbce4c29756270d189a5e400ac05e91192161d83a0bcb6e68492e8" +dependencies = [ + "bytemuck", + "font-types", + "once_cell", +] + [[package]] name = "reborrow" version = "0.5.5" @@ -5554,6 +5687,12 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "ryu-js" version = "1.0.3" @@ -5788,7 +5927,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68" dependencies = [ "bytemuck", - "read-fonts", + "read-fonts 0.41.0", +] + +[[package]] +name = "skrifa" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526e654b303ff4ad73a5a40b25de2b3ce3d039c5e3b6da5f89ae6e57004cb40f" +dependencies = [ + "bytemuck", + "read-fonts 0.44.0", ] [[package]] @@ -8254,6 +8403,15 @@ dependencies = [ "zune-core", ] +[[package]] +name = "zune-jpegxl" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba11ecd07cc23351500e840ae03841b7e4997923ec8e4832ee3ae199ea0b6b4" +dependencies = [ + "zune-core", +] + [[package]] name = "zvariant" version = "5.15.0" diff --git a/Cargo.toml b/Cargo.toml index 2d88486d4..093eaf3c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,23 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["read"] } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "41fb227542efb8a7748caa1c659f271d8605303c", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +91,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +123,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +232,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/pdf/Cargo.toml b/crates/pdf/Cargo.toml index 68aabfbd7..8f26ec854 100644 --- a/crates/pdf/Cargo.toml +++ b/crates/pdf/Cargo.toml @@ -10,7 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] -craft-eps = { workspace = true } +craft-ps = { workspace = true } craft-pdf.workspace = true effectcraft-svg = { workspace = true } kurbo = { workspace = true } diff --git a/crates/pdf/src/cff.rs b/crates/pdf/src/cff.rs index cb7214cc2..efc853caa 100644 --- a/crates/pdf/src/cff.rs +++ b/crates/pdf/src/cff.rs @@ -366,14 +366,6 @@ pub struct Cff { pub encoding: [u16; 256], } -/// The first font name in a CFF program's Name INDEX. -pub fn font_name(data: &[u8]) -> Option { - let hdr = *data.get(2)? as usize; - let (names, _) = index(data, hdr)?; - let r = names.first()?.clone(); - Some(String::from_utf8_lossy(data.get(r)?).into_owned()) -} - impl Cff { pub fn parse(data: &[u8]) -> Option { let d = data; diff --git a/crates/pdf/src/font.rs b/crates/pdf/src/font.rs index 8bd91831e..2e9347a2c 100644 --- a/crates/pdf/src/font.rs +++ b/crates/pdf/src/font.rs @@ -350,36 +350,6 @@ impl Font { } } - /// A simple font outside a PDF (EPS text): `program` is an embedded font program (CFF when - /// the flag is set, else Type 1), otherwise the bundled stand-in for `name` is used; - /// `names` is the encoding (code → glyph name), else the program's built-in encoding or - /// StandardEncoding. Advances are the program's. - pub fn standalone(name: &str, program: Option<(&[u8], bool)>, names: Option>>) -> Font { - let mut f = Font::blank(name, false); - f.program = match program { - Some((data, true)) => Cff::parse(data).map(|c| Program::Cff(Box::new(c))), - Some((data, false)) => Type1::parse(data).map(|t| Program::Type1(Box::new(t))), - None => None, - } - .unwrap_or_else(|| Program::Fallback(fallback(name))); - match &f.program { - Program::Cff(c) => f.matrix = Affine::new(c.font_matrix), - Program::Type1(t) => f.matrix = t.font_matrix.map(Affine::new).unwrap_or(f.matrix), - _ => {} - } - let symbol = matches!(f.program, Program::Fallback(_)) && (name.contains("Symbol") || name.contains("Dingbats")); - f.names = match names { - // Unencoded codes draw .notdef (not the built-in encoding). - Some(n) => (0..256).map(|c| Some(n.get(c).cloned().flatten().unwrap_or_else(|| ".notdef".into()))).collect(), - None => match &f.program { - Program::Type1(t) if !t.encoding.is_empty() => (0..256).map(|c| t.encoding.get(&(c as u8)).cloned()).collect(), - _ if symbol => vec![None; 256], - _ => (0..256).map(|c| Base::Standard.name(c as u8)).collect(), - }, - }; - f - } - pub fn load(file: &File, d: &Dict, skipped: &mut Vec) -> Font { let subtype = file.get(d, "Subtype").and_then(Obj::name).unwrap_or("Type1").to_string(); let base_name = file.get(d, "BaseFont").and_then(Obj::name).unwrap_or("").to_string(); diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index ff914e759..994cbcc30 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -18,7 +18,6 @@ mod font; mod image; mod object; mod page; -mod ps; mod read; mod shading; mod type1; @@ -188,13 +187,58 @@ fn parse_pdf(bytes: &[u8], index: usize, framing: Framing) -> Result Ok(finish(nodes, flags, skipped, dw.max(1.0), dh.max(1.0), to_doc)) } +fn eps_fallback_font(name: &[u8]) -> Option<&'static [u8]> { + use effectcraft_text::fonts::{INTER_BOLD, INTER_ITALIC, INTER_REGULAR, INTER_SEMIBOLD, JETBRAINS_MONO_REGULAR, NOTO_SERIF_REGULAR}; + let name = String::from_utf8_lossy(name).to_ascii_lowercase(); + Some(if name.contains("courier") || name.contains("mono") || name.contains("consol") { + JETBRAINS_MONO_REGULAR + } else if name.contains("times") + || name.contains("serif") && !name.contains("sans") + || name.contains("georgia") + || name.contains("garamond") + || name.contains("minion") + || name.contains("roman") + { + NOTO_SERIF_REGULAR + } else if name.contains("bold") || name.contains("black") || name.contains("heavy") { + INTER_BOLD + } else if name.contains("semibold") || name.contains("demi") { + INTER_SEMIBOLD + } else if name.contains("italic") || name.contains("oblique") { + INTER_ITALIC + } else { + INTER_REGULAR + }) +} + fn parse_eps(bytes: &[u8]) -> Result { - let (ps, bb) = ps::eps_parts(bytes).ok_or(Error::NoBoundingBox)?; - let mut it = ps::Interp::new(bb); - it.run(ps); - let (nodes, flags, skipped) = it.b.finish(); - let to_doc = Affine::new([1.0, 0.0, 0.0, -1.0, -bb[0], bb[3]]); - Ok(finish(nodes, flags, skipped, (bb[2] - bb[0]).max(1.0), (bb[3] - bb[1]).max(1.0), to_doc)) + let limits = craft_ps::read::Limits { + // Preserve EffectCraft's established 8,000,000-unit PostScript execution budget. + steps: 8_000_000, + stack_overflow_noop: true, + skip_images: true, + keep_unpainted: true, + zero_division_zero: true, + fallback_font: Some(eps_fallback_font), + ..Default::default() + }; + let converted = craft_ps::read::eps_to_pdf(bytes, limits).map_err(|message| match message.as_str() { + "not PostScript" | "the EPS has no bounding box" => Error::NoBoundingBox, + _ => Error::Read(message), + })?; + let mut doc = parse_pdf(&converted.pdf, 0, Framing::Placed)?; + for skipped in &mut doc.skipped { + if skipped == "content (path limit)" { + *skipped = "PostScript (path limit)".to_string(); + } + } + doc.skipped.extend(converted.warnings.into_iter().map(|warning| match warning.as_str() { + "the program runs too long" | "out of memory" => "PostScript (operation limit)".to_string(), + "executable name resolution limit" => "PostScript (recursion limit)".to_string(), + "content (path limit)" => "PostScript (path limit)".to_string(), + _ => warning, + })); + Ok(doc) } /// The document's layer names (the root's children), bottom first. diff --git a/crates/pdf/src/object.rs b/crates/pdf/src/object.rs index df475a4bb..dbe1ca706 100644 --- a/crates/pdf/src/object.rs +++ b/crates/pdf/src/object.rs @@ -516,6 +516,7 @@ fn ascii_hex(data: &[u8], max: usize) -> Option> { Some(out) } +#[cfg(test)] pub fn ascii85(data: &[u8]) -> Vec { // The PostScript reader uses this unbounded entry point. No Vec can hold more // than usize::MAX bytes, so its output cannot exceed this bound. diff --git a/crates/pdf/src/page.rs b/crates/pdf/src/page.rs index ba67b39aa..21880daa0 100644 --- a/crates/pdf/src/page.rs +++ b/crates/pdf/src/page.rs @@ -499,12 +499,23 @@ impl<'a> Interp<'a> { (Some("OC"), Some(Obj::Dict(ocg))) => self.ocg_name(ocg), _ => None, }; - match layer { - Some(name) => { + let actual_text = match (args.first().and_then(Obj::name), args.get(1)) { + (Some("Span"), Some(Obj::Dict(props))) => props.get("ActualText").and_then(|v| match self.file.resolve(v) { + Obj::Str(bytes) => Some(crate::color::text_string(bytes)), + _ => None, + }), + _ => None, + }; + match (layer, actual_text) { + (Some(name), _) => { self.marked.push(Some(self.b.depth())); self.b.open(&name, true); } - None => self.marked.push(None), + (None, Some(text)) => { + self.marked.push(Some(self.b.depth())); + self.b.open(&format!("Text: {text}"), false); + } + (None, None) => self.marked.push(None), } } "EMC" => { diff --git a/crates/pdf/src/ps.rs b/crates/pdf/src/ps.rs deleted file mode 100644 index 3d734e46c..000000000 --- a/crates/pdf/src/ps.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Encapsulated PostScript: a small PostScript interpreter (PostScript Language Reference, 3rd -//! edition, and the EPSF 3.0 specification) covering what exported vector EPS files use: the -//! operand and dictionary stacks, procedures and `def`, arithmetic, control flow, arrays and -//! dictionaries, the graphics state, path construction (including arcs) and painting, clipping -//! and device colours, and text (`findfont` / `selectfont`, `show` and its variants, `charpath`, -//! `stringwidth`, re-encoded fonts) with embedded Type 1 and CFF programs or the bundled -//! stand-in fonts. Images are skipped (their inline data is stepped over), as is -//! Level 3 smooth shading (`shfill`). - -use std::cell::RefCell; -use std::collections::HashMap; -use std::rc::Rc; - -use effectcraft_svg::{Affine, BezPath, Cap, FillRule, Join, Paint, Stroke}; -use kurbo::{PathEl, Point}; - -use crate::build::{Builder, MAX_PATH}; -use crate::font::Font; -use crate::object::{ascii85, is_white, parse_num}; - -mod builtin; -mod eps; -mod exec; -mod paths; -mod scanner; -mod text; -mod value; - -pub use eps::eps_parts; -use value::{DictRef, GState, V}; - -pub(crate) struct Interp { - pub b: Builder, - st: Vec, - dicts: Vec, - gs: GState, - saved: Vec, - budget: usize, - /// Nested procedure calls (recursion is cut off at [`MAX_CALL_DEPTH`]). - calls: usize, - /// Fonts by name: `definefont`d dictionaries. - font_dir: HashMap, - /// Embedded font programs found in the file (name → (program, CFF)). - embedded: HashMap>, bool)>, - /// Fonts built for drawing, by base font and encoding. - font_cache: HashMap>, - page: [f64; 4], - pub unknown: Vec, -} diff --git a/crates/pdf/src/ps/builtin.rs b/crates/pdf/src/ps/builtin.rs deleted file mode 100644 index a19aeb6da..000000000 --- a/crates/pdf/src/ps/builtin.rs +++ /dev/null @@ -1,1076 +0,0 @@ -use super::eps::find_from; -use super::exec::MAX_STACK; -use super::scanner::Src; -use super::text::encoding_array; -use super::value::{Flow, V, array, matrix_of, matrix_val, new_dict}; -use super::{Affine, BezPath, Cap, FillRule, Interp, Join, PathEl, Point, Rc, RefCell, parse_num}; - -impl Interp { - pub(super) fn builtin(&mut self, n: &str, src: &mut Src) -> Result<(), Flow> { - // Every handler leaves the stacks untouched when the operator is outside its family. - if self.try_stack_op(n) - || self.try_arithmetic_op(n) - || self.try_logic_op(n) - || self.try_control_op(n, src)? - || self.try_dictionary_op(n) - || self.try_collection_op(n) - || self.try_environment_op(n, src)? - || self.try_graphics_op(n)? - || self.try_coordinate_op(n) - || self.try_path_op(n)? - || self.try_paint_op(n)? - { - return Ok(()); - } - match n { - // Text (see `text_op`). - "scalefont" | "makefont" | "selectfont" | "setfont" | "show" | "charpath" | "glyphshow" | "rootfont" | "currentfont" | "setcachedevice" - | "setcharwidth" | "ashow" | "widthshow" | "awidthshow" | "xshow" | "yshow" | "xyshow" | "kshow" | "cshow" | "stringwidth" | "definefont" - | "StandardEncoding" | "ISOLatin1Encoding" | "eexec" | "StartData" | "undefinefont" => self.text_op(n, src)?, - // Images: operands popped, inline data skipped. - "image" | "imagemask" | "colorimage" => { - let mut reads_file = false; - let check = |v: &V, rf: &mut bool| { - if matches!(v, V::File) || matches!(v, V::Proc(p) if p.iter().any(|x| matches!(x, V::Name(n) if &**n == "currentfile"))) { - *rf = true; - } - }; - if n == "colorimage" { - let ncomp = self.popn().max(1.0) as usize; - let multi = matches!(self.pop(), V::Bool(true)); - for _ in 0..if multi { ncomp.min(4) } else { 1 } { - let v = self.pop(); - check(&v, &mut reads_file); - } - for _ in 0..4 { - self.pop(); - } - } else { - match self.pop() { - V::Dict(d) => { - if let Some(ds) = d.borrow().get("DataSource") { - check(ds, &mut reads_file); - } - } - top => { - check(&top, &mut reads_file); - for _ in 0..4 { - self.pop(); - } - } - } - } - if reads_file { - src.skip_image_data(); - } - self.b.skip("image"); - } - _ => { - if self.unknown.len() < 32 && !self.unknown.iter().any(|u| u == n) { - self.unknown.push(n.to_string()); - } - } - } - Ok(()) - } - - fn repeat_proc(&mut self, src: &mut Src) -> Result<(), Flow> { - let p = self.pop(); - let k = self.popn().clamp(0.0, 1e6) as usize; - for _ in 0..k { - self.spend(1)?; - match self.exec_obj(p.clone(), src) { - Err(Flow::Exit) => break, - r => r?, - } - } - - Ok(()) - } - - fn for_proc(&mut self, src: &mut Src) -> Result<(), Flow> { - let p = self.pop(); - let lim = self.popn(); - let inc = self.popn(); - let mut i = self.popn(); - let mut guard = 0; - while inc != 0.0 && ((inc > 0.0 && i <= lim) || (inc < 0.0 && i >= lim)) && guard < 1_000_000 { - self.spend(1)?; - self.push(V::Num(i)); - match self.exec_obj(p.clone(), src) { - Err(Flow::Exit) => break, - r => r?, - } - i += inc; - guard += 1; - } - - Ok(()) - } - - fn loop_proc(&mut self, src: &mut Src) -> Result<(), Flow> { - let p = self.pop(); - for _ in 0..1_000_000 { - self.spend(1)?; - match self.exec_obj(p.clone(), src) { - Err(Flow::Exit) => break, - r => r?, - } - } - - Ok(()) - } - - fn forall_proc(&mut self, src: &mut Src) -> Result<(), Flow> { - let p = self.pop(); - match self.pop() { - V::Dict(d) => { - let items: Vec<(String, V)> = d.borrow().iter().map(|(k, v)| (k.clone(), v.clone())).collect(); - for (k, v) in items { - self.spend(1)?; - self.push(V::Lit(k.into())); - self.push(v); - match self.exec_obj(p.clone(), src) { - Err(Flow::Exit) => break, - r => r?, - } - } - } - V::Str(s) => { - let bytes = s.borrow().clone(); - for c in bytes { - self.spend(1)?; - self.push(V::Num(c as f64)); - match self.exec_obj(p.clone(), src) { - Err(Flow::Exit) => break, - r => r?, - } - } - } - a => { - for v in a.items().unwrap_or_default() { - self.spend(1)?; - self.push(v); - match self.exec_obj(p.clone(), src) { - Err(Flow::Exit) => break, - r => r?, - } - } - } - } - - Ok(()) - } - - fn try_stack_op(&mut self, n: &str) -> bool { - match n { - // Stack. - "pop" => { - self.pop(); - } - "exch" => { - let b = self.pop(); - let a = self.pop(); - self.push(b); - self.push(a); - } - "dup" => { - let a = self.st.last().cloned().unwrap_or(V::Null); - self.push(a); - } - "copy" => { - match self.pop() { - V::Num(k) => { - let k = (k.max(0.0) as usize).min(self.st.len()); - // A copy past the operand limit copies nothing, and the values copied - // count as operations (one for eight): repeated doubling spends the budget. - if self.st.len().saturating_add(k) <= MAX_STACK { - self.charge(k / 8); - let tail: Vec = self.st[self.st.len() - k..].to_vec(); - self.st.extend(tail); - } - } - V::Array(dst) => { - let s = self.pop().items().unwrap_or_default(); - let mut d = dst.borrow_mut(); - for (i, v) in s.into_iter().enumerate() { - if i < d.len() { - d[i] = v; - } - } - drop(d); - self.push(V::Array(dst)); - } - other => self.push(other), - }; - } - "index" => { - let k = self.popn().max(0.0) as usize; - let v = if k < self.st.len() { self.st[self.st.len() - 1 - k].clone() } else { V::Null }; - self.push(v); - } - "roll" => { - let j = self.popn() as i64; - let k = (self.popn().max(0.0) as usize).min(self.st.len()); - if k > 0 { - let s = self.st.len() - k; - let r = j.rem_euclid(k as i64) as usize; - self.st[s..].rotate_right(r); - } - } - "clear" => self.st.clear(), - "count" => self.push(V::Num(self.st.len() as f64)), - "mark" | "[" | "<<" => self.push(V::Mark), - "cleartomark" => { - while let Some(v) = self.st.pop() { - if matches!(v, V::Mark) { - break; - } - } - } - "counttomark" => { - let k = self.st.iter().rev().position(|v| matches!(v, V::Mark)).unwrap_or(self.st.len()); - self.push(V::Num(k as f64)); - } - "]" => { - let k = self.st.iter().rev().position(|v| matches!(v, V::Mark)).unwrap_or(self.st.len()); - let items = self.st.split_off(self.st.len() - k); - self.st.pop(); - self.push(array(items)); - } - ">>" => { - let k = self.st.iter().rev().position(|v| matches!(v, V::Mark)).unwrap_or(self.st.len()); - let items = self.st.split_off(self.st.len() - k); - self.st.pop(); - let d = new_dict(); - for kv in items.as_chunks::<2>().0 { - d.borrow_mut().insert(kv[0].key(), kv[1].clone()); - } - self.push(V::Dict(d)); - } - _ => return false, - } - true - } - - fn try_arithmetic_op(&mut self, n: &str) -> bool { - match n { - // Arithmetic. - "add" | "sub" | "mul" | "div" | "idiv" | "mod" | "atan" | "exp" | "max" | "min" => { - let b = self.popn(); - let a = self.popn(); - let v = match n { - "add" => a + b, - "sub" => a - b, - "mul" => a * b, - "div" => { - if b == 0.0 { - 0.0 - } else { - a / b - } - } - // `checked_*` give 0 both for a zero divisor and for the one overflowing - // case, `i64::MIN / -1` (`/` and `%` panic on it in every build). - "idiv" => (a as i64).checked_div(b as i64).unwrap_or(0) as f64, - "mod" => (a as i64).checked_rem(b as i64).unwrap_or(0) as f64, - "atan" => a.atan2(b).to_degrees().rem_euclid(360.0), - "exp" => a.powf(b), - "max" => a.max(b), - _ => a.min(b), - }; - self.push(V::Num(if v.is_finite() { v } else { 0.0 })); - } - "neg" | "abs" | "sqrt" | "sin" | "cos" | "ln" | "log" | "cvi" | "cvr" | "round" | "floor" | "ceiling" | "truncate" => { - let a = match self.pop() { - V::Str(s) => parse_num(&s.borrow()).unwrap_or(0.0), - v => v.num().unwrap_or(0.0), - }; - let v = match n { - "neg" => -a, - "abs" => a.abs(), - "sqrt" => a.max(0.0).sqrt(), - "sin" => a.to_radians().sin(), - "cos" => a.to_radians().cos(), - "ln" => a.ln(), - "log" => a.log10(), - "cvi" | "truncate" => a.trunc(), - "round" => (a + 0.5).floor(), - "floor" => a.floor(), - "ceiling" => a.ceil(), - _ => a, - }; - self.push(V::Num(if v.is_finite() { v } else { 0.0 })); - } - _ => return false, - } - true - } - - fn try_logic_op(&mut self, n: &str) -> bool { - match n { - // Comparison and logic. - "eq" | "ne" => { - let b = self.pop(); - let a = self.pop(); - let eq = match (&a, &b) { - (V::Num(x), V::Num(y)) => x == y, - (V::Bool(x), V::Bool(y)) => x == y, - (V::Null, V::Null) => true, - (V::Array(x), V::Array(y)) => Rc::ptr_eq(x, y), - (V::Dict(x), V::Dict(y)) => Rc::ptr_eq(x, y), - (x, y) => !x.key().is_empty() && x.key() == y.key(), - }; - self.push(V::Bool(eq == (n == "eq"))); - } - "gt" | "ge" | "lt" | "le" => { - let b = self.popn(); - let a = self.popn(); - self.push(V::Bool(match n { - "gt" => a > b, - "ge" => a >= b, - "lt" => a < b, - _ => a <= b, - })); - } - "not" => match self.pop() { - V::Bool(b) => self.push(V::Bool(!b)), - v => self.push(V::Num(!(v.num().unwrap_or(0.0) as i64) as f64)), - }, - "and" | "or" | "xor" => { - let b = self.pop(); - let a = self.pop(); - match (a, b) { - (V::Bool(x), V::Bool(y)) => self.push(V::Bool(match n { - "and" => x && y, - "or" => x || y, - _ => x ^ y, - })), - (x, y) => { - let (x, y) = (x.num().unwrap_or(0.0) as i64, y.num().unwrap_or(0.0) as i64); - self.push(V::Num(match n { - "and" => x & y, - "or" => x | y, - _ => x ^ y, - } as f64)); - } - } - } - "true" => self.push(V::Bool(true)), - "false" => self.push(V::Bool(false)), - "null" => self.push(V::Null), - _ => return false, - } - true - } - - fn try_control_op(&mut self, n: &str, src: &mut Src) -> Result { - match n { - // Control. - "exec" => { - let v = self.pop(); - self.exec_obj(v, src)?; - } - "if" => { - let p = self.pop(); - if let V::Bool(true) = self.pop() { - self.exec_obj(p, src)?; - } - } - "ifelse" => { - let f = self.pop(); - let t = self.pop(); - let c = matches!(self.pop(), V::Bool(true)); - self.exec_obj(if c { t } else { f }, src)?; - } - // Each pass of a loop counts against the budget. - "repeat" => self.repeat_proc(src)?, - "for" => self.for_proc(src)?, - "loop" => self.loop_proc(src)?, - "forall" => self.forall_proc(src)?, - "exit" => return Err(Flow::Exit), - "stop" => return Err(Flow::Stop), - "stopped" => { - let p = self.pop(); - let stopped = match self.exec_obj(p, src) { - Err(Flow::Quit) => return Err(Flow::Quit), - Err(_) => true, - Ok(()) => false, - }; - self.push(V::Bool(stopped)); - } - "quit" => return Err(Flow::Quit), - "showpage" | "copypage" => {} - _ => return Ok(false), - } - Ok(true) - } - - fn try_dictionary_op(&mut self, n: &str) -> bool { - match n { - // Dictionaries. - "def" => { - let v = self.pop(); - let k = self.pop().key(); - if let Some(d) = self.dicts.last() { - d.borrow_mut().insert(k, v); - } - } - "store" => { - let v = self.pop(); - let k = self.pop().key(); - let d = self.dicts.iter().rev().find(|d| d.borrow().contains_key(&k)).or(self.dicts.last()).cloned(); - if let Some(d) = d { - d.borrow_mut().insert(k, v); - } - } - "load" => { - let k = self.pop().key(); - let v = self.lookup(&k).unwrap_or(V::Op(k.into())); - self.push(v); - } - "undef" => { - let k = self.pop().key(); - if let V::Dict(d) = self.pop() { - d.borrow_mut().remove(&k); - } - } - "dict" => { - self.pop(); - self.push(V::Dict(new_dict())); - } - "begin" => { - if let V::Dict(d) = self.pop() - && self.dicts.len() < 64 - { - self.dicts.push(d); - } - } - "end" => { - if self.dicts.len() > 1 { - self.dicts.pop(); - } - } - "currentdict" => { - let d = self.dicts.last().cloned().unwrap_or_else(new_dict); - self.push(V::Dict(d)); - } - "userdict" | "globaldict" | "systemdict" | "statusdict" | "errordict" | "$error" => { - let d = self.dicts[0].clone(); - self.push(V::Dict(d)); - } - "where" => { - let k = self.pop().key(); - match self.dicts.iter().rev().find(|d| d.borrow().contains_key(&k)).cloned() { - Some(d) => { - self.push(V::Dict(d)); - self.push(V::Bool(true)); - } - None => self.push(V::Bool(false)), - } - } - "known" => { - let k = self.pop().key(); - let v = match self.pop() { - V::Dict(d) => d.borrow().contains_key(&k), - _ => false, - }; - self.push(V::Bool(v)); - } - "countdictstack" => self.push(V::Num(self.dicts.len() as f64)), - "cleardictstack" => self.dicts.truncate(1), - "findresource" | "findfont" | "findencoding" => { - let category = if n == "findresource" { self.pop().key() } else { String::new() }; - let key = self.pop().key(); - match (n, category.as_str()) { - ("findfont", _) | (_, "Font") => { - let f = self.find_font(&key); - self.push(V::Dict(f)); - } - ("findencoding", _) | (_, "Encoding") => self.push(encoding_array(&key)), - _ => self.push(V::Dict(new_dict())), - } - } - "defineresource" => { - let category = self.pop().key(); - let v = self.pop(); - let key = self.pop().key(); - if let (V::Dict(d), "Font") = (&v, category.as_str()) { - self.font_dir.insert(key, d.clone()); - } - self.push(v); - } - "resourcestatus" => { - self.pop(); - self.pop(); - self.push(V::Bool(false)); - } - _ => return false, - } - true - } - - fn try_collection_op(&mut self, n: &str) -> bool { - match n { - // Arrays and strings. - // The storage made counts as operations (a value, or eight bytes, each), so a loop - // of large constructors spends the budget rather than the memory. - "array" => { - let k = self.popn().clamp(0.0, 1e6) as usize; - self.charge(k); - self.push(array(vec![V::Null; k])); - } - "string" => { - let k = self.popn().clamp(0.0, 1e7) as usize; - self.charge(k / 8); - self.push(V::Str(Rc::new(RefCell::new(vec![0; k])))); - } - "length" => { - let l = match self.pop() { - V::Str(s) => s.borrow().len(), - V::Dict(d) => d.borrow().len(), - V::Name(s) | V::Lit(s) => s.len(), - v => v.items().map_or(0, |i| i.len()), - }; - self.push(V::Num(l as f64)); - } - "get" => { - let k = self.pop(); - let v = match self.pop() { - V::Dict(d) => d.borrow().get(&k.key()).cloned().unwrap_or(V::Null), - V::Str(s) => V::Num(s.borrow().get(k.num().unwrap_or(0.0) as usize).copied().unwrap_or(0) as f64), - a => a.items().and_then(|i| i.get(k.num().unwrap_or(0.0) as usize).cloned()).unwrap_or(V::Null), - }; - self.push(v); - } - "put" => { - let v = self.pop(); - let k = self.pop(); - match self.pop() { - V::Dict(d) => { - d.borrow_mut().insert(k.key(), v); - } - V::Array(a) => { - let i = k.num().unwrap_or(0.0) as usize; - if let Some(slot) = a.borrow_mut().get_mut(i) { - *slot = v; - } - } - V::Str(s) => { - let i = k.num().unwrap_or(0.0) as usize; - if let Some(slot) = s.borrow_mut().get_mut(i) { - *slot = v.num().unwrap_or(0.0) as u8; - } - } - _ => {} - } - } - "getinterval" => { - let c = self.popn().max(0.0) as usize; - let i = self.popn().max(0.0) as usize; - match self.pop() { - V::Str(s) => { - let b = s.borrow(); - let part = b.get(i.min(b.len())..(i + c).min(b.len())).unwrap_or(&[]).to_vec(); - drop(b); - self.push(V::Str(Rc::new(RefCell::new(part)))); - } - a => { - let items = a.items().unwrap_or_default(); - let part = items.get(i.min(items.len())..(i + c).min(items.len())).unwrap_or(&[]).to_vec(); - self.push(array(part)); - } - } - } - "putinterval" => { - self.pop(); - self.pop(); - self.pop(); - } - "aload" => { - let a = self.pop(); - for v in a.items().unwrap_or_default() { - self.push(v); - } - self.push(a); - } - "astore" => { - let a = self.pop(); - if let V::Array(arr) = &a { - let k = arr.borrow().len().min(self.st.len()); - let items = self.st.split_off(self.st.len() - k); - *arr.borrow_mut() = items; - } - self.push(a); - } - "cvx" => match self.pop() { - V::Array(a) => self.push(V::Proc(Rc::new(a.borrow().clone()))), - V::Lit(s) => self.push(V::Name(s)), - V::Str(s) => { - // Executable string: tokenize it as a procedure. - let bytes = s.borrow().clone(); - let mut sub = Src { d: &bytes, pos: 0 }; - let mut body = vec![]; - while let Some(t) = sub.token(0) { - body.push(t); - } - self.push(V::Proc(Rc::new(body))); - } - v => self.push(v), - }, - "cvlit" => match self.pop() { - V::Proc(p) => self.push(array(p.as_ref().clone())), - V::Name(s) => self.push(V::Lit(s)), - v => self.push(v), - }, - "cvn" => { - let k = self.pop().key(); - self.push(V::Lit(k.into())); - } - "cvs" => { - self.pop(); - let k = self.pop().key(); - self.push(V::Str(Rc::new(RefCell::new(k.into_bytes())))); - } - "xcheck" => { - let v = self.pop(); - self.push(V::Bool(matches!(v, V::Proc(_) | V::Name(_) | V::Op(_)))); - } - "type" => { - let t = match self.pop() { - V::Num(_) => "realtype", - V::Bool(_) => "booleantype", - V::Name(_) | V::Lit(_) => "nametype", - V::Op(_) => "operatortype", - V::Str(_) => "stringtype", - V::Proc(_) | V::Array(_) => "arraytype", - V::Dict(_) => "dicttype", - V::Mark => "marktype", - V::Null => "nulltype", - V::File => "filetype", - }; - self.push(V::Name(t.into())); - } - "bind" | "readonly" | "executeonly" | "noaccess" => {} - _ => return false, - } - true - } - - fn try_environment_op(&mut self, n: &str, src: &mut Src) -> Result { - match n { - "languagelevel" => self.push(V::Num(3.0)), - "version" | "product" => self.push(V::Str(Rc::new(RefCell::new(b"3010".to_vec())))), - "save" => { - self.spend(self.gs.path.elements().len())?; - self.saved.push(self.gs.clone()); - self.gs.depth = self.b.depth(); - self.push(V::Null); - } - "restore" => { - self.pop(); - self.grestore(); - } - "currentfile" => self.push(V::File), - "readstring" | "readhexstring" | "readline" => { - self.pop(); - self.pop(); - self.push(V::Str(Rc::new(RefCell::new(vec![])))); - self.push(V::Bool(false)); - } - "flushfile" | "closefile" | "print" | "==" | "=" | "pstack" | "setpagedevice" | "setglobal" | "setpacking" | "setshared" | "setobjectformat" - | "setsmoothness" => { - if !matches!(n, "pstack") { - self.pop(); - } - } - "currentglobal" | "currentpacking" | "currentshared" => self.push(V::Bool(false)), - // Operators that return values must push them, or the rest of the program reads a - // shifted stack: Illustrator's EPS prolog queries the device this way and then drew - // nothing (#955). Values are a plain device's defaults (PostScript Language - // Reference, 3rd ed., chapter 8). - "currentflat" => self.push(V::Num(1.0)), - "currentscreen" => { - self.push(V::Num(60.0)); - self.push(V::Num(45.0)); - self.push(V::Proc(Rc::new(vec![]))); - } - "currentblackgeneration" | "currentundercolorremoval" | "currenttransfer" => self.push(V::Proc(Rc::new(vec![]))), - "currentcolortransfer" => { - for _ in 0..4 { - self.push(V::Proc(Rc::new(vec![]))); - } - } - "currentpagedevice" | "currenthalftone" | "currentsystemparams" | "currentuserparams" | "currentdevparams" => { - if n == "currentdevparams" { - self.pop(); - } - self.push(V::Dict(new_dict())); - } - "setuserparams" | "setsystemparams" | "setcolortransfer" | "setblackgeneration" | "setundercolorremoval" => { - let k = if n == "setcolortransfer" { 4 } else { 1 }; - for _ in 0..k { - self.pop(); - } - } - // `file status` → false; `string status` → false (no such file). - "status" => { - self.pop(); - self.push(V::Bool(false)); - } - "dictstack" => { - self.pop(); - let ds: Vec = self.dicts.iter().map(|d| V::Dict(d.clone())).collect(); - self.push(array(ds)); - } - "maxlength" => { - let k = match self.pop() { - V::Dict(d) => d.borrow().len(), - _ => 0, - }; - self.push(V::Num(k.saturating_add(16) as f64)); - } - "internaldict" => { - self.pop(); - let d = self.dicts[0].clone(); - self.push(V::Dict(d)); - } - "undefineresource" => { - self.pop(); - self.pop(); - } - // `[ … /Name pdfmark`: a Distiller annotation; other interpreters discard it. - "pdfmark" => { - while let Some(v) = self.st.pop() { - if matches!(v, V::Mark) { - break; - } - } - } - // `source [params] /Name filter`. A SubFileDecode of the current file with a count of - // 0 reads to its end-of-data string: skip that data (an embedded XMP packet, which - // otherwise ran as PostScript). Other filters read what their source reads. - "filter" => { - let name = self.pop().key(); - let mut skipped = false; - let source = if name == "SubFileDecode" && !matches!(self.st.last(), Some(V::Dict(_))) { - let eod = match self.pop() { - V::Str(s) => s.borrow().clone(), - _ => vec![], - }; - let count = self.popn(); - let source = self.pop(); - if matches!(source, V::File) && count == 0.0 && !eod.is_empty() { - src.pos = match find_from(src.d, &eod, src.pos) { - Some(p) => p.saturating_add(eod.len()), - None => src.d.len(), - }; - skipped = true; - } - source - } else { - if matches!(self.st.last(), Some(V::Dict(_))) { - self.pop(); - } - self.pop() - }; - // Data already stepped over leaves nothing for `image` to skip. - self.push(if skipped { V::Null } else { source }); - } - "vmstatus" => { - for _ in 0..3 { - self.push(V::Num(0.0)); - } - } - _ => return Ok(false), - } - Ok(true) - } - - fn try_graphics_op(&mut self, n: &str) -> Result { - match n { - // Graphics state. - "gsave" => { - self.spend(self.gs.path.elements().len())?; - let mut g = self.gs.clone(); - g.depth = self.b.depth(); - self.saved.push(g); - } - "grestore" => self.grestore(), - "grestoreall" => { - while !self.saved.is_empty() { - self.grestore(); - } - } - "initgraphics" => { - self.gs.ctm = Affine::IDENTITY; - self.gs.lw = 1.0; - self.gs.color = [0.0; 3]; - } - "setlinewidth" => self.gs.lw = self.popn(), - "currentlinewidth" => self.push(V::Num(self.gs.lw)), - "setlinecap" => self.gs.cap = [Cap::Butt, Cap::Round, Cap::Square][(self.popn().max(0.0) as usize).min(2)], - "setlinejoin" => self.gs.join = [Join::Miter, Join::Round, Join::Bevel][(self.popn().max(0.0) as usize).min(2)], - "setmiterlimit" => self.gs.miter = self.popn(), - "setdash" => { - let off = self.popn(); - let a: Vec = self.pop().items().unwrap_or_default().iter().filter_map(V::num).collect(); - self.gs.dash = (!a.is_empty() && a.iter().any(|v| *v > 0.0)).then_some((a, off)); - } - "setflat" | "setstrokeadjust" | "setoverprint" | "setrenderingintent" | "setcolorrendering" | "sethalftone" | "settransfer" => { - self.pop(); - } - // frequency angle proc - "setscreen" => { - for _ in 0..3 { - self.pop(); - } - } - "setgray" => { - let g = self.popn().clamp(0.0, 1.0); - self.gs.color = [g; 3]; - } - "setrgbcolor" => { - let b = self.popn(); - let g = self.popn(); - let r = self.popn(); - self.gs.color = [r, g, b].map(|v| v.clamp(0.0, 1.0)); - } - "sethsbcolor" => { - let v = self.popn().clamp(0.0, 1.0); - let s = self.popn().clamp(0.0, 1.0); - let h = self.popn().rem_euclid(1.0) * 6.0; - let (i, f) = (h.floor() as i32, h.fract()); - let (p, q, t) = (v * (1.0 - s), v * (1.0 - s * f), v * (1.0 - s * (1.0 - f))); - self.gs.color = match i { - 0 => [v, t, p], - 1 => [q, v, p], - 2 => [p, v, t], - 3 => [p, q, v], - 4 => [t, p, v], - _ => [v, p, q], - }; - } - "setcmykcolor" => { - let k = self.popn().clamp(0.0, 1.0); - let y = self.popn().clamp(0.0, 1.0); - let m = self.popn().clamp(0.0, 1.0); - let c = self.popn().clamp(0.0, 1.0); - self.gs.color = [(1.0 - c) * (1.0 - k), (1.0 - m) * (1.0 - k), (1.0 - y) * (1.0 - k)]; - } - "setcolorspace" => { - self.pop(); - } - "setcolor" => { - // Device colour by operand count (patterns are not drawn). - let k = self.st.iter().rev().take_while(|v| matches!(v, V::Num(_))).count().min(4); - let c: Vec = self.st.split_off(self.st.len() - k).iter().filter_map(V::num).collect(); - self.gs.color = match c.len() { - 1 => [c[0]; 3], - 3 => [c[0], c[1], c[2]], - 4 => [(1.0 - c[0]) * (1.0 - c[3]), (1.0 - c[1]) * (1.0 - c[3]), (1.0 - c[2]) * (1.0 - c[3])], - _ => self.gs.color, - }; - } - "currentgray" => self.push(V::Num((self.gs.color[0] + self.gs.color[1] + self.gs.color[2]) / 3.0)), - "currentrgbcolor" => { - for c in self.gs.color { - self.push(V::Num(c)); - } - } - _ => return Ok(false), - } - Ok(true) - } - - fn try_coordinate_op(&mut self, n: &str) -> bool { - match n { - // Coordinates. - "matrix" => self.push(matrix_val(Affine::IDENTITY)), - "identmatrix" | "defaultmatrix" => { - self.pop(); - self.push(matrix_val(Affine::IDENTITY)); - } - "currentmatrix" => { - self.pop(); - self.push(matrix_val(self.gs.ctm)); - } - "setmatrix" => { - let m = self.pop(); - self.gs.ctm = matrix_of(&m).unwrap_or(Affine::IDENTITY); - } - "concat" => { - let m = self.pop(); - if let Some(m) = matrix_of(&m) { - self.gs.ctm *= m; - } - } - "concatmatrix" => { - self.pop(); - let b = self.pop(); - let a = self.pop(); - let (a, b) = (matrix_of(&a).unwrap_or(Affine::IDENTITY), matrix_of(&b).unwrap_or(Affine::IDENTITY)); - self.push(matrix_val(b * a)); - } - "invertmatrix" => { - self.pop(); - let a = self.pop(); - self.push(matrix_val(matrix_of(&a).unwrap_or(Affine::IDENTITY).inverse())); - } - "translate" | "scale" => { - let top = self.pop(); - let (m_out, y) = match top { - V::Array(_) => (Some(top), self.popn()), - v => (None, v.num().unwrap_or(0.0)), - }; - let x = self.popn(); - let t = if n == "translate" { Affine::translate((x, y)) } else { Affine::scale_non_uniform(x, y) }; - match m_out { - Some(_) => self.push(matrix_val(t)), - None => self.gs.ctm *= t, - } - } - "rotate" => { - let top = self.pop(); - match top { - V::Array(_) => { - let a = self.popn(); - self.push(matrix_val(Affine::rotate(a.to_radians()))); - } - v => self.gs.ctm *= Affine::rotate(v.num().unwrap_or(0.0).to_radians()), - } - } - "transform" | "itransform" | "dtransform" | "idtransform" => { - let top = self.pop(); - let (m, y) = match top { - V::Array(_) | V::Proc(_) => (matrix_of(&top).unwrap_or(Affine::IDENTITY), self.popn()), - v => (self.gs.ctm, v.num().unwrap_or(0.0)), - }; - let x = self.popn(); - let m = if n.starts_with('i') { m.inverse() } else { m }; - let p = if n.contains('d') { - let c = m.as_coeffs(); - Point::new(c[0] * x + c[2] * y, c[1] * x + c[3] * y) - } else { - m * Point::new(x, y) - }; - self.push(V::Num(p.x)); - self.push(V::Num(p.y)); - } - _ => return false, - } - true - } - - fn try_path_op(&mut self, n: &str) -> Result { - match n { - // Paths. - "newpath" => { - self.gs.path = BezPath::new(); - self.gs.cur = None; - self.gs.start = None; - } - "moveto" => { - let p = self.user_point(); - self.move_to(p)?; - } - "rmoveto" => { - let d = self.user_point(); - let c = self.current_user(); - self.move_to(Point::new(c.x + d.x, c.y + d.y))?; - } - "lineto" => { - let p = self.user_point(); - self.line_to(p)?; - } - "rlineto" => { - let d = self.user_point(); - let c = self.current_user(); - self.line_to(Point::new(c.x + d.x, c.y + d.y))?; - } - "curveto" | "rcurveto" => { - let p3 = self.user_point(); - let p2 = self.user_point(); - let p1 = self.user_point(); - if n == "rcurveto" { - let c = self.current_user(); - let o = |p: Point| Point::new(c.x + p.x, c.y + p.y); - self.curve_to(o(p1), o(p2), o(p3))?; - } else { - self.curve_to(p1, p2, p3)?; - } - } - "closepath" => { - if self.gs.cur.is_some() { - self.room(1)?; - self.gs.path.close_path(); - self.gs.cur = self.gs.start; - } - } - "arc" => self.arc(false)?, - "arcn" => self.arc(true)?, - "currentpoint" => { - let c = self.current_user(); - self.push(V::Num(c.x)); - self.push(V::Num(c.y)); - } - "pathbbox" => { - self.spend(self.gs.path.elements().len())?; - let r = kurbo::Shape::bounding_box(&self.gs.path); - let inv = self.gs.ctm.inverse(); - let (a, b) = (inv * Point::new(r.x0, r.y0), inv * Point::new(r.x1, r.y1)); - for v in [a.x.min(b.x), a.y.min(b.y), a.x.max(b.x), a.y.max(b.y)] { - self.push(V::Num(v)); - } - } - "flattenpath" | "reversepath" | "strokepath" | "initclip" => {} - "clippath" => { - let p = self.page; - self.gs.path = kurbo::Shape::to_path(&kurbo::Rect::new(p[0], p[1], p[2], p[3]), 0.1); - } - _ => return Ok(false), - } - Ok(true) - } - - fn try_paint_op(&mut self, n: &str) -> Result { - match n { - // Painting. - "fill" => self.paint(Some(FillRule::NonZero), false), - "eofill" => self.paint(Some(FillRule::EvenOdd), false), - "stroke" => self.paint(None, true), - "clip" | "eoclip" => { - let rule = if n == "clip" { FillRule::NonZero } else { FillRule::EvenOdd }; - self.spend(self.gs.path.elements().len())?; - let p = self.gs.path.clone(); - if !p.elements().iter().all(|e| matches!(e, PathEl::MoveTo(_))) { - self.b.clip(p, rule); - } - } - "rectfill" | "rectstroke" | "rectclip" => { - let paths = self.rect_path()?; - if n == "rectstroke" && matches!(self.st.last(), Some(V::Array(_))) { - self.pop(); - } - let mut all = BezPath::new(); - for p in paths { - all.extend(p); - } - match n { - "rectclip" => self.b.clip(all, FillRule::NonZero), - _ => { - let saved = std::mem::replace(&mut self.gs.path, all); - self.paint(if n == "rectfill" { Some(FillRule::NonZero) } else { None }, n == "rectstroke"); - self.gs.path = saved; - } - } - } - "shfill" => { - self.pop(); - self.b.skip("smooth shading (shfill)"); - } - _ => return Ok(false), - } - Ok(true) - } -} diff --git a/crates/pdf/src/ps/eps.rs b/crates/pdf/src/ps/eps.rs deleted file mode 100644 index af5bf93be..000000000 --- a/crates/pdf/src/ps/eps.rs +++ /dev/null @@ -1,53 +0,0 @@ -use super::{HashMap, Rc}; - -/// The PostScript section of an EPS file (DOS EPS binary header handled) and its bounding box -/// (`%%HiResBoundingBox` preferred), read with `craft-eps`: the header comments, and the trailer -/// for a box deferred with `(atend)`. A binary header that points outside the file is refused. -pub fn eps_parts(bytes: &[u8]) -> Option<(&[u8], [f64; 4])> { - let ps = craft_eps::sections(bytes).ok()?.postscript; - Some((ps, craft_eps::Comments::read(ps).page_box()?)) -} - -pub(super) fn find_from(hay: &[u8], needle: &[u8], from: usize) -> Option { - hay.get(from..)?.windows(needle.len()).position(|w| w == needle).map(|p| p + from) -} - -/// Embedded font programs of an EPS file: Type 1 fonts (`… /FontName /X … currentfile eexec -/// … cleartomark`, hexadecimal or binary) and CFF font sets (`… StartData `). -pub(super) fn embedded_fonts(ps: &[u8]) -> HashMap>, bool)> { - let mut out = HashMap::new(); - for font in craft_eps::embedded_font_programs(ps) { - let name = if font.cff { crate::cff::font_name(&font.program) } else { font.name }; - if let Some(name) = name { - out.insert(name, (Rc::new(font.program), font.cff)); - } - } - out -} - -#[cfg(test)] -mod tests { - use super::embedded_fonts; - - #[test] - fn font_discovery_looks_back_once_per_header() { - // 20,000 `eexec` words before any font header: each used to search the whole prefix - // for a header again. The font after them is still found. - let mut ps = b"%!PS-Adobe-3.0 EPSF-3.0\n".to_vec(); - ps.extend_from_slice("eexec ".repeat(20_000).as_bytes()); - ps.extend_from_slice(b"\n%!PS-AdobeFont-1.0: Real\n/FontName /Real def\ncurrentfile eexec\n0000\ncleartomark\n"); - let fonts = embedded_fonts(&ps); - assert_eq!(fonts.len(), 1); - assert!(fonts.contains_key("Real")); - } - - #[test] - fn header_less_font_after_a_short_one_does_not_take_its_header() { - let a = "%!PS-AdobeFont-1.0: A\n/FontName /A def\ncurrentfile eexec\n0000\ncleartomark\n"; - let b = "/FontName /B def\ncurrentfile eexec\n0000\ncleartomark\n"; - let ps = format!("%!PS-Adobe-3.0 EPSF-3.0\n{a}{b}"); - let fonts = embedded_fonts(ps.as_bytes()); - let (data, _) = fonts.get("B").expect("second font found"); - assert!(!String::from_utf8_lossy(data).contains("AdobeFont"), "{}", String::from_utf8_lossy(data)); - } -} diff --git a/crates/pdf/src/ps/exec.rs b/crates/pdf/src/ps/exec.rs deleted file mode 100644 index 233ff82b0..000000000 --- a/crates/pdf/src/ps/exec.rs +++ /dev/null @@ -1,182 +0,0 @@ -use super::eps::embedded_fonts; -use super::scanner::Src; -use super::value::{Flow, GState, V, new_dict}; -use super::{Affine, BezPath, Builder, Cap, HashMap, Interp, Join}; - -/// The deepest procedure nesting run (deeper recursion stops the program). -const MAX_CALL_DEPTH: usize = 256; - -/// The most values the operand stack holds: a push past it is dropped, and `copy` copies -/// nothing rather than grow the stack past it. -pub(super) const MAX_STACK: usize = 100_000; - -impl Interp { - pub fn new(page: [f64; 4]) -> Interp { - Interp { - b: Builder::new(), - st: vec![], - dicts: vec![new_dict()], - gs: GState { - ctm: Affine::IDENTITY, - color: [0.0; 3], - lw: 1.0, - cap: Cap::Butt, - join: Join::Miter, - miter: 10.0, - dash: None, - path: BezPath::new(), - cur: None, - start: None, - depth: 1, - font: None, - }, - saved: vec![], - budget: 8_000_000, - calls: 0, - font_dir: HashMap::new(), - embedded: HashMap::new(), - font_cache: HashMap::new(), - page, - unknown: vec![], - } - } - - pub fn run(&mut self, data: &[u8]) { - self.embedded = embedded_fonts(data); - let mut src = Src { d: data, pos: 0 }; - while let Some(t) = src.token(0) { - if let Err(Flow::Quit) = self.exec_token(t, &mut src) { - break; - } - } - } - - pub(super) fn pop(&mut self) -> V { - self.st.pop().unwrap_or(V::Null) - } - - pub(super) fn popn(&mut self) -> f64 { - self.pop().num().unwrap_or(0.0) - } - - pub(super) fn push(&mut self, v: V) { - if self.st.len() < MAX_STACK { - self.st.push(v); - } - } - - /// Count `n` units of work (values copied, storage allocated) against the budget without - /// stopping the program here: once it is spent, the next operator stops it. - pub(super) fn charge(&mut self, n: usize) { - self.budget = self.budget.saturating_sub(n); - } - - pub(super) fn lookup(&self, k: &str) -> Option { - self.dicts.iter().rev().find_map(|d| d.borrow().get(k).cloned()) - } - - /// A token read from the file: procedures are pushed, names executed. - fn exec_token(&mut self, t: V, src: &mut Src) -> Result<(), Flow> { - match t { - V::Name(n) => self.exec_name(&n, src), - other => { - self.push(other); - Ok(()) - } - } - } - - /// Execute a value as an object (procedures run). - pub(super) fn exec_obj(&mut self, v: V, src: &mut Src) -> Result<(), Flow> { - match v { - V::Proc(p) => { - if self.calls >= MAX_CALL_DEPTH { - self.b.skip("PostScript (recursion limit)"); - return Err(Flow::Quit); - } - self.calls += 1; - let mut r = Ok(()); - for x in p.iter() { - match x { - V::Name(n) => { - r = self.exec_name(n, src); - if r.is_err() { - break; - } - } - V::Op(op) => { - r = self.spend(1).and_then(|()| self.builtin(op, src)); - if r.is_err() { - break; - } - } - // Other items count against the budget as names do. - other => { - r = self.spend(1); - if r.is_err() { - break; - } - self.push(other.clone()); - } - } - } - self.calls -= 1; - r - } - // An executable name can run another (`exec` of `/exec cvx`), so names count too. - V::Name(n) => { - if self.calls >= MAX_CALL_DEPTH { - self.b.skip("PostScript (recursion limit)"); - return Err(Flow::Quit); - } - self.calls += 1; - let r = self.exec_name(&n, src); - self.calls -= 1; - r - } - V::Op(op) => { - self.spend(1)?; - self.builtin(&op, src) - } - other => { - self.push(other); - Ok(()) - } - } - } - - fn exec_name(&mut self, n: &str, src: &mut Src) -> Result<(), Flow> { - self.spend(1)?; - if let Some(v) = self.lookup(n) { - return match v { - V::Proc(_) => self.exec_obj(v, src), - // An operator stored under another name (`/mo /moveto load def`, as Illustrator's - // EPS prolog does for every path operator) runs that operator. It pushed the - // operator's name instead, so such files drew nothing (#955). - V::Op(op) => self.builtin(&op, src), - // An executable name (`/y /x cvx def`) runs what that name is bound to. - V::Name(_) => self.exec_obj(v, src), - other => { - self.push(other); - Ok(()) - } - }; - } - self.builtin(n, src) - } - - /// Count `n` operations against the budget, and stop the program when fewer are left. An - /// operator that makes, reads or copies path elements counts each one as an operation. - pub(super) fn spend(&mut self, n: usize) -> Result<(), Flow> { - match self.budget.checked_sub(n) { - Some(left) => { - self.budget = left; - Ok(()) - } - None => { - self.b.skip("PostScript (operation limit)"); - Err(Flow::Quit) - } - } - } -} diff --git a/crates/pdf/src/ps/paths.rs b/crates/pdf/src/ps/paths.rs deleted file mode 100644 index 30b5a7087..000000000 --- a/crates/pdf/src/ps/paths.rs +++ /dev/null @@ -1,187 +0,0 @@ -use super::value::{Flow, V}; -use super::{Affine, BezPath, FillRule, Interp, MAX_PATH, Paint, PathEl, Point, Stroke}; - -/// The angle from `a` counterclockwise to `b` (degrees, 0 to 360), worked out from what is left -/// of each after whole turns. -fn ccw_turn(a: f64, b: f64) -> f64 { - (b % 360.0 - a % 360.0).rem_euclid(360.0) -} - -/// The most turns one `arc` or `arcn` draws. -const MAX_ARC_TURNS: f64 = 1024.0; - -impl Interp { - fn device_scale(&self) -> f64 { - self.gs.ctm.determinant().abs().sqrt() - } - - pub(super) fn user_point(&mut self) -> Point { - let y = self.popn(); - let x = self.popn(); - Point::new(x, y) - } - - /// Stop the program when a path of `len` elements would be longer than [`MAX_PATH`]. - pub(super) fn path_fits(&mut self, len: usize) -> Result<(), Flow> { - if len <= MAX_PATH { - return Ok(()); - } - self.b.skip("PostScript (path limit)"); - Err(Flow::Quit) - } - - /// [`Self::path_fits`] for the current path with `n` more elements. - pub(super) fn room(&mut self, n: usize) -> Result<(), Flow> { - self.path_fits(self.gs.path.elements().len().saturating_add(n)) - } - - pub(super) fn move_to(&mut self, p: Point) -> Result<(), Flow> { - // A moveto right after a moveto replaces it (PostScript Language Reference §8.2, `moveto`). - if matches!(self.gs.path.elements().last(), Some(PathEl::MoveTo(_))) { - self.gs.path.pop(); - } - self.room(1)?; - let q = self.gs.ctm * p; - self.gs.path.move_to(q); - self.gs.cur = Some(q); - self.gs.start = Some(q); - Ok(()) - } - - pub(super) fn line_to(&mut self, p: Point) -> Result<(), Flow> { - self.room(1 + usize::from(self.gs.cur.is_none()))?; - let q = self.gs.ctm * p; - if self.gs.cur.is_none() { - self.gs.path.move_to(q); - self.gs.start = Some(q); - } - self.gs.path.line_to(q); - self.gs.cur = Some(q); - Ok(()) - } - - pub(super) fn curve_to(&mut self, a: Point, b: Point, c: Point) -> Result<(), Flow> { - self.room(1 + usize::from(self.gs.cur.is_none()))?; - let m = self.gs.ctm; - if self.gs.cur.is_none() { - self.gs.path.move_to(m * a); - } - self.gs.path.curve_to(m * a, m * b, m * c); - self.gs.cur = Some(m * c); - Ok(()) - } - - pub(super) fn current_user(&self) -> Point { - self.gs.ctm.inverse() * self.gs.cur.unwrap_or_default() - } - - pub(super) fn arc(&mut self, neg: bool) -> Result<(), Flow> { - let a2 = self.popn(); - let a1 = self.popn(); - let r = self.popn(); - let c = self.user_point(); - // `arc` raises `a2` by multiples of 360 until it is at least `a1`, and `arcn` lowers it - // until it is at most `a1` (PostScript Language Reference §8.2, `arc` and `arcn`). Those - // sweeps, and the first endpoint, are worked out from what is left of each angle after - // whole turns. - let sweep = if !neg && a2 < a1 { - ccw_turn(a1, a2) - } else if neg && a2 > a1 { - -ccw_turn(a2, a1) - } else { - a2 - a1 - }; - // A sweep of more than `MAX_ARC_TURNS` turns is shortened by whole pairs of turns to - // between `MAX_ARC_TURNS - 2` and `MAX_ARC_TURNS` turns, with a skip note. The arc still - // ends at `a2`, and an even-odd fill or clip of it covers the same area as the full sweep. - let max = MAX_ARC_TURNS * 360.0; - let sweep = if sweep.abs() > max { - self.b.skip("arc (too many turns)"); - let s = sweep.signum(); - s * (max - 720.0 + (s * (a2 % 720.0 - a1 % 720.0)).rem_euclid(720.0)) - } else { - sweep - }; - let (a1, sweep) = ((a1 % 360.0).to_radians(), sweep.to_radians()); - let start = Point::new(c.x + r * a1.cos(), c.y + r * a1.sin()); - if self.gs.cur.is_some() { - self.line_to(start)?; - } else { - self.move_to(start)?; - } - let arc = kurbo::Arc::new(c, (r, r), a1, sweep, 0.0); - let m = self.gs.ctm; - // kurbo divides an arc into more curves the larger the radius (about 3.7 × 10^49 for a - // quarter turn at a radius of 10^300, more than a usize can count), so each one counts - // against the budget and the path limit. - let mut curves = arc.append_iter(0.1); - while let Some(PathEl::CurveTo(p1, p2, p3)) = curves.next() { - self.room(1)?; - self.spend(1)?; - self.gs.path.curve_to(m * p1, m * p2, m * p3); - self.gs.cur = Some(m * p3); - } - Ok(()) - } - - pub(super) fn paint(&mut self, fill: Option, stroke: bool) { - let path = std::mem::take(&mut self.gs.path); - self.gs.cur = None; - self.gs.start = None; - let s = self.device_scale(); - let st = stroke.then(|| Stroke { - paint: Paint::Color(self.gs.color), - opacity: 1.0, - width: if self.gs.lw <= 0.0 { 1.0 } else { self.gs.lw * s }, - cap: self.gs.cap, - join: self.gs.join, - miter: self.gs.miter.max(1.0), - dash: self.gs.dash.as_ref().map(|(a, o)| (a.iter().map(|v| v * s).collect(), o * s)), - }); - self.b.fill_stroke(path, Affine::IDENTITY, fill.map(|r| (Paint::Color(self.gs.color), 1.0, r)), st); - } - - pub(super) fn rect_path(&mut self) -> Result, Flow> { - // x y w h, or an array / string of numbers. - let top = self.pop(); - let nums: Vec = match &top { - V::Array(_) | V::Proc(_) => { - let items = top.items().unwrap_or_default(); - // An array's rectangles count against the budget, five path elements each. - self.spend(items.len() / 4 * 5)?; - items.iter().filter_map(V::num).collect() - } - V::Num(h) => { - let w = self.popn(); - let y = self.popn(); - let x = self.popn(); - vec![x, y, w, *h] - } - _ => vec![], - }; - self.path_fits(nums.len() / 4 * 5)?; - let m = self.gs.ctm; - Ok(nums - .as_chunks::<4>() - .0 - .iter() - .map(|r| { - let mut p = BezPath::new(); - p.move_to(m * Point::new(r[0], r[1])); - p.line_to(m * Point::new(r[0] + r[2], r[1])); - p.line_to(m * Point::new(r[0] + r[2], r[1] + r[3])); - p.line_to(m * Point::new(r[0], r[1] + r[3])); - p.close_path(); - p - }) - .collect()) - } - - pub(super) fn grestore(&mut self) { - if let Some(g) = self.saved.pop() { - let d = g.depth; - self.gs = g; - self.b.close_to(d); - } - } -} diff --git a/crates/pdf/src/ps/scanner.rs b/crates/pdf/src/ps/scanner.rs deleted file mode 100644 index 59933e214..000000000 --- a/crates/pdf/src/ps/scanner.rs +++ /dev/null @@ -1,223 +0,0 @@ -use super::value::V; -use super::{Rc, RefCell, ascii85, is_white, parse_num}; - -/// Source tokenizer (the data source for `currentfile`). -pub(super) struct Src<'a> { - pub(super) d: &'a [u8], - pub(crate) pos: usize, -} - -impl Src<'_> { - fn skip_ws(&mut self) { - while self.pos < self.d.len() { - let c = self.d[self.pos]; - if is_white(c) { - self.pos += 1; - } else if c == b'%' { - let s = self.pos; - while self.pos < self.d.len() && !matches!(self.d[self.pos], b'\n' | b'\r') { - self.pos += 1; - } - // DSC: skip embedded binary / data sections. - let line = &self.d[s..self.pos]; - if line.starts_with(b"%%BeginData:") || line.starts_with(b"%%BeginBinary:") || line.starts_with(b"%%BeginPreview") { - let end: &[u8] = if line.starts_with(b"%%BeginData:") { - b"%%EndData" - } else if line.starts_with(b"%%BeginBinary:") { - b"%%EndBinary" - } else { - b"%%EndPreview" - }; - match self.d[self.pos..].windows(end.len()).position(|w| w == end) { - Some(p) => self.pos += p, - None => self.pos = self.d.len(), - } - } - } else { - break; - } - } - } - - fn word(&mut self) -> &[u8] { - let s = self.pos; - while self.pos < self.d.len() { - let c = self.d[self.pos]; - if is_white(c) || matches!(c, b'(' | b')' | b'<' | b'>' | b'[' | b']' | b'{' | b'}' | b'/' | b'%') { - break; - } - self.pos += 1; - } - &self.d[s..self.pos] - } - - /// The next token; `{ … }` comes back as a whole procedure. - pub(super) fn token(&mut self, depth: usize) -> Option { - self.skip_ws(); - let c = *self.d.get(self.pos)?; - Some(match c { - b'{' => { - self.pos += 1; - let mut body = vec![]; - loop { - self.skip_ws(); - match self.d.get(self.pos) { - None => break, - Some(b'}') => { - self.pos += 1; - break; - } - _ => { - if depth > 100 { - return None; - } - match self.token(depth + 1) { - Some(t) => body.push(t), - None => break, - } - } - } - } - V::Proc(Rc::new(body)) - } - b'}' => { - self.pos += 1; - V::Null - } - b'/' => { - self.pos += 1; - let imm = self.d.get(self.pos) == Some(&b'/'); - if imm { - self.pos += 1; - } - let w = String::from_utf8_lossy(self.word()).into_owned(); - // `//name` (immediately evaluated) is treated like a plain name. - if imm { V::Name(w.into()) } else { V::Lit(w.into()) } - } - b'(' => { - self.pos += 1; - let mut out = vec![]; - let mut depth = 1; - while self.pos < self.d.len() { - let c = self.d[self.pos]; - self.pos += 1; - match c { - b'\\' => { - let e = self.d.get(self.pos).copied().unwrap_or(b'\\'); - self.pos += 1; - match e { - b'n' => out.push(b'\n'), - b'r' => out.push(b'\r'), - b't' => out.push(b'\t'), - b'0'..=b'7' => { - let mut v = (e - b'0') as u32; - for _ in 0..2 { - match self.d.get(self.pos) { - Some(d @ b'0'..=b'7') => { - v = v * 8 + (d - b'0') as u32; - self.pos += 1; - } - _ => break, - } - } - out.push(v as u8); - } - b'\n' | b'\r' => {} - o => out.push(o), - } - } - b'(' => { - depth += 1; - out.push(c); - } - b')' => { - depth -= 1; - if depth == 0 { - break; - } - out.push(c); - } - _ => out.push(c), - } - } - V::Str(Rc::new(RefCell::new(out))) - } - b'<' if self.d.get(self.pos + 1) == Some(&b'<') => { - self.pos += 2; - V::Name("<<".into()) - } - b'>' if self.d.get(self.pos + 1) == Some(&b'>') => { - self.pos += 2; - V::Name(">>".into()) - } - b'<' if self.d.get(self.pos + 1) == Some(&b'~') => { - let s = self.pos; - while self.pos + 1 < self.d.len() && !(self.d[self.pos] == b'~' && self.d[self.pos + 1] == b'>') { - self.pos += 1; - } - self.pos = (self.pos + 2).min(self.d.len()); - V::Str(Rc::new(RefCell::new(ascii85(&self.d[s..self.pos])))) - } - b'<' => { - self.pos += 1; - let mut hex = vec![]; - while self.pos < self.d.len() && self.d[self.pos] != b'>' { - if self.d[self.pos].is_ascii_hexdigit() { - hex.push(self.d[self.pos]); - } - self.pos += 1; - } - self.pos += 1; - if hex.len() % 2 == 1 { - hex.push(b'0'); - } - let h = |c: u8| (c as char).to_digit(16).unwrap_or(0) as u8; - V::Str(Rc::new(RefCell::new(hex.chunks(2).map(|p| (h(p[0]) << 4) | h(p[1])).collect()))) - } - b'[' | b']' => { - self.pos += 1; - V::Name(if c == b'[' { "[" } else { "]" }.into()) - } - b')' | b'>' => { - self.pos += 1; - V::Null - } - _ => { - let w = self.word(); - if w.is_empty() { - self.pos += 1; - return Some(V::Null); - } - match parse_num(w) { - Some(n) => V::Num(n), - None => { - // Radix numbers (16#FF). - let s = String::from_utf8_lossy(w).into_owned(); - match s.split_once('#').and_then(|(r, v)| i64::from_str_radix(v, r.parse::().ok().filter(|r| (2..=36).contains(r))?).ok()) { - Some(n) => V::Num(n as f64), - None => V::Name(s.into()), - } - } - } - } - }) - } - - /// Step over inline image data that follows an `image` operator reading `currentfile`. - pub(super) fn skip_image_data(&mut self) { - self.skip_ws(); - if self.d[self.pos..].starts_with(b"<~") || self.d.get(self.pos).is_some_and(|c| (b'!'..=b'u').contains(c) && !c.is_ascii_hexdigit()) { - match self.d[self.pos..].windows(2).position(|w| w == b"~>") { - Some(p) => self.pos += p + 2, - None => self.pos = self.d.len(), - } - return; - } - while self.pos < self.d.len() && (self.d[self.pos].is_ascii_hexdigit() || is_white(self.d[self.pos])) { - self.pos += 1; - } - if self.d.get(self.pos) == Some(&b'>') { - self.pos += 1; - } - } -} diff --git a/crates/pdf/src/ps/text.rs b/crates/pdf/src/ps/text.rs deleted file mode 100644 index d4cee07f8..000000000 --- a/crates/pdf/src/ps/text.rs +++ /dev/null @@ -1,329 +0,0 @@ -use super::scanner::Src; -use super::value::{DictRef, Flow, V, array, matrix_of, matrix_val, new_dict}; -use super::{Affine, BezPath, FillRule, Font, HashMap, Interp, Paint, Point, Rc, RefCell}; - -// ------------------------------------------------------------------ text - -/// An encoding array of glyph names (`StandardEncoding`; `ISOLatin1Encoding` and others are -/// approximated by WinAnsi, which agrees with ISO Latin-1 on the printable codes). -pub(super) fn encoding_array(name: &str) -> V { - let base = if name == "StandardEncoding" { crate::encoding::Base::Standard } else { crate::encoding::Base::WinAnsi }; - array((0..256).map(|c| V::Lit(base.name(c as u8).unwrap_or_else(|| ".notdef".into()).into())).collect()) -} - -fn dict_matrix(d: &DictRef, key: &str) -> Affine { - d.borrow().get(key).and_then(matrix_of).unwrap_or(Affine::IDENTITY) -} - -/// A copy of a font dictionary with `m` applied after its matrix (`scalefont`, `makefont`). -fn transformed(font: &DictRef, m: Affine) -> DictRef { - let copy: HashMap = font.borrow().clone(); - let d = Rc::new(RefCell::new(copy)); - let old = dict_matrix(&d, "__m"); - d.borrow_mut().insert("__m".into(), matrix_val(m * old)); - d -} - -impl Interp { - /// A font dictionary by name: one `definefont` made, else a new dictionary for an - /// embedded program or a bundled stand-in. - pub(super) fn find_font(&mut self, key: &str) -> DictRef { - if let Some(d) = self.font_dir.get(key) { - return d.clone(); - } - let d = new_dict(); - { - let mut m = d.borrow_mut(); - m.insert("FontName".into(), V::Lit(key.into())); - m.insert("FontType".into(), V::Num(1.0)); - m.insert("FontMatrix".into(), matrix_val(Affine::scale(0.001))); - m.insert("FID".into(), V::Null); - m.insert("__base".into(), V::Lit(key.into())); - m.insert("__m".into(), matrix_val(Affine::IDENTITY)); - } - self.font_dir.insert(key.to_string(), d.clone()); - d - } - - /// The drawable font of a font dictionary (its base program and encoding) and the matrix - /// from text space (font size 1) to user space. - fn font_of(&mut self, d: &DictRef) -> Option<(Rc, Affine)> { - if matches!(d.borrow().get("FontType"), Some(V::Num(t)) if *t == 3.0) { - // Type 3 fonts (glyph procedures) are not run. - self.b.skip("EPS Type 3 font"); - return None; - } - let (base, names) = { - let m = d.borrow(); - let base = m.get("__base").or_else(|| m.get("FontName")).map(V::key)?; - let names: Option>> = m.get("Encoding").and_then(V::items).map(|a| { - a.iter() - .map(|v| match v { - V::Lit(n) | V::Name(n) if &**n != ".notdef" => Some(n.to_string()), - _ => None, - }) - .collect() - }); - (base, names) - }; - let key = match &names { - Some(n) => format!("{base}\u{0}{}", n.iter().map(|x| x.as_deref().unwrap_or("")).collect::>().join(" ")), - None => base.clone(), - }; - let font = match self.font_cache.get(&key) { - Some(f) => f.clone(), - None => { - // Not embedded: a bundled stand-in, as for PDF. - let prog = self.embedded.get(&base).cloned(); - let f = Rc::new(Font::standalone(&base, prog.as_ref().map(|(d, cff)| (d.as_slice(), *cff)), names)); - self.font_cache.insert(key, f.clone()); - f - } - }; - Some((font, dict_matrix(d, "__m"))) - } - - /// A string's glyph outlines (device space) from the current point, with an extra - /// displacement `extra(index, code)` (user space) after each glyph; moves the current - /// point. - fn text_path(&mut self, bytes: &[u8], mut extra: impl FnMut(usize, u32) -> (f64, f64)) -> Result, Flow> { - let Some(d) = self.gs.font.clone() else { return Ok(None) }; - let Some((font, m)) = self.font_of(&d) else { return Ok(None) }; - let mut p = self.current_user(); - let mut path = BezPath::new(); - let mut text = String::new(); - let ctm = self.gs.ctm; - for (i, &code) in bytes.iter().enumerate() { - let code = code as u32; - // Every input character costs at least one unit, so empty outlines are not free. - self.spend(1)?; - if let Some(g) = font.glyph(code) { - // Each outline element counts against the path limit and the budget before it - // is copied, so a long string cannot expand into unbounded geometry. - let n = g.elements().len(); - self.path_fits(path.elements().len().saturating_add(n))?; - self.spend(n)?; - path.extend(ctm * Affine::translate(p.to_vec2()) * m * (*g).clone()); - } - text.push_str(&font.unicode(code)); - let adv = m * Point::new(font.width(code), 0.0) - m * Point::ZERO; - let (ex, ey) = extra(i, code); - p += adv + kurbo::Vec2::new(ex, ey); - } - self.move_to(p)?; - Ok(Some((path, text))) - } - - fn fill_text(&mut self, path: BezPath, text: &str) { - let label: String = text.chars().filter(|c| !c.is_control()).take(40).collect(); - let name = if label.trim().is_empty() { "Text".to_string() } else { format!("Text: {}", label.trim()) }; - self.b.fill_stroke_named(&name, path, Affine::IDENTITY, Some((Paint::Color(self.gs.color), 1.0, FillRule::NonZero)), None); - } - - fn pop_string(&mut self) -> Vec { - match self.pop() { - V::Str(s) => s.borrow().clone(), - _ => vec![], - } - } - - fn show_with(&mut self, s: &[u8], extra: impl FnMut(usize, u32) -> (f64, f64)) -> Result<(), Flow> { - match self.text_path(s, extra)? { - Some((path, text)) => self.fill_text(path, &text), - None => self.b.skip("text (no font)"), - } - Ok(()) - } - - /// Text and font operators (PostScript Language Reference §5.1, §8.2). - pub(super) fn text_op(&mut self, n: &str, src: &mut Src) -> Result<(), Flow> { - match n { - "scalefont" | "makefont" => { - let m = if n == "scalefont" { - Affine::scale(self.popn()) - } else { - let v = self.pop(); - matrix_of(&v).unwrap_or(Affine::IDENTITY) - }; - let font = match self.pop() { - V::Dict(d) => d, - _ => self.find_font("Helvetica"), - }; - self.push(V::Dict(transformed(&font, m))); - } - "selectfont" => { - let size = self.pop(); - let key = self.pop().key(); - let font = self.find_font(&key); - let m = match &size { - V::Num(s) => Affine::scale(*s), - other => matrix_of(other).unwrap_or(Affine::IDENTITY), - }; - self.gs.font = Some(transformed(&font, m)); - } - "setfont" => { - if let V::Dict(d) = self.pop() { - self.gs.font = Some(d); - } - } - "currentfont" | "rootfont" => { - let d = self.gs.font.clone().unwrap_or_else(new_dict); - self.push(V::Dict(d)); - } - "definefont" => { - let v = self.pop(); - let key = self.pop().key(); - if let V::Dict(d) = &v { - if !d.borrow().contains_key("__base") { - // A font the file defines itself: its embedded program, by name. - d.borrow_mut().insert("__base".into(), V::Lit(key.as_str().into())); - d.borrow_mut().insert("__m".into(), matrix_val(Affine::IDENTITY)); - } - self.font_dir.insert(key, d.clone()); - } - self.push(v); - } - "undefinefont" => { - let key = self.pop().key(); - self.font_dir.remove(&key); - } - "StandardEncoding" | "ISOLatin1Encoding" => self.push(encoding_array(n)), - "show" => { - let s = self.pop_string(); - self.show_with(&s, |_, _| (0.0, 0.0))?; - } - "ashow" => { - let s = self.pop_string(); - let ay = self.popn(); - let ax = self.popn(); - self.show_with(&s, |_, _| (ax, ay))?; - } - "widthshow" => { - let s = self.pop_string(); - let ch = self.popn() as u32; - let cy = self.popn(); - let cx = self.popn(); - self.show_with(&s, |_, c| if c == ch { (cx, cy) } else { (0.0, 0.0) })?; - } - "awidthshow" => { - let s = self.pop_string(); - let ay = self.popn(); - let ax = self.popn(); - let ch = self.popn() as u32; - let cy = self.popn(); - let cx = self.popn(); - self.show_with(&s, |_, c| if c == ch { (cx + ax, cy + ay) } else { (ax, ay) })?; - } - "kshow" | "cshow" => { - // The procedure between characters is not run. - let s = self.pop_string(); - self.pop(); - self.show_with(&s, |_, _| (0.0, 0.0))?; - } - "xshow" | "yshow" | "xyshow" => { - let disp: Vec = self.pop().items().unwrap_or_default().iter().filter_map(V::num).collect(); - let s = self.pop_string(); - self.explicit_show(&s, &disp, n)?; - } - "glyphshow" => { - let name = self.pop().key(); - let Some(d) = self.gs.font.clone() else { return Ok(()) }; - // Drawn through a one-glyph encoding. - let mut e: Vec = (0..256).map(|_| V::Lit(".notdef".into())).collect(); - e[65] = V::Lit(name.as_str().into()); - let tmp = transformed(&d, Affine::IDENTITY); - tmp.borrow_mut().insert("Encoding".into(), array(e)); - self.gs.font = Some(tmp); - self.show_with(b"A", |_, _| (0.0, 0.0))?; - self.gs.font = Some(d); - } - "charpath" => { - self.pop(); - let s = self.pop_string(); - let saved = std::mem::take(&mut self.gs.path); - let start = self.gs.start; - match self.text_path(&s, |_, _| (0.0, 0.0))? { - Some((glyphs, _)) => { - // The outlines join the path: each element counts against the budget and - // the path limit. - self.gs.path = saved; - self.room(glyphs.elements().len() + 1)?; - self.spend(glyphs.elements().len())?; - self.gs.path.extend(glyphs); - if let Some(c) = self.gs.cur { - self.gs.path.move_to(c); - } - self.gs.start = start; - } - None => self.gs.path = saved, - } - } - "stringwidth" => { - let s = self.pop_string(); - let (mut w, mut h) = (0.0, 0.0); - if let Some(d) = self.gs.font.clone() - && let Some((font, m)) = self.font_of(&d) - { - for &c in &s { - let v = m * Point::new(font.width(c as u32), 0.0) - m * Point::ZERO; - w += v.x; - h += v.y; - } - } - self.push(V::Num(w)); - self.push(V::Num(h)); - } - "setcachedevice" => { - for _ in 0..6 { - self.pop(); - } - } - "setcharwidth" => { - self.pop(); - self.pop(); - } - // An embedded Type 1 program's encrypted part (read by `embedded_fonts`). - "eexec" => { - if matches!(self.pop(), V::File) { - let rest = &src.d[src.pos.min(src.d.len())..]; - src.pos += rest.windows(11).position(|w| w == b"cleartomark").map_or(rest.len(), |p| p + 11); - } - } - // A CFF font set's binary data (read by `embedded_fonts`). - "StartData" => { - let len = self.popn().max(0.0) as usize; - self.pop(); - src.pos = src.pos.saturating_add(1).saturating_add(len).min(src.d.len()); - } - _ => {} - } - Ok(()) - } - - /// `xshow` / `yshow` / `xyshow`: glyph displacements from a number array instead of the - /// advances. - fn explicit_show(&mut self, s: &[u8], disp: &[f64], n: &str) -> Result<(), Flow> { - let step = if n == "xyshow" { 2 } else { 1 }; - let d: Vec<(f64, f64)> = (0..s.len()) - .map(|k| { - let i = k * step; - let v = |j: usize| disp.get(j).copied().unwrap_or(0.0); - match n { - "xshow" => (v(i), 0.0), - "yshow" => (0.0, v(i)), - _ => (v(i), v(i + 1)), - } - }) - .collect(); - let Some(fd) = self.gs.font.clone() else { - self.b.skip("text (no font)"); - return Ok(()); - }; - let Some((font, m)) = self.font_of(&fd) else { return Ok(()) }; - self.show_with(s, move |k, c| { - let adv = m * Point::new(font.width(c), 0.0) - m * Point::ZERO; - let (dx, dy) = d.get(k).copied().unwrap_or((0.0, 0.0)); - (dx - adv.x, dy - adv.y) - }) - } -} diff --git a/crates/pdf/src/ps/value.rs b/crates/pdf/src/ps/value.rs deleted file mode 100644 index 3cfafed6e..000000000 --- a/crates/pdf/src/ps/value.rs +++ /dev/null @@ -1,88 +0,0 @@ -use super::{Affine, BezPath, Cap, HashMap, Join, Point, Rc, RefCell}; - -pub(crate) type DictRef = Rc>>; - -#[derive(Clone)] -pub(crate) enum V { - Num(f64), - Bool(bool), - /// An executable name. - Name(Rc), - /// A literal name (`/name`). - Lit(Rc), - /// A built-in operator, as `load` returns it for a name no dictionary defines. - Op(Rc), - Str(Rc>>), - Proc(Rc>), - Array(Rc>>), - Dict(DictRef), - Mark, - Null, - /// `currentfile`. - File, -} - -impl V { - pub(super) fn num(&self) -> Option { - match self { - V::Num(n) => Some(*n), - _ => None, - } - } - pub(super) fn key(&self) -> String { - match self { - V::Name(n) | V::Lit(n) | V::Op(n) => n.to_string(), - V::Str(s) => String::from_utf8_lossy(&s.borrow()).into_owned(), - V::Num(n) => format!("{n}"), - V::Bool(b) => format!("{b}"), - _ => String::new(), - } - } - pub(super) fn items(&self) -> Option> { - match self { - V::Array(a) => Some(a.borrow().clone()), - V::Proc(p) => Some(p.as_ref().clone()), - _ => None, - } - } -} - -pub(super) enum Flow { - Exit, - Stop, - Quit, -} - -#[derive(Clone)] -pub(super) struct GState { - pub(crate) ctm: Affine, - pub(crate) color: [f64; 3], - pub(crate) lw: f64, - pub(crate) cap: Cap, - pub(crate) join: Join, - pub(crate) miter: f64, - pub(crate) dash: Option<(Vec, f64)>, - pub(crate) path: BezPath, - pub(crate) cur: Option, - pub(crate) start: Option, - pub(crate) depth: usize, - /// The current font dictionary. - pub(crate) font: Option, -} - -pub(super) fn new_dict() -> DictRef { - Rc::new(RefCell::new(HashMap::new())) -} - -pub(super) fn array(v: Vec) -> V { - V::Array(Rc::new(RefCell::new(v))) -} - -pub(super) fn matrix_of(v: &V) -> Option { - let a: Vec = v.items()?.iter().filter_map(V::num).collect(); - (a.len() == 6).then(|| Affine::new([a[0], a[1], a[2], a[3], a[4], a[5]])) -} - -pub(super) fn matrix_val(m: Affine) -> V { - array(m.as_coeffs().iter().map(|c| V::Num(*c)).collect()) -} diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index b4b04d2ac..7bf7d9890 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -82,6 +82,21 @@ fn pdf_paths_clip_gradient_and_layers() { } } +#[test] +fn pdf_actual_text_is_exposed_as_a_logical_group() { + let content = "/Span << /ActualText (Logical text) >> BDC\n1 0 0 rg 10 10 20 20 re f\nEMC"; + let objs = vec![ + (1, "<< /Type /Catalog /Pages 2 0 R >>".to_string(), None), + (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".to_string(), None), + (3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 100 100] /Resources << >> /Contents 4 0 R >>".to_string(), None), + (4, "<< >>".to_string(), Some(content.as_bytes().to_vec())), + ]; + + let doc = parse(&pdf(&objs, 1)).unwrap(); + + assert_eq!(shape_names(&doc), vec!["Text: Logical text"]); +} + #[test] fn pdf_forms_rotation_cmyk_and_alpha() { let content = "q 2 0 0 2 0 0 cm /Fm0 Do Q\n/GS0 gs 0 0 0 1 k 0 0 10 10 re f\n"; @@ -231,6 +246,12 @@ fn eps_postscript_subset() { assert_eq!(parse(b"hello"), Err(Error::NotVector)); } +#[test] +fn eps_without_a_bounding_box_keeps_the_public_error_variant() { + let eps = b"%!PS-Adobe-3.0 EPSF-3.0\n%%EndComments\n0 0 10 10 rectfill\n"; + assert_eq!(parse(eps), Err(Error::NoBoundingBox)); +} + #[test] fn filters_decode() { assert_eq!(object::ascii85(b"<~87cURD]i,\"Ebo80~>"), b"Hello World!".to_vec()); @@ -450,6 +471,9 @@ pub(crate) fn shape_names(doc: &Doc) -> Vec { fn walk(g: &effectcraft_svg::Group, out: &mut Vec) { for c in &g.children { match c { + // Marked text from the shared PostScript adapter is a logical text object whose + // outlined glyph paths remain children for rendering and editing. + Node::Group(s) if s.name.starts_with("Text: ") => out.push(s.name.clone()), Node::Group(s) => walk(s, out), Node::Shape(s) => out.push(s.name.clone()), Node::Image(i) => out.push(i.name.clone()), diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index 32541b038..782eedab3 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,8 +5,9 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "2fea4b4ce28678e30bd546885a323aaa8fa243ef"; -const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; +const REV: &str = "41fb227542efb8a7748caa1c659f271d8605303c"; +const PACKAGES: &[(&str, &str)] = + &[("craft-pdf", "0.1.0"), ("craft-ps", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { let output = Command::new(std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into())) @@ -33,7 +34,7 @@ fn validate(metadata: &Value) -> Result<(), String> { return Err(format!("{name}: expected exactly {version} from {source}")); } } - for (name, allowed) in [("craft-pdf", "read"), ("hayro-syntax", "std")] { + for (name, allowed) in [("craft-pdf", "read"), ("craft-ps", "read"), ("hayro-syntax", "std")] { let package = packages.iter().find(|p| p["name"] == name).ok_or_else(|| format!("missing {name}"))?; let node = nodes.iter().find(|n| n["id"] == package["id"]).ok_or_else(|| format!("{name}: missing resolved node"))?; let features = node["features"].as_array().ok_or_else(|| format!("{name}: missing resolved features"))?; @@ -61,7 +62,8 @@ mod tests { json!({"id": name, "name": name, "version": version, "source": format!("git+https://github.com/storytold/craft-libs?rev={REV}#{REV}")}) }).collect(); json!({"packages": packages, "resolve": {"nodes": [ - {"id": "hayro-syntax", "features": ["std"]}, {"id": "craft-pdf", "features": ["read"]} + {"id": "hayro-syntax", "features": ["std"]}, {"id": "craft-pdf", "features": ["read"]}, + {"id": "craft-ps", "features": ["read"]} ]}}) } From 02e304a19b0d93762ca94ca17311b5a65276fe25 Mon Sep 17 00:00:00 2001 From: Zinadin Zidan Date: Sat, 14 Nov 2026 22:18:48 +0600 Subject: [PATCH 43/99] Angles: typing into a negative angle's degrees replaces its minus sign (#3367) The degrees field of an angle (Rotation, an effect's angle) showed the remainder's size, with the minus sign painted beside it, and a typed number was taken as a size that kept the sign: 50 typed into 0x-20.0 gave -50. The minus sign is now part of the degrees' text, so it is selected with the rest when typing starts, and a typed number is the new remainder with its sign: 50 gives +50, -50 gives -50. A positive remainder still shows its + beside the field. Fixes #3367 --- crates/ui-egui/src/panels/fx_widgets.rs | 26 +++++++++++++------------ crates/ui-egui/tests/it/ui_angles.rs | 22 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/panels/fx_widgets.rs b/crates/ui-egui/src/panels/fx_widgets.rs index b3140d394..f9ef8e6b2 100644 --- a/crates/ui-egui/src/panels/fx_widgets.rs +++ b/crates/ui-egui/src/panels/fx_widgets.rs @@ -41,15 +41,15 @@ pub fn parse_angle(s: &str) -> Option { s.parse().ok() } -/// The angle after the degrees field of `v` (which shows `shown`, the remainder's size) went to +/// The angle after the degrees field of `v` (which shows `shown`, the signed remainder) went to /// `new`. A drag moves the angle by the pointer's distance, so it runs through zero into negative -/// angles; a typed number is a size, so the remainder keeps its sign. +/// angles; a typed number is the new remainder, its sign included (#3367). fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 { if dragging { return v + (new - shown); } - let (rev, deg) = split_angle(v); - rev as f64 * 360.0 + if deg < 0.0 || (deg == 0.0 && v < 0.0) { -new } else { new } + let (rev, _) = split_angle(v); + rev as f64 * 360.0 + new } /// An angle value, `0x+45.0°`, at `at` (top left): the revolutions and the degrees @@ -58,13 +58,14 @@ fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 { pub fn angle_field(ui: &mut egui::Ui, at: Pos2, id: egui::Id, v: f64, decimals: usize, t: &Tokens) -> (Rect, Rect, Option) { let (rev, deg) = split_angle(v); let (rr, new_rev, _) = widgets::hot_int_at(ui, at, id.with("rev"), rev, 0.1, "x", t); - let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "-" } else { "+" }, Tokens::ui(12.0), t.hot_text); + // A negative remainder's minus sign is part of the degrees' text, so typing replaces it (#3367). + let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "" } else { "+" }, Tokens::ui(12.0), t.hot_text); let (dr, new_deg, _) = - widgets::hot_number_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg.abs(), &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t); + widgets::hot_number_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg, &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t); let dragging = new_deg.is_some() && ui.ctx().is_being_dragged(id); let out = match (new_rev, new_deg) { (Some(r), _) => Some(r as f64 * 360.0 + deg), - (None, Some(d)) => Some(degrees_edit(v, deg.abs(), d, dragging)), + (None, Some(d)) => Some(degrees_edit(v, deg, d, dragging)), (None, None) => None, }; (rr, dr, out) @@ -624,18 +625,19 @@ mod tests { #[test] fn dragging_degrees_crosses_zero_into_negative_angles() { - // The field shows the size (0.3), so a 1-degree drag left lands on -0.7, and keeps going. + // A 1-degree drag left from 0.3 lands on -0.7, and keeps going. let mut v = 0.3; for _ in 0..3 { let (_, deg) = split_angle(v); - v = degrees_edit(v, deg.abs(), deg.abs() - 1.0, true); + v = degrees_edit(v, deg, deg - 1.0, true); } assert!((v + 2.7).abs() < 1e-9, "{v}"); // And back up through zero. let (_, deg) = split_angle(v); - assert!((degrees_edit(v, deg.abs(), deg.abs() + 3.0, true) - 0.3).abs() < 1e-9); - // Typing keeps the sign shown. - assert_eq!(degrees_edit(-30.0, 30.0, 45.0, false), -45.0); + assert!((degrees_edit(v, deg, deg + 3.0, true) - 0.3).abs() < 1e-9); + // A typed number is the remainder with its sign; the revolutions stay (#3367). + assert_eq!(degrees_edit(-30.0, -30.0, 45.0, false), 45.0); + assert_eq!(degrees_edit(-30.0, -30.0, -45.0, false), -45.0); assert_eq!(degrees_edit(405.0, 45.0, 10.0, false), 370.0); } diff --git a/crates/ui-egui/tests/it/ui_angles.rs b/crates/ui-egui/tests/it/ui_angles.rs index 40ad17bc1..c98dfa9ff 100644 --- a/crates/ui-egui/tests/it/ui_angles.rs +++ b/crates/ui-egui/tests/it/ui_angles.rs @@ -191,3 +191,25 @@ fn commit_edits(click_away: bool) { } } } + +/// #3367: on a negative angle the minus sign is part of the degrees typing replaces, so typing +/// 50 into `0x-20.0°` sets +50°. It used to keep the sign (-50°). Committing the text as it +/// opened keeps the angle. +#[test] +fn typing_into_a_negative_angle_replaces_its_sign() { + for panel in [Panel::EffectControls, Panel::Timeline, Panel::Properties] { + for (start, text, expected) in + [(-20.0, Some("50"), 50.0), (-20.0, Some("-50"), -50.0), (-20.0, None, -20.0), (-400.0, None, -400.0), (45.0, Some("-30"), -30.0)] + { + let (mut h, layer, uid) = harness(panel, start); + let p = component(&h, panel, uid, false); + click(&mut h, p); + if let Some(text) = text { + h.input_mut().events.push(Event::Text(text.into())); + h.step(); + } + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(angle(&h, layer, uid), expected, "{panel:?}: {start} then {text:?}"); + } + } +} From a4bd8858af18f91448e3d814a018823125c94192 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 16:21:01 +0000 Subject: [PATCH 44/99] style: format shared PDF dependency validator --- xtask/src/pdf_deps.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index 782eedab3..0fb1cd327 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -6,8 +6,7 @@ use std::process::Command; use serde_json::Value; const REV: &str = "41fb227542efb8a7748caa1c659f271d8605303c"; -const PACKAGES: &[(&str, &str)] = - &[("craft-pdf", "0.1.0"), ("craft-ps", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; +const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("craft-ps", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { let output = Command::new(std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into())) From 3bc37b0b8b22d1c1b5bcc45f3f71c118eb3111e7 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 19:18:24 +0100 Subject: [PATCH 45/99] Drop the duplicate expression_toggled that the merge brought in from main --- crates/ui-egui/src/panels/timeline.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index af7254e5e..dd92ef941 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -4298,19 +4298,6 @@ fn prop_context_menu( } } -/// An expression was just added to `prop` (it had none) or removed: adding one opens its -/// editor, which comes into view and takes the keyboard with the new expression selected -/// (#1072); removing it leaves nothing to take the keyboard. -fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) { - let uid = prop.uid; - if prop.expr.is_none() { - app.ui.timeline.expr_closed.remove(&uid); - focus_expression(ctx, uid, [usize::MAX, 0]); - } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == uid) { - ctx.data_mut(|d| d.remove::(expr_focus_id())); - } -} - /// The value editors and the property pick whip. fn prop_value_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, ectx: &EvalCtx<'_>, prop: &Property, name_x: f32) { let vis = g.tl.vis; From c1f3a03a9d0aa0591cd52979c29b8ff65235719e Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 46/99] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From 2780a503029349a721d85acf0decea93f20a4d21 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 47/99] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From 0a3d74fb5474e599e63908914d39fcd0e22c8e61 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 48/99] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From cf94d1a9809b96d4eede176733f85e4a234a46fd Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 49/99] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From dd3c6e968da0920d36f2e5bb5aa35b30076c754c Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 20:00:53 +0000 Subject: [PATCH 50/99] test(ui): serialize GPU picker integration --- crates/ui-egui/tests/it/ui_crypto_pick.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/tests/it/ui_crypto_pick.rs b/crates/ui-egui/tests/it/ui_crypto_pick.rs index 03e49ca18..d863e73f7 100644 --- a/crates/ui-egui/tests/it/ui_crypto_pick.rs +++ b/crates/ui-egui/tests/it/ui_crypto_pick.rs @@ -632,6 +632,7 @@ fn clicks_wait_for_the_probe_and_edits_popups_dialogs_and_comp_switches_end_or_b /// each Resolution. Skips without a GPU adapter. #[test] fn picks_on_the_gpu_viewer() { + let _gpu = crate::gpu_test::lock(); let Some(probe) = effectcraft_gpu::Gpu::headless() else { eprintln!("no GPU adapter: skipping"); return; From 4e8cd4638b22221cfda8626e09804b9de16ffbb7 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 00:34:59 +0000 Subject: [PATCH 51/99] ci: serialize one-shard Sonar coverage tests --- .github/workflows/sonarcloud.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 7d193b610..1bc7c9f8b 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -17,11 +17,12 @@ concurrency: jobs: sonarcloud: # Track shared CI improvements on main. - uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main + uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@72d2fbfb3dd1bf27e1bdc7107be72c70749c6876 with: timeout-minutes: 120 # GPU tests share a process-local lock; separate coverage shards create independent # software Vulkan devices, bypassing that lock and potentially contending on llvmpipe. shards: 1 + rust-test-threads: "1" fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 secrets: inherit From df79630f6f2e00d099c07def39b0230cb759e328 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 01:36:12 +0000 Subject: [PATCH 52/99] ci: use merged test thread limit for Sonar coverage --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 1bc7c9f8b..6adc57765 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -17,7 +17,7 @@ concurrency: jobs: sonarcloud: # Track shared CI improvements on main. - uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@72d2fbfb3dd1bf27e1bdc7107be72c70749c6876 + uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main with: timeout-minutes: 120 # GPU tests share a process-local lock; separate coverage shards create independent From 3a2a564b4bba88c85b5c0ddf5bf1b9936f98ac58 Mon Sep 17 00:00:00 2001 From: Madhav Agarwal Date: Sun, 15 Nov 2026 09:08:04 +0530 Subject: [PATCH 53/99] docs: bring ROADMAP.md current through 2026-11-15 --- ROADMAP.md | 1 + docs/target-app-parity.md | 1 + 2 files changed, 2 insertions(+) diff --git a/ROADMAP.md b/ROADMAP.md index 656487144..88fa7335e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,6 +2,7 @@ **Stage: alpha** · next: beta, ~30 points of "ready for real work" and ~350–620 h away +> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (releases v0.22.0 through v0.24.1; .aep gained project export (#2594), drag-and-drop import (#3103), an audit of hostile inputs with every loss reported (#3299, #3300, #3319, #3365), placeholders for unmapped effects (#3087), Lumetri Color, Puppet, CC Color Neutralizer, EXtractoR/IDentifier, HDR Highlight Compression, Echo, Linear Wipe, Offset and Color Stabilizer mappings, text-animator and Source Text expressions (#3170) and twice the import speed (#3302); GPU rendering 2.6× faster with one upload per frame and single-copy readback (#3335), smooth preview lanes (#3345), bounded GPU memory (#3028), shared multi-layer EXR decode (#474), EXR output options (#2915, #2916) and a WebAssembly ABI 2 plug-in path (#3329); eighteen effect parameters now take After Effects' ranges (#3470–#3480, #3483–#3484, #3487–#3491), with Color Stabilizer sampling (#3125), masked Grid/Checkerboard/Circle (#3121), Cryptomatte selection and Matte Only (#2839, #3130), fast-conformed frame blending (#3180) and bounded Levels and time-stretch math; number-field arithmetic (#3195), expressionError (#3219), prop.get with footage (#3231), reversed-layer audio (#3239), keyframed audio waveforms (#1722), Effect Controls lock and rename selection (#3193, #3198), viewer snapping (#2681, #3229), Graph Editor theming (#3202), Convert To Bezier Path (#3237), stopwatch Add Expression (#3192), Shift-drag timeline snapping (#1828), anchored marquee (#2859), Go to Time (#3373), text layers whose names follow their text (#3233), mute-aware audio preview (#2104), ScriptUI panel bars (#2796), Closed-path and Effect Controls arrow fixes (#2817, #2869) and accessible Info, Flowchart, Script Console and 3D Camera Tracker blocks (#1341); a file-dialog crash fix (#3084), crash diagnostics and replayable repros (#3357, #1224), Flatpak updater and nightly release fixes (#3516, #3520), craft-libs format and update cutovers, and CI test stabilisation (#3650, #3689, #3704); readiness estimates unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) > **Last reviewed:** 2026-10-22 · **Last updated:** 2026-11-05 · **Change:** minor (ProRes alpha final-run conformance; previously: features of 30 October in the progress log: text Line Join, Timeline drag-reorder and multi-select of effects, viewer edge pan, ScriptUI drag capture and dock size; previously: localization recount after #1774) · **Target:** Adobe After Effects 2026 (26.5.0.89) EffectCraft aims to do what After Effects does, with the same panels, menus and behaviour, written diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 247887345..09f9df6bc 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1,5 +1,6 @@ # Parity with After Effects +> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (ROADMAP sync over 5–15 November: .aep export, drag-and-drop import, hostile-input audit and loss reporting, effect placeholders and mappings, 2.6× GPU rendering, EXR output options, eighteen aligned effect ranges and a broad editor/expression fix batch; releases v0.22.0–v0.24.1. No parity numbers re-measured; the 10 October re-measure and all readiness estimates are unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) > **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-12 · **Change:** minor (issue, catalog and export-format references re-audited against `upstream/main` 470ea7a3; the 10 October re-measure is otherwise unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) The authoritative assessment of how close EffectCraft is to After Effects, and how much work is From 26fa70007a470cd6ac93f1bdfdc773e8226bb424 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 09:21:33 +0000 Subject: [PATCH 54/99] fix(gpu): serialize readback mapping cleanup --- crates/gpu/src/context.rs | 44 ++++++++++---- crates/gpu/src/readback.rs | 120 +++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 13 deletions(-) diff --git a/crates/gpu/src/context.rs b/crates/gpu/src/context.rs index d074fe213..cce00bc7f 100644 --- a/crates/gpu/src/context.rs +++ b/crates/gpu/src/context.rs @@ -1207,17 +1207,25 @@ impl GpuContext { if !ticket.active() { return; } + let mapping = Arc::new(crate::readback::Mapping::new()); let b = buffer.clone(); + let callback_mapping = Arc::clone(&mapping); buffer.map_async(wgpu::MapMode::Read, .., move |r| { - if !ticket.active() { - b.unmap(); + if let Err(e) = r { + callback_mapping.failed(); + ticket.complete(Err(format!("GPU buffer mapping: {e}"))); return; } - let result = r.map_err(|e| format!("GPU buffer mapping: {e}")).and_then(|_| { - let view = b.get_mapped_range(..).map_err(|e| format!("GPU mapped range: {e}"))?; - crate::readback::packed(&view, row, stride, height) - }); - b.unmap(); + if !callback_mapping.mapped() { + return; + } + if !ticket.active() { + callback_mapping.unmap(|| b.unmap()); + return; + } + let result = + b.get_mapped_range(..).map_err(|e| format!("GPU mapped range: {e}")).and_then(|view| crate::readback::packed(&view, row, stride, height)); + callback_mapping.unmap(|| b.unmap()); ticket.complete(result); }); } @@ -1264,20 +1272,30 @@ impl GpuContext { if !ticket.active() { return Err("GPU readback cancelled".into()); } + let mapping = Arc::new(crate::readback::Mapping::new()); let b = buffer.clone(); + let callback_mapping = Arc::clone(&mapping); buffer.map_async(wgpu::MapMode::Read, .., move |r| { + if let Err(e) = r { + callback_mapping.failed(); + ticket.complete(Err(format!("GPU buffer mapping: {e}"))); + return; + } + if !callback_mapping.mapped() { + return; + } // Timed out or cancelled: nobody reads the mapping. if !ticket.active() { - b.unmap(); + callback_mapping.unmap(|| b.unmap()); return; } // Mapped: the waiting thread reads the rows and unmaps (an empty vector = mapped). - ticket.complete(r.map(|_| Vec::new()).map_err(|e| format!("GPU buffer mapping: {e}"))); + ticket.complete(Ok(Vec::new())); }); - // On any failure, unmap (harmless when not mapped; cancels a pending map) so a mapped - // buffer can never be handed out again. + // A timeout can cancel a pending map while its callback is being dispatched. The shared + // guard makes sure the callback and waiter cannot both unmap the same buffer. let fail = |e: String| { - buffer.unmap(); + mapping.unmap(|| buffer.unmap()); e }; self.wait_mapped(&rx, submission).map_err(fail)?.map_err(fail)?; @@ -1285,7 +1303,7 @@ impl GpuContext { let view = buffer.get_mapped_range(..).map_err(|e| format!("GPU mapped range: {e}")); view.and_then(|view| read(&view)) }; - buffer.unmap(); + mapping.unmap(|| buffer.unmap()); result } diff --git a/crates/gpu/src/readback.rs b/crates/gpu/src/readback.rs index 290ae08de..51d941640 100644 --- a/crates/gpu/src/readback.rs +++ b/crates/gpu/src/readback.rs @@ -4,6 +4,7 @@ use std::collections::BTreeMap; #[cfg(not(target_arch = "wasm32"))] use std::sync::Condvar; +use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::{Arc, Mutex, Weak}; use std::time::Duration; @@ -92,6 +93,48 @@ pub(crate) struct Ticket { id: u64, } +/// Tracks one GPU buffer mapping shared by the callback and its waiter. A timeout can race a +/// late callback, so the buffer must be unmapped exactly once. A failed map is never unmapped. +pub(crate) struct Mapping(AtomicU8); + +impl Mapping { + const PENDING: u8 = 0; + const MAPPED: u8 = 1; + const FAILED: u8 = 2; + const FINISHED: u8 = 3; + + pub(crate) fn new() -> Self { + Self(AtomicU8::new(Self::PENDING)) + } + + /// Claim a successful map callback. False means a timeout already cancelled the map. + pub(crate) fn mapped(&self) -> bool { + self.0.compare_exchange(Self::PENDING, Self::MAPPED, Ordering::AcqRel, Ordering::Acquire).is_ok() + } + + /// Record a failed map so the waiter will not unmap a buffer that was never mapped. + pub(crate) fn failed(&self) { + let _ = self.0.compare_exchange(Self::PENDING, Self::FAILED, Ordering::AcqRel, Ordering::Acquire); + } + + /// Unmap once if mapping is pending (cancel it) or mapped (release it). + pub(crate) fn unmap(&self, unmap: impl FnOnce()) { + let mut unmap = Some(unmap); + loop { + let state = self.0.load(Ordering::Acquire); + if state != Self::PENDING && state != Self::MAPPED { + return; + } + if self.0.compare_exchange(state, Self::FINISHED, Ordering::AcqRel, Ordering::Acquire).is_ok() { + if let Some(unmap) = unmap.take() { + unmap(); + } + return; + } + } + } +} + /// User callbacks run outside locks and are isolated one at a time. On panic=abort /// (including the usual wasm build), Rust panics cannot be caught: the host must /// avoid panicking callbacks. This branch does not claim abort-mode recovery. @@ -402,6 +445,83 @@ mod tests { use super::*; use std::sync::atomic::{AtomicUsize, Ordering}; + #[test] + fn timeout_racing_late_map_callback_unmaps_once() { + let mapping = Arc::new(Mapping::new()); + let unmap_calls = Arc::new(AtomicUsize::new(0)); + let barrier = Arc::new(std::sync::Barrier::new(3)); + + let timeout_mapping = Arc::clone(&mapping); + let timeout_calls = Arc::clone(&unmap_calls); + let timeout_barrier = Arc::clone(&barrier); + let timeout = std::thread::spawn(move || { + timeout_barrier.wait(); + timeout_mapping.unmap(|| { + timeout_calls.fetch_add(1, Ordering::SeqCst); + }); + }); + + let callback_mapping = Arc::clone(&mapping); + let callback_calls = Arc::clone(&unmap_calls); + let callback_barrier = Arc::clone(&barrier); + let callback = std::thread::spawn(move || { + callback_barrier.wait(); + if callback_mapping.mapped() { + callback_mapping.unmap(|| { + callback_calls.fetch_add(1, Ordering::SeqCst); + }); + } + }); + + barrier.wait(); + timeout.join().unwrap(); + callback.join().unwrap(); + assert_eq!(unmap_calls.load(Ordering::SeqCst), 1); + } + + #[test] + fn timeout_before_map_callback_cancels_late_map() { + let mapping = Mapping::new(); + let unmap_calls = AtomicUsize::new(0); + + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + assert!(!mapping.mapped()); + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + + assert_eq!(unmap_calls.load(Ordering::SeqCst), 1); + } + + #[test] + fn mapped_callback_and_timeout_release_once() { + let mapping = Mapping::new(); + let unmap_calls = AtomicUsize::new(0); + assert!(mapping.mapped()); + + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + + assert_eq!(unmap_calls.load(Ordering::SeqCst), 1); + } + + #[test] + fn failed_map_is_not_unmapped() { + let mapping = Mapping::new(); + let unmap_calls = AtomicUsize::new(0); + mapping.failed(); + mapping.unmap(|| { + unmap_calls.fetch_add(1, Ordering::SeqCst); + }); + assert_eq!(unmap_calls.load(Ordering::SeqCst), 0); + } + #[test] fn early_rejection_reports_no_pixels_exactly_once() { let calls = Arc::new(AtomicUsize::new(0)); From e6a8cf8cec3a0f1aee9f2b17e8b9565623439036 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:05:11 +0100 Subject: [PATCH 55/99] Export: WebM Opus from craft-audio; remove crates/opusenc WebM export (VP9 and AV1) now encodes Opus with craft_audio::opus::Encoder (the opus-encode feature). The shared encoder was imported from this crate, and craft-libs #1593 ports the speed-ups that landed here afterwards, so the packets are byte-identical to effectcraft-opusenc. Encoder errors are export errors instead of panics. All direct craft-libs dependencies, the lockfile and the PDF dependency validator move to b850981f, the head of craft-libs #1593. Repin to its merge commit once it lands. Refs storytold/craft-libs#778 --- Cargo.lock | 217 ++++-- Cargo.toml | 50 +- crates/export/Cargo.toml | 3 +- crates/export/src/lib.rs | 2 +- crates/export/src/webm.rs | 33 +- crates/export/src/webm_av1.rs | 15 +- crates/export/tests/it/opus_roundtrip.rs | 10 +- crates/opusenc/Cargo.toml | 15 - crates/opusenc/README.md | 136 ---- crates/opusenc/src/bands.rs | 720 ------------------- crates/opusenc/src/energy.rs | 212 ------ crates/opusenc/src/lib.rs | 553 --------------- crates/opusenc/src/mdct.rs | 363 ---------- crates/opusenc/src/range.rs | 472 ------------- crates/opusenc/src/rate.rs | 560 --------------- crates/opusenc/src/resample.rs | 160 ----- crates/opusenc/src/silk.rs | 858 ----------------------- crates/opusenc/src/silk/analysis.rs | 418 ----------- crates/opusenc/src/silk/lpc.rs | 370 ---------- crates/opusenc/src/silk/nlsf.rs | 130 ---- crates/opusenc/src/silk/pulses.rs | 113 --- crates/opusenc/src/silk/tables.rs | 540 -------------- crates/opusenc/src/tables.rs | 122 ---- crates/opusenc/tests/it/common/mod.rs | 285 -------- crates/opusenc/tests/it/ffmpeg.rs | 81 --- crates/opusenc/tests/it/main.rs | 5 - crates/opusenc/tests/it/modes.rs | 272 ------- docs/architecture.md | 1 - xtask/src/main.rs | 1 - xtask/src/pdf_deps.rs | 2 +- 30 files changed, 237 insertions(+), 6482 deletions(-) delete mode 100644 crates/opusenc/Cargo.toml delete mode 100644 crates/opusenc/README.md delete mode 100644 crates/opusenc/src/bands.rs delete mode 100644 crates/opusenc/src/energy.rs delete mode 100644 crates/opusenc/src/lib.rs delete mode 100644 crates/opusenc/src/mdct.rs delete mode 100644 crates/opusenc/src/range.rs delete mode 100644 crates/opusenc/src/rate.rs delete mode 100644 crates/opusenc/src/resample.rs delete mode 100644 crates/opusenc/src/silk.rs delete mode 100644 crates/opusenc/src/silk/analysis.rs delete mode 100644 crates/opusenc/src/silk/lpc.rs delete mode 100644 crates/opusenc/src/silk/nlsf.rs delete mode 100644 crates/opusenc/src/silk/pulses.rs delete mode 100644 crates/opusenc/src/silk/tables.rs delete mode 100644 crates/opusenc/src/tables.rs delete mode 100644 crates/opusenc/tests/it/common/mod.rs delete mode 100644 crates/opusenc/tests/it/ffmpeg.rs delete mode 100644 crates/opusenc/tests/it/main.rs delete mode 100644 crates/opusenc/tests/it/modes.rs diff --git a/Cargo.lock b/Cargo.lock index 7af09affa..2e4d65d86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,6 +138,21 @@ dependencies = [ "equator", ] +[[package]] +name = "alloc-no-stdlib" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2fb6cfd47bf496ff64095c20eaba0c201404ee38714d4142fcfa1dc334fcc7a" + +[[package]] +name = "alloc-stdlib" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5c1865780388bfa186411ab5f247819487fc4864c6e9c3106611fa347586e1" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -697,6 +712,16 @@ dependencies = [ "syn 3.0.6", ] +[[package]] +name = "brotli-decompressor" +version = "6.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75c74c9c51b9140663e196b5fb88bc94c334d7a497c8311cb759d8557874747f" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.20.3" @@ -1092,21 +1117,21 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c)", "thiserror 2.0.21", ] [[package]] name = "craft-doc" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "craft-ecproj-format", "craft-pcraft-format", @@ -1120,12 +1145,12 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "thiserror 2.0.21", ] @@ -1133,7 +1158,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "serde", "serde_json", @@ -1143,12 +1168,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "serde_json", ] @@ -1156,17 +1181,20 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" +dependencies = [ + "gif", +] [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1186,11 +1214,45 @@ dependencies = [ "writeable", ] +[[package]] +name = "craft-image-codecs" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" +dependencies = [ + "craft-jpeg", + "craft-metadata", + "crc32fast", + "exr", + "flate2", + "half", + "hayro-jpeg2000", + "image", + "image-webp", + "jpeg-encoder", + "png", + "rayon", + "serde_json", + "thiserror 2.0.21", + "tiff", + "zune-core", + "zune-jpeg", + "zune-jpegxl", +] + +[[package]] +name = "craft-jpeg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ + "craft-zip", "serde_json", "thiserror 2.0.21", ] @@ -1198,7 +1260,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "thiserror 2.0.21", ] @@ -1214,17 +1276,30 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "miniz_oxide 0.9.1", "serde_json", ] +[[package]] +name = "craft-metadata" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" +dependencies = [ + "brotli-decompressor", + "chrono", + "craft-tiff", + "quick-xml 0.41.0", + "serde", +] + [[package]] name = "craft-pcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ + "flate2", "serde", "serde_json", "thiserror 2.0.21", @@ -1233,7 +1308,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1242,7 +1317,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "encoding_rs", "flate2", @@ -1253,7 +1328,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "dispatch2", "egui", @@ -1264,19 +1339,31 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ + "craft-image-codecs", "craft-xml", "flate2", "kurbo", "roxmltree", "thiserror 2.0.21", + "vectorcraft-geom", + "vectorcraft-pathops", +] + +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" +dependencies = [ + "serde", + "thiserror 2.0.21", ] [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1297,7 +1384,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "chrono", "dunce", @@ -1324,7 +1411,7 @@ dependencies = [ [[package]] name = "craft-vectorcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "flate2", "serde", @@ -1335,9 +1422,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c)", "rayon", "thiserror 2.0.21", ] @@ -1345,7 +1432,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "thiserror 2.0.21", ] @@ -1353,12 +1440,23 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "quick-xml 0.41.0", + "serde", "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.3", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1718,13 +1816,12 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c)", "craft-video", "effectcraft-color", "effectcraft-effects", "effectcraft-keyframe", "effectcraft-media", - "effectcraft-opusenc", "effectcraft-project", "effectcraft-raster", "effectcraft-render", @@ -1888,7 +1985,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -1928,13 +2025,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "effectcraft-opusenc" -version = "0.24.1" -dependencies = [ - "craft-audio", -] - [[package]] name = "effectcraft-path" version = "0.24.1" @@ -3463,7 +3553,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "hayro-ccitt", ] @@ -3473,11 +3563,14 @@ name = "hayro-jpeg2000" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" +dependencies = [ + "fearless_simd", +] [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=b850981f835f39859077cf62ff4e76462e76167c#b850981f835f39859077cf62ff4e76462e76167c" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -3734,6 +3827,7 @@ dependencies = [ "moxcms", "num-traits", "png", + "qoi", "tiff", "zune-core", "zune-jpeg", @@ -3864,6 +3958,12 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-encoder" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b454d911ac55068f53495488d8ccd0646eaa540c033a28ee15b07838afafb01f" + [[package]] name = "js-sys" version = "0.3.106" @@ -5153,6 +5253,15 @@ version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -6724,6 +6833,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" @@ -8261,6 +8391,15 @@ dependencies = [ "zune-core", ] +[[package]] +name = "zune-jpegxl" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba11ecd07cc23351500e840ae03841b7e4997923ec8e4832ee3ae199ea0b6b4" +dependencies = [ + "zune-core", +] + [[package]] name = "zvariant" version = "5.15.0" diff --git a/Cargo.toml b/Cargo.toml index ae0fd3d09..bf1cb6747 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,24 +11,24 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-doc = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-vectorcraft-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-doc = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } +craft-vectorcraft-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "b850981f835f39859077cf62ff4e76462e76167c", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -58,7 +58,6 @@ effectcraft-engine = { path = "crates/engine" } effectcraft-host = { path = "crates/host" } effectcraft-ui-egui = { path = "crates/ui-egui" } effectcraft-automation = { path = "crates/automation" } -effectcraft-opusenc = { path = "crates/opusenc" } effectcraft-script = { path = "crates/script" } effectcraft-plugin = { path = "crates/plugin" } effectcraft-helper-host = { path = "crates/helper-host" } @@ -92,9 +91,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode", "opus-encode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -124,7 +123,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -196,9 +195,6 @@ opt-level = 3 [profile.dev.package.effectcraft-media] opt-level = 3 -[profile.dev.package.effectcraft-opusenc] -opt-level = 3 - [profile.dev.package.effectcraft-export] opt-level = 3 @@ -233,8 +229,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "b850981f835f39859077cf62ff4e76462e76167c", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index 164b10a7f..c18d80984 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "effectcraft-export" -description = "Render Queue jobs and output modules: H.264 MP4 (+AAC), ProRes and uncompressed MOV (+PCM) , HEVC / AV1 MP4 (+AAC) and WebM (VP9 or AV1) via craft-libs codecs, Opus via effectcraft-opusenc, PNG/JPEG/TIFF/EXR/Targa sequences, animated GIF, WAV/AIFF" +description = "Render Queue jobs and output modules: H.264 MP4 (+AAC), ProRes and uncompressed MOV (+PCM) , HEVC / AV1 MP4 (+AAC) and WebM (VP9 or AV1) via craft-libs codecs, Opus via craft-audio, PNG/JPEG/TIFF/EXR/Targa sequences, animated GIF, WAV/AIFF" version.workspace = true edition.workspace = true license.workspace = true @@ -17,7 +17,6 @@ effectcraft-render = { workspace = true } craft-video = { workspace = true } craft-audio = { workspace = true } craft-media = { workspace = true } -effectcraft-opusenc = { workspace = true } image = { workspace = true, features = ["png", "jpeg", "tiff", "exr", "tga"] } exr = { workspace = true } gif = { workspace = true } diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs index d9af7b2aa..adf6fd4d5 100644 --- a/crates/export/src/lib.rs +++ b/crates/export/src/lib.rs @@ -9,7 +9,7 @@ //! | OpenEXR sequence | one file per frame, scan lines | 32-bit float (default) or half float, linear light, premultiplied; compression None, RLE, ZIPS, ZIP (default), PIZ, PXR24, B44, B44A, DWAA, DWAB | yes | — | //! | Targa sequence | one file per frame | uncompressed 8-bit: 24-bit RGB, 32-bit RGB + Alpha (8 alpha bits), 8-bit grey for Alpha; top-left origin | yes (straight or premultiplied) | — | //! | Animated GIF | GIF89a | 256-colour palette per frame (NeuQuant) | 1-bit | — | -//! | WebM | WebM (Matroska) | VP9 profile 0 (`craft_video::vp9`: key + inter frames, a key frame every 2 s, loop filter), 8-bit 4:2:0; or AV1 (`craft_video::av1`) | VP9 alpha (BlockAdditional) | Opus (`effectcraft-opusenc`: SILK / hybrid / CELT by bitrate and application), 48 kHz | +//! | WebM | WebM (Matroska) | VP9 profile 0 (`craft_video::vp9`: key + inter frames, a key frame every 2 s, loop filter), 8-bit 4:2:0; or AV1 (`craft_video::av1`) | VP9 alpha (BlockAdditional) | Opus (`craft_audio::opus::Encoder`: SILK / hybrid / CELT by bitrate and application), 48 kHz | //! | HEVC | MP4 (`hvc1`) | `craft_video::hevc` Main / Main 10 4:2:0, I + P slices, bitrate or constant quality, level, key-frame interval | no | AAC-LC (`craft_audio::aac`) | //! | AV1 | MP4 (`av01`) | `craft_video::av1` Main 8/10-bit 4:2:0, key + inter frames | no | AAC-LC (`craft_audio::aac`) | //! | WAV / AIFF | RIFF WAVE / AIFF (AIFF-C for float) | — | — | PCM 16/24-bit or 32-bit float, mono/stereo (audio only) | diff --git a/crates/export/src/webm.rs b/crates/export/src/webm.rs index 2802ac928..3633728bf 100644 --- a/crates/export/src/webm.rs +++ b/crates/export/src/webm.rs @@ -8,18 +8,19 @@ //! with `AlphaMode` 1 on the track, as WebM defines. VP9 comes from `craft_video::vp9` (key //! frames every two seconds, inter frames between them: SimpleBlocks carry the key flag, inter //! BlockGroups a ReferenceBlock; the alpha stream's key frames line up with the colour stream's), -//! Opus from `effectcraft-opusenc` (CELT, 48 kHz stereo, 20 ms packets, +//! Opus from `craft_audio::opus::Encoder` (SILK / hybrid / CELT, 48 kHz, 20 ms packets, //! `CodecDelay` = pre-skip). WAV (RIFF, PCM or IEEE float) and AIFF (big-endian PCM, 80-bit //! extended sample rate; AIFF-C `fl32` for float) follow their published file layouts. use std::io::{Seek, SeekFrom, Write}; +use craft_audio::opus::encoder as opus; use effectcraft_project::Comp; use effectcraft_project::render_queue::{AudioFormat, Channels}; use effectcraft_time::{TICKS_PER_SECOND, Tick}; use crate::encode::{mix, pcm_bytes}; -use crate::{Cx, Report, Result, State, batch_size, io, wants_audio}; +use crate::{Cx, ExportError, Report, Result, State, batch_size, io, wants_audio}; pub(crate) const OPUS_RATE: u32 = 48_000; @@ -124,13 +125,18 @@ fn cluster(frames: &mut [Frame]) -> Vec { } /// The Opus encoder of a WebM output: the module's channel count, bitrate and application. -pub(crate) fn opus_encoder(job: &Cx) -> effectcraft_opusenc::OpusEncoder { +pub(crate) fn opus_encoder(job: &Cx) -> Result { let channels = if job.output.audio_channels == 1 { 1 } else { 2 }; let app = match job.output.opus_application { - effectcraft_project::render_queue::OpusApplication::Audio => effectcraft_opusenc::Application::Audio, - effectcraft_project::render_queue::OpusApplication::Voip => effectcraft_opusenc::Application::Voip, + effectcraft_project::render_queue::OpusApplication::Audio => opus::Application::Audio, + effectcraft_project::render_queue::OpusApplication::Voip => opus::Application::Voip, }; - effectcraft_opusenc::OpusEncoder::with_application(channels, job.output.opus_bitrate_kbps.clamp(6, 510) * 1000, app) + opus::Encoder::with_application(channels, job.output.opus_bitrate_kbps.clamp(6, 510) * 1000, app).map_err(opus_error) +} + +/// An Opus encoder error as an export error. +pub(crate) fn opus_error(e: opus::Error) -> ExportError { + ExportError::Encode(format!("Opus: {e}")) } pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut State<'_>) -> Result { @@ -156,7 +162,7 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta let mut alpha_enc = alpha.then(|| craft_video::vp9::Vp9Encoder::new(cfg.clone())); let with_audio = wants_audio(job); let opus_channels = if job.output.audio_channels == 1 { 1usize } else { 2 }; - let mut opus = with_audio.then(|| opus_encoder(job)); + let mut opus = with_audio.then(|| opus_encoder(job)).transpose()?; let total = st.total; let frame_ms = |k: u64| -> i64 { ((k as i128 * 1000 * rate.den as i128 + rate.num as i128 / 2) / rate.num as i128) as i64 }; let duration_ms = frame_ms(total) as f64; @@ -229,8 +235,8 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta let mut cursor = span_start.to_units_floor(OPUS_RATE as i64); let mut pcm_left: Vec = vec![]; let mut packets = 0u64; - let mut audio_until = |until: Tick, frames: &mut Vec, finish: bool| { - let Some(enc) = opus.as_mut() else { return }; + let mut audio_until = |until: Tick, frames: &mut Vec, finish: bool| -> Result<()> { + let Some(enc) = opus.as_mut() else { return Ok(()) }; let end = until.to_units_floor(OPUS_RATE as i64); if end > cursor { let n = (end - cursor) as usize; @@ -238,7 +244,7 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta pcm_left.extend(mix(job, start, n, OPUS_RATE)); cursor = end; } - let fs = effectcraft_opusenc::OpusEncoder::FRAME_SIZE * opus_channels; + let fs = craft_audio::opus::Encoder::FRAME_SIZE * opus_channels; if finish && !pcm_left.is_empty() { // Pad the last packet (pre-skip + padding cover the encoder delay). let pad = (fs - pcm_left.len() % fs) % fs + fs; @@ -247,11 +253,12 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta // Packets are read in place and the encoded samples dropped once: draining each packet // from the front would shift the rest of the batch's audio every 20 ms. for packet in pcm_left.chunks_exact(fs) { - let pkt = enc.encode_float(packet); + let pkt = enc.encode_float(packet).map_err(crate::webm::opus_error)?; frames.push(Frame { ms: packets as i64 * 20, track: 2, key: true, prev_ms: None, data: pkt, alpha: None }); packets += 1; } pcm_left.drain(..pcm_left.len() / fs * fs); + Ok(()) }; let batch = batch_size(); @@ -281,7 +288,7 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta } drop(pixels); let t_end = if end >= total { span_end } else { job.settings.frame_time(comp, end) }; - audio_until(t_end, &mut frames, end >= total); + audio_until(t_end, &mut frames, end >= total)?; let c = cluster(&mut frames); file.write_all(&c).map_err(io)?; seg_len += c.len() as u64; @@ -290,7 +297,7 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta } if total == 0 { let mut frames = vec![]; - audio_until(span_end, &mut frames, true); + audio_until(span_end, &mut frames, true)?; if !frames.is_empty() { let c = cluster(&mut frames); file.write_all(&c).map_err(io)?; diff --git a/crates/export/src/webm_av1.rs b/crates/export/src/webm_av1.rs index 2e75257f7..fc9545a10 100644 --- a/crates/export/src/webm_av1.rs +++ b/crates/export/src/webm_av1.rs @@ -46,7 +46,7 @@ pub(crate) async fn webm_av1(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut let mut venc = crate::hevc_av1::Av1::new(w, h, rate, job.output, codes)?; let with_audio = wants_audio(job); let opus_channels = if job.output.audio_channels == 1 { 1usize } else { 2 }; - let mut opus = with_audio.then(|| opus_encoder(job)); + let mut opus = with_audio.then(|| opus_encoder(job)).transpose()?; let total = st.total; let frame_ms = |k: u64| -> i64 { ((k as i128 * 1000 * rate.den as i128 + rate.num as i128 / 2) / rate.num as i128) as i64 }; let duration_ms = frame_ms(total) as f64; @@ -111,8 +111,8 @@ pub(crate) async fn webm_av1(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut let mut cursor = span_start.to_units_floor(OPUS_RATE as i64); let mut pcm_left: Vec = vec![]; let mut packets = 0u64; - let mut audio_until = |until: Tick, blocks: &mut Vec, finish: bool| { - let Some(enc) = opus.as_mut() else { return }; + let mut audio_until = |until: Tick, blocks: &mut Vec, finish: bool| -> Result<()> { + let Some(enc) = opus.as_mut() else { return Ok(()) }; let end = until.to_units_floor(OPUS_RATE as i64); if end > cursor { let n = (end - cursor) as usize; @@ -120,7 +120,7 @@ pub(crate) async fn webm_av1(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut pcm_left.extend(mix(job, start, n, OPUS_RATE)); cursor = end; } - let fs = effectcraft_opusenc::OpusEncoder::FRAME_SIZE * opus_channels; + let fs = craft_audio::opus::Encoder::FRAME_SIZE * opus_channels; if finish && !pcm_left.is_empty() { let pad = (fs - pcm_left.len() % fs) % fs + fs; pcm_left.extend(std::iter::repeat_n(0.0, pad)); @@ -128,11 +128,12 @@ pub(crate) async fn webm_av1(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut // Packets are read in place and the encoded samples dropped once: draining each packet // from the front would shift the rest of the batch's audio every 20 ms. for packet in pcm_left.chunks_exact(fs) { - let pkt = enc.encode_float(packet); + let pkt = enc.encode_float(packet).map_err(crate::webm::opus_error)?; blocks.push(Block { ms: packets as i64 * 20, track: 2, key: true, data: pkt }); packets += 1; } pcm_left.drain(..pcm_left.len() / fs * fs); + Ok(()) }; let batch = batch_size(); @@ -159,13 +160,13 @@ pub(crate) async fn webm_av1(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut } } let t_end = if end >= total { span_end } else { job.settings.frame_time(comp, end) }; - audio_until(t_end, &mut blocks, end >= total); + audio_until(t_end, &mut blocks, end >= total)?; flush_blocks(&mut blocks, &mut file, &mut seg_len)?; st.advance(end - i)?; i = end; } if total == 0 { - audio_until(span_end, &mut blocks, true); + audio_until(span_end, &mut blocks, true)?; flush_blocks(&mut blocks, &mut file, &mut seg_len)?; } let mut size = [0u8; 8]; diff --git a/crates/export/tests/it/opus_roundtrip.rs b/crates/export/tests/it/opus_roundtrip.rs index c333946d8..478ca9d3f 100644 --- a/crates/export/tests/it/opus_roundtrip.rs +++ b/crates/export/tests/it/opus_roundtrip.rs @@ -1,9 +1,9 @@ -//! Round trip of `effectcraft-opusenc` through FilmCraft's spec-derived Opus decoder, plus an +//! Round trip of WebM export's Opus encoder (`craft_audio::opus::Encoder`) through FilmCraft's spec-derived Opus decoder, plus an //! ffmpeg oracle (skipped when ffmpeg is not installed) reading an Ogg Opus file written here. use std::process::Command; -use effectcraft_opusenc::OpusEncoder; +use craft_audio::opus::Encoder as OpusEncoder; const SR: f32 = 48_000.0; const FRAME: usize = OpusEncoder::FRAME_SIZE; @@ -11,12 +11,12 @@ const FRAME: usize = OpusEncoder::FRAME_SIZE; /// Encodes interleaved `pcm`, padding the tail so the encoder's look-ahead is flushed. fn encode(pcm: &[f32], channels: u8, bitrate: u32) -> (OpusEncoder, Vec>) { let c = channels as usize; - let mut enc = OpusEncoder::new(channels, bitrate); + let mut enc = OpusEncoder::new(channels, bitrate).expect("1 or 2 channels"); let total = pcm.len() / c + enc.pre_skip() as usize; let frames = total.div_ceil(FRAME); let mut padded = pcm.to_vec(); padded.resize(frames * FRAME * c, 0.0); - let packets = padded.chunks(FRAME * c).map(|f| enc.encode_float(f)).collect(); + let packets = padded.chunks(FRAME * c).map(|f| enc.encode_float(f).expect("one whole frame")).collect(); (enc, packets) } @@ -303,7 +303,7 @@ fn ogg_page(out: &mut Vec, packet: &[u8], header_type: u8, granule: u64, seq fn ogg_opus(enc: &OpusEncoder, packets: &[Vec], len: usize) -> Vec { let mut out = Vec::new(); ogg_page(&mut out, &enc.opus_head(), 0x02, 0, 0); - let vendor = b"effectcraft-opusenc"; + let vendor = b"craft-audio"; let mut tags = b"OpusTags".to_vec(); tags.extend_from_slice(&(vendor.len() as u32).to_le_bytes()); tags.extend_from_slice(vendor); diff --git a/crates/opusenc/Cargo.toml b/crates/opusenc/Cargo.toml deleted file mode 100644 index db7f2b7f8..000000000 --- a/crates/opusenc/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "effectcraft-opusenc" -description = "Clean-room pure-Rust Opus encoder (RFC 6716 SILK NB/MB/WB, hybrid SWB/FB and CELT FB modes, 48 kHz, 20 ms; RFC 7845 OpusHead) for WebM export audio" -version.workspace = true -edition.workspace = true -license.workspace = true -rust-version.workspace = true - -[lints] -workspace = true - -[dependencies] - -[dev-dependencies] -craft-audio = { workspace = true } diff --git a/crates/opusenc/README.md b/crates/opusenc/README.md deleted file mode 100644 index 8a822ceac..000000000 --- a/crates/opusenc/README.md +++ /dev/null @@ -1,136 +0,0 @@ -# effectcraft-opusenc - -Clean-room, pure-Rust Opus encoder for EffectCraft's WebM export audio (layer L0, `std` only, -no `unsafe`, builds for `wasm32-unknown-unknown`). - -All three Opus modes, 20 ms packets (one frame per packet), 48 kHz float input, mono or stereo: - -- **CELT** (fullband): MDCT transform coding, constant packet size. -- **SILK** (narrowband 8 kHz, mediumband 12 kHz, wideband 16 kHz internal rate): linear - prediction with long-term (pitch) prediction; packet size varies around the target bitrate. -- **Hybrid** (super-wideband, fullband): SILK wideband codes 0–8 kHz and CELT codes bands 17 and - up (8 kHz and above) in the same range-coded frame; constant packet size. - -```rust -use effectcraft_opusenc::{Application, OpusEncoder}; -let mut enc = OpusEncoder::with_application(2, 48_000, Application::Voip); -let packet = enc.encode_float(&vec![0.0; OpusEncoder::FRAME_SIZE * 2]); -// enc.mode(), enc.bandwidth(), enc.pre_skip(), enc.opus_head() ... -``` - -`OpusEncoder::new(channels, bitrate)` is `with_application(.., Application::Audio)`. -`OpusEncoder::with_mode(channels, bitrate, mode, bandwidth)` forces a mode/bandwidth pair -(SILK: NB/MB/WB; hybrid: SWB/FB; CELT: FB). - -## Mode table - -Chosen once per stream (constant-bitrate export, no in-stream switching) from the bitrate per -channel (bitrate / channels; the total is clamped to 6 kb/s per channel … 510 kb/s): - -| per-channel bitrate | `Application::Voip` | `Application::Audio` (default) | -|---------------------|-------------------------|--------------------------------| -| < 10 kb/s | SILK narrowband (8 kHz) | SILK wideband | -| 10–12 kb/s | SILK mediumband (12 kHz)| SILK wideband | -| 12–16 kb/s | SILK wideband (16 kHz) | SILK wideband | -| 16–18 kb/s | SILK wideband | hybrid fullband | -| 18–28 kb/s | hybrid super-wideband | hybrid fullband | -| 28–36 kb/s | hybrid fullband | hybrid fullband | -| 36–40 kb/s | hybrid fullband | CELT fullband | -| ≥ 40 kb/s | CELT fullband | CELT fullband | - -TOC configurations (RFC 6716 §3.1, Table 2): SILK NB/MB/WB 20 ms = 1/5/9, hybrid SWB/FB 20 ms -= 13/15, CELT FB 20 ms = 31; the stereo bit is set for two channels; frame-count code 0. - -`pre_skip()` is 120 samples in every mode: the CELT MDCT overlap, and for SILK/hybrid the -decimator delay (83 samples at 48 kHz, 88 for narrowband) plus the decoder's SILK delay (one -internal-rate sample and the resampler delay of RFC 6716 Table 54). The SILK and CELT halves of a -hybrid frame are therefore aligned without extra buffering. - -## What is implemented - -**SILK** (RFC 6716 §4.2, encoder direction; own analysis and search design): - -- 48 kHz → 8/12/16 kHz decimation with a linear-phase Kaiser-windowed-sinc FIR. -- Per frame: energy VAD (inactive / unvoiced / voiced), open-loop pitch search (normalised - correlation with octave checks, joint lag + contour codebook choice, §4.2.7.6.1), windowed - autocorrelation LPC (Levinson, lag window, bandwidth expansion), LPC → NLSF by root search, - NLSF quantisation (stage-1 preselection by weighted distance, backwards-predictive stage-2 - scalar quantiser reproducing the decoder's dequantisation exactly, rate-distortion choice), - LTP codebook search over the three periodicity codebooks, independent + delta gain coding. -- Analysis-by-synthesis excitation: every sample is chosen by running the decoder's exact - fixed-point reconstruction (LTP from the decoder's own past output, LPC synthesis with the Q12 - coefficients of the *dequantised* NLSFs, gain rescaling between subframes, quantisation - offsets, the LCG sign sequence), so encoder and decoder never drift. A noise-feedback loop - shapes the coding noise by `1/A(z/γ)` (γ 0.75–0.9, coarser quantisation → more shaping), and a - small rate penalty biases pulses towards zero. -- Excitation coding: rate level, per-block pulse counts with LSB escapes, shell coding, LSBs and - signs (§4.2.7.8). -- Rate control: per-frame search over a gain offset (integer bracket, then bisection) to the - frame budget; SILK-only streams carry a bit reservoir across frames (packet sizes vary). -- Stereo: mid/side with the decoder's stereo prediction (§4.2.7.1, §4.2.8; ridge-regularised - least-squares weights, quantised to the decoder grid, interpolation mirrored), mid-only frames - when the predicted side is negligible, side gains floored at the mid gains. -- Not implemented: LBRR (in-band FEC), NLSF interpolation, 10/40/60 ms frames, DTX. - -**Hybrid** (§4.3 with start band 17): the SILK frame is written first, then the redundancy flag -(always 0) when there is room, then a CELT frame coding bands 17–18 (SWB) or 17–20 (FB) in the -same range coder with the remaining packet bytes (no silence flag or post-filter in hybrid -frames, decoder band-energy reset for uncoded bands mirrored). SILK gets 72 % (SWB) / 62 % (FB) -of the per-channel bitrate, at most the bitrate minus 6 kb/s, and never more than leaves CELT a -fifth of the packet (at least 80 bits). - -**CELT** (unchanged): forward MDCT with the low-overlap window, band energies with inter/intra -coarse prediction, fine and final energy bits, the decoder's exact bit allocation, spreading, -recursive band splitting, greedy PVQ search. Not implemented: transient frames, TF changes, -pitch post-filter, intensity stereo, dynamic allocation, VBR. All-zero CELT frames become 3-byte -silence packets. - -## Measured (tests in `tests/`, craft-audio's Opus decoder) - -Synthetic speech (glottal pulses 100–200 Hz through three moving formants, syllable envelopes, -pauses) and music (three-note harmonic chords); waveform SNR against the input band-limited to -the mode's bandwidth (full band for hybrid/CELT), residual delay 0 (±1 for narrowband) after the -pre-skip: - -| mode / bandwidth | bitrate target → actual | speech SNR | music SNR | -|--------------------|-------------------------|------------|-----------| -| SILK NB | 8 → 7.5 kb/s | 15.9 dB | 6.9 dB (9 kb/s) | -| SILK MB | 11 → 10.1 kb/s | 21.8 dB | 7.9 dB | -| SILK WB | 12 → 10.9 kb/s | 21.5 dB | 8.1 dB | -| SILK WB | 16 → 14.3 kb/s | 28.1 dB | 12.1 dB | -| SILK WB | 24 → 21.1 kb/s | 37.0 dB | 19.7 dB | -| hybrid SWB | 24 kb/s (CBR) | 28.7 dB | 13.0 dB | -| hybrid FB | 32 kb/s (CBR) | 32.1 dB | 15.6 dB | -| CELT FB | 12 kb/s (CBR) | 13.0 dB | — | - -At 12 kb/s mono, SILK wideband beats the CELT path on speech by ~8 dB (21.0 vs 13.0 dB -full-band SNR). SILK bitrates land within −13 % … 0 % of the target (speech spends little in -pauses), hybrid is exact. Stereo SILK WB at 32 kb/s: 41 dB dual-mono, 40/37 dB panned, 22/19 dB -for two independent speech signals. - -ffmpeg (external oracle, Ogg Opus written by the test) decodes every mode with both its native -`opus` decoder and `libopus` without errors, honouring pre-skip and end trimming, with the same -SNRs (libopus residual delay 0, ffmpeg's native decoder 0–4 samples). The only message tolerated -is ffmpeg's raw-PCM muxer timestamp complaint that its native decoder also prints for -narrowband files encoded by libopus itself. - -## Specifications - -- RFC 6716, *Definition of the Opus Audio Codec* (September 2012), with the RFC 8251 updates - (October 2017) as implemented by the decoder we round-trip against. -- RFC 7845, *Ogg Encapsulation for the Opus Audio Codec* (April 2016), §5.1 `OpusHead` and - §4.2 pre-skip. - -## Provenance - -Implemented from the RFC text. Constant tables (CELT band edges, `eMeans`, the coarse-energy -Laplace model, the allocation table, ICDFs; all SILK probability tables and codebooks: NLSF -stage-1/2 codebooks and prediction weights, gain, pitch, contour, LTP and pulse ICDFs, stereo -weights) and the decoder-side normative arithmetic the encoder must reproduce bit-exactly (CELT -allocation; SILK NLSF dequantisation and stabilisation, NLSF → LPC conversion, `log2lin`, the -fixed-point division/inverse helpers and the LPC analysis filter) are mirrored from FilmCraft's -first-party, spec-derived `filmcraft-opus` decoder (MIT OR Apache-2.0). That decoder, now -`craft_audio::opus` in craft-libs, is also the round-trip oracle in `tests/` and `crates/export/tests/it/opus_roundtrip.rs` (ffmpeg is a second, -external oracle when installed). All encoder-side analysis and search (pitch, LPC, NLSF and -LTP search, noise feedback, rate control, stereo prediction, the decimator) is our own design. -No third-party encoder or decoder source (libopus or otherwise) was consulted. diff --git a/crates/opusenc/src/bands.rs b/crates/opusenc/src/bands.rs deleted file mode 100644 index f90a554c4..000000000 --- a/crates/opusenc/src/bands.rs +++ /dev/null @@ -1,720 +0,0 @@ -//! Band shape coding: PVQ search and codeword indexing, spreading, recursive band splitting -//! (RFC 6716 §4.3.4, encoder direction). -//! -//! The encoder codes 20 ms long-block frames only (no transients, no TF changes), and stereo -//! as dual (independent L/R) stereo, so a band is always coded by `quant_partition` with a single -//! block. Every bit-budget computation mirrors the decoder so both sides take the same -//! split/pulse decisions. - -use crate::range::{BITRES, RangeEncoder, ilog}; -use crate::rate::{Mode, QTHETA_OFFSET, get_pulses}; -use crate::tables::EBANDS; -use crate::{CeltFrame, rate::Allocation}; - -pub const SPREAD_NORMAL: usize = 2; - -#[inline] -fn frac_mul16(a: i32, b: i32) -> i32 { - (16384 + (a as i16 as i32) * (b as i16 as i32)) >> 15 -} - -fn bitexact_cos(x: i32) -> i32 { - let tmp = (4096 + x * x) >> 13; - let x2 = tmp; - let x2 = (32767 - x2) + frac_mul16(x2, -7651 + frac_mul16(x2, 8277 + frac_mul16(-626, x2))); - 1 + x2 -} - -fn bitexact_log2tan(isin: i32, icos: i32) -> i32 { - let lc = ilog(icos as u32); - let ls = ilog(isin as u32); - let icos = icos << (15 - lc); - let isin = isin << (15 - ls); - (ls - lc) * (1 << 11) + frac_mul16(isin, frac_mul16(isin, -2597) + 7932) - frac_mul16(icos, frac_mul16(icos, -2597) + 7932) -} - -fn compute_qn(n: i32, b: i32, offset: i32, pulse_cap: i32, stereo: bool) -> i32 { - const EXP2_TABLE8: [i32; 8] = [16384, 17866, 19483, 21247, 23170, 25267, 27554, 30048]; - let mut n2 = 2 * n - 1; - if stereo && n == 2 { - n2 -= 1; - } - let mut qb = (b + n2 * offset) / n2; - qb = qb.min(b - pulse_cap - (4 << BITRES)); - qb = qb.min(8 << BITRES); - if qb < (1 << BITRES >> 1) { - 1 - } else { - let qn = EXP2_TABLE8[(qb & 0x7) as usize] >> (14 - (qb >> BITRES)); - (qn + 1) >> 1 << 1 - } -} - -/// One elementary pass of the spreading rotation, inverted (the decoder applies the forward -/// pass; the encoder undoes it before the pulse search). -fn exp_rotation1_inv(x: &mut [f32], len: usize, stride: usize, c: f32, s: f32) { - if len <= stride { - return; - } - if len > 2 * stride { - for i in 0..=len - 2 * stride - 1 { - let x1 = x[i]; - let x2 = x[i + stride]; - x[i + stride] = c * x2 - s * x1; - x[i] = c * x1 + s * x2; - } - } - for i in (0..len - stride).rev() { - let x1 = x[i]; - let x2 = x[i + stride]; - x[i + stride] = c * x2 - s * x1; - x[i] = c * x1 + s * x2; - } -} - -/// Inverse of the decoder's spreading rotation (§4.3.4.3) for one block of `len` samples. -pub fn exp_rotation_inv(x: &mut [f32], len: usize, k: usize, spread: usize) { - const SPREAD_FACTOR: [usize; 3] = [15, 10, 5]; - if 2 * k >= len || spread == 0 { - return; - } - let factor = SPREAD_FACTOR[spread - 1]; - let gain = len as f32 / (len + factor * k) as f32; - let theta = 0.5 * gain * gain; - let c = (0.5 * std::f32::consts::PI * theta).cos(); - let s = (0.5 * std::f32::consts::PI * (1.0 - theta)).cos(); - let mut stride2 = 0; - if len >= 8 { - stride2 = 1; - while stride2 * stride2 + stride2 < len { - stride2 += 1; - } - } - // The decoder applies (stride2: s, c) then (1: c, s); undo in reverse order. - exp_rotation1_inv(x, len, 1, c, s); - if stride2 != 0 { - exp_rotation1_inv(x, len, stride2, s, c); - } -} - -/// Relative slack for the pulse-candidate filter in [`pvq_search`]: far above the f32 rounding of -/// the filter score (a few 1e-7), far below the spread of real scores. -const PVQ_SCORE_SLACK: f32 = 1e-5; - -/// Greedy PVQ search: the integer vector `y` with `sum |y| = k` closest in direction to `x`. -pub fn pvq_search(x: &[f32], k: usize, y: &mut [i32]) { - let n = x.len(); - y[..n].fill(0); - // `abs`, `dy` (2 y + 1, infinite in the padding) and the per-pass scores `score`, each padded to - // whole 8-lane chunks. - let np = n.next_multiple_of(8); - let mut buf = vec![0f32; 3 * np]; - let (abs, rest) = buf.split_at_mut(np); - let (dy, score) = rest.split_at_mut(np); - for (a, v) in abs.iter_mut().zip(x) { - *a = v.abs(); - } - let sum: f32 = abs[..n].iter().sum(); - if !sum.is_finite() || sum <= 1e-15 { - y[0] = k as i32; - return; - } - let mut placed = 0usize; - let mut xy = 0f32; - let mut yy = 0f32; - if k > n / 2 { - // Pre-project onto the pyramid (rounding down) and place the rest greedily. - let r = (k as f32 - 1.0) / sum; - for j in 0..n { - // Non-negative and at most k, so the truncating cast is the floor. - let p = (abs[j] * r) as i32; - y[j] = p; - placed += p as usize; - xy += abs[j] * p as f32; - yy += (p * p) as f32; - } - } - for j in 0..np { - dy[j] = if j < n { 2.0 * y[j] as f32 + 1.0 } else { f32::INFINITY }; - } - while placed < k { - // Vectorisable scores (xy + |x_j|)^2 / (yy + 2 y_j + 1) and their maximum. - for ((sc, &a), &d) in score.iter_mut().zip(abs.iter()).zip(dy.iter()) { - let t = xy + a; - *sc = t * t / (yy + d); - } - let mut lane_max = [0f32; 8]; - for c in score.as_chunks::<8>().0 { - for i in 0..8 { - lane_max[i] = if c[i] > lane_max[i] { c[i] } else { lane_max[i] }; - } - } - let top = lane_max.iter().fold(0f32, |m, &v| if v > m { v } else { m }); - // The exact cross-multiplied test below, in index order with the first maximum winning, only - // matters for entries within rounding distance of the top score: every other entry is beaten - // by the top one whenever it is reached and never beats it afterwards. Running the test on - // those alone therefore picks the same pulse as running it on all of them. - let filter = top > 1e-30 && top.is_finite(); - let lo = top * (1.0 - PVQ_SCORE_SLACK); - // Usually exactly one entry qualifies; its index falls out of a lane-wise count. - let mut count = [0u32; 8]; - let mut index = [0u32; 8]; - for (ci, c) in score.as_chunks::<8>().0.iter().enumerate() { - for i in 0..8 { - let hit = u32::from(c[i] >= lo); - count[i] += hit; - index[i] += hit * (ci * 8 + i) as u32; - } - } - let mut best = 0usize; - if filter && count.iter().sum::() == 1 { - best = index.iter().sum::() as usize; - } else { - let mut best_num = -1f32; - let mut best_den = 1f32; - for j in 0..n { - if !filter || score[j] >= lo { - let num = xy + abs[j]; - let num = num * num; - let den = yy + 2.0 * y[j] as f32 + 1.0; - if num * best_den > best_num * den { - best_num = num; - best_den = den; - best = j; - } - } - } - } - xy += abs[best]; - yy += 2.0 * y[best] as f32 + 1.0; - y[best] += 1; - dy[best] = 2.0 * y[best] as f32 + 1.0; - placed += 1; - } - for j in 0..n { - if x[j] < 0.0 { - y[j] = -y[j]; - } - } -} - -/// Largest band width and pulse count the encoder codes (176 coefficients, `get_pulses(40)` = 128). -const PVQ_MAX_N: usize = 176; -const PVQ_MAX_K: usize = 128; - -/// Row-major `V(n, k)` for `n <= max_n`, `k <= max_k` with row stride `max_k + 1`, saturated at -/// `u32::MAX` (a codebook that large is never coded, see `rate::fits_in32`). -fn build_pvq_table(max_n: usize, max_k: usize) -> Vec { - let w = max_k + 1; - let mut v = vec![0u32; (max_n + 1) * w]; - v[0] = 1; - for nn in 1..=max_n { - v[nn * w] = 1; - for kk in 1..=max_k { - let sum = v[(nn - 1) * w + kk] as u64 + v[nn * w + kk - 1] as u64 + v[(nn - 1) * w + kk - 1] as u64; - v[nn * w + kk] = sum.min(u32::MAX as u64) as u32; - } - } - v -} - -fn pvq_table() -> &'static [u32] { - static TABLE: std::sync::OnceLock> = std::sync::OnceLock::new(); - TABLE.get_or_init(|| build_pvq_table(PVQ_MAX_N, PVQ_MAX_K)) -} - -/// Encodes the PVQ codeword `y` (`sum |y| = k`) as the index the RFC 6716 §4.3.4.2 decoder maps -/// back to `y`. -pub fn encode_pulses(y: &[i32], k: usize, enc: &mut RangeEncoder) { - let n = y.len(); - // Shapes outside the coded range (never produced by the band layout) get a local table. - let local; - let (v, w) = if n <= PVQ_MAX_N && k <= PVQ_MAX_K { - (pvq_table(), PVQ_MAX_K + 1) - } else { - local = build_pvq_table(n, k); - (&local[..], k + 1) - }; - let row = |nn: usize| &v[nn * w..(nn + 1) * w]; - let total = row(n)[k] as u64; - let mut index = 0u64; - let mut kk = k; - for j in 0..n { - if kk == 0 { - break; - } - let rem = n - j; - let t = y[j].unsigned_abs() as usize; - let below = row(rem - 1); - // Codewords with |y_j| = t start at sum_{m < kk - t} V(rem-1, m) within their sign half. - let mut base: u64 = below[..kk - t].iter().map(|&x| x as u64).sum(); - if y[j] < 0 { - base += (below[kk] as u64 + row(rem)[kk] as u64) / 2; - } - index += base; - kk -= t; - } - debug_assert!(total <= u32::MAX as u64); - if total >= 2 { - enc.uint(index as u32, total as u32); - } -} - -pub struct BandEnc<'m, 'e> { - pub m: &'m Mode, - pub enc: &'e mut RangeEncoder, - pub i: usize, - pub spread: usize, - pub remaining_bits: i32, - iy: Vec, - tmp: Vec, -} - -impl BandEnc<'_, '_> { - /// `compute_theta` for a mono split (single block): measures the energy split between the - /// two halves and codes the quantised angle with the triangular pdf. - fn compute_theta_split(&mut self, xa: &[f32], xb: &[f32], b: &mut i32, lm: i32) -> (i32, i32, i32) { - let n = xa.len() as i32; - let i = self.i; - let pulse_cap = self.m.log_n[i] + lm * (1 << BITRES); - let offset = (pulse_cap >> 1) - QTHETA_OFFSET; - let qn = compute_qn(n, *b, offset, pulse_cap, false); - let tell = self.enc.tell_frac(); - let mut itheta = 0i32; - if qn != 1 { - let mid = xa.iter().map(|v| v * v).sum::().sqrt(); - let side = xb.iter().map(|v| v * v).sum::().sqrt(); - let ang = (side as f64).atan2(mid as f64) * std::f64::consts::FRAC_2_PI; - let it = ((ang * qn as f64 + 0.5).floor() as i32).clamp(0, qn) as u32; - let q = qn as u32; - let half = q >> 1; - let ft = (half + 1) * (half + 1); - let (fl, fs) = if it <= half { ((it * (it + 1)) >> 1, it + 1) } else { (ft - (((q + 1 - it) * (q + 2 - it)) >> 1), q + 1 - it) }; - self.enc.encode(fl, fl + fs, ft); - itheta = ((it * 16384) / q) as i32; - } - let qalloc = self.enc.tell_frac() - tell; - *b -= qalloc; - let delta = if itheta == 0 { - -16384 - } else if itheta == 16384 { - 16384 - } else { - let imid = bitexact_cos(itheta); - let iside = bitexact_cos(16384 - itheta); - frac_mul16((n - 1) << 7, bitexact_log2tan(iside, imid)) - }; - (itheta, delta, qalloc) - } - - /// `quant_partition` (single block, encoder side). - pub fn quant_partition(&mut self, x: &[f32], mut b: i32, mut lm: i32) { - let n = x.len(); - let i = self.i; - let cache = self.m.cache(lm, i); - let cache_max = cache[cache[0] as usize] as i32; - if lm != -1 && b > cache_max + 12 && n > 2 { - let half = n >> 1; - let (xa, xb) = x.split_at(half); - lm -= 1; - let (itheta, delta, qalloc) = self.compute_theta_split(xa, xb, &mut b, lm); - let mut mbits = 0.max(b.min((b - delta) / 2)); - let mut sbits = b - mbits; - self.remaining_bits -= qalloc; - let mut rebalance = self.remaining_bits; - if mbits >= sbits { - self.quant_partition(xa, mbits, lm); - rebalance = mbits - (rebalance - self.remaining_bits); - if rebalance > 3 << BITRES && itheta != 0 { - sbits += rebalance - (3 << BITRES); - } - self.quant_partition(xb, sbits, lm); - } else { - self.quant_partition(xb, sbits, lm); - rebalance = sbits - (rebalance - self.remaining_bits); - if rebalance > 3 << BITRES && itheta != 16384 { - mbits += rebalance - (3 << BITRES); - } - self.quant_partition(xa, mbits, lm); - } - return; - } - let m = self.m; - let mut q = m.bits2pulses(i, lm, b); - let mut curr_bits = m.pulses2bits(i, lm, q); - self.remaining_bits -= curr_bits; - while self.remaining_bits < 0 && q > 0 { - self.remaining_bits += curr_bits; - q -= 1; - curr_bits = m.pulses2bits(i, lm, q); - self.remaining_bits -= curr_bits; - } - if q != 0 { - let k = get_pulses(q) as usize; - let mut tmp = std::mem::take(&mut self.tmp); - tmp.clear(); - tmp.extend_from_slice(x); - exp_rotation_inv(&mut tmp, n, k, self.spread); - let mut iy = std::mem::take(&mut self.iy); - iy.clear(); - iy.resize(n, 0); - pvq_search(&tmp, k, &mut iy); - encode_pulses(&iy, k, self.enc); - self.iy = iy; - self.tmp = tmp; - } - } -} - -/// Shape-coding controls, independent of the selected band allocation. -pub struct BandCoding { - pub spread: usize, - pub total_bits: i32, -} - -/// Codes all band shapes (`quant_all_bands`, encoder side, long blocks). `x` holds -/// `frame.channels` channels of `n_total` normalised MDCT coefficients each. -pub fn quant_all_bands(m: &Mode, frame: CeltFrame, x: &[f32], n_total: usize, allocation: &Allocation, coding: BandCoding, enc: &mut RangeEncoder) { - let CeltFrame { start, end, channels: c, lm } = frame; - let Allocation { pulses, dual_stereo, intensity, coded_bands, balance, .. } = allocation; - let (dual_stereo, intensity, coded_bands, mut balance) = (*dual_stereo, *intensity, *coded_bands, *balance); - let BandCoding { spread, total_bits } = coding; - let mm = 1usize << lm; - debug_assert!(c == 1 || dual_stereo || intensity <= start, "stereo frames are coded as dual stereo"); - let mut ctx = BandEnc { m, enc, i: 0, spread, remaining_bits: 0, iy: Vec::new(), tmp: Vec::new() }; - for i in start..end { - ctx.i = i; - let xo = mm * EBANDS[i] as usize; - let n = mm * EBANDS[i + 1] as usize - xo; - let tell = ctx.enc.tell_frac(); - if i != start { - balance -= tell; - } - let remaining_bits = total_bits - tell - 1; - ctx.remaining_bits = remaining_bits; - let b = if i < coded_bands { - let curr_balance = balance / 3.min(coded_bands as i32 - i as i32); - 0.max(16383.min((remaining_bits + 1).min(pulses[i] + curr_balance))) - } else { - 0 - }; - // Bands at and above `intensity` (= coded_bands) carry no bits, so they emit no symbols. - if i < coded_bands || c == 1 { - if c == 2 && dual_stereo && i < intensity { - ctx.quant_partition(&x[xo..xo + n], b / 2, lm as i32); - ctx.quant_partition(&x[n_total + xo..n_total + xo + n], b / 2, lm as i32); - } else { - ctx.quant_partition(&x[xo..xo + n], b, lm as i32); - } - } - balance += pulses[i] + tell; - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::range::dec::RangeDecoder; - - fn exp_rotation1(x: &mut [f32], len: usize, stride: usize, c: f32, s: f32) { - let ms = -s; - if len <= stride { - return; - } - for i in 0..len - stride { - let x1 = x[i]; - let x2 = x[i + stride]; - x[i + stride] = c * x2 + s * x1; - x[i] = c * x1 + ms * x2; - } - if len > 2 * stride { - for i in (0..=len - 2 * stride - 1).rev() { - let x1 = x[i]; - let x2 = x[i + stride]; - x[i + stride] = c * x2 + s * x1; - x[i] = c * x1 + ms * x2; - } - } - } - - /// The decoder's spreading rotation (single block). - fn exp_rotation(x: &mut [f32], len: usize, k: usize, spread: usize) { - const SPREAD_FACTOR: [usize; 3] = [15, 10, 5]; - if 2 * k >= len || spread == 0 { - return; - } - let factor = SPREAD_FACTOR[spread - 1]; - let gain = len as f32 / (len + factor * k) as f32; - let theta = 0.5 * gain * gain; - let c = (0.5 * std::f32::consts::PI * theta).cos(); - let s = (0.5 * std::f32::consts::PI * (1.0 - theta)).cos(); - let mut stride2 = 0; - if len >= 8 { - stride2 = 1; - while stride2 * stride2 + stride2 < len { - stride2 += 1; - } - } - if stride2 != 0 { - exp_rotation1(x, len, stride2, s, c); - } - exp_rotation1(x, len, 1, c, s); - } - - #[test] - fn spreading_inverse_is_exact() { - for &len in &[8usize, 16, 24, 48, 96, 176] { - for k in [1usize, 2, 3, 5] { - let orig: Vec = (0..len).map(|i| ((i * 31 % 17) as f32 - 8.0) / 8.0).collect(); - let mut x = orig.clone(); - exp_rotation_inv(&mut x, len, k, SPREAD_NORMAL); - exp_rotation(&mut x, len, k, SPREAD_NORMAL); - for (a, b) in x.iter().zip(&orig) { - assert!((a - b).abs() < 1e-4, "len={len} k={k}"); - } - } - } - } - - /// PVQ decoder of RFC 6716 §4.3.4.2 (as in FilmCraft's decoder). - fn decode_pulses(n: usize, k: usize, dec: &mut RangeDecoder) -> Vec { - let w = k + 1; - let mut v = vec![0u64; (n + 1) * w]; - v[0] = 1; - for nn in 1..=n { - v[nn * w] = 1; - for kk in 1..=k { - v[nn * w + kk] = v[(nn - 1) * w + kk].saturating_add(v[nn * w + kk - 1]).saturating_add(v[(nn - 1) * w + kk - 1]); - } - } - let total = v[n * w + k]; - let mut i = if total >= 2 { dec.uint(total as u32) as u64 } else { 0 }; - let mut y = vec![0i32; n]; - let mut kk = k; - for j in 0..n { - let rem = n - j; - if kk == 0 { - break; - } - let vv = |nn: usize, kx: usize| v[nn * w + kx]; - let mut p = (vv(rem - 1, kk) + vv(rem, kk)) / 2; - let neg = i >= p; - if neg { - i -= p; - } - let k0 = kk; - p -= vv(rem - 1, kk); - while p > i && kk > 0 { - kk -= 1; - p -= vv(rem - 1, kk); - } - let mag = (k0 - kk) as i32; - y[j] = if neg { -mag } else { mag }; - i -= p.min(i); - } - y - } - - fn all_codewords(n: usize, k: usize) -> Vec> { - if n == 0 { - return if k == 0 { vec![vec![]] } else { vec![] }; - } - let mut out = Vec::new(); - for t in -(k as i32)..=(k as i32) { - for mut rest in all_codewords(n - 1, k - t.unsigned_abs() as usize) { - rest.insert(0, t); - out.push(rest); - } - } - out - } - - #[test] - fn pvq_index_roundtrip_exhaustive() { - for n in 1..6usize { - for k in 1..6usize { - for y in all_codewords(n, k) { - let mut e = RangeEncoder::new(); - encode_pulses(&y, k, &mut e); - let buf = e.done(16); - let mut d = RangeDecoder::new(&buf); - assert_eq!(decode_pulses(n, k, &mut d), y, "n={n} k={k}"); - } - } - } - } - - /// The per-call table encoder this module used before the shared table. - fn encode_pulses_reference(y: &[i32], k: usize, enc: &mut RangeEncoder) { - let n = y.len(); - let w = k + 1; - let mut v = vec![0u64; (n + 1) * w]; - v[0] = 1; - for nn in 1..=n { - v[nn * w] = 1; - for kk in 1..=k { - let a = v[(nn - 1) * w + kk]; - let b = v[nn * w + kk - 1]; - let c = v[(nn - 1) * w + kk - 1]; - v[nn * w + kk] = a.saturating_add(b).saturating_add(c); - } - } - let total = v[n * w + k]; - let vv = |nn: usize, kx: usize| v[nn * w + kx]; - let mut index = 0u64; - let mut kk = k; - for j in 0..n { - if kk == 0 { - break; - } - let rem = n - j; - let t = y[j].unsigned_abs() as usize; - let mut base: u64 = (0..kk - t).map(|m| vv(rem - 1, m)).sum(); - if y[j] < 0 { - base += (vv(rem - 1, kk) + vv(rem, kk)) / 2; - } - index += base; - kk -= t; - } - if total >= 2 { - enc.uint(index as u32, total as u32); - } - } - - #[test] - fn pvq_table_encode_matches_per_call_table() { - let mut seed = 0x9E37_79B9_7F4A_7C15u64; - let mut next = move |m: u64| { - seed ^= seed << 13; - seed ^= seed >> 7; - seed ^= seed << 17; - seed % m - }; - let mut checked = 0; - for n in (1..=PVQ_MAX_N).step_by(5).chain([PVQ_MAX_N]) { - for k in (1..=PVQ_MAX_K).step_by(3).chain([PVQ_MAX_K]) { - if crate::rate::pvq_v(n, k) > u32::MAX as u128 { - continue; - } - for _ in 0..4 { - let mut y = vec![0i32; n]; - for _ in 0..k { - let at = next(n as u64) as usize; - y[at] += if next(2) == 0 { 1 } else { -1 }; - } - // Opposite pulses cancel; top up so that sum |y| = k again. - let mut have: usize = y.iter().map(|v| v.unsigned_abs() as usize).sum(); - while have < k { - let at = next(n as u64) as usize; - y[at] += if y[at] < 0 { -1 } else { 1 }; - have += 1; - } - let (mut a, mut b) = (RangeEncoder::new(), RangeEncoder::new()); - encode_pulses(&y, k, &mut a); - encode_pulses_reference(&y, k, &mut b); - assert_eq!(a.done(16), b.done(16), "n={n} k={k}"); - checked += 1; - } - } - } - assert!(checked > 100, "{checked}"); - } - - /// The scalar greedy search the vectorised one replaced. - fn pvq_search_ref(x: &[f32], k: usize, y: &mut [i32]) { - let n = x.len(); - y[..n].fill(0); - let abs: Vec = x.iter().map(|v| v.abs()).collect(); - let sum: f32 = abs.iter().sum(); - if !sum.is_finite() || sum <= 1e-15 { - y[0] = k as i32; - return; - } - let mut placed = 0usize; - let mut xy = 0f32; - let mut yy = 0f32; - if k > n / 2 { - let r = (k as f32 - 1.0) / sum; - for j in 0..n { - let p = (abs[j] * r).floor() as i32; - y[j] = p; - placed += p as usize; - xy += abs[j] * p as f32; - yy += (p * p) as f32; - } - } - while placed < k { - let mut best = 0usize; - let mut best_num = -1f32; - let mut best_den = 1f32; - for j in 0..n { - let num = xy + abs[j]; - let num = num * num; - let den = yy + 2.0 * y[j] as f32 + 1.0; - if num * best_den > best_num * den { - best_num = num; - best_den = den; - best = j; - } - } - xy += abs[best]; - yy += 2.0 * y[best] as f32 + 1.0; - y[best] += 1; - placed += 1; - } - for j in 0..n { - if x[j] < 0.0 { - y[j] = -y[j]; - } - } - } - - #[test] - fn pvq_search_matches_scalar_reference() { - let mut state = 0x9e3779b97f4a7c15u64; - let mut rnd = move || { - state ^= state << 13; - state ^= state >> 7; - state ^= state << 17; - (state >> 40) as f32 / (1u64 << 24) as f32 * 2.0 - 1.0 - }; - let mut a = vec![0i32; 200]; - let mut b = vec![0i32; 200]; - let mut cases = 0; - for round in 0..6000 { - let n = 1 + (round * 37 + (rnd().abs() * 176.0) as usize) % 176; - let k = 1 + (rnd().abs() * 127.0) as usize; - let scale = [1.0f32, 1e-9, 1e6, 3e-3][round % 4]; - let x: Vec = (0..n) - .map(|_| match round % 6 { - 0 => rnd(), - 1 => if rnd() > 0.8 { rnd() } else { 0.0 }, - 2 => (rnd() * 4.0).round() / 4.0, - 3 => if rnd() > 0.0 { 1.0 } else { -1.0 }, - 4 => rnd().powi(5), - _ => if rnd() > 0.95 { 3.0 * rnd() } else { 1e-4 * rnd() }, - } * scale) - .collect(); - pvq_search(&x, k, &mut a); - pvq_search_ref(&x, k, &mut b); - assert_eq!(a[..n], b[..n], "n={n} k={k} round={round}"); - cases += 1; - } - assert_eq!(cases, 6000); - } - - #[test] - fn pvq_search_finds_good_direction() { - let x: Vec = (0..32).map(|i| ((i as f32) * 0.7).sin()).collect(); - let mut y = vec![0i32; 32]; - for k in [1usize, 4, 16, 64] { - pvq_search(&x, k, &mut y); - assert_eq!(y.iter().map(|v| v.unsigned_abs() as usize).sum::(), k); - let xy: f32 = x.iter().zip(&y).map(|(a, &b)| a * b as f32).sum(); - let yy: f32 = y.iter().map(|&b| (b * b) as f32).sum(); - let xx: f32 = x.iter().map(|a| a * a).sum(); - let corr = xy / (xx * yy).sqrt(); - assert!(corr > if k >= 16 { 0.9 } else { 0.2 }, "k={k} corr={corr}"); - } - } -} diff --git a/crates/opusenc/src/energy.rs b/crates/opusenc/src/energy.rs deleted file mode 100644 index 1d4b12719..000000000 --- a/crates/opusenc/src/energy.rs +++ /dev/null @@ -1,212 +0,0 @@ -//! Band energy quantisation: Laplace-coded coarse energy with inter/intra prediction, fine -//! energy and the final refinement bits (RFC 6716 §4.3.2, encoder direction). -//! -//! The quantised energies are updated with exactly the decoder's arithmetic so the prediction -//! state never drifts between encoder and decoder. - -use crate::CeltFrame; -use crate::range::RangeEncoder; -use crate::rate::{Allocation, MAX_FINE_BITS}; -use crate::tables::{BETA_COEF, BETA_INTRA, E_PROB_MODEL, NB_EBANDS, PRED_COEF, SMALL_ENERGY_ICDF}; - -const LAPLACE_MINP: u32 = 1; -const LAPLACE_NMIN: u32 = 16; - -fn laplace_get_freq1(fs0: u32, decay: u32) -> u32 { - let ft = 32768 - LAPLACE_MINP * (2 * LAPLACE_NMIN) - fs0; - (ft * (16384 - decay)) >> 15 -} - -/// Encodes a Laplace-distributed integer (`fs` = probability of 0 in Q15, `decay` in Q14). -/// Returns the value actually coded (very large magnitudes are clamped to the representable -/// range). -pub fn laplace_encode(enc: &mut RangeEncoder, value: i32, mut fs: u32, decay: u32) -> i32 { - let mut fl = 0u32; - let mut coded = value; - if value != 0 { - let s: i32 = if value < 0 { -1 } else { 0 }; - let val = value.abs(); - fl = fs; - fs = laplace_get_freq1(fs, decay); - let mut i = 1; - while fs > 0 && i < val { - fs *= 2; - fl += fs + 2 * LAPLACE_MINP; - fs = (fs * decay) >> 15; - i += 1; - } - if fs == 0 { - let ndi_max = (32768 - fl + LAPLACE_MINP - 1) as i32; - let ndi_max = (ndi_max - s) >> 1; - let di = (val - i).min(ndi_max - 1); - fl = (fl as i32 + (2 * di + 1 + s) * LAPLACE_MINP as i32) as u32; - fs = LAPLACE_MINP.min(32768 - fl); - let mag = i + di; - coded = if s < 0 { -mag } else { mag }; - } else { - fs += LAPLACE_MINP; - if s == 0 { - fl += fs; - } - } - } - enc.encode_bin(fl, fl + fs, 15); - coded -} - -/// `quant_coarse_energy` for one prediction mode. `e` holds the target log2 energies (relative -/// to `E_MEANS`), `old_e` the quantised energies, updated in place. `budget` is the frame size in -/// bits. -pub fn quant_coarse_energy(frame: CeltFrame, e: &[f32; 2 * NB_EBANDS], old_e: &mut [f32; 2 * NB_EBANDS], intra: bool, enc: &mut RangeEncoder, budget: i32) { - let CeltFrame { start, end, channels: c, lm } = frame; - let prob = &E_PROB_MODEL[lm][intra as usize]; - let (coef, beta) = if intra { (0.0, BETA_INTRA) } else { (PRED_COEF[lm], BETA_COEF[lm]) }; - let mut prev = [0f32; 2]; - for i in start..end { - for ch in 0..c { - let idx = i + ch * NB_EBANDS; - let oldc = old_e[idx].max(-9.0); - let x = e[idx]; - let f = x - coef * oldc - prev[ch]; - let mut qi = (f + 0.5).floor().clamp(-64.0, 64.0) as i32; - let tell = enc.tell(); - // Keep a few bits per remaining band in reserve when the budget runs out. - let bits_left = budget - tell - 3 * c as i32 * (end - i) as i32; - if i != start && bits_left < 30 { - if bits_left < 24 { - qi = qi.min(1); - } - if bits_left < 16 { - qi = qi.max(-1); - } - } - if budget - tell >= 15 { - let pi = 2 * i.min(20); - qi = laplace_encode(enc, qi, (prob[pi] as u32) << 7, (prob[pi + 1] as u32) << 6); - } else if budget - tell >= 2 { - qi = qi.clamp(-1, 1); - enc.icdf(if qi < 0 { (-2 * qi - 1) as usize } else { (2 * qi) as usize }, &SMALL_ENERGY_ICDF, 2); - } else if budget - tell >= 1 { - qi = qi.clamp(-1, 0); - enc.bit_logp(qi == -1, 1); - } else { - qi = -1; - } - let q = qi as f32; - old_e[idx] = oldc; - let tmp = coef * old_e[idx] + prev[ch] + q; - old_e[idx] = tmp; - prev[ch] = prev[ch] + q - beta * q; - } - } -} - -/// `quant_fine_energy`: raw bits refining each band's quantised energy. -pub fn quant_fine_energy(frame: CeltFrame, e: &[f32; 2 * NB_EBANDS], old_e: &mut [f32; 2 * NB_EBANDS], fine_quant: &[i32; NB_EBANDS], enc: &mut RangeEncoder) { - let CeltFrame { start, end, channels: c, .. } = frame; - for i in start..end { - let fq = fine_quant[i]; - if fq <= 0 { - continue; - } - for ch in 0..c { - let idx = i + ch * NB_EBANDS; - let err = e[idx] - old_e[idx]; - let levels = 1i32 << fq; - let q2 = (((err + 0.5) * levels as f32).floor() as i32).clamp(0, levels - 1); - enc.bits(q2 as u32, fq as u32); - let offset = (q2 as f32 + 0.5) * (1 << (14 - fq)) as f32 / 16384.0 - 0.5; - old_e[idx] += offset; - } - } -} - -/// `quant_energy_finalise`: spends the bits left at the end of the frame on one more bit of -/// energy resolution per band, in priority order. -pub fn quant_energy_finalise( - frame: CeltFrame, - e: &[f32; 2 * NB_EBANDS], - old_e: &mut [f32; 2 * NB_EBANDS], - allocation: &Allocation, - mut bits_left: i32, - enc: &mut RangeEncoder, -) { - let CeltFrame { start, end, channels: c, .. } = frame; - let Allocation { fine_quant, fine_priority, .. } = allocation; - for prio in 0..2 { - let mut i = start; - while i < end && bits_left >= c as i32 { - if fine_quant[i] >= MAX_FINE_BITS || fine_priority[i] != prio { - i += 1; - continue; - } - for ch in 0..c { - let idx = i + ch * NB_EBANDS; - let q2 = (e[idx] - old_e[idx] >= 0.0) as u32; - enc.bits(q2, 1); - let offset = (q2 as f32 - 0.5) * (1 << (14 - fine_quant[i] - 1)) as f32 / 16384.0; - old_e[idx] += offset; - bits_left -= 1; - } - i += 1; - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::range::dec::RangeDecoder; - - /// Laplace decoder of RFC 6716 §4.3.2.1 (as in FilmCraft's decoder). - fn laplace_decode(dec: &mut RangeDecoder, mut fs: u32, decay: u32) -> i32 { - let mut val = 0i32; - let fm = dec.decode(32768); - let mut fl = 0u32; - if fm >= fs { - val += 1; - fl = fs; - fs = laplace_get_freq1(fs, decay) + LAPLACE_MINP; - while fs > LAPLACE_MINP && fm >= fl + 2 * fs { - fs *= 2; - fl += fs; - fs = (((fs - 2 * LAPLACE_MINP) * decay) >> 15) + LAPLACE_MINP; - val += 1; - } - if fs <= LAPLACE_MINP { - let di = (fm - fl) >> 1; - val += di as i32; - fl += 2 * di * LAPLACE_MINP; - } - if fm < fl + fs { - val = -val; - } else { - fl += fs; - } - } - dec.update(fl, (fl + fs).min(32768), 32768); - val - } - - #[test] - fn laplace_roundtrip_all_models() { - for lm in 0..4 { - for intra in 0..2 { - for band in 0..21 { - let prob = &E_PROB_MODEL[lm][intra]; - let (fs, decay) = ((prob[2 * band] as u32) << 7, (prob[2 * band + 1] as u32) << 6); - let vals: Vec = (-64..=64).collect(); - let mut e = RangeEncoder::new(); - let coded: Vec = vals.iter().map(|&v| laplace_encode(&mut e, v, fs, decay)).collect(); - let size = (e.tell() as usize).div_ceil(8); - let buf = e.done(size); - let mut d = RangeDecoder::new(&buf); - for (&v, &c) in vals.iter().zip(&coded) { - assert!(c == v || (c.signum() == v.signum() && c.abs() < v.abs()), "clamp {v} -> {c}"); - assert_eq!(laplace_decode(&mut d, fs, decay), c, "lm={lm} intra={intra} band={band} v={v}"); - } - } - } - } - } -} diff --git a/crates/opusenc/src/lib.rs b/crates/opusenc/src/lib.rs deleted file mode 100644 index b4346ebd6..000000000 --- a/crates/opusenc/src/lib.rs +++ /dev/null @@ -1,553 +0,0 @@ -//! Clean-room pure-Rust Opus encoder (RFC 6716 SILK, hybrid and CELT modes; RFC 7845 `OpusHead`). -//! -//! Produces 20 ms Opus packets from 48 kHz float input, mono or stereo. The coding mode and -//! audio bandwidth are chosen once per stream from the per-channel bitrate and the -//! [`Application`] (see the crate README for the table): -//! -//! - **SILK** (narrowband/mediumband/wideband): linear-predictive speech coding at an internal -//! rate of 8/12/16 kHz; packet sizes vary around the target bitrate. -//! - **Hybrid** (super-wideband/fullband): SILK wideband codes 0–8 kHz and CELT codes the bands -//! above in the same range-coded frame; constant packet size. -//! - **CELT** (fullband): MDCT transform coding; constant packet size. -//! -//! Layer L0: no dependencies beyond `std`; no `unsafe`; builds for `wasm32-unknown-unknown`. -//! -//! ``` -//! use effectcraft_opusenc::{Application, Mode, OpusEncoder}; -//! let mut enc = OpusEncoder::new(2, 128_000); -//! let pcm = vec![0.0f32; OpusEncoder::FRAME_SIZE * 2]; -//! let packet = enc.encode_float(&pcm); -//! assert_eq!(packet[0] >> 3, 31); // CELT-only, fullband, 20 ms -//! assert_eq!(enc.opus_head().len(), 19); -//! let voip = OpusEncoder::with_application(1, 16_000, Application::Voip); -//! assert_eq!(voip.mode(), Mode::Silk); -//! ``` - -#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] - -mod bands; -mod energy; -mod mdct; -mod range; -mod rate; -mod resample; -mod silk; -mod tables; - -use std::sync::OnceLock; - -use bands::{BandCoding, SPREAD_NORMAL, quant_all_bands}; -use energy::{quant_coarse_energy, quant_energy_finalise, quant_fine_energy}; -use mdct::Mdct; -use range::{BITRES, RangeEncoder}; -use rate::{AllocationInput, Mode as CeltMode, compute_allocation}; -use resample::Downsampler; -use silk::SilkEncoder; -use tables::{E_MEANS, EBANDS, NB_EBANDS, OVERLAP, PREEMPH, SPREAD_ICDF, TF_SELECT_TABLE, TRIM_ICDF}; - -/// Band range, channel count and transform size shared by CELT coding stages. -#[derive(Clone, Copy)] -struct CeltFrame { - start: usize, - end: usize, - channels: usize, - lm: usize, -} - -/// Samples per channel in one 20 ms frame at 48 kHz. -const N: usize = 960; -/// LM of a 20 ms frame (8 short blocks). -const LM: usize = 3; -/// Smallest CELT payload the encoder produces (bytes). -const MIN_FRAME_BYTES: usize = 16; -/// Largest payload allowed in one frame (RFC 6716 §3.4, R2). -const MAX_FRAME_BYTES: usize = 1275; -/// First CELT band coded in hybrid frames (8 kHz). -const HYBRID_START_BAND: usize = 17; - -fn celt_mode() -> &'static CeltMode { - static MODE: OnceLock = OnceLock::new(); - MODE.get_or_init(CeltMode::new) -} - -/// Intended use of the stream; selects the mode/bandwidth table. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -pub enum Application { - /// General audio (music, mixed content): CELT unless the bitrate is low. - #[default] - Audio, - /// Speech: SILK and hybrid over a wider bitrate range, narrower bandwidths at low rates. - Voip, -} - -/// Opus coding mode (RFC 6716 §2). -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum Mode { - /// MDCT transform coding only. - Celt, - /// Linear-prediction coding only. - Silk, - /// SILK below 8 kHz plus CELT above. - Hybrid, -} - -/// Coded audio bandwidth (RFC 6716 §2, Table 1). -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum Bandwidth { - /// 4 kHz (8 kHz sampling). - Narrowband, - /// 6 kHz (12 kHz sampling). - Mediumband, - /// 8 kHz (16 kHz sampling). - Wideband, - /// 12 kHz (24 kHz sampling). - SuperWideband, - /// 20 kHz (48 kHz sampling). - Fullband, -} - -/// Mode and bandwidth for a per-channel bitrate (bits per second per channel). -fn choose_mode(app: Application, per_channel: u32) -> (Mode, Bandwidth) { - match app { - Application::Voip => match per_channel { - 0..10_000 => (Mode::Silk, Bandwidth::Narrowband), - 10_000..12_000 => (Mode::Silk, Bandwidth::Mediumband), - 12_000..18_000 => (Mode::Silk, Bandwidth::Wideband), - 18_000..28_000 => (Mode::Hybrid, Bandwidth::SuperWideband), - 28_000..40_000 => (Mode::Hybrid, Bandwidth::Fullband), - _ => (Mode::Celt, Bandwidth::Fullband), - }, - Application::Audio => match per_channel { - 0..16_000 => (Mode::Silk, Bandwidth::Wideband), - 16_000..36_000 => (Mode::Hybrid, Bandwidth::Fullband), - _ => (Mode::Celt, Bandwidth::Fullband), - }, - } -} - -/// SILK side of a SILK-only or hybrid stream. -struct SilkPath { - enc: SilkEncoder, - down: Vec, - /// Bits per frame aimed at (excluding the TOC byte in SILK-only mode). - target_bits: f64, - /// Bits saved (positive) or overspent by previous frames (SILK-only mode). - reservoir: f64, -} - -/// Opus encoder for one mono or stereo stream at 48 kHz. -pub struct OpusEncoder { - channels: usize, - application: Application, - mode: Mode, - bandwidth: Bandwidth, - /// Requested bitrate (clamped), bits per second. - bitrate_bps: u32, - /// Payload bytes per packet in CELT and hybrid modes (the packet is one byte longer: the - /// TOC). - frame_bytes: usize, - mdct: Mdct, - /// Last input sample of each channel (pre-emphasis filter memory, ×32768). - preemph_mem: [f32; 2], - /// Last `OVERLAP` pre-emphasised samples of each channel. - hist: Vec, - /// Quantised band energies, exactly as the decoder holds them. - old_band_e: [f32; 2 * NB_EBANDS], - block: Vec, - freq: Vec, - silk: Option, -} - -impl OpusEncoder { - /// Samples per channel per packet (20 ms at 48 kHz). - pub const FRAME_SIZE: usize = N; - - /// Creates a general-audio encoder ([`Application::Audio`]) for `channels` (1 or 2) - /// channels of 48 kHz audio at `bitrate_bps` (total for all channels). - pub fn new(channels: u8, bitrate_bps: u32) -> Self { - Self::with_application(channels, bitrate_bps, Application::Audio) - } - - /// Creates an encoder for `channels` (1 or 2) channels of 48 kHz audio at `bitrate_bps` - /// (total for all channels; clamped to 6 kb/s per channel – 510 kb/s), choosing the mode - /// and bandwidth for `application`. - pub fn with_application(channels: u8, bitrate_bps: u32, application: Application) -> Self { - let c = channels.max(1) as u32; - let (mode, bandwidth) = choose_mode(application, bitrate_bps.clamp(6_000 * c, 510_000) / c); - Self::build(channels, bitrate_bps, application, mode, bandwidth) - } - - /// Creates an encoder with an explicit mode and bandwidth instead of the application's - /// table. Valid combinations: SILK with narrowband, mediumband or wideband; hybrid with - /// super-wideband or fullband; CELT with fullband. - /// - /// # Panics - /// On any other combination, or when `channels` is not 1 or 2. - pub fn with_mode(channels: u8, bitrate_bps: u32, mode: Mode, bandwidth: Bandwidth) -> Self { - let ok = match mode { - Mode::Silk => bandwidth <= Bandwidth::Wideband, - Mode::Hybrid => bandwidth >= Bandwidth::SuperWideband, - Mode::Celt => bandwidth == Bandwidth::Fullband, - }; - assert!(ok, "unsupported mode/bandwidth combination {mode:?}/{bandwidth:?}"); - Self::build(channels, bitrate_bps, Application::Audio, mode, bandwidth) - } - - fn build(channels: u8, bitrate_bps: u32, application: Application, mode: Mode, bandwidth: Bandwidth) -> Self { - assert!(channels == 1 || channels == 2, "Opus family-0 streams have 1 or 2 channels"); - let c = channels as usize; - let bitrate_bps = bitrate_bps.clamp(6_000 * c as u32, 510_000); - let packet_bytes = (bitrate_bps as usize).div_ceil(400); - let frame_bytes = packet_bytes.saturating_sub(1).clamp(MIN_FRAME_BYTES, MAX_FRAME_BYTES); - let silk = match mode { - Mode::Celt => None, - Mode::Silk | Mode::Hybrid => { - let fs_khz = match bandwidth { - Bandwidth::Narrowband => 8, - Bandwidth::Mediumband => 12, - _ => 16, - }; - let target_bits = if mode == Mode::Silk { - bitrate_bps as f64 / 50.0 - 8.0 - } else { - // SILK gets most of a hybrid packet; CELT codes 8 kHz and up with the rest. - let per = (bitrate_bps / c as u32) as f64; - let share = if bandwidth == Bandwidth::SuperWideband { 0.72 } else { 0.62 }; - c as f64 * (per * share).min(per - 6_000.0).max(per * 0.5) / 50.0 - }; - Some(SilkPath { - enc: SilkEncoder::new(fs_khz, c), - down: (0..c).map(|_| Downsampler::new(fs_khz as u32 * 1000)).collect(), - target_bits, - reservoir: 0.0, - }) - } - }; - OpusEncoder { - channels: c, - application, - mode, - bandwidth, - bitrate_bps, - frame_bytes, - mdct: Mdct::new(N), - preemph_mem: [0.0; 2], - hist: vec![0.0; c * OVERLAP], - old_band_e: [0.0; 2 * NB_EBANDS], - block: vec![0.0; N + OVERLAP], - freq: vec![0.0; c * N], - silk, - } - } - - /// Number of channels. - pub fn channels(&self) -> u8 { - self.channels as u8 - } - - /// The application the encoder was created for. - pub fn application(&self) -> Application { - self.application - } - - /// Coding mode of every packet of the stream. - pub fn mode(&self) -> Mode { - self.mode - } - - /// Coded audio bandwidth of every packet of the stream. - pub fn bandwidth(&self) -> Bandwidth { - self.bandwidth - } - - /// Bitrate in bits per second: the constant packet size × 50 packets per second in CELT - /// and hybrid modes, the (average) target in SILK mode. - pub fn bitrate(&self) -> u32 { - match self.mode { - Mode::Silk => self.bitrate_bps, - _ => ((self.frame_bytes + 1) * 8 * 50) as u32, - } - } - - /// Samples at 48 kHz the decoder must discard from the start of the stream (the `OpusHead` - /// pre-skip): the encoder's total delay. CELT: the 120-sample MDCT overlap. SILK/hybrid: - /// the decimator (83 samples, 88 for narrowband) plus the decoder's SILK delay (one - /// internal-rate sample and the resampler delay of RFC 6716 Table 54), which also rounds - /// to 120 samples. - pub fn pre_skip(&self) -> u16 { - let (fs, table54_ms) = match (self.mode, self.bandwidth) { - (Mode::Celt, _) => return OVERLAP as u16, - (_, Bandwidth::Narrowband) => (8_000, 0.538), - (_, Bandwidth::Mediumband) => (12_000, 0.692), - _ => (16_000, 0.706), - }; - (resample::delay(fs) as f64 + 48_000.0 / fs as f64 + table54_ms * 48.0).round() as u16 - } - - /// The 19-byte `OpusHead` identification header (RFC 7845 §5.1): version 1, channel count, - /// pre-skip, input sample rate 48000, output gain 0, channel mapping family 0. - pub fn opus_head(&self) -> Vec { - let mut h = Vec::with_capacity(19); - h.extend_from_slice(b"OpusHead"); - h.push(1); - h.push(self.channels as u8); - h.extend_from_slice(&self.pre_skip().to_le_bytes()); - h.extend_from_slice(&48_000u32.to_le_bytes()); - h.extend_from_slice(&0i16.to_le_bytes()); - h.push(0); - h - } - - /// TOC byte (RFC 6716 §3.1, Table 2) of a 20 ms single-frame packet. - fn toc(&self) -> u8 { - let config: u8 = match (self.mode, self.bandwidth) { - (Mode::Silk, Bandwidth::Narrowband) => 1, - (Mode::Silk, Bandwidth::Mediumband) => 5, - (Mode::Silk, _) => 9, - (Mode::Hybrid, Bandwidth::SuperWideband) => 13, - (Mode::Hybrid, _) => 15, - (Mode::Celt, _) => 31, - }; - (config << 3) | if self.channels == 2 { 4 } else { 0 } - } - - /// Encodes one 20 ms frame of interleaved f32 samples in [-1, 1] (exactly - /// `FRAME_SIZE * channels` values) and returns one Opus packet. - pub fn encode_float(&mut self, pcm: &[f32]) -> Vec { - let c = self.channels; - assert_eq!(pcm.len(), N * c, "encode_float takes exactly FRAME_SIZE samples per channel"); - let mut packet = vec![self.toc()]; - match self.mode { - Mode::Celt => { - let (log_e, silence) = self.celt_analysis(pcm); - let len = self.frame_bytes; - packet.extend_from_slice(&self.encode_celt(RangeEncoder::new(), len, 0..NB_EBANDS, &log_e, silence)); - } - Mode::Silk => { - let x = self.silk_input(pcm); - // The SILK state exists whenever the mode uses SILK (set with the mode). - if let Some(sp) = self.silk.as_mut() { - let target = sp.target_bits + 0.25 * sp.reservoir; - let mut enc = RangeEncoder::new(); - sp.enc.encode(&x, target.max(24.0), (MAX_FRAME_BYTES * 8) as i32, &mut enc); - let bytes = (enc.tell() as usize).div_ceil(8).max(2); - let lim = 4.0 * sp.target_bits; - sp.reservoir = (sp.reservoir + sp.target_bits - (bytes * 8) as f64).clamp(-lim, lim); - packet.extend_from_slice(&enc.done(bytes)); - } - } - Mode::Hybrid => { - let x = self.silk_input(pcm); - let len = self.frame_bytes; - let total = (len * 8) as i32; - let celt_min = (total / 5).max(80); - let mut enc = RangeEncoder::new(); - if let Some(sp) = self.silk.as_mut() { - sp.enc.encode(&x, sp.target_bits, total - celt_min, &mut enc); - } - // No redundancy (RFC 6716 §4.5.1); the flag is present when there is room. - if enc.tell() + 17 + 20 <= total { - enc.bit_logp(false, 12); - } - let (log_e, _) = self.celt_analysis(pcm); - let end = if self.bandwidth == Bandwidth::SuperWideband { 19 } else { NB_EBANDS }; - packet.extend_from_slice(&self.encode_celt(enc, len, HYBRID_START_BAND..end, &log_e, false)); - } - } - packet - } - - /// Decimates the input to the SILK internal rate (16-bit scale), one vector per channel. - fn silk_input(&mut self, pcm: &[f32]) -> Vec> { - let c = self.channels; - let Some(sp) = self.silk.as_mut() else { return vec![vec![]; c] }; - let mut out = Vec::with_capacity(c); - let mut tmp = vec![0f32; N]; - for ch in 0..c { - for (j, t) in tmp.iter_mut().enumerate() { - let s = pcm[j * c + ch]; - *t = if s.is_finite() { s.clamp(-1.0, 1.0) * 32768.0 } else { 0.0 }; - } - let mut y = Vec::with_capacity(N / 3); - sp.down[ch].process(&tmp, &mut y); - out.push(y); - } - out - } - - /// Pre-emphasis, the MDCT, band energies (log2, relative to `E_MEANS`) and normalised - /// bands; returns the energies and whether the frame is digital silence. - fn celt_analysis(&mut self, pcm: &[f32]) -> ([f32; 2 * NB_EBANDS], bool) { - let c = self.channels; - let mut log_e = [0f32; 2 * NB_EBANDS]; - let mut peak = 0f32; - for ch in 0..c { - self.block[..OVERLAP].copy_from_slice(&self.hist[ch * OVERLAP..(ch + 1) * OVERLAP]); - let mut mem = self.preemph_mem[ch]; - for j in 0..N { - let s = pcm[j * c + ch]; - let s = if s.is_finite() { s.clamp(-2.0, 2.0) * 32768.0 } else { 0.0 }; - let v = s - PREEMPH * mem; - mem = s; - self.block[OVERLAP + j] = v; - } - self.preemph_mem[ch] = mem; - self.hist[ch * OVERLAP..(ch + 1) * OVERLAP].copy_from_slice(&self.block[N..]); - peak = self.block.iter().fold(peak, |p, v| p.max(v.abs())); - let freq = &mut self.freq[ch * N..(ch + 1) * N]; - self.mdct.forward(&self.block, freq); - for i in 0..NB_EBANDS { - let lo = (EBANDS[i] as usize) << LM; - let hi = (EBANDS[i + 1] as usize) << LM; - let e = (1e-27f32 + freq[lo..hi].iter().map(|v| v * v).sum::()).sqrt(); - log_e[ch * NB_EBANDS + i] = e.log2() - E_MEANS[i]; - let g = 1.0 / e; - for v in freq[lo..hi].iter_mut() { - *v *= g; - } - } - } - (log_e, peak < 1e-4) - } - - /// Codes one CELT frame (RFC 6716 §4.3, in bitstream order) of `len` bytes into `enc` - /// (which already holds the SILK frame in hybrid mode), coding bands `start..end`, and - /// finalises the frame. - fn encode_celt(&mut self, mut enc: RangeEncoder, len: usize, bands: std::ops::Range, log_e: &[f32; 2 * NB_EBANDS], silence: bool) -> Vec { - let m = celt_mode(); - let c = self.channels; - let frame = CeltFrame { start: bands.start, end: bands.end, channels: c, lm: LM }; - let CeltFrame { start, end, .. } = frame; - if c == 1 { - for i in 0..NB_EBANDS { - self.old_band_e[i] = self.old_band_e[i].max(self.old_band_e[NB_EBANDS + i]); - } - } - if silence && start == 0 { - // The silence flag; the decoder treats every remaining bit as consumed. - enc.bit_logp(true, 15); - self.old_band_e = [-28.0; 2 * NB_EBANDS]; - return enc.done(2); - } - let total_bits_raw = len as i32 * 8; - if enc.tell() == 1 { - enc.bit_logp(false, 15); - } - // No pitch post-filter (only signalled in CELT-only frames). - if start == 0 && enc.tell() + 16 <= total_bits_raw { - enc.bit_logp(false, 1); - } - // Long blocks only. - if enc.tell() + 3 <= total_bits_raw { - enc.bit_logp(false, 3); - } - // Coarse energy, choosing intra or inter prediction by trial (whichever is cheaper). - if enc.tell() + 3 <= total_bits_raw { - let mut enc_intra = enc.clone(); - let mut old_intra = self.old_band_e; - enc_intra.bit_logp(true, 3); - quant_coarse_energy(frame, log_e, &mut old_intra, true, &mut enc_intra, total_bits_raw); - enc.bit_logp(false, 3); - let mut old_inter = self.old_band_e; - quant_coarse_energy(frame, log_e, &mut old_inter, false, &mut enc, total_bits_raw); - if enc_intra.tell_frac() < enc.tell_frac() { - enc = enc_intra; - self.old_band_e = old_intra; - } else { - self.old_band_e = old_inter; - } - } else { - quant_coarse_energy(frame, log_e, &mut self.old_band_e, false, &mut enc, total_bits_raw); - } - // TF resolution: no changes. - { - let mut budget = total_bits_raw; - let mut tell = enc.tell(); - let mut logp = 4; - let tf_select_rsv = LM > 0 && tell + logp < budget; - budget -= tf_select_rsv as i32; - for _ in start..end { - if tell + logp <= budget { - enc.bit_logp(false, logp as u32); - tell = enc.tell(); - } - logp = 5; - } - if tf_select_rsv && TF_SELECT_TABLE[LM][0] != TF_SELECT_TABLE[LM][2] { - enc.bit_logp(false, 1); - } - } - if enc.tell() + 4 <= total_bits_raw { - enc.icdf(SPREAD_NORMAL, &SPREAD_ICDF, 5); - } - // Dynamic allocation: no boosts. - let cap = m.init_caps(LM, c); - let offsets = [0i32; NB_EBANDS]; - let total_bits = total_bits_raw << BITRES; - let mut tellf = enc.tell_frac(); - for &cp in cap.iter().take(end).skip(start) { - if tellf + (6 << BITRES) < total_bits && 0 < cp { - enc.bit_logp(false, 6); - tellf = enc.tell_frac(); - } - } - let alloc_trim = 5; - if tellf + (6 << BITRES) <= total_bits { - enc.icdf(alloc_trim as usize, &TRIM_ICDF, 7); - } - let bits = (total_bits_raw << BITRES) - enc.tell_frac() - 1; - let alloc = compute_allocation(m, frame, AllocationInput { offsets: &offsets, cap: &cap, trim: alloc_trim, bits }, &mut enc); - quant_fine_energy(frame, log_e, &mut self.old_band_e, &alloc.fine_quant, &mut enc); - quant_all_bands(m, frame, &self.freq, N, &alloc, BandCoding { spread: SPREAD_NORMAL, total_bits: total_bits_raw << BITRES }, &mut enc); - let bits_left = total_bits_raw - enc.tell(); - quant_energy_finalise(frame, log_e, &mut self.old_band_e, &alloc, bits_left, &mut enc); - debug_assert!(enc.tell() <= total_bits_raw, "frame overflow: {} > {}", enc.tell(), total_bits_raw); - if c == 1 { - let (a, b) = self.old_band_e.split_at_mut(NB_EBANDS); - b.copy_from_slice(a); - } - // The decoder forgets the energies of bands it did not code. - for ch in 0..2 { - for i in (0..start).chain(end..NB_EBANDS) { - self.old_band_e[ch * NB_EBANDS + i] = 0.0; - } - } - enc.done(len) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn opus_head_layout() { - let e = OpusEncoder::new(2, 96_000); - let h = e.opus_head(); - assert_eq!(&h[..8], b"OpusHead"); - assert_eq!(h[8], 1); - assert_eq!(h[9], 2); - assert_eq!(u16::from_le_bytes([h[10], h[11]]), e.pre_skip()); - assert_eq!(u32::from_le_bytes([h[12], h[13], h[14], h[15]]), 48_000); - assert_eq!(&h[16..], &[0, 0, 0]); - } - - #[test] - fn packet_sizes_follow_bitrate() { - for (ch, rate) in [(1u8, 64_000u32), (2, 128_000), (2, 256_000)] { - let mut e = OpusEncoder::new(ch, rate); - let pcm: Vec = (0..N * ch as usize).map(|i| (i as f32 * 0.05).sin() * 0.5).collect(); - let p = e.encode_float(&pcm); - assert_eq!(p.len(), rate as usize / 400); - assert_eq!(p[0], 0xF8 | if ch == 2 { 4 } else { 0 }); - assert_eq!(e.bitrate(), rate); - } - } - - #[test] - fn silence_is_a_tiny_packet() { - let mut e = OpusEncoder::new(1, 64_000); - let p = e.encode_float(&vec![0.0; N]); - assert_eq!(p.len(), 3); - } -} diff --git a/crates/opusenc/src/mdct.rs b/crates/opusenc/src/mdct.rs deleted file mode 100644 index 131c4a7a1..000000000 --- a/crates/opusenc/src/mdct.rs +++ /dev/null @@ -1,363 +0,0 @@ -//! Forward MDCT with the CELT low-overlap window (RFC 6716 §4.3.7, run in the analysis -//! direction). -//! -//! A 20 ms frame is a 1920-point MDCT (960 coefficients) whose window is zero for 420 samples, -//! rises over the 120-sample overlap, is flat for 840 samples, falls over the next 120 samples -//! and is zero again for the last 420. The input block is therefore the 120 overlap samples kept -//! from the previous frame followed by the 960 new samples. The MDCT is folded into a DCT-IV, -//! which is computed with an N/2-point complex FFT. - -use crate::tables::OVERLAP; - -#[derive(Clone, Copy, Default, Debug)] -pub struct Cpx { - pub re: f32, - pub im: f32, -} - -impl Cpx { - #[inline] - fn mul(self, o: Cpx) -> Cpx { - Cpx { re: self.re * o.re - self.im * o.im, im: self.re * o.im + self.im * o.re } - } - #[inline] - fn add(self, o: Cpx) -> Cpx { - Cpx { re: self.re + o.re, im: self.im + o.im } - } - #[inline] - fn sub(self, o: Cpx) -> Cpx { - Cpx { re: self.re - o.re, im: self.im - o.im } - } -} - -/// Mixed-radix (2, 3, 4, 5) forward complex FFT, unscaled (decimation in time, recursive). -pub struct Fft { - n: usize, - factors: Vec, - twiddle: Vec, -} - -impl Fft { - pub fn new(n: usize) -> Fft { - let mut factors = Vec::new(); - let mut m = n; - for p in [4usize, 2, 3, 5] { - while m.is_multiple_of(p) { - factors.push(p); - m /= p; - } - } - assert_eq!(m, 1, "unsupported FFT size {n}"); - let twiddle = (0..n) - .map(|k| { - let ph = -2.0 * std::f64::consts::PI * k as f64 / n as f64; - Cpx { re: ph.cos() as f32, im: ph.sin() as f32 } - }) - .collect(); - Fft { n, factors, twiddle } - } - - pub fn process(&self, data: &mut [Cpx], scratch: &mut Vec) { - scratch.clear(); - scratch.extend_from_slice(&data[..self.n]); - self.rec(&mut data[..self.n], scratch, 1, self.n, 0, 1); - } - - fn rec(&self, out: &mut [Cpx], inp: &[Cpx], in_stride: usize, n: usize, fi: usize, tw_stride: usize) { - let p = self.factors[fi]; - let m = n / p; - if m == 1 { - for (i, o) in out.iter_mut().enumerate().take(p) { - *o = inp[i * in_stride]; - } - } else { - for q in 0..p { - self.rec(&mut out[q * m..(q + 1) * m], &inp[q * in_stride..], in_stride * p, m, fi + 1, tw_stride * p); - } - } - // The twiddle index q * k * tw_stride is always below n, so no modulo is needed. - let tw = &self.twiddle; - match p { - 2 => { - for k in 0..m { - let a0 = out[k]; - let a1 = out[m + k].mul(tw[k * tw_stride]); - out[k] = a0.add(a1); - out[m + k] = a0.sub(a1); - } - } - 4 => { - for k in 0..m { - let t0 = out[k]; - let t1 = out[m + k].mul(tw[k * tw_stride]); - let t2 = out[2 * m + k].mul(tw[2 * k * tw_stride]); - let t3 = out[3 * m + k].mul(tw[3 * k * tw_stride]); - let (s0, d0) = (t0.add(t2), t0.sub(t2)); - let (s1, d1) = (t1.add(t3), t1.sub(t3)); - out[k] = s0.add(s1); - out[2 * m + k] = s0.sub(s1); - // The odd outputs combine d0 with -j * d1 = (d1.im, -d1.re) and its negative. - out[m + k] = Cpx { re: d0.re + d1.im, im: d0.im - d1.re }; - out[3 * m + k] = Cpx { re: d0.re - d1.im, im: d0.im + d1.re }; - } - } - 3 => { - // Imaginary part of exp(-2 pi i / 3) = -sqrt(3) / 2. - let h = tw[self.n / 3].im; - for k in 0..m { - let t0 = out[k]; - let t1 = out[m + k].mul(tw[k * tw_stride]); - let t2 = out[2 * m + k].mul(tw[2 * k * tw_stride]); - let (s, d) = (t1.add(t2), t1.sub(t2)); - let a = Cpx { re: t0.re - 0.5 * s.re, im: t0.im - 0.5 * s.im }; - out[k] = t0.add(s); - // j * h * d = (-h * d.im, h * d.re) - out[m + k] = Cpx { re: a.re - h * d.im, im: a.im + h * d.re }; - out[2 * m + k] = Cpx { re: a.re + h * d.im, im: a.im - h * d.re }; - } - } - _ => { - // Generic DFT butterfly (radix 5, once per transform). - let roots: [Cpx; 5] = std::array::from_fn(|q| if q < p { tw[q * (self.n / p)] } else { Cpx::default() }); - let mut t = [Cpx::default(); 5]; - for k in 0..m { - t[0] = out[k]; - for q in 1..p { - t[q] = out[q * m + k].mul(tw[q * k * tw_stride]); - } - for q2 in 0..p { - let mut acc = t[0]; - for q in 1..p { - acc = acc.add(t[q].mul(roots[(q * q2) % p])); - } - out[q2 * m + k] = acc; - } - } - } - } - } -} - -/// Forward MDCT producing `n` coefficients from a block of `n + OVERLAP` samples. -pub struct Mdct { - /// Number of coefficients (half the MDCT length). - n: usize, - fft: Fft, - pre: Vec, - post: Vec, - /// Rising half of the low-overlap window (RFC 6716 §4.3.7). - pub window: [f32; OVERLAP], - scale: f32, - z: Vec, - scratch: Vec, - v: Vec, -} - -impl Mdct { - pub fn new(n: usize) -> Mdct { - let n2 = n / 2; - let pi = std::f64::consts::PI; - let pre = (0..n2) - .map(|m| { - let ph = -pi * m as f64 / n as f64; - Cpx { re: ph.cos() as f32, im: ph.sin() as f32 } - }) - .collect(); - let post = (0..n2) - .map(|p| { - let ph = -pi * (p as f64 + 0.25) / n as f64; - Cpx { re: ph.cos() as f32, im: ph.sin() as f32 } - }) - .collect(); - let mut window = [0f32; OVERLAP]; - for (i, w) in window.iter_mut().enumerate() { - let x = std::f64::consts::FRAC_PI_2 * (i as f64 + 0.5) / OVERLAP as f64; - let s = x.sin(); - *w = (std::f64::consts::FRAC_PI_2 * s * s).sin() as f32; - } - Mdct { n, fft: Fft::new(n2), pre, post, window, scale: 2.0 / n as f32, z: Vec::new(), scratch: Vec::new(), v: vec![0.0; n] } - } - - /// Transforms `block` (`n + OVERLAP` samples: the previous frame's last `OVERLAP` samples, then - /// `n` new ones) into `out[..n]`, scaled so that the RFC 6716 decoder's inverse MDCT and - /// overlap-add reproduce the input. - pub fn forward(&mut self, block: &[f32], out: &mut [f32]) { - let n = self.n; - let n2 = n / 2; - debug_assert_eq!(block.len(), n + OVERLAP); - // Place the windowed block into the (virtual) 2n-sample MDCT input u at offset `pad`. - let pad = (n - OVERLAP) / 2; - let w = &self.window; - let u = |t: usize| -> f32 { - if t < pad || t >= pad + n + OVERLAP { - return 0.0; - } - let j = t - pad; - let g = if j < OVERLAP { - w[j] - } else if j >= n { - w[OVERLAP - 1 - (j - n)] - } else { - 1.0 - }; - block[j] * g - }; - // Fold to a DCT-IV input: v = (-c_r - d, a - b_r) over the four quarters of u. - for m in 0..n2 { - self.v[m] = -u(n + n2 - 1 - m) - u(n + n2 + m); - self.v[n2 + m] = u(m) - u(n2 + n2 - 1 - m); - } - // DCT-IV via an n/2-point complex FFT. - self.z.clear(); - for m in 0..n2 { - let wv = Cpx { re: self.v[2 * m], im: self.v[n - 1 - 2 * m] }; - self.z.push(wv.mul(self.pre[m])); - } - self.fft.process(&mut self.z, &mut self.scratch); - for p in 0..n2 { - let y = self.z[p].mul(self.post[p]); - out[2 * p] = y.re * self.scale; - out[n - 1 - 2 * p] = -y.im * self.scale; - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - /// Direct MDCT definition X[k] = sum u[t] cos(pi/N (t + 1/2 + N/2)(k + 1/2)). - fn direct(block: &[f32], n: usize, window: &[f32; OVERLAP]) -> Vec { - let pad = (n - OVERLAP) / 2; - let mut u = vec![0f64; 2 * n]; - for (j, &b) in block.iter().enumerate() { - let g = if j < OVERLAP { - window[j] - } else if j >= n { - window[OVERLAP - 1 - (j - n)] - } else { - 1.0 - }; - u[pad + j] = (b * g) as f64; - } - (0..n) - .map(|k| { - (0..2 * n).map(|t| u[t] * (std::f64::consts::PI / n as f64 * (t as f64 + 0.5 + n as f64 / 2.0) * (k as f64 + 0.5)).cos()).sum::() * 2.0 - / n as f64 - }) - .collect() - } - - #[test] - fn fft_matches_dft() { - // Every radix combination, including the 480-point size of the 20 ms frame. - for &n in &[2usize, 3, 4, 5, 6, 8, 12, 15, 16, 20, 24, 30, 48, 60, 120, 240, 480] { - let fft = Fft::new(n); - let x: Vec = (0..n).map(|i| Cpx { re: ((i * 37 % 101) as f32 - 50.0) / 7.0, im: ((i * 53 % 89) as f32 - 44.0) / 9.0 }).collect(); - let mut y = x.clone(); - fft.process(&mut y, &mut Vec::new()); - for k in 0..n { - let (mut re, mut im) = (0f64, 0f64); - for (j, v) in x.iter().enumerate() { - let ph = -2.0 * std::f64::consts::PI * ((j * k) % n) as f64 / n as f64; - re += v.re as f64 * ph.cos() - v.im as f64 * ph.sin(); - im += v.re as f64 * ph.sin() + v.im as f64 * ph.cos(); - } - assert!((y[k].re as f64 - re).abs() < 2e-3 && (y[k].im as f64 - im).abs() < 2e-3, "n={n} k={k}: ({}, {}) vs ({re}, {im})", y[k].re, y[k].im); - } - } - } - - #[test] - fn matches_direct_formula() { - for &n in &[240usize, 960] { - let block: Vec = (0..n + OVERLAP).map(|i| ((i * 37 % 101) as f32 - 50.0) / 7.0).collect(); - let mut m = Mdct::new(n); - let mut out = vec![0f32; n]; - m.forward(&block, &mut out); - let d = direct(&block, n, &m.window); - for k in 0..n { - assert!((out[k] as f64 - d[k]).abs() < 1e-2, "n={n} k={k}: {} vs {}", out[k], d[k]); - } - } - } - - // ---- Replica of the RFC 6716 decoder inverse MDCT (as in FilmCraft's decoder) ---- - - fn imdct_backward(n_full: usize, input: &[f32], out: &mut [f32], window: &[f32]) { - let n2 = n_full >> 1; - let n4 = n_full >> 2; - let t: Vec = (0..n2).map(|i| (2.0 * std::f64::consts::PI * (i as f64 + 0.125) / n_full as f64).cos() as f32).collect(); - let fft = Fft::new(n4); - let mut z = Vec::new(); - for i in 0..n4 { - let x1 = input[2 * i]; - let x2 = input[n2 - 1 - 2 * i]; - let yr = x2 * t[i] + x1 * t[n4 + i]; - let yi = x1 * t[i] - x2 * t[n4 + i]; - z.push(Cpx { re: yi, im: yr }); - } - fft.process(&mut z, &mut Vec::new()); - let overlap = OVERLAP; - let base = overlap >> 1; - let y = &mut out[base..base + n2]; - for i in 0..n4.div_ceil(2) { - let front = z[i]; - let back = z[n4 - 1 - i]; - let (re, im) = (front.im, front.re); - let (t0, t1) = (t[i], t[n4 + i]); - let yr0 = re * t0 + im * t1; - let yi0 = re * t1 - im * t0; - let (re, im) = (back.im, back.re); - let (t0, t1) = (t[n4 - i - 1], t[n2 - i - 1]); - let yr1 = re * t0 + im * t1; - let yi1 = re * t1 - im * t0; - y[2 * i] = yr0; - y[n2 - 1 - 2 * i] = yi0; - y[n2 - 2 - 2 * i] = yr1; - y[2 * i + 1] = yi1; - } - for i in 0..overlap / 2 { - let x1 = out[overlap - 1 - i]; - let x2 = out[i]; - let w1 = window[i]; - let w2 = window[overlap - 1 - i]; - out[i] = x2 * w2 - x1 * w1; - out[overlap - 1 - i] = x2 * w1 + x1 * w2; - } - } - - /// MDCT analysis followed by the decoder's IMDCT + TDAC overlap-add reproduces the input - /// delayed by exactly `OVERLAP` samples. - #[test] - fn perfect_reconstruction_through_decoder_imdct() { - let n = 960; - let frames = 5; - let sig: Vec = (0..n * frames).map(|i| (i as f32 * 0.013).sin() * 1000.0 + ((i * 7919) % 211) as f32 - 105.0).collect(); - let mut m = Mdct::new(n); - let mut hist = vec![0f32; OVERLAP]; - // Decoder memory: [frame output n][folded tail OVERLAP/2] laid out like decode_mem. - let mut mem = vec![0f32; n + OVERLAP]; - let mut decoded = Vec::new(); - for f in 0..frames { - let mut block = hist.clone(); - block.extend_from_slice(&sig[f * n..(f + 1) * n]); - hist.copy_from_slice(&block[n..]); - let mut coefs = vec![0f32; n]; - m.forward(&block, &mut coefs); - // Shift: the previous folded tail (at n..n+OVERLAP/2) moves to 0..OVERLAP/2. - mem.copy_within(n..n + OVERLAP / 2, 0); - imdct_backward(2 * n, &coefs, &mut mem, &m.window); - decoded.extend_from_slice(&mem[..n]); - } - let mut err = 0f64; - let mut sum = 0f64; - for t in OVERLAP..n * frames { - let d = decoded[t] as f64 - sig[t - OVERLAP] as f64; - err += d * d; - sum += (sig[t - OVERLAP] as f64).powi(2); - } - let snr = 10.0 * (sum / err).log10(); - assert!(snr > 80.0, "reconstruction SNR {snr:.1} dB"); - } -} diff --git a/crates/opusenc/src/range.rs b/crates/opusenc/src/range.rs deleted file mode 100644 index daedd58ae..000000000 --- a/crates/opusenc/src/range.rs +++ /dev/null @@ -1,472 +0,0 @@ -//! Range encoder (RFC 6716 §5.1), the exact inverse of the §4.1 range decoder. -//! -//! Range-coded symbols are written from the front of the buffer and raw bits from the back; the -//! bit accounting ([`RangeEncoder::tell`], [`RangeEncoder::tell_frac`]) matches the decoder's, so -//! every budget decision the decoder takes can be mirrored exactly. - -const SYM_BITS: u32 = 8; -const CODE_BITS: u32 = 32; -const SYM_MAX: u32 = (1 << SYM_BITS) - 1; -const CODE_SHIFT: u32 = CODE_BITS - SYM_BITS - 1; -const CODE_TOP: u32 = 1 << (CODE_BITS - 1); -const CODE_BOT: u32 = CODE_TOP >> SYM_BITS; -/// Bit resolution of [`RangeEncoder::tell_frac`] (1/8 bit). -pub const BITRES: u32 = 3; - -/// Number of bits needed to represent `x` (0 for 0). -#[inline] -pub fn ilog(x: u32) -> i32 { - (32 - x.leading_zeros()) as i32 -} - -#[derive(Clone, Debug)] -pub struct RangeEncoder { - out: Vec, - end: Vec, - end_window: u32, - nend_bits: i32, - nbits_total: i32, - rng: u32, - low: u32, - rem: i32, - ext: u32, -} - -impl Default for RangeEncoder { - fn default() -> Self { - Self::new() - } -} - -impl RangeEncoder { - pub fn new() -> Self { - RangeEncoder { - out: Vec::new(), - end: Vec::new(), - end_window: 0, - nend_bits: 0, - nbits_total: (CODE_BITS + 1) as i32, - rng: CODE_TOP, - low: 0, - rem: -1, - ext: 0, - } - } - - /// Current range (equals the decoder's range after the same symbols). - #[cfg(test)] - pub fn rng(&self) -> u32 { - self.rng - } - - fn carry_out(&mut self, c: u32) { - if c != SYM_MAX { - let carry = c >> SYM_BITS; - if self.rem >= 0 { - self.out.push((self.rem as u32 + carry) as u8); - } - if self.ext > 0 { - let sym = (SYM_MAX + carry) & SYM_MAX; - for _ in 0..self.ext { - self.out.push(sym as u8); - } - self.ext = 0; - } - self.rem = (c & SYM_MAX) as i32; - } else { - self.ext += 1; - } - } - - #[inline] - fn normalize(&mut self) { - while self.rng <= CODE_BOT { - self.carry_out(self.low >> CODE_SHIFT); - self.low = (self.low << SYM_BITS) & (CODE_TOP - 1); - self.rng <<= SYM_BITS; - self.nbits_total += SYM_BITS as i32; - } - } - - /// Encodes the symbol with cumulative range `[fl, fh)` of total `ft`. - pub fn encode(&mut self, fl: u32, fh: u32, ft: u32) { - let r = self.rng / ft; - if fl > 0 { - self.low += self.rng - r * (ft - fl); - self.rng = r * (fh - fl); - } else { - self.rng -= r * (ft - fh); - } - self.normalize(); - } - - /// Like [`Self::encode`] with `ft = 1 << bits`. - pub fn encode_bin(&mut self, fl: u32, fh: u32, bits: u32) { - let r = self.rng >> bits; - let ft = 1u32 << bits; - if fl > 0 { - self.low += self.rng - r * (ft - fl); - self.rng = r * (fh - fl); - } else { - self.rng -= r * (ft - fh); - } - self.normalize(); - } - - /// Encodes a binary symbol whose probability of being 1 is `1/2^logp`. - pub fn bit_logp(&mut self, val: bool, logp: u32) { - let r = self.rng; - let s = r >> logp; - let r2 = r - s; - if val { - self.low += r2; - self.rng = s; - } else { - self.rng = r2; - } - self.normalize(); - } - - /// Encodes symbol `s` with an "inverse CDF" table (`ft = 1 << ftb`). - pub fn icdf(&mut self, s: usize, icdf: &[u8], ftb: u32) { - let r = self.rng >> ftb; - if s > 0 { - self.low += self.rng - r * icdf[s - 1] as u32; - self.rng = r * (icdf[s - 1] as u32 - icdf[s] as u32); - } else { - self.rng -= r * icdf[s] as u32; - } - self.normalize(); - } - - /// Encodes a uniformly distributed integer `fl` in `[0, ft)` (`ft >= 2`). - pub fn uint(&mut self, fl: u32, ft: u32) { - debug_assert!(ft > 1 && fl < ft); - let ft1 = ft - 1; - let ftb = ilog(ft1); - if ftb > 8 { - let ftb = (ftb - 8) as u32; - let top = (ft1 >> ftb) + 1; - let v = fl >> ftb; - self.encode(v, v + 1, top); - self.bits(fl & ((1 << ftb) - 1), ftb); - } else { - self.encode(fl, fl + 1, ft); - } - } - - /// Writes `bits` raw bits (0..=25) to the end of the buffer. - pub fn bits(&mut self, val: u32, bits: u32) { - if bits == 0 { - return; - } - let mut window = self.end_window; - let mut used = self.nend_bits; - if used as u32 + bits > CODE_BITS { - while used >= SYM_BITS as i32 { - self.end.push((window & SYM_MAX) as u8); - window >>= SYM_BITS; - used -= SYM_BITS as i32; - } - } - window |= val << used; - used += bits as i32; - self.end_window = window; - self.nend_bits = used; - self.nbits_total += bits as i32; - } - - /// Number of bits written so far (rounded up), identical to the decoder's `tell`. - #[inline] - pub fn tell(&self) -> i32 { - self.nbits_total - ilog(self.rng) - } - - /// Number of 1/8 bits written so far (rounded up), identical to the decoder's `tell_frac`. - pub fn tell_frac(&self) -> i32 { - let nbits = (self.nbits_total as u32) << BITRES; - let mut l = ilog(self.rng) as u32; - let mut r = self.rng >> (l - 16); - for _ in 0..BITRES { - r = (r * r) >> 15; - let b = r >> 16; - l = (l << 1) | b; - r >>= b; - } - nbits.wrapping_sub(l) as i32 - } - - /// Finalises the stream into a buffer of exactly `size` bytes (range data at the front, raw - /// bits at the back, zero padding in between; a partial raw-bit byte is merged into the byte - /// just before the full raw-bit bytes). - pub fn done(mut self, size: usize) -> Vec { - let mut l = CODE_BITS as i32 - ilog(self.rng); - let mut msk = (CODE_TOP - 1) >> l; - let mut end = (self.low.wrapping_add(msk)) & !msk; - if (end | msk) >= self.low.wrapping_add(self.rng) { - l += 1; - msk >>= 1; - end = (self.low.wrapping_add(msk)) & !msk; - } - while l > 0 { - self.carry_out(end >> CODE_SHIFT); - end = (end << SYM_BITS) & (CODE_TOP - 1); - l -= SYM_BITS as i32; - } - if self.rem >= 0 || self.ext > 0 { - self.carry_out(0); - } - let mut window = self.end_window; - let mut used = self.nend_bits; - while used >= SYM_BITS as i32 { - self.end.push((window & SYM_MAX) as u8); - window >>= SYM_BITS; - used -= SYM_BITS as i32; - } - let mut buf = vec![0u8; size]; - let full = self.end.len().min(size); - let room = size - full; - let n = self.out.len().min(room); - buf[..n].copy_from_slice(&self.out[..n]); - for (k, &b) in self.end.iter().take(full).enumerate() { - buf[size - 1 - k] = b; - } - if used > 0 && room > 0 { - buf[room - 1] |= window as u8; - } - buf - } -} - -#[cfg(test)] -pub(crate) mod dec { - //! Minimal range decoder (RFC 6716 §4.1) used to verify the encoder. - use super::*; - const CODE_EXTRA: u32 = (CODE_BITS - 2) % SYM_BITS + 1; - - pub struct RangeDecoder<'a> { - buf: &'a [u8], - offs: usize, - end_offs: usize, - end_window: u32, - nend_bits: i32, - nbits_total: i32, - rng: u32, - val: u32, - rem: u32, - } - - impl<'a> RangeDecoder<'a> { - pub fn new(buf: &'a [u8]) -> Self { - let mut d = RangeDecoder { - buf, - offs: 0, - end_offs: 0, - end_window: 0, - nend_bits: 0, - nbits_total: (CODE_BITS + 1 - ((CODE_BITS - CODE_EXTRA) / SYM_BITS) * SYM_BITS) as i32, - rng: 1 << CODE_EXTRA, - val: 0, - rem: 0, - }; - d.rem = d.read_byte(); - d.val = d.rng - 1 - (d.rem >> (SYM_BITS - CODE_EXTRA)); - d.normalize(); - d - } - fn read_byte(&mut self) -> u32 { - if self.offs < self.buf.len() { - self.offs += 1; - self.buf[self.offs - 1] as u32 - } else { - 0 - } - } - fn read_byte_from_end(&mut self) -> u32 { - if self.end_offs < self.buf.len() { - self.end_offs += 1; - self.buf[self.buf.len() - self.end_offs] as u32 - } else { - 0 - } - } - fn normalize(&mut self) { - while self.rng <= CODE_BOT { - self.nbits_total += SYM_BITS as i32; - self.rng <<= SYM_BITS; - let sym = self.rem; - self.rem = self.read_byte(); - let sym = ((sym << SYM_BITS) | self.rem) >> (SYM_BITS - CODE_EXTRA); - self.val = ((self.val << SYM_BITS).wrapping_add(SYM_MAX & !sym)) & (CODE_TOP - 1); - } - } - pub fn rng(&self) -> u32 { - self.rng - } - pub fn decode(&mut self, ft: u32) -> u32 { - let ext = self.rng / ft; - let s = self.val / ext; - ft - (s + 1).min(ft) - } - pub fn update(&mut self, fl: u32, fh: u32, ft: u32) { - let ext = self.rng / ft; - let s = ext * (ft - fh); - self.val = self.val.wrapping_sub(s); - self.rng = if fl > 0 { ext * (fh - fl) } else { self.rng - s }; - self.normalize(); - } - pub fn bit_logp(&mut self, logp: u32) -> bool { - let r = self.rng; - let d = self.val; - let s = r >> logp; - let ret = d < s; - if !ret { - self.val = d - s; - } - self.rng = if ret { s } else { r - s }; - self.normalize(); - ret - } - pub fn icdf(&mut self, icdf: &[u8], ftb: u32) -> usize { - let mut s = self.rng; - let d = self.val; - let r = s >> ftb; - let mut ret = 0usize; - let mut t; - loop { - t = s; - s = r * icdf[ret] as u32; - if d >= s { - break; - } - ret += 1; - } - self.val = d - s; - self.rng = t - s; - self.normalize(); - ret - } - pub fn uint(&mut self, ft: u32) -> u32 { - let ft1 = ft - 1; - let ftb = ilog(ft1); - if ftb > 8 { - let ftb = (ftb - 8) as u32; - let top = (ft1 >> ftb) + 1; - let s = self.decode(top); - self.update(s, s + 1, top); - (s << ftb) | self.bits(ftb) - } else { - let s = self.decode(ft); - self.update(s, s + 1, ft); - s - } - } - pub fn bits(&mut self, bits: u32) -> u32 { - let mut window = self.end_window; - let mut available = self.nend_bits; - if (available as u32) < bits { - loop { - window |= self.read_byte_from_end() << available; - available += SYM_BITS as i32; - if available > (CODE_BITS - SYM_BITS) as i32 { - break; - } - } - } - let ret = window & ((1u32 << bits) - 1); - self.end_window = window >> bits; - self.nend_bits = available - bits as i32; - self.nbits_total += bits as i32; - ret - } - pub fn tell(&self) -> i32 { - self.nbits_total - ilog(self.rng) - } - } -} - -#[cfg(test)] -mod tests { - use super::dec::RangeDecoder; - use super::*; - - struct Lcg(u32); - impl Lcg { - fn next(&mut self) -> u32 { - self.0 = self.0.wrapping_mul(1664525).wrapping_add(1013904223); - self.0 >> 8 - } - } - - #[test] - fn starts_at_one_bit() { - let e = RangeEncoder::new(); - assert_eq!(e.tell(), 1); - assert_eq!(e.tell_frac(), 8); - } - - #[test] - fn roundtrip_mixed_symbols_and_tell_matches() { - let mut rng = Lcg(7); - let icdf: [u8; 4] = [200, 120, 30, 0]; - for trial in 0..300 { - let n = 1 + (rng.next() % 300) as usize; - let mut ops = Vec::new(); - for _ in 0..n { - match rng.next() % 5 { - 0 => { - let ft = 2 + rng.next() % 1000; - ops.push((0u8, rng.next() % ft, ft)); - } - 1 => { - let logp = 1 + rng.next() % 15; - ops.push((1, rng.next().is_multiple_of(5) as u32, logp)); - } - 2 => { - let bits = 1 + rng.next() % 24; - ops.push((2, rng.next() & ((1 << bits) - 1), bits)); - } - 3 => { - let ft = 2 + rng.next() % 100_000_000; - ops.push((3, rng.next() % ft, ft)); - } - _ => ops.push((4, rng.next() % 4, 0)), - } - } - let mut e = RangeEncoder::new(); - let mut tells = Vec::new(); - for &(k, v, p) in &ops { - match k { - 0 => e.encode(v, v + 1, p), - 1 => e.bit_logp(v != 0, p), - 2 => e.bits(v, p), - 3 => e.uint(v, p), - _ => e.icdf(v as usize, &icdf, 8), - } - tells.push(e.tell()); - } - // Exactly the number of bytes `tell` says were used must suffice. - let size = (e.tell() as usize).div_ceil(8); - let final_rng = e.rng(); - let buf = e.done(size); - assert_eq!(buf.len(), size); - let mut d = RangeDecoder::new(&buf); - for (i, &(k, v, p)) in ops.iter().enumerate() { - let got = match k { - 0 => { - let s = d.decode(p); - d.update(s, s + 1, p); - s - } - 1 => d.bit_logp(p) as u32, - 2 => d.bits(p), - 3 => d.uint(p), - _ => d.icdf(&icdf, 8) as u32, - }; - assert_eq!(got, v, "trial {trial} op {i} kind {k}"); - assert_eq!(d.tell(), tells[i], "tell mismatch trial {trial} op {i}"); - } - assert_eq!(d.rng(), final_rng); - } - } -} diff --git a/crates/opusenc/src/rate.rs b/crates/opusenc/src/rate.rs deleted file mode 100644 index ff6ccae95..000000000 --- a/crates/opusenc/src/rate.rs +++ /dev/null @@ -1,560 +0,0 @@ -//! Pulse cache and bit allocation (RFC 6716 §4.3.3, §4.3.4.1). -//! -//! The allocation must be bit-identical to the decoder's, so this mirrors FilmCraft's -//! spec-derived `filmcraft-opus` decoder (first-party, MIT OR Apache-2.0) step by step; the only -//! difference is that the encoder *writes* the band-skip, intensity and dual-stereo symbols. - -use crate::CeltFrame; -use crate::range::{BITRES, RangeEncoder, ilog}; -use crate::tables::{ALLOC, EBANDS, LOG2_FRAC_TABLE, MAX_LM, NB_EBANDS}; - -const MAX_PSEUDO: i32 = 40; -const LOG_MAX_PSEUDO: i32 = 6; -pub const MAX_FINE_BITS: i32 = 8; -const FINE_OFFSET: i32 = 21; -pub const QTHETA_OFFSET: i32 = 4; -pub const QTHETA_OFFSET_TWOPHASE: i32 = 16; -const ALLOC_STEPS: i32 = 6; - -/// Number of pulses represented by pseudo-pulse index `i`. -pub fn get_pulses(i: i32) -> i32 { - if i < 8 { i } else { (8 + (i & 7)) << ((i >> 3) - 1) } -} - -/// Conservative (rounded up) log2 of `val` with `frac` fractional bits. -pub fn log2_frac(mut val: u32, mut frac: u32) -> i32 { - let mut l = ilog(val); - if val & val.wrapping_sub(1) != 0 { - if l > 16 { - val = ((val - 1) >> (l - 16)) + 1; - } else { - val <<= 16 - l; - } - let mut l = (l - 1) << frac; - loop { - let b = (val >> 16) as i32; - l += b << frac; - val = (val + b as u32) >> b; - val = (val * val + 0x7FFF) >> 15; - if frac == 0 { - break; - } - frac -= 1; - } - l + (val > 0x8000) as i32 - } else { - l -= 1; - l << frac - } -} - -/// PVQ codebook size V(N, K) (saturating far above 2^32). -pub fn pvq_v(n: usize, k: usize) -> u128 { - if k == 0 { - return 1; - } - if n == 0 { - return 0; - } - let mut row = vec![0u128; k + 1]; - row[0] = 1; - for _ in 0..n { - let mut prev_diag = row[0]; - for kk in 1..=k { - let up = row[kk]; - let v = up.saturating_add(row[kk - 1]).saturating_add(prev_diag); - prev_diag = up; - row[kk] = v.min(u128::MAX >> 8); - } - row[0] = 1; - } - row[k] -} - -fn fits_in32(n: usize, k: i32) -> bool { - pvq_v(n, k as usize) <= u32::MAX as u128 -} - -/// Precomputed per-mode data. -pub struct Mode { - /// log2 of band width in 1/8 bits. - pub log_n: [i32; NB_EBANDS], - cache_index: Vec, - cache_bits: Vec, - caps: Vec, -} - -impl Mode { - pub fn new() -> Mode { - let mut log_n = [0i32; NB_EBANDS]; - for (i, l) in log_n.iter_mut().enumerate() { - *l = log2_frac((EBANDS[i + 1] - EBANDS[i]) as u32, BITRES); - } - let (cache_index, cache_bits) = compute_pulse_cache(MAX_LM as i32); - let mut m = Mode { log_n, cache_index, cache_bits, caps: Vec::new() }; - m.caps = compute_caps(&m); - m - } - - #[inline] - pub fn cache(&self, lm: i32, band: usize) -> &[u8] { - let idx = self.cache_index[((lm + 1) as usize) * NB_EBANDS + band]; - &self.cache_bits[idx.max(0) as usize..] - } - - pub fn bits2pulses(&self, band: usize, lm: i32, bits: i32) -> i32 { - let cache = self.cache(lm, band); - let mut lo = 0i32; - let mut hi = cache[0] as i32; - let bits = bits - 1; - for _ in 0..LOG_MAX_PSEUDO { - let mid = (lo + hi + 1) >> 1; - if cache[mid as usize] as i32 >= bits { - hi = mid; - } else { - lo = mid; - } - } - let lo_bits = if lo == 0 { -1 } else { cache[lo as usize] as i32 }; - if bits - lo_bits <= cache[hi as usize] as i32 - bits { lo } else { hi } - } - - pub fn pulses2bits(&self, band: usize, lm: i32, pulses: i32) -> i32 { - if pulses == 0 { 0 } else { self.cache(lm, band)[pulses as usize] as i32 + 1 } - } - - /// Per-band allocation caps for this frame (`init_caps`). - pub fn init_caps(&self, lm: usize, c: usize) -> [i32; NB_EBANDS] { - let mut cap = [0i32; NB_EBANDS]; - for (i, cp) in cap.iter_mut().enumerate() { - let n = (EBANDS[i + 1] - EBANDS[i]) << lm; - *cp = ((self.caps[NB_EBANDS * (2 * lm + c - 1) + i] as i32 + 64) * c as i32 * n) >> 2; - } - cap - } -} - -fn compute_pulse_cache(lm_max: i32) -> (Vec, Vec) { - let nb = NB_EBANDS; - let rows = (lm_max + 2) as usize; - let mut index = vec![-1i16; nb * rows]; - let mut entries: Vec<(usize, i32, usize)> = Vec::new(); - let mut curr = 0usize; - for i in 0..rows { - for j in 0..nb { - let n = (((EBANDS[j + 1] - EBANDS[j]) << i) >> 1) as usize; - index[i * nb + j] = -1; - 'search: for k in 0..=i { - for nn in 0..nb { - if k == i && nn >= j { - break; - } - if n == (((EBANDS[nn + 1] - EBANDS[nn]) << k) >> 1) as usize { - index[i * nb + j] = index[k * nb + nn]; - break 'search; - } - } - } - if index[i * nb + j] == -1 && n != 0 { - let mut k = 0; - while k < MAX_PSEUDO && fits_in32(n, get_pulses(k + 1)) { - k += 1; - } - index[i * nb + j] = curr as i16; - entries.push((n, k, curr)); - curr += (k + 1) as usize; - } - } - } - let mut bits = vec![0u8; curr]; - for &(n, k, off) in &entries { - let maxk = get_pulses(k) as usize; - let tmp = required_bits(n, maxk, BITRES); - for j in 1..=k { - bits[off + j as usize] = (tmp[get_pulses(j) as usize] - 1) as u8; - } - bits[off] = k as u8; - } - (index, bits) -} - -fn required_bits(n: usize, maxk: usize, frac: u32) -> Vec { - let mut out = vec![0i32; maxk + 1]; - if n == 1 { - for o in out.iter_mut().skip(1) { - *o = 1 << frac; - } - } else { - for (k, o) in out.iter_mut().enumerate().skip(1) { - *o = log2_frac(pvq_v(n, k) as u32, frac); - } - } - out -} - -fn compute_caps(m: &Mode) -> Vec { - let nb = NB_EBANDS; - let mut caps = vec![0u8; (MAX_LM + 1) * 2 * nb]; - for i in 0..=MAX_LM as i32 { - for c in 1..=2i32 { - for j in 0..nb { - let mut n0 = EBANDS[j + 1] - EBANDS[j]; - - let max_bits = if n0 << i == 1 { - (c * (1 + MAX_FINE_BITS)) << BITRES - } else { - let mut lm0 = 0; - if n0 > 2 { - n0 >>= 1; - lm0 -= 1; - } else if n0 <= 1 { - lm0 = i.min(1); - n0 <<= lm0; - } - let pcache = m.cache(lm0, j); - let mut mb = pcache[pcache[0] as usize] as i32 + 1; - let mut n = n0; - for k in 0..(i - lm0) { - mb <<= 1; - let offset = ((m.log_n[j] + ((lm0 + k) << BITRES)) >> 1) - QTHETA_OFFSET; - let num = 459 * ((2 * n - 1) * offset + mb); - let den = ((2 * n - 1) << 9) - 459; - let qb = ((num + (den >> 1)) / den).min(57); - mb += qb; - n <<= 1; - } - if c == 2 { - mb <<= 1; - let offset = ((m.log_n[j] + (i << BITRES)) >> 1) - if n == 2 { QTHETA_OFFSET_TWOPHASE } else { QTHETA_OFFSET }; - let ndof = 2 * n - 1 - (n == 2) as i32; - let p = if n == 2 { 512 } else { 487 }; - let num = p * (mb + ndof * offset); - let den = (ndof << 9) - p; - let qb = ((num + (den >> 1)) / den).min(if n == 2 { 64 } else { 61 }); - mb += qb; - } - let ndof = c * n + if c == 2 && n > 2 { 1 } else { 0 }; - let mut offset = ((m.log_n[j] + (i << BITRES)) >> 1) - FINE_OFFSET; - if n == 2 { - offset += (1 << BITRES) >> 2; - } - let num = mb + ndof * offset; - let den = (ndof - 1) << BITRES; - let qb = ((num + (den >> 1)) / den).min(MAX_FINE_BITS); - mb += (c * qb) << BITRES; - mb - }; - let w = c * ((EBANDS[j + 1] - EBANDS[j]) << i); - let v = (4 * max_bits / w) - 64; - caps[((i * 2 + c - 1) as usize) * nb + j] = v.clamp(0, 255) as u8; - } - } - } - caps -} - -/// Result of the allocation process. -pub struct Allocation { - pub coded_bands: usize, - pub intensity: usize, - pub dual_stereo: bool, - pub balance: i32, - pub pulses: [i32; NB_EBANDS], - pub fine_quant: [i32; NB_EBANDS], - pub fine_priority: [i32; NB_EBANDS], -} - -/// Per-band limits, boosts and available budget for the allocation search. -pub struct AllocationInput<'a> { - pub offsets: &'a [i32; NB_EBANDS], - pub cap: &'a [i32; NB_EBANDS], - pub trim: i32, - pub bits: i32, -} - -/// `clt_compute_allocation`, encoder side. Stereo frames are always coded as dual (L/R) stereo -/// with no intensity bands, and no band is skipped voluntarily. -pub fn compute_allocation(m: &Mode, frame: CeltFrame, input: AllocationInput<'_>, enc: &mut RangeEncoder) -> Allocation { - let CeltFrame { start, end, channels: c, lm } = frame; - let AllocationInput { offsets, cap, trim: alloc_trim, bits: total } = input; - let ci = c as i32; - let lmi = lm as i32; - let mut total = total.max(0); - let mut skip_start = start; - let skip_rsv = if total >= 1 << BITRES { 1 << BITRES } else { 0 }; - total -= skip_rsv; - let mut intensity_rsv = 0; - let mut dual_stereo_rsv = 0; - if c == 2 { - intensity_rsv = LOG2_FRAC_TABLE[end - start]; - if intensity_rsv > total { - intensity_rsv = 0; - } else { - total -= intensity_rsv; - dual_stereo_rsv = if total >= 1 << BITRES { 1 << BITRES } else { 0 }; - total -= dual_stereo_rsv; - } - } - let mut bits1 = [0i32; NB_EBANDS]; - let mut bits2 = [0i32; NB_EBANDS]; - let mut thresh = [0i32; NB_EBANDS]; - let mut trim_offset = [0i32; NB_EBANDS]; - for j in start..end { - let w = EBANDS[j + 1] - EBANDS[j]; - thresh[j] = (ci << BITRES).max(((3 * w) << lmi << BITRES) >> 4); - trim_offset[j] = (ci * w * (alloc_trim - 5 - lmi) * (end as i32 - j as i32 - 1) * (1 << (lmi + BITRES as i32))) >> 6; - if w << lmi == 1 { - trim_offset[j] -= ci << BITRES; - } - } - let nb_alloc = ALLOC.len() as i32; - let mut lo = 1; - let mut hi = nb_alloc - 1; - loop { - let mut done = false; - let mut psum = 0; - let mid = (lo + hi) >> 1; - for j in (start..end).rev() { - let n = EBANDS[j + 1] - EBANDS[j]; - let mut bitsj = (ci * n * (ALLOC[mid as usize][j] as i32)) << lmi >> 2; - if bitsj > 0 { - bitsj = (bitsj + trim_offset[j]).max(0); - } - bitsj += offsets[j]; - if bitsj >= thresh[j] || done { - done = true; - psum += bitsj.min(cap[j]); - } else if bitsj >= ci << BITRES { - psum += ci << BITRES; - } - } - if psum > total { - hi = mid - 1; - } else { - lo = mid + 1; - } - if lo > hi { - break; - } - } - hi = lo; - lo -= 1; - for j in start..end { - let n = EBANDS[j + 1] - EBANDS[j]; - let mut bits1j = (ci * n * (ALLOC[lo as usize][j] as i32)) << lmi >> 2; - let mut bits2j = if hi >= nb_alloc { cap[j] } else { (ci * n * (ALLOC[hi as usize][j] as i32)) << lmi >> 2 }; - if bits1j > 0 { - bits1j = (bits1j + trim_offset[j]).max(0); - } - if bits2j > 0 { - bits2j = (bits2j + trim_offset[j]).max(0); - } - if lo > 0 { - bits1j += offsets[j]; - } - bits2j += offsets[j]; - if offsets[j] > 0 { - skip_start = j; - } - bits2j = (bits2j - bits1j).max(0); - bits1[j] = bits1j; - bits2[j] = bits2j; - } - let interpolation = - AllocationInterpolation { skip_start, bits1: &bits1, bits2: &bits2, thresh: &thresh, cap, total, skip_rsv, intensity_rsv, dual_stereo_rsv }; - interp_bits2pulses(m, frame, interpolation, enc) -} - -/// Bracketing allocation vectors and signalling reserves for the interpolation stage. -struct AllocationInterpolation<'a> { - skip_start: usize, - bits1: &'a [i32; NB_EBANDS], - bits2: &'a [i32; NB_EBANDS], - thresh: &'a [i32; NB_EBANDS], - cap: &'a [i32; NB_EBANDS], - total: i32, - skip_rsv: i32, - intensity_rsv: i32, - dual_stereo_rsv: i32, -} - -fn interp_bits2pulses(m: &Mode, frame: CeltFrame, interpolation: AllocationInterpolation<'_>, enc: &mut RangeEncoder) -> Allocation { - let CeltFrame { start, end, channels: c, lm } = frame; - let AllocationInterpolation { skip_start, bits1, bits2, thresh, cap, mut total, skip_rsv, mut intensity_rsv, mut dual_stereo_rsv } = interpolation; - let ci = c as i32; - let alloc_floor = ci << BITRES; - let stereo = (c > 1) as i32; - let log_m = (lm as i32) << BITRES; - let mut lo = 0; - let mut hi = 1 << ALLOC_STEPS; - for _ in 0..ALLOC_STEPS { - let mid = (lo + hi) >> 1; - let mut psum = 0; - let mut done = false; - for j in (start..end).rev() { - let tmp = bits1[j] + ((mid * bits2[j]) >> ALLOC_STEPS); - if tmp >= thresh[j] || done { - done = true; - psum += tmp.min(cap[j]); - } else if tmp >= alloc_floor { - psum += alloc_floor; - } - } - if psum > total { - hi = mid; - } else { - lo = mid; - } - } - let mut bits = [0i32; NB_EBANDS]; - let mut psum = 0; - let mut done = false; - for j in (start..end).rev() { - let mut tmp = bits1[j] + ((lo * bits2[j]) >> ALLOC_STEPS); - if tmp < thresh[j] && !done { - tmp = if tmp >= alloc_floor { alloc_floor } else { 0 }; - } else { - done = true; - } - tmp = tmp.min(cap[j]); - bits[j] = tmp; - psum += tmp; - } - let s = start; - let mut coded_bands = end; - loop { - let j = coded_bands - 1; - if j <= skip_start { - total += skip_rsv; - break; - } - let mut left = total - psum; - let span = EBANDS[coded_bands] - EBANDS[s]; - let percoeff = left / span; - left -= span * percoeff; - let rem = (left - (EBANDS[j] - EBANDS[s])).max(0); - let band_width = EBANDS[coded_bands] - EBANDS[j]; - let band_bits = bits[j] + percoeff * band_width + rem; - if band_bits >= thresh[j].max(alloc_floor + (1 << BITRES)) { - // Keep this band (and every band below it). - enc.bit_logp(true, 1); - break; - } - psum -= bits[j] + intensity_rsv; - if intensity_rsv > 0 { - intensity_rsv = LOG2_FRAC_TABLE[j - s]; - } - psum += intensity_rsv; - if band_bits >= alloc_floor { - psum += alloc_floor; - bits[j] = alloc_floor; - } else { - bits[j] = 0; - } - coded_bands -= 1; - } - let intensity = if intensity_rsv > 0 { - // No intensity stereo: every coded band is coded in full. - enc.uint((coded_bands - s) as u32, (coded_bands + 1 - s) as u32); - coded_bands - } else { - 0 - }; - if intensity <= s { - total += dual_stereo_rsv; - dual_stereo_rsv = 0; - } - let dual_stereo = if dual_stereo_rsv > 0 { - enc.bit_logp(true, 1); - true - } else { - false - }; - let mut left = total - psum; - let span = EBANDS[coded_bands] - EBANDS[s]; - let percoeff = left / span; - left -= span * percoeff; - for j in s..coded_bands { - bits[j] += percoeff * (EBANDS[j + 1] - EBANDS[j]); - } - for j in s..coded_bands { - let tmp = left.min(EBANDS[j + 1] - EBANDS[j]); - bits[j] += tmp; - left -= tmp; - } - let mut ebits = [0i32; NB_EBANDS]; - let mut fine_priority = [0i32; NB_EBANDS]; - let mut balance = 0; - for j in s..coded_bands { - let n0 = EBANDS[j + 1] - EBANDS[j]; - let n = n0 << lm; - let bit = bits[j] + balance; - let mut excess; - if n > 1 { - excess = (bit - cap[j]).max(0); - bits[j] = bit - excess; - let den = ci * n + if c == 2 && n > 2 && !dual_stereo && j < intensity { 1 } else { 0 }; - let nclogn = den * (m.log_n[j] + log_m); - let mut offset = (nclogn >> 1) - den * FINE_OFFSET; - if n == 2 { - offset += (den << BITRES) >> 2; - } - if bits[j] + offset < (den * 2) << BITRES { - offset += nclogn >> 2; - } else if bits[j] + offset < (den * 3) << BITRES { - offset += nclogn >> 3; - } - let mut eb = (bits[j] + offset + (den << (BITRES - 1))).max(0); - eb = (eb / den) >> BITRES; - if ci * eb > (bits[j] >> BITRES) { - eb = bits[j] >> stereo >> BITRES; - } - eb = eb.min(MAX_FINE_BITS); - ebits[j] = eb; - fine_priority[j] = (eb * (den << BITRES) >= bits[j] + offset) as i32; - bits[j] -= (ci * eb) << BITRES; - } else { - excess = (bit - (ci << BITRES)).max(0); - bits[j] = bit - excess; - ebits[j] = 0; - fine_priority[j] = 1; - } - if excess > 0 { - let extra_fine = (excess >> (stereo + BITRES as i32)).min(MAX_FINE_BITS - ebits[j]); - ebits[j] += extra_fine; - let extra_bits = (extra_fine * ci) << BITRES; - fine_priority[j] = (extra_bits >= excess - balance) as i32; - excess -= extra_bits; - } - balance = excess; - } - for j in coded_bands..end { - ebits[j] = bits[j] >> stereo >> BITRES; - bits[j] = 0; - fine_priority[j] = (ebits[j] < 1) as i32; - } - Allocation { coded_bands, intensity, dual_stereo, balance, pulses: bits, fine_quant: ebits, fine_priority } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn caps_match_decoder_reference() { - let m = Mode::new(); - let first_rows: [u8; 42] = [ - 224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, 178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, - 240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, - ]; - assert_eq!(&m.caps[..42], &first_rows[..]); - } - - #[test] - fn pvq_counts() { - assert_eq!(pvq_v(5, 1), 10); - assert_eq!(pvq_v(1, 7), 2); - assert_eq!(pvq_v(2, 9), 36); - assert_eq!(pvq_v(3, 2), 18); - } -} diff --git a/crates/opusenc/src/resample.rs b/crates/opusenc/src/resample.rs deleted file mode 100644 index 1acc9a4e7..000000000 --- a/crates/opusenc/src/resample.rs +++ /dev/null @@ -1,160 +0,0 @@ -//! 48 kHz → 8/12/16 kHz decimator feeding the SILK layer (own design). -//! -//! A linear-phase low-pass FIR (Kaiser-windowed sinc at 48 kHz) evaluated only at the retained -//! output phases. Its group delay ([`delay`]) is a whole number of 48 kHz samples, chosen so -//! that the SILK path (this filter + the decoder's internal-rate delay and resampler, RFC 6716 -//! Table 54) lands within a fraction of a sample of the CELT path's 120-sample MDCT overlap. - -/// Group delay of the decimator to `fs_out` in 48 kHz samples (the filter has `2 * delay + 1` -/// taps). -pub fn delay(fs_out: u32) -> usize { - if fs_out == 8_000 { 88 } else { 83 } -} - -/// Zeroth-order modified Bessel function of the first kind (power series). -fn bessel_i0(x: f64) -> f64 { - let mut sum = 1.0; - let mut term = 1.0; - let q = x * x / 4.0; - for k in 1..64 { - term *= q / (k * k) as f64; - sum += term; - if term < sum * 1e-17 { - break; - } - } - sum -} - -/// Windowed-sinc low-pass with cutoff `fc` (Hz at 48 kHz), unit DC gain. -fn design(fc: f64, beta: f64, delay: usize) -> Vec { - let wc = 2.0 * std::f64::consts::PI * fc / 48_000.0; - let i0b = bessel_i0(beta); - let mut h: Vec = (0..2 * delay + 1) - .map(|k| { - let m = k as f64 - delay as f64; - let sinc = if m == 0.0 { wc / std::f64::consts::PI } else { (wc * m).sin() / (std::f64::consts::PI * m) }; - let r = m / delay as f64; - sinc * bessel_i0(beta * (1.0 - r * r).max(0.0).sqrt()) / i0b - }) - .collect(); - let s: f64 = h.iter().sum(); - for v in h.iter_mut() { - *v /= s; - } - h.iter().map(|&v| v as f32).collect() -} - -/// Dot product with eight independent partial sums, which the compiler can vectorise (a single -/// running sum is bound by the latency of the float addition). The sums are combined pairwise. -#[inline] -fn dot8(a: &[f32], b: &[f32]) -> f32 { - let mut s = [0f32; 8]; - let (ca, ra) = a.as_chunks::<8>(); - let (cb, rb) = b.as_chunks::<8>(); - for (x, y) in ca.iter().zip(cb) { - for l in 0..8 { - s[l] += x[l] * y[l]; - } - } - let mut acc = ((s[0] + s[4]) + (s[1] + s[5])) + ((s[2] + s[6]) + (s[3] + s[7])); - for (x, y) in ra.iter().zip(rb) { - acc += x * y; - } - acc -} - -/// Decimates one channel of 48 kHz audio by 3, 4 or 6. -#[derive(Clone)] -pub struct Downsampler { - factor: usize, - h: Vec, - taps: usize, - /// The last `taps - 1` input samples followed by the current frame. - buf: Vec, -} - -impl Downsampler { - /// `fs_out` is 8000, 12000 or 16000. - pub fn new(fs_out: u32) -> Self { - let factor = (48_000 / fs_out) as usize; - // Cutoff at 95 % of the output Nyquist frequency (pass band to ~88 %, stop band from ~110 %). - let fc = 0.95 * fs_out as f64 / 2.0; - let d = delay(fs_out); - let taps = 2 * d + 1; - Downsampler { factor, h: design(fc, 6.5, d), taps, buf: vec![0.0; taps - 1] } - } - - /// Decimates `input` (a multiple of the factor long), appending to `out`. Output sample `j` - /// is the filtered input at frame position `factor * j`, delayed by [`delay`]. - pub fn process(&mut self, input: &[f32], out: &mut Vec) { - debug_assert!(input.len().is_multiple_of(self.factor)); - let taps = self.taps; - self.buf.truncate(taps - 1); - self.buf.extend_from_slice(input); - for j in 0..input.len() / self.factor { - let t = taps - 1 + self.factor * j; - let win = &self.buf[t + 1 - taps..=t]; - // h is symmetric, so the window can be taken in forward order. - out.push(dot8(win, &self.h)); - } - let n = self.buf.len(); - self.buf.copy_within(n - (taps - 1).., 0); - self.buf.truncate(taps - 1); - } -} - -#[cfg(test)] -mod tests { - use super::*; - - fn tone(f: f64, n: usize) -> Vec { - (0..n).map(|i| (2.0 * std::f64::consts::PI * f * i as f64 / 48_000.0).sin() as f32).collect() - } - - fn rms(x: &[f32]) -> f64 { - (x.iter().map(|&v| (v as f64).powi(2)).sum::() / x.len() as f64).sqrt() - } - - #[test] - fn dot8_matches_sequential_sum() { - for len in [0usize, 1, 7, 8, 9, 63, 167, 251] { - let a: Vec = (0..len).map(|i| ((i * 37 % 101) as f32 - 50.0) / 50.0).collect(); - let b: Vec = (0..len).map(|i| ((i * 53 % 89) as f32 - 44.0) / 44.0).collect(); - let exact: f64 = a.iter().zip(&b).map(|(&x, &y)| x as f64 * y as f64).sum(); - assert!((dot8(&a, &b) as f64 - exact).abs() < 1e-4, "len {len}"); - } - } - - #[test] - fn passes_band_and_rejects_aliases() { - for &(fs, pass, stop) in &[(16_000u32, 6_000.0, 8_600.0), (12_000, 4_500.0, 6_500.0), (8_000, 3_000.0, 4_500.0)] { - for &(f, want_pass) in &[(pass, true), (stop, false)] { - let mut d = Downsampler::new(fs); - let x = tone(f, 9600); - let mut y = Vec::new(); - for c in x.chunks(960) { - d.process(c, &mut y); - } - let r = rms(&y[y.len() / 2..]) * std::f64::consts::SQRT_2; - if want_pass { - assert!((r - 1.0).abs() < 0.02, "{fs}: {f} Hz gain {r}"); - } else { - assert!(r < 0.01, "{fs}: {f} Hz leaks {r}"); - } - } - } - } - - #[test] - fn delay_is_exact() { - let mut d = Downsampler::new(16_000); - let mut x = vec![0f32; 960]; - x[300] = 1.0; - let mut y = Vec::new(); - d.process(&x, &mut y); - // The impulse at 300 shows up centred at 48 kHz time 300 + 83 = 383 (output 127.67). - let peak = y.iter().enumerate().max_by(|a, b| a.1.total_cmp(b.1)).map(|(i, _)| i).unwrap_or(0); - assert!((peak as f64 - (300.0 + delay(16_000) as f64) / 3.0).abs() < 1.0, "peak at {peak}"); - } -} diff --git a/crates/opusenc/src/silk.rs b/crates/opusenc/src/silk.rs deleted file mode 100644 index 9e202c958..000000000 --- a/crates/opusenc/src/silk.rs +++ /dev/null @@ -1,858 +0,0 @@ -//! SILK layer encoder (RFC 6716 §4.2, encoder direction), 20 ms frames at 8, 12 or 16 kHz. -//! -//! Each frame is analysed (VAD, open-loop pitch, windowed-autocorrelation LPC, LTP codebook -//! search), its NLSFs are quantised, and the excitation is chosen sample by sample by running -//! the decoder's exact fixed-point reconstruction (LTP and LPC synthesis with the dequantised -//! Q12/Q14 coefficients, quantisation offsets and the pseudo-random sign sequence), so the -//! encoder always holds the decoder's state and there is no drift. A noise-feedback loop -//! shapes the coding noise with a bandwidth-expanded LPC envelope, and a per-frame search over -//! a gain offset hits the bit budget. Stereo input is coded as mid/side with the decoder's -//! stereo prediction (§4.2.8). No LBRR, no NLSF interpolation. - -pub(crate) mod analysis; -pub(crate) mod lpc; -mod nlsf; -mod pulses; -#[allow(dead_code)] -pub(crate) mod tables; - -use lpc::{MAX_LPC_ORDER, div32_varq, inverse32_varq, nlsf2a, rshift_round, sat16, smlawb, smulwb, smulww}; -use tables::{ - DELTA_GAIN, GAIN_MSB, LTP_FILTER, LTP_PERIODICITY, LTP_SCALE, LTP_TAPS_0, LTP_TAPS_1, LTP_TAPS_2, MID_ONLY, NLSF_EXT, NLSF_INTERP, NLSF_SEL_NBMB, - NLSF_SEL_WB, NLSF_STAGE1, NLSF_STAGE2, PITCH_CONTOUR, PITCH_HIGH, PITCH_LOW, STEREO_PRED_JOINT, STEREO_WEIGHTS_Q13, TYPE_ACTIVE, TYPE_INACTIVE, UNIFORM3, - UNIFORM4, UNIFORM5, UNIFORM8, -}; - -use crate::range::RangeEncoder; - -const MAX_FRAME: usize = 320; -const LTP_ORDER: usize = 5; -/// Frame RMS (16-bit scale) below which a frame is coded as inactive (VAD off). -const VAD_RMS: f32 = 30.0; -/// Normalised pitch correlation above which a frame is a voicing candidate. -const VOICING_THRESHOLD: f64 = 0.45; -/// Minimum LTP prediction gain (energy ratio) for a frame to be coded as voiced. -const MIN_LTP_GAIN: f64 = 1.3; -/// Rate penalty (squared pulse units per unit magnitude) of the excitation quantiser. -const RD_LAMBDA: f64 = 0.15; -/// Extra gain offset (log2) for inactive frames. -const INACTIVE_OFFSET: f64 = 1.0; -/// Noise feedback: the coding noise is shaped by `1 / A(z/γ)` (A the short-term predictor). -/// γ = 0 leaves it white (closed-loop DPCM, best waveform SNR at high rates), γ = 1 shapes it -/// like the spectral envelope (open-loop residual coding, needed at low rates). γ grows with the -/// gain offset, i.e. as the quantisation gets coarser. -fn nf_gamma(offset: f64) -> f64 { - (0.75 + 0.05 * offset).clamp(0.75, 0.9) -} - -/// `silk_log2lin` (decoder arithmetic). -fn log2lin(in_log_q7: i32) -> i32 { - if in_log_q7 < 0 { - return 0; - } - if in_log_q7 >= 3967 { - return i32::MAX; - } - let out = 1i32 << (in_log_q7 >> 7); - let frac = in_log_q7 & 0x7F; - if in_log_q7 < 2048 { out + ((out * smlawb(frac, frac * (128 - frac), -174)) >> 7) } else { out + (out >> 7) * smlawb(frac, frac * (128 - frac), -174) } -} - -fn gain_q16(index: i32) -> i32 { - log2lin((smulwb(0x1D1C71, index) + 2090).min(3967)) -} - -/// The decoder's LPC analysis filter on 16-bit samples. -fn lpc_analysis_filter(out: &mut [i16], input: &[i16], b: &[i32], d: usize) { - let len = out.len(); - for ix in d..len { - let mut acc: i32 = 0; - for j in 0..d { - acc = acc.wrapping_add((input[ix - 1 - j] as i32).wrapping_mul(b[j])); - } - let v = ((input[ix] as i32) << 12).wrapping_sub(acc); - out[ix] = sat16(rshift_round(v, 12)) as i16; - } - for v in out.iter_mut().take(d.min(len)) { - *v = 0; - } -} - -/// The part of the decoder's channel state that the reconstruction depends on. -#[derive(Clone)] -struct DecState { - prev_gain_q16: i32, - s_lpc_q14: [i32; MAX_LPC_ORDER], - out_buf: [i16; MAX_FRAME], - last_gain_index: i32, -} - -impl DecState { - fn new() -> Self { - DecState { prev_gain_q16: 65536, s_lpc_q14: [0; MAX_LPC_ORDER], out_buf: [0; MAX_FRAME], last_gain_index: 10 } - } - - /// The decoder's reset of the side channel when it is coded again after mid-only frames. - fn reset_side(&mut self) { - self.out_buf = [0; MAX_FRAME]; - self.s_lpc_q14 = [0; MAX_LPC_ORDER]; - self.last_gain_index = 10; - } -} - -/// Coded parameters of one frame (everything except gains and pulses). -#[derive(Clone, Default)] -struct Params { - vad: bool, - signal_type: usize, - quant_offset_type: usize, - nlsf_ix: [i32; 17], - a_q12: [i32; MAX_LPC_ORDER], - lag_index: i32, - contour: usize, - per_index: usize, - ltp_index: [usize; 4], - pitch_l: [i32; 4], - /// RMS (16-bit scale) of the open-loop prediction residual per subframe. - res_rms: [f32; 4], -} - -/// Gains, seed and pulses chosen by the quantiser. -struct Coded { - gain_ix: [i32; 4], - gains_q16: [i32; 4], - seed: usize, - pulses: Vec, -} - -/// Noise-feedback history (decoded − input), most recent first, as a double-length ring: each -/// sample is stored at `pos` and `pos + MAX_LPC_ORDER`, so `buf[pos..pos + MAX_LPC_ORDER]` is -/// always the contiguous window and a push costs two stores instead of a shift. -struct NfRing { - buf: [f64; 2 * MAX_LPC_ORDER], - /// Index of the most recent sample, always below `MAX_LPC_ORDER`. - pos: usize, -} - -impl NfRing { - fn new(hist: &[f64; MAX_LPC_ORDER]) -> Self { - let mut buf = [0.0; 2 * MAX_LPC_ORDER]; - buf[..MAX_LPC_ORDER].copy_from_slice(hist); - buf[MAX_LPC_ORDER..].copy_from_slice(hist); - NfRing { buf, pos: 0 } - } - - /// The history, most recent first. - fn window(&self) -> &[f64] { - self.buf.get(self.pos..self.pos + MAX_LPC_ORDER).unwrap_or(&[]) - } - - /// Makes `v` the most recent sample and drops the oldest. - fn push(&mut self, v: f64) { - self.pos = self.pos.checked_sub(1).unwrap_or(MAX_LPC_ORDER - 1); - for i in [self.pos, self.pos + MAX_LPC_ORDER] { - if let Some(slot) = self.buf.get_mut(i) { - *slot = v; - } - } - } - - /// The history as a plain array, most recent first. - fn to_array(&self) -> [f64; MAX_LPC_ORDER] { - let mut out = [0.0; MAX_LPC_ORDER]; - for (o, v) in out.iter_mut().zip(self.window()) { - *o = *v; - } - out - } -} - -#[derive(Clone)] -struct Channel { - fs_khz: usize, - len: usize, - sub: usize, - order: usize, - dec: DecState, - /// The last two frames of input (internal rate, 16-bit scale). - hist: Vec, - /// Recent output errors (decoded − input), most recent first, for noise feedback. - nf: [f64; MAX_LPC_ORDER], -} - -impl Channel { - fn new(fs_khz: usize) -> Self { - let len = 20 * fs_khz; - Channel { - fs_khz, - len, - sub: 5 * fs_khz, - order: if fs_khz == 16 { 16 } else { 10 }, - dec: DecState::new(), - hist: vec![0.0; 2 * len], - nf: [0.0; MAX_LPC_ORDER], - } - } - - fn push_history(&mut self, x: &[f32]) { - let l = self.len; - self.hist.copy_within(l.., 0); - self.hist[l..].copy_from_slice(x); - } - - /// Frame analysis: VAD, signal type, pitch, LPC/NLSF quantisation and LTP taps. - fn analyze(&self, x: &[f32]) -> Params { - let l = self.len; - let sub = self.sub; - let order = self.order; - let wb = order == 16; - let mut buf = self.hist.clone(); - buf.extend_from_slice(x); - let start = 2 * l; - let rms = (x.iter().map(|v| v * v).sum::() / l as f32).sqrt(); - let vad = rms > VAD_RMS; - let pitch = if vad { Some(analysis::pitch_search(&buf, start, l, self.fs_khz)) } else { None }; - let mut voiced = pitch.as_ref().is_some_and(|p| p.score > VOICING_THRESHOLD); - - let a = analysis::lpc(&buf[start - l / 4..], order, self.fs_khz); - let target: Vec = match analysis::a2nlsf(&a) { - Some(w) => w.iter().map(|v| v / std::f64::consts::PI * 32768.0).collect(), - None => (1..=order).map(|k| k as f64 * 32768.0 / (order + 1) as f64).collect(), - }; - let quant = |signal_type: usize| { - let (ix, nlsf) = nlsf::quantize(&target, signal_type, wb); - (ix, nlsf2a(&nlsf[..order])) - }; - let mut p = Params { vad, ..Default::default() }; - let (mut ix, mut a_q12) = quant(if voiced { 2 } else { 1 }); - // Open-loop residual with the quantised predictor. - let mut r = vec![0f64; buf.len()]; - for n in order..buf.len() { - let mut acc = buf[n] as f64; - for j in 0..order { - acc -= a_q12[j] as f64 / 4096.0 * buf[n - 1 - j] as f64; - } - r[n] = acc; - } - if voiced && let Some(pitch) = &pitch { - let ltp = analysis::ltp_search(&r, start, sub, &pitch.lags); - let gain = ltp.energy.iter().sum::() / ltp.err.iter().sum::().max(1e-9); - if gain >= MIN_LTP_GAIN { - p.lag_index = pitch.lag_index; - p.contour = pitch.contour; - p.pitch_l = pitch.lags; - p.per_index = ltp.per_index; - p.ltp_index = ltp.ltp_index; - } else { - voiced = false; - (ix, a_q12) = quant(1); - } - } - // Gains follow the short-term residual level (the long-term predictor then only - // reduces the number of pulses), which keeps the noise-to-signal ratio steady. - for k in 0..4 { - let e: f64 = r[start + k * sub..start + (k + 1) * sub].iter().map(|v| v * v).sum(); - p.res_rms[k] = (e / sub as f64).sqrt() as f32; - } - p.signal_type = if !vad { - 0 - } else if voiced { - 2 - } else { - 1 - }; - p.quant_offset_type = 0; - p.nlsf_ix = ix; - p.a_q12 = a_q12; - p - } - - /// Chooses gains and pulses for target `x` by running the decoder's reconstruction, and - /// advances the mirrored decoder state. `offset` scales the gains (log2), `floor` gives - /// minimum gains (Q16) per subframe. Returns the coded values and the decoded frame. - fn quantize(&mut self, p: &Params, x: &[f32], offset: f64, floor: Option<&[i32; 4]>, seed: usize) -> (Coded, Vec) { - let l = self.len; - let sub = self.sub; - let order = self.order; - let st = &mut self.dec; - let mut ring = NfRing::new(&self.nf); - let off = if p.signal_type == 0 { offset + INACTIVE_OFFSET } else { offset }; - let gamma = nf_gamma(off); - let mut nf_c = [0f64; MAX_LPC_ORDER]; - let mut gpow = 1.0; - for j in 0..order { - gpow *= gamma; - nf_c[j] = p.a_q12[j] as f64 / 4096.0 * gpow; - } - // Gains (independent coding of the first subframe, deltas for the rest). - let mut gain_ix = [0i32; 4]; - let mut gains_q16 = [0i32; 4]; - let mut prev = st.last_gain_index; - for k in 0..4 { - let mut g = p.res_rms[k] as f64 * off.exp2(); - if let Some(f) = floor { - g = g.max(f[k] as f64 / 65536.0); - } - let want = (((g * 65536.0).max(1.0).log2() * 128.0 - 2090.0) / (1_907_825.0 / 65536.0)).round().clamp(0.0, 63.0) as i32; - if k == 0 { - gain_ix[0] = want; - prev = want.max(prev - 16).clamp(0, 63); - } else { - let mut best = (i32::MAX, 0i32, prev); - for ind in 0..41 { - let tmp = ind - 4; - let thr = 2 * 36 - 64 + prev; - let d = if tmp > thr { prev + (tmp << 1) - thr } else { prev + tmp }.clamp(0, 63); - let e = (d - want).abs(); - if e < best.0 { - best = (e, ind, d); - } - } - gain_ix[k] = best.1; - prev = best.2; - } - gains_q16[k] = gain_q16(prev); - } - st.last_gain_index = prev; - - // Analysis-by-synthesis excitation quantisation through the decoder's exact synthesis. - let voiced = p.signal_type == 2; - let offset_q10 = [[100, 240], [32, 100]][p.signal_type >> 1][p.quant_offset_type]; - let off16 = offset_q10 << 4; - let mut seed_v = seed as i32; - let mut pulses = vec![0i32; l]; - let mut xq = vec![0i16; l]; - let mut s_lpc = [0i32; MAX_FRAME / 4 + MAX_LPC_ORDER]; - s_lpc[..MAX_LPC_ORDER].copy_from_slice(&st.s_lpc_q14); - let mut s_ltp = [0i16; MAX_FRAME]; - let mut s_ltp_q15 = [0i32; 2 * MAX_FRAME]; - let ltp_mem = l; - let mut ltp_buf_idx = ltp_mem; - let a_q12 = &p.a_q12; - let ltp_scale_q14 = 15565; - for k in 0..4 { - let mut b_q14 = [0i32; LTP_ORDER]; - if voiced { - let ix = p.ltp_index[k]; - let taps = match p.per_index { - 0 => LTP_TAPS_0[ix], - 1 => LTP_TAPS_1[ix], - _ => LTP_TAPS_2[ix], - }; - for i in 0..LTP_ORDER { - b_q14[i] = taps[i] << 7; - } - } - let gain_q10 = gains_q16[k] >> 6; - let mut inv_gain_q31 = inverse32_varq(gains_q16[k], 47); - let gain_adj_q16 = if gains_q16[k] != st.prev_gain_q16 { - let g = div32_varq(st.prev_gain_q16, gains_q16[k], 16); - for v in s_lpc[..MAX_LPC_ORDER].iter_mut() { - *v = smulww(g, *v); - } - g - } else { - 1 << 16 - }; - st.prev_gain_q16 = gains_q16[k]; - let lag = p.pitch_l[k]; - if voiced { - let lag_u = lag as usize; - if k == 0 { - let start_idx = (ltp_mem as isize - lag as isize - order as isize - (LTP_ORDER / 2) as isize).max(0) as usize; - lpc_analysis_filter(&mut s_ltp[start_idx..ltp_mem], &st.out_buf[start_idx..ltp_mem], a_q12, order); - inv_gain_q31 = smulwb(inv_gain_q31, ltp_scale_q14) << 2; - for i in 0..(lag_u + LTP_ORDER / 2).min(ltp_mem) { - s_ltp_q15[ltp_buf_idx - i - 1] = smulwb(inv_gain_q31, s_ltp[ltp_mem - i - 1] as i32); - } - } else if gain_adj_q16 != 1 << 16 { - for i in 0..(lag_u + LTP_ORDER / 2).min(ltp_buf_idx) { - let q = ltp_buf_idx - i - 1; - s_ltp_q15[q] = smulww(gain_adj_q16, s_ltp_q15[q]); - } - } - } - let inv_g = 16_777_216.0 / gain_q10.max(1) as f64; - for i in 0..sub { - let n = k * sub + i; - seed_v = seed_v.wrapping_mul(196_314_165).wrapping_add(907_633_515); - let ltp_q14 = if voiced { - let base = ltp_buf_idx as isize - lag as isize + (LTP_ORDER / 2) as isize; - let g = |o: isize| -> i32 { if base - o >= 0 { s_ltp_q15[(base - o) as usize] } else { 0 } }; - let mut pred = 2i32; - for o in 0..LTP_ORDER { - pred = smlawb(pred, g(o as isize), b_q14[o]); - } - pred << 1 - } else { - 0 - }; - let mut lpc_pred = (order >> 1) as i32; - for j in 0..order { - lpc_pred = smlawb(lpc_pred, s_lpc[MAX_LPC_ORDER + i - 1 - j], a_q12[j]); - } - let lpc_q14 = lpc_pred.saturating_mul(16); - // Target excitation (Q14) for this sample. - let fb: f64 = nf_c.iter().zip(ring.window()).take(order).map(|(c, e)| c * e).sum(); - let tgt = (x[n] as f64 + fb).clamp(-32768.0, 32767.0) * inv_g - lpc_q14 as f64 - ltp_q14 as f64; - let sgn = if seed_v < 0 { -1.0 } else { 1.0 }; - let u = sgn * tgt; - let pf = (u - off16 as f64) / 16384.0; - let p0 = if pf > 0.0 { (pf + 0.078_125).round() } else { (pf - 0.078_125).round() } as i32; - let level = |q: i32| -> i32 { - let mut e = q << 14; - if e > 0 { - e -= 80 << 4; - } else if e < 0 { - e += 80 << 4; - } - e + off16 - }; - let mut best = (f64::MAX, 0i32); - for q in [p0 - 1, p0, p0 + 1, 0] { - let q = q.clamp(-pulses::MAX_PULSE, pulses::MAX_PULSE); - let d = (level(q) as f64 - u) / 16384.0; - let cost = d * d + RD_LAMBDA * q.abs() as f64; - if cost < best.0 { - best = (cost, q); - } - } - let q = best.1; - pulses[n] = q; - let mut e = level(q); - if seed_v < 0 { - e = -e; - } - seed_v = seed_v.wrapping_add(q); - let res = e.wrapping_add(ltp_q14); - if voiced { - s_ltp_q15[ltp_buf_idx] = res << 1; - ltp_buf_idx += 1; - } - let v = res.saturating_add(lpc_q14); - s_lpc[MAX_LPC_ORDER + i] = v; - xq[n] = sat16(rshift_round(smulww(v, gain_q10), 8)) as i16; - ring.push(xq[n] as f64 - x[n] as f64); - } - s_lpc.copy_within(sub..sub + MAX_LPC_ORDER, 0); - } - self.nf = ring.to_array(); - st.s_lpc_q14.copy_from_slice(&s_lpc[..MAX_LPC_ORDER]); - st.out_buf[..l].copy_from_slice(&xq); - (Coded { gain_ix, gains_q16, seed, pulses }, xq) - } - - /// Writes the frame's indices and pulses (`decode_indices` + `decode_pulses` order, coded - /// independently). - fn write(&self, enc: &mut RangeEncoder, p: &Params, c: &Coded) { - let ix = p.signal_type * 2 + p.quant_offset_type; - if p.vad { - enc.icdf(ix - 2, &TYPE_ACTIVE, 8); - } else { - enc.icdf(ix, &TYPE_INACTIVE, 8); - } - enc.icdf((c.gain_ix[0] >> 3) as usize, GAIN_MSB[p.signal_type], 8); - enc.icdf((c.gain_ix[0] & 7) as usize, &UNIFORM8, 8); - for k in 1..4 { - enc.icdf(c.gain_ix[k] as usize, &DELTA_GAIN, 8); - } - let wb = self.order == 16; - let i1 = p.nlsf_ix[0] as usize; - enc.icdf(i1, NLSF_STAGE1[(p.signal_type >> 1) + if wb { 2 } else { 0 }], 8); - for i in 0..self.order { - let cb = if wb { 8 + NLSF_SEL_WB[i1][i] as usize } else { NLSF_SEL_NBMB[i1][i] as usize }; - let v = p.nlsf_ix[i + 1] + 4; - if v <= 0 { - enc.icdf(0, NLSF_STAGE2[cb], 8); - enc.icdf((-v) as usize, &NLSF_EXT, 8); - } else if v >= 8 { - enc.icdf(8, NLSF_STAGE2[cb], 8); - enc.icdf((v - 8) as usize, &NLSF_EXT, 8); - } else { - enc.icdf(v as usize, NLSF_STAGE2[cb], 8); - } - } - // No NLSF interpolation. - enc.icdf(4, &NLSF_INTERP, 8); - if p.signal_type == 2 { - let half = (self.fs_khz >> 1) as i32; - enc.icdf((p.lag_index / half) as usize, &PITCH_HIGH, 8); - let low = match self.fs_khz { - 8 => PITCH_LOW[0], - 12 => PITCH_LOW[1], - _ => PITCH_LOW[2], - }; - enc.icdf((p.lag_index % half) as usize, low, 8); - enc.icdf(p.contour, if self.fs_khz == 8 { PITCH_CONTOUR[1] } else { PITCH_CONTOUR[3] }, 8); - enc.icdf(p.per_index, <P_PERIODICITY, 8); - for k in 0..4 { - enc.icdf(p.ltp_index[k], LTP_FILTER[p.per_index], 8); - } - // LTP scaling index 0 (15565 in Q14), matching `quantize`. - enc.icdf(0, <P_SCALE, 8); - } - enc.icdf(c.seed, &UNIFORM4, 8); - pulses::encode(enc, &c.pulses, p.signal_type, p.quant_offset_type); - } -} - -/// Quantises a stereo prediction weight (Q13) to the decoder's grid (§4.2.7.1): returns the -/// (UNIFORM3, UNIFORM5, joint) indices and the reconstructed value. -fn quant_pred(w: f64) -> ([usize; 3], i32) { - let mut best = (f64::MAX, [0usize; 3], 0i32); - for i in 0..15 { - let low = STEREO_WEIGHTS_Q13[i]; - let step = smulwb(STEREO_WEIGHTS_Q13[i + 1] - low, 6554); - for j in 0..5 { - let v = low + step * (2 * j as i32 + 1); - let e = (v as f64 - w).abs(); - if e < best.0 { - best = (e, [i % 3, j, i / 3], v); - } - } - } - (best.1, best.2) -} - -/// Per-frame preparation shared by every rate-loop trial. -struct Prep { - x: [Vec; 2], - params: [Params; 2], - mid_only: bool, - pred_ix: [[usize; 3]; 2], - pred_q13: [i32; 2], -} - -/// One rate-loop trial: the frame coded at gain offset `offset`. -struct Trial { - offset: f64, - bits: i32, - state: SilkEncoder, - coder: RangeEncoder, -} - -/// SILK encoder for one mono or stereo (mid/side) stream. -#[derive(Clone)] -pub struct SilkEncoder { - fs_khz: usize, - channels: usize, - ch: [Channel; 2], - pred_prev_q13: [i32; 2], - prev_mid_only: bool, - /// Last mid sample of the previous frame (for the stereo predictor's low-pass). - prev_mid: f32, - frame: usize, - /// Gain offset chosen for the previous frame (search starting point). - pub last_offset: f64, -} - -impl SilkEncoder { - pub fn new(fs_khz: usize, channels: usize) -> Self { - SilkEncoder { - fs_khz, - channels, - ch: [Channel::new(fs_khz), Channel::new(fs_khz)], - pred_prev_q13: [0; 2], - prev_mid_only: false, - prev_mid: 0.0, - frame: 0, - last_offset: 1.0, - } - } - - /// Samples per channel of one 20 ms frame at the internal rate. - pub fn frame_len(&self) -> usize { - 20 * self.fs_khz - } - - fn prepare(&self, input: &[Vec]) -> Prep { - let l = self.frame_len(); - if self.channels == 1 { - let x = input[0].clone(); - let p = self.ch[0].analyze(&x); - return Prep { x: [x, vec![0.0; l]], params: [p, Params::default()], mid_only: true, pred_ix: [[0; 3]; 2], pred_q13: [0; 2] }; - } - let mid: Vec = (0..l).map(|i| 0.5 * (input[0][i] + input[1][i])).collect(); - let side: Vec = (0..l).map(|i| 0.5 * (input[0][i] - input[1][i])).collect(); - let lp = |j: usize| -> f64 { - let a = if j == 0 { self.prev_mid } else { mid[j - 1] }; - let c = if j + 1 < l { mid[j + 1] } else { mid[l - 1] }; - (a as f64 + 2.0 * mid[j] as f64 + c as f64) / 4.0 - }; - // Least-squares prediction of the side from the low-passed mid and the mid. - let (mut r00, mut r01, mut r11, mut c0, mut c1, mut ss, mut mm) = (0f64, 0f64, 0f64, 0f64, 0f64, 0f64, 0f64); - for j in 0..l { - let (a, b, s) = (lp(j), mid[j] as f64, side[j] as f64); - r00 += a * a; - r01 += a * b; - r11 += b * b; - c0 += a * s; - c1 += b * s; - ss += s * s; - mm += b * b; - } - // Ridge regularisation: the low-passed mid and the mid are nearly collinear. - let lam = 0.02 * 0.5 * (r00 + r11) + 1e-9; - let (a00, a11) = (r00 + lam, r11 + lam); - let det = a00 * a11 - r01 * r01; - let (p0, p1) = ((c0 * a11 - c1 * r01) / det, (c1 * a00 - c0 * r01) / det); - let lim = 13732.0; - let quant = |p0: f64, p1: f64| { - let (ix0, q0) = quant_pred(((p0 + p1) * 8192.0).clamp(-lim, lim)); - let (ix1, q1) = quant_pred((p1 * 8192.0).clamp(-lim, lim)); - ([ix0, ix1], [q0 - q1, q1]) - }; - // Side residual with the decoder's interpolated predictor. - let fs = self.fs_khz as i32; - let denom_q16 = (1 << 16) / (8 * fs); - let interp = 8 * self.fs_khz; - let residual = |pred_q13: [i32; 2]| -> Vec { - let d0 = rshift_round((pred_q13[0] - self.pred_prev_q13[0]) as i16 as i32 * denom_q16 as i16 as i32, 16); - let d1 = rshift_round((pred_q13[1] - self.pred_prev_q13[1]) as i16 as i32 * denom_q16 as i16 as i32, 16); - let (mut pp0, mut pp1) = (self.pred_prev_q13[0] + d0, self.pred_prev_q13[1] + d1); - (0..l) - .map(|j| { - if j + 1 < interp { - pp0 += d0; - pp1 += d1; - } else { - pp0 = pred_q13[0]; - pp1 = pred_q13[1]; - } - (side[j] as f64 - (pp0 as f64 * lp(j) + pp1 as f64 * mid[j] as f64) / 8192.0) as f32 - }) - .collect() - }; - let energy = |v: &[f32]| -> f64 { v.iter().map(|&x| (x as f64).powi(2)).sum() }; - let (mut pred_ix, mut pred_q13) = quant(p0, p1); - let mut res = residual(pred_q13); - let mut res_e = energy(&res); - // Never predict worse than not predicting at all. - if res_e > ss { - (pred_ix, pred_q13) = quant(0.0, 0.0); - res = residual(pred_q13); - res_e = energy(&res); - } - let res_rms = (res_e / l as f64).sqrt(); - let mid_rms = (mm / l as f64).sqrt(); - let mid_only = res_rms < 0.01 * mid_rms + 1.0; - let pm = self.ch[0].analyze(&mid); - let ps = if mid_only { Params::default() } else { self.ch[1].analyze(&res) }; - Prep { x: [mid, res], params: [pm, ps], mid_only, pred_ix, pred_q13 } - } - - /// Codes one frame into `enc` with gain offset `offset`. - fn code(&mut self, prep: &Prep, offset: f64, enc: &mut RangeEncoder) { - let stereo = self.channels == 2; - let side_vad = stereo && !prep.mid_only && prep.params[1].vad; - enc.bit_logp(prep.params[0].vad, 1); - enc.bit_logp(false, 1); - if stereo { - enc.bit_logp(side_vad, 1); - enc.bit_logp(false, 1); - let [a, b] = prep.pred_ix; - enc.icdf(5 * a[2] + b[2], &STEREO_PRED_JOINT, 8); - enc.icdf(a[0], &UNIFORM3, 8); - enc.icdf(a[1], &UNIFORM5, 8); - enc.icdf(b[0], &UNIFORM3, 8); - enc.icdf(b[1], &UNIFORM5, 8); - if !side_vad { - enc.icdf(prep.mid_only as usize, &MID_ONLY, 8); - } - } - let seed = self.frame & 3; - let (cm, _) = self.ch[0].quantize(&prep.params[0], &prep.x[0], offset, None, seed); - self.ch[0].write(enc, &prep.params[0], &cm); - if stereo { - if !prep.mid_only { - if self.prev_mid_only { - self.ch[1].dec.reset_side(); - } - let (cs, _) = self.ch[1].quantize(&prep.params[1], &prep.x[1], offset, Some(&cm.gains_q16), seed); - self.ch[1].write(enc, &prep.params[1], &cs); - } - self.pred_prev_q13 = prep.pred_q13; - self.prev_mid_only = prep.mid_only; - } - } - - /// Encodes one 20 ms frame (`input`: one internal-rate, 16-bit-scale vector per channel) - /// into `enc`, aiming at `target_bits` total and never exceeding `max_bits`. - pub fn encode(&mut self, input: &[Vec], target_bits: f64, max_bits: i32, enc: &mut RangeEncoder) { - let prep = self.prepare(input); - let start_bits = enc.tell(); - // Every trial codes the frame into a clone of the encoder and the range coder. The result - // is kept per offset: the hard-limit check below hits the memo for the chosen offset, and - // the final step adopts that trial instead of coding the frame once more. - let mut trials: Vec = Vec::new(); - let mut trial = |s: &Self, o: f64| -> i32 { - if let Some(t) = trials.iter().find(|t| t.offset == o) { - return t.bits; - } - let mut state = s.clone(); - let mut coder = enc.clone(); - state.code(&prep, o, &mut coder); - let bits = coder.tell() - start_bits; - trials.push(Trial { offset: o, bits, state, coder }); - bits - }; - // Bisection on the gain offset: the smallest offset (finest quantisation) within budget. - let target = target_bits.min(max_bits as f64); - // Bits are not strictly monotonic in the offset (very coarse quantisation feeds large - // errors back), so walk an integer grid from the previous frame's offset to find a - // bracket [infeasible, feasible], then bisect inside it. - const MIN_O: f64 = -3.0; - const MAX_O: f64 = 6.0; - let mut best_any = (i32::MAX, MAX_O); - let mut probe = |o: f64| -> bool { - let b = trial(self, o); - if b < best_any.0 { - best_any = (b, o); - } - b as f64 <= target - }; - let g0 = self.last_offset.round().clamp(MIN_O, MAX_O); - let mut bracket = None; - if probe(g0) { - let mut hi = g0; - loop { - if hi - 1.0 < MIN_O { - bracket = Some((None, hi)); - break; - } - if probe(hi - 1.0) { - hi -= 1.0; - } else { - bracket = Some((Some(hi - 1.0), hi)); - break; - } - } - } else { - let mut lo = g0; - while lo + 1.0 <= MAX_O { - if probe(lo + 1.0) { - bracket = Some((Some(lo), lo + 1.0)); - break; - } - lo += 1.0; - } - } - let mut o = match bracket { - Some((Some(mut lo), mut hi)) => { - for _ in 0..4 { - let m = 0.5 * (lo + hi); - if probe(m) { - hi = m; - } else { - lo = m; - } - } - hi - } - Some((None, hi)) => hi, - None => best_any.1, - }; - // Hard limit (hybrid packets must leave room for CELT). - while trial(self, o) > max_bits && o < 12.0 { - o += 1.0; - } - match trials.iter().position(|t| t.offset == o) { - Some(i) => { - let t = trials.swap_remove(i); - *self = t.state; - *enc = t.coder; - } - None => self.code(&prep, o, enc), - } - self.end_frame(&prep, o); - } - - /// Advances the input history and the frame counter after frame `prep` was coded at `o`. - fn end_frame(&mut self, prep: &Prep, o: f64) { - self.last_offset = o; - for ch in 0..self.channels { - self.ch[ch].push_history(&prep.x[ch]); - } - if self.channels == 2 { - self.prev_mid = prep.x[0][self.frame_len() - 1]; - } - self.frame += 1; - } -} - -#[cfg(test)] -mod tests { - use super::*; - - /// Deterministic speech-like test input: two harmonics with a moving pitch, a syllable - /// envelope, noise and short silences, at the internal rate and 16-bit scale. - fn signal(len: usize, fs_khz: usize, seed: u32) -> Vec { - let mut s = seed; - let fs = (fs_khz * 1000) as f64; - (0..len) - .map(|i| { - s = s.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); - let noise = (s >> 8) as f64 / (1u32 << 24) as f64 - 0.5; - let t = i as f64 / fs; - let f0 = 140.0 + 40.0 * (t * 1.3).sin(); - let env = ((t * 4.0).sin().max(0.0)).powf(0.7); - let voiced = (std::f64::consts::TAU * f0 * t).sin() + 0.5 * (std::f64::consts::TAU * 2.0 * f0 * t).sin(); - (8000.0 * env * voiced + 600.0 * noise) as f32 - }) - .collect() - } - - #[test] - fn nf_ring_matches_a_shifted_history() { - let mut hist = [0f64; MAX_LPC_ORDER]; - for (i, h) in hist.iter_mut().enumerate() { - *h = i as f64 * 0.5 - 3.0; - } - let mut ring = NfRing::new(&hist); - assert_eq!(ring.window(), &hist[..]); - for n in 0..100 { - let v = (n as f64 * 0.37).sin() * 100.0; - hist.copy_within(0..MAX_LPC_ORDER - 1, 1); - hist[0] = v; - ring.push(v); - assert_eq!(ring.window(), &hist[..], "after push {n}"); - } - assert_eq!(ring.to_array(), hist); - } - - /// The rate loop adopts the memoised trial for the chosen offset. A second encoder that codes - /// every frame afresh at that offset (what the loop did before the memo) must produce the - /// same bytes, frame after frame, so the adopted encoder and range-coder states are exact. - #[test] - fn adopting_the_memoised_trial_equals_coding_the_frame_again() { - for (fs_khz, channels, target_bits, max_bits) in - [(8, 1, 200.0, 1000), (12, 1, 320.0, 1000), (16, 1, 480.0, 1000), (16, 2, 640.0, 1000), (16, 1, 900.0, 400), (8, 2, 120.0, 160)] - { - let mut memo = SilkEncoder::new(fs_khz, channels); - let mut fresh = memo.clone(); - let l = memo.frame_len(); - let frames = 40; - let left = signal(l * frames, fs_khz, 7); - let right: Vec = signal(l * frames + 37, fs_khz, 11)[37..].iter().map(|v| v * 0.6).collect(); - for f in 0..frames { - let mut input = vec![left[f * l..(f + 1) * l].to_vec()]; - if channels == 2 { - input.push(right[f * l..(f + 1) * l].to_vec()); - } - let mut enc = RangeEncoder::new(); - memo.encode(&input, target_bits, max_bits, &mut enc); - let o = memo.last_offset; - let prep = fresh.prepare(&input); - let mut enc_fresh = RangeEncoder::new(); - fresh.code(&prep, o, &mut enc_fresh); - fresh.end_frame(&prep, o); - assert_eq!(enc.tell(), enc_fresh.tell(), "{fs_khz} kHz {channels} ch frame {f}"); - assert_eq!(enc.done(1275), enc_fresh.done(1275), "{fs_khz} kHz {channels} ch frame {f}"); - for c in 0..channels { - assert_eq!(memo.ch[c].nf, fresh.ch[c].nf, "noise feedback, channel {c}, frame {f}"); - assert_eq!(memo.ch[c].dec.s_lpc_q14, fresh.ch[c].dec.s_lpc_q14, "LPC state, channel {c}, frame {f}"); - } - } - } - } -} diff --git a/crates/opusenc/src/silk/analysis.rs b/crates/opusenc/src/silk/analysis.rs deleted file mode 100644 index d80052046..000000000 --- a/crates/opusenc/src/silk/analysis.rs +++ /dev/null @@ -1,418 +0,0 @@ -//! Encoder-side signal analysis for SILK (own design): windowed autocorrelation LPC, LPC → NLSF -//! conversion, open-loop pitch search and LTP codebook search. - -use super::tables::{CB_NB_20, CB_WB_20, LTP_FILTER, LTP_PERIODICITY, LTP_TAPS_0, LTP_TAPS_1, LTP_TAPS_2}; - -/// Short-term prediction coefficients `a` (prediction `x[n] ≈ Σ a[j] x[n-1-j]`) from the -/// windowed segment `x`, with a Gaussian lag window and white-noise correction. -pub fn lpc(x: &[f32], order: usize, fs_khz: usize) -> Vec { - let n = x.len(); - // Asymmetric window: sin² rise over the first half, flat, cos fall over the last 1/8. - let rise = n / 2; - let fall = n / 8; - let w = |i: usize| -> f64 { - if i < rise { - let s = (std::f64::consts::FRAC_PI_2 * (i as f64 + 0.5) / rise as f64).sin(); - s * s - } else if i >= n - fall { - (std::f64::consts::FRAC_PI_2 * (i + fall - n) as f64 / fall as f64 + 0.0).cos() - } else { - 1.0 - } - }; - let xw: Vec = x.iter().enumerate().map(|(i, &v)| v as f64 * w(i)).collect(); - let mut r = vec![0f64; order + 1]; - for (k, rk) in r.iter_mut().enumerate() { - *rk = xw[k..].iter().zip(&xw).map(|(a, b)| a * b).sum(); - } - if r[0] <= 1e-6 { - return vec![0.0; order]; - } - // White-noise correction (-40 dB) and a 50 Hz Gaussian lag window. - r[0] *= 1.0 + 1e-4; - let f0 = 2.0 * std::f64::consts::PI * 50.0 / (fs_khz as f64 * 1000.0); - for (k, rk) in r.iter_mut().enumerate().skip(1) { - *rk *= (-0.5 * (f0 * k as f64).powi(2)).exp(); - } - let mut a = levinson(&r, order); - // Mild bandwidth expansion keeps the NLSFs apart. - let mut g = 1.0; - for v in a.iter_mut() { - g *= 0.996; - *v *= g; - } - a -} - -/// Levinson-Durbin recursion on autocorrelation `r` (predictor convention as in [`lpc`]). -pub fn levinson(r: &[f64], order: usize) -> Vec { - let mut a = vec![0f64; order]; - let mut err = r[0]; - let mut tmp = vec![0f64; order]; - for i in 0..order { - let mut acc = r[i + 1]; - for j in 0..i { - acc -= a[j] * r[i - j]; - } - let k = (acc / err).clamp(-0.9999, 0.9999); - tmp[..i].copy_from_slice(&a[..i]); - for j in 0..i { - a[j] = tmp[j] - k * tmp[i - 1 - j]; - } - a[i] = k; - err *= 1.0 - k * k; - if err <= 0.0 { - break; - } - } - a -} - -/// Evaluates the symmetric polynomial `p` (length `d + 1`, `d` even) as the cosine series -/// `e^{jωd/2} P(e^{jω})`, with `cos_m(m)` giving `cos(m ω)`. -#[inline] -fn cos_series_with(p: &[f64], cos_m: impl Fn(usize) -> f64) -> f64 { - let h = (p.len() - 1) / 2; - let mut s = p[h]; - for k in 0..h { - s += 2.0 * p[k] * cos_m(h - k); - } - s -} - -fn cos_series(p: &[f64], w: f64) -> f64 { - cos_series_with(p, |m| (m as f64 * w).cos()) -} - -/// Number of grid intervals the root search scans over `[0, π]`. -const GRID: usize = 1024; -/// Largest multiple of ω in the series (half the LPC order, at most 16 / 2). -const MAX_H: usize = 8; -/// Bisection steps per root: the bracket shrinks to 3e-9 rad, far below one Q15 NLSF step (9.6e-5 rad). -const BISECT_STEPS: usize = 20; - -/// `cos(m · π g / GRID)` for every grid point `g` and `m` in `0..=MAX_H`, computed with the same -/// expression as [`cos_series`], so the table values are bit-identical to calling `cos` there. -fn grid_cos() -> &'static [[f64; MAX_H + 1]] { - static TABLE: std::sync::OnceLock> = std::sync::OnceLock::new(); - TABLE.get_or_init(|| { - (0..=GRID) - .map(|g| { - let w = std::f64::consts::PI * g as f64 / GRID as f64; - std::array::from_fn(|m| (m as f64 * w).cos()) - }) - .collect() - }) -} - -fn roots(p: &[f64], out: &mut Vec) { - let grid = grid_cos(); - let at_grid = |g: usize| cos_series_with(p, |m| grid[g][m]); - let mut w0 = 0.0; - let mut f0 = at_grid(0); - for g in 1..=GRID { - let w1 = std::f64::consts::PI * g as f64 / GRID as f64; - let f1 = at_grid(g); - if f0 == 0.0 { - out.push(w0); - } else if f0 * f1 < 0.0 { - let (mut lo, mut hi, mut flo) = (w0, w1, f0); - for _ in 0..BISECT_STEPS { - let mid = 0.5 * (lo + hi); - let fm = cos_series(p, mid); - if fm * flo <= 0.0 { - hi = mid; - } else { - lo = mid; - flo = fm; - } - } - out.push(0.5 * (lo + hi)); - } - w0 = w1; - f0 = f1; - } -} - -/// LPC → normalised line spectral frequencies in radians (ascending, `order` values), or `None` -/// when the root search fails (unstable or degenerate filter). -pub fn a2nlsf(a: &[f64]) -> Option> { - let d = a.len(); - if d > 2 * MAX_H { - return None; - } - let mut c = vec![0f64; d + 2]; - c[0] = 1.0; - for k in 0..d { - c[k + 1] = -a[k]; - } - let mut p = vec![0f64; d + 2]; - let mut q = vec![0f64; d + 2]; - for k in 0..d + 2 { - p[k] = c[k] + c[d + 1 - k]; - q[k] = c[k] - c[d + 1 - k]; - } - // Remove the trivial roots at z = -1 (P) and z = +1 (Q). - let mut p1 = vec![0f64; d + 1]; - let mut q1 = vec![0f64; d + 1]; - p1[0] = p[0]; - q1[0] = q[0]; - for k in 1..=d { - p1[k] = p[k] - p1[k - 1]; - q1[k] = q[k] + q1[k - 1]; - } - let mut r = Vec::with_capacity(d); - roots(&p1, &mut r); - roots(&q1, &mut r); - if r.len() != d { - return None; - } - r.sort_by(f64::total_cmp); - Some(r) -} - -/// Normalised cross-correlation of `x[n]` and `x[n - lag]` over `n` in `range`. -fn ncorr(x: &[f32], range: std::ops::Range, lag: usize) -> f64 { - let (mut xy, mut xx, mut yy) = (0f64, 0f64, 0f64); - for n in range { - let a = x[n] as f64; - let b = x[n - lag] as f64; - xy += a * b; - xx += a * a; - yy += b * b; - } - if xy <= 0.0 { 0.0 } else { xy / (xx * yy + 1e-9).sqrt() } -} - -pub struct Pitch { - pub lag_index: i32, - pub contour: usize, - pub lags: [i32; 4], - pub score: f64, -} - -/// Open-loop pitch search on `x` (history followed by the frame starting at `start`, `len` -/// samples, four subframes) at `fs_khz`. -pub fn pitch_search(x: &[f32], start: usize, len: usize, fs_khz: usize) -> Pitch { - let fs = fs_khz as i32; - let min_lag = 2 * fs; - let max_lag = 18 * fs - 1; - let sub = len / 4; - let nl = (max_lag - min_lag + 1) as usize; - // Whole-frame score per lag. - let full: Vec = (0..nl).map(|i| ncorr(x, start..start + len, min_lag as usize + i)).collect(); - let mut best = 0usize; - for i in 0..nl { - // Slight preference for shorter lags. - if full[i] * (1.0 - 0.0004 * i as f64) > full[best] * (1.0 - 0.0004 * best as f64) { - best = i; - } - } - let mut lag = min_lag + best as i32; - // Prefer a sub-multiple when it explains the signal almost as well (octave errors). - for div in [4, 3, 2] { - let cand = (lag as f64 / div as f64).round() as i32; - let mut cbest = (0.0, 0); - for c in cand - 1..=cand + 1 { - if c >= min_lag && c <= max_lag { - let s = full[(c - min_lag) as usize]; - if s > cbest.0 { - cbest = (s, c); - } - } - } - if cbest.1 != 0 && cbest.0 > 0.9 * full[(lag - min_lag) as usize] { - lag = cbest.1; - break; - } - } - let score = full[(lag - min_lag) as usize]; - // Contour: per-subframe lag offsets around the chosen lag. - let cb: &[[i32; 4]] = if fs_khz == 8 { &CB_NB_20 } else { &CB_WB_20 }; - // The contour search revisits the same (subframe, lag) pairs for neighbouring base lags and - // codebook entries, so each correlation is computed once. - let span = (18 * fs - min_lag + 1) as usize; - let memo = std::cell::RefCell::new(vec![f64::NAN; 4 * span]); - let sub_score = |k: usize, l: i32| -> f64 { - let l = l.clamp(min_lag, 18 * fs); - let slot = k * span + (l - min_lag) as usize; - let cached = memo.borrow()[slot]; - if !cached.is_nan() { - return cached; - } - let v = ncorr(x, start + k * sub..start + (k + 1) * sub, l as usize); - memo.borrow_mut()[slot] = v; - v - }; - let mut best = (f64::MIN, lag, 0usize); - for l0 in (lag - 2).max(min_lag)..=(lag + 2).min(max_lag) { - for (ci, offs) in cb.iter().enumerate() { - let s: f64 = (0..4).map(|k| sub_score(k, l0 + offs[k])).sum::() - 0.002 * ci as f64; - if s > best.0 { - best = (s, l0, ci); - } - } - } - let (_, l0, ci) = best; - let mut lags = [0i32; 4]; - for k in 0..4 { - lags[k] = (l0 + cb[ci][k]).clamp(min_lag, 18 * fs); - } - Pitch { lag_index: l0 - min_lag, contour: ci, lags, score } -} - -/// Result of the LTP codebook search. -pub struct Ltp { - pub per_index: usize, - pub ltp_index: [usize; 4], - /// Residual energy after LTP prediction / before, per subframe. - pub err: [f64; 4], - pub energy: [f64; 4], -} - -fn icdf_bits(icdf: &[u8], s: usize) -> f64 { - let hi = if s == 0 { 256 } else { icdf[s - 1] as u32 }; - let p = (hi - icdf[s] as u32).max(1) as f64 / 256.0; - -p.log2() -} - -/// Searches the three LTP codebooks (RFC 6716 Tables 39–42) for the taps that best predict the -/// residual `r` (history + frame starting at `start`) from its past at the per-subframe `lags`. -pub fn ltp_search(r: &[f64], start: usize, sub: usize, lags: &[i32; 4]) -> Ltp { - let mut rr = [[0f64; 25]; 4]; - let mut cv = [[0f64; 5]; 4]; - let mut e = [0f64; 4]; - for k in 0..4 { - let s0 = start + k * sub; - let lag = lags[k] as usize; - for n in s0..s0 + sub { - let t = r[n]; - e[k] += t * t; - let base = n + 2 - lag; - for i in 0..5 { - let vi = r[base - i]; - cv[k][i] += t * vi; - for j in 0..5 { - rr[k][i * 5 + j] += vi * r[base - j]; - } - } - } - } - let books: [&[[i32; 5]]; 3] = [<P_TAPS_0, <P_TAPS_1, <P_TAPS_2]; - let mut best = (f64::MAX, 0usize, [0usize; 4], [0f64; 4]); - for (p, book) in books.iter().enumerate() { - let mut total = icdf_bits(<P_PERIODICITY, p) * 1e-3 * e.iter().sum::() / 4.0; - let mut idx = [0usize; 4]; - let mut errs = [0f64; 4]; - for k in 0..4 { - let mut bk = (f64::MAX, 0usize, 0f64); - for (i, taps) in book.iter().enumerate() { - let b: [f64; 5] = std::array::from_fn(|j| taps[j] as f64 / 128.0); - let mut err = e[k]; - for a in 0..5 { - err -= 2.0 * b[a] * cv[k][a]; - for c in 0..5 { - err += b[a] * b[c] * rr[k][a * 5 + c]; - } - } - let cost = err + icdf_bits(LTP_FILTER[p], i) * 1e-3 * e[k]; - if cost < bk.0 { - bk = (cost, i, err.max(0.0)); - } - } - total += bk.0; - idx[k] = bk.1; - errs[k] = bk.2; - } - if total < best.0 { - best = (total, p, idx, errs); - } - } - Ltp { per_index: best.1, ltp_index: best.2, err: best.3, energy: e } -} - -#[cfg(test)] -mod tests { - use super::super::lpc::nlsf2a; - use super::*; - - #[test] - fn nlsf_roundtrip_through_decoder_conversion() { - // A resonant 10th/16th-order predictor from a synthetic signal. - for &(order, fs) in &[(10usize, 8usize), (16, 16)] { - let mut st = [0f64; 4]; - let mut seed = 1u32; - let x: Vec = (0..400) - .map(|_| { - seed = seed.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); - let w = (seed >> 9) as f64 / (1u32 << 23) as f64 - 1.0; - let y = w + 1.6 * st[0] - 0.9 * st[1] + 0.3 * st[2] - 0.2 * st[3]; - st = [y, st[0], st[1], st[2]]; - (y * 1000.0) as f32 - }) - .collect(); - let a = lpc(&x, order, fs); - let nlsf = a2nlsf(&a).expect("roots"); - let q15: Vec = nlsf.iter().map(|w| (w / std::f64::consts::PI * 32768.0).round() as i32).collect(); - let a_q12 = nlsf2a(&q15); - for j in 0..order { - assert!((a_q12[j] as f64 / 4096.0 - a[j]).abs() < 0.02, "order {order} coef {j}: {} vs {}", a_q12[j] as f64 / 4096.0, a[j]); - } - } - } - - /// The root search as it was before the grid table: `cos` called for every evaluation. - fn roots_reference(p: &[f64], out: &mut Vec) { - let mut w0 = 0.0; - let mut f0 = cos_series(p, w0); - for g in 1..=GRID { - let w1 = std::f64::consts::PI * g as f64 / GRID as f64; - let f1 = cos_series(p, w1); - if f0 == 0.0 { - out.push(w0); - } else if f0 * f1 < 0.0 { - let (mut lo, mut hi, mut flo) = (w0, w1, f0); - for _ in 0..BISECT_STEPS { - let mid = 0.5 * (lo + hi); - let fm = cos_series(p, mid); - if fm * flo <= 0.0 { - hi = mid; - } else { - lo = mid; - flo = fm; - } - } - out.push(0.5 * (lo + hi)); - } - w0 = w1; - f0 = f1; - } - } - - #[test] - fn grid_table_roots_are_bit_identical_to_direct_cos() { - let mut seed = 7u64; - let mut rnd = move || { - seed ^= seed << 13; - seed ^= seed >> 7; - seed ^= seed << 17; - (seed >> 11) as f64 / (1u64 << 53) as f64 * 2.0 - 1.0 - }; - let mut found = 0; - for len in [11usize, 17] { - for _ in 0..300 { - let mut p = vec![0f64; len]; - for k in 0..len / 2 + 1 { - p[k] = rnd(); - p[len - 1 - k] = p[k]; - } - let (mut a, mut b) = (Vec::new(), Vec::new()); - roots(&p, &mut a); - roots_reference(&p, &mut b); - assert_eq!(a.iter().map(|v| v.to_bits()).collect::>(), b.iter().map(|v| v.to_bits()).collect::>()); - found += a.len(); - } - } - assert!(found > 1000, "{found}"); - } -} diff --git a/crates/opusenc/src/silk/lpc.rs b/crates/opusenc/src/silk/lpc.rs deleted file mode 100644 index e0f8c107e..000000000 --- a/crates/opusenc/src/silk/lpc.rs +++ /dev/null @@ -1,370 +0,0 @@ -//! Fixed-point NLSF decoding, NLSF→LPC conversion and filter stabilisation -//! (RFC 6716 §4.2.7.5, with the RFC 8251 §6/§7 overflow fixes). -//! -//! This is the decoder's normative arithmetic, mirrored from FilmCraft's first-party, -//! spec-derived `filmcraft-opus` decoder (MIT OR Apache-2.0): the encoder must reconstruct the -//! quantised NLSFs and LPC coefficients bit-exactly as the decoder does. - -use super::tables::{ - COS_Q12, LSF_ORDER_NBMB, LSF_ORDER_WB, NLSF_CB_NBMB, NLSF_CB_WB, NLSF_MIN_SPACING_NBMB, NLSF_MIN_SPACING_WB, NLSF_PRED_NBMB, NLSF_PRED_WB, NLSF_PSEL_NBMB, - NLSF_PSEL_WB, -}; - -pub const MAX_LPC_ORDER: usize = 16; - -#[inline] -pub fn smulwb(a: i32, b: i32) -> i32 { - ((a as i64 * (b as i16) as i64) >> 16) as i32 -} -#[inline] -pub fn smlawb(a: i32, b: i32, c: i32) -> i32 { - a.wrapping_add(smulwb(b, c)) -} -#[inline] -pub fn smulww(a: i32, b: i32) -> i32 { - ((a as i64 * b as i64) >> 16) as i32 -} -#[inline] -pub fn smmul(a: i32, b: i32) -> i32 { - ((a as i64 * b as i64) >> 32) as i32 -} -#[inline] -pub fn rshift_round(a: i32, s: u32) -> i32 { - if s == 1 { (a >> 1) + (a & 1) } else { ((a >> (s - 1)) + 1) >> 1 } -} -#[inline] -pub fn rshift_round64(a: i64, s: u32) -> i64 { - if s == 1 { (a >> 1) + (a & 1) } else { ((a >> (s - 1)) + 1) >> 1 } -} -#[inline] -pub fn sat16(a: i32) -> i32 { - a.clamp(-32768, 32767) -} - -/// `silk_INVERSE32_varQ`: approximation of `(1 << q_res) / b32`. -pub fn inverse32_varq(b32: i32, q_res: i32) -> i32 { - let b_headrm = b32.unsigned_abs().leading_zeros() as i32 - 1; - let b32_nrm = b32.wrapping_shl(b_headrm as u32); - let b32_inv = (i32::MAX >> 2) / (b32_nrm >> 16); - let mut result = b32_inv << 16; - let err_q32 = ((1i32 << 29).wrapping_sub(smulwb(b32_nrm, b32_inv))).wrapping_shl(3); - result = result.wrapping_add(((err_q32 as i64 * b32_inv as i64) >> 16) as i32); - let lshift = 61 - b_headrm - q_res; - if lshift <= 0 { - let s = (-lshift) as u32; - let lim_hi = i32::MAX >> s; - let lim_lo = i32::MIN >> s; - result.clamp(lim_lo, lim_hi) << s - } else if lshift < 32 { - result >> lshift - } else { - 0 - } -} - -/// `silk_DIV32_varQ`: approximation of `(a32 << q_res) / b32`. -pub fn div32_varq(a32: i32, b32: i32, q_res: i32) -> i32 { - let a_headrm = a32.unsigned_abs().leading_zeros() as i32 - 1; - let a32_nrm = a32.wrapping_shl(a_headrm as u32); - let b_headrm = b32.unsigned_abs().leading_zeros() as i32 - 1; - let b32_nrm = b32.wrapping_shl(b_headrm as u32); - let b32_inv = (i32::MAX >> 2) / (b32_nrm >> 16); - let mut result = smulwb(a32_nrm, b32_inv); - let a32_nrm = a32_nrm.wrapping_sub(((smmul(b32_nrm, result) as i64) << 3) as i32); - result = smlawb(result, a32_nrm, b32_inv); - let lshift = 29 + a_headrm - b_headrm - q_res; - if lshift < 0 { - let s = (-lshift) as u32; - let lim_hi = i32::MAX >> s; - let lim_lo = i32::MIN >> s; - result.clamp(lim_lo, lim_hi) << s - } else if lshift < 32 { - result >> lshift - } else { - 0 - } -} - -pub fn sqrt_approx(x: i32) -> i32 { - if x <= 0 { - return 0; - } - let lz = x.leading_zeros() as i32; - let frac = (x.rotate_right((24 - lz).rem_euclid(32) as u32)) & 0x7f; - let mut y = if lz & 1 != 0 { 32768 } else { 46214 }; - y >>= lz >> 1; - smlawb(y, y, 213 * frac) -} - -/// Decodes the stage-1/stage-2 indices into stabilised NLSFs (Q15). -pub fn nlsf_decode(indices: &[i32], wb: bool) -> [i32; MAX_LPC_ORDER] { - let order = if wb { 16 } else { 10 }; - let i1 = indices[0] as usize; - let cb1: &[i32] = if wb { &NLSF_CB_WB[i1] } else { &NLSF_CB_NBMB[i1] }; - let qstep = if wb { 9830 } else { 11796 }; - // Residual dequantisation with backwards prediction. - let mut res_q10 = [0i32; MAX_LPC_ORDER]; - let mut out_q10 = 0i32; - for i in (0..order).rev() { - let pred = if i + 1 < order { - let sel = if wb { NLSF_PSEL_WB[i1][i] } else { NLSF_PSEL_NBMB[i1][i] } as usize; - let w = if wb { NLSF_PRED_WB[sel][i] } else { NLSF_PRED_NBMB[sel][i] }; - (out_q10 * w) >> 8 - } else { - 0 - }; - let mut v = indices[i + 1] << 10; - if v > 0 { - v -= 102; - } else if v < 0 { - v += 102; - } - out_q10 = smlawb(pred, v, qstep); - res_q10[i] = out_q10; - } - // Laroia weights. - let mut nlsf = [0i32; MAX_LPC_ORDER]; - for k in 0..order { - let prev = if k == 0 { 0 } else { cb1[k - 1] }; - let next = if k + 1 == order { 256 } else { cb1[k + 1] }; - let w = (1024 / (cb1[k] - prev).max(1) + 1024 / (next - cb1[k]).max(1)).min(32767); - let w_q9 = sqrt_approx(w << 16); - let v = (cb1[k] << 7) + (res_q10[k] << 14) / w_q9.max(1); - nlsf[k] = v.clamp(0, 32767); - } - let dmin: &[i32] = if wb { &NLSF_MIN_SPACING_WB } else { &NLSF_MIN_SPACING_NBMB }; - nlsf_stabilize(&mut nlsf[..order], dmin); - nlsf -} - -pub fn nlsf_stabilize(nlsf: &mut [i32], dmin: &[i32]) { - let l = nlsf.len(); - for _ in 0..20 { - let mut min_diff = nlsf[0] - dmin[0]; - let mut idx = 0; - for i in 1..l { - let d = nlsf[i] - (nlsf[i - 1] + dmin[i]); - if d < min_diff { - min_diff = d; - idx = i; - } - } - let d = 32768 - (nlsf[l - 1] + dmin[l]); - if d < min_diff { - min_diff = d; - idx = l; - } - if min_diff >= 0 { - return; - } - if idx == 0 { - nlsf[0] = dmin[0]; - } else if idx == l { - nlsf[l - 1] = 32768 - dmin[l]; - } else { - let mut min_center = dmin[..idx].iter().sum::(); - min_center += dmin[idx] >> 1; - let mut max_center = 32768 - dmin[idx + 1..=l].iter().sum::(); - max_center -= dmin[idx] >> 1; - let c = rshift_round(nlsf[idx - 1] + nlsf[idx], 1); - let c = if min_center > max_center { c.clamp(max_center, min_center) } else { c.clamp(min_center, max_center) }; - nlsf[idx - 1] = c - (dmin[idx] >> 1); - nlsf[idx] = nlsf[idx - 1] + dmin[idx]; - } - } - // Fallback. - nlsf.sort_unstable(); - nlsf[0] = nlsf[0].max(dmin[0]); - for i in 1..l { - nlsf[i] = nlsf[i].max(sat16(nlsf[i - 1] + dmin[i])); - } - nlsf[l - 1] = nlsf[l - 1].min(32768 - dmin[l]); - for i in (0..l - 1).rev() { - nlsf[i] = nlsf[i].min(nlsf[i + 1] - dmin[i + 1]); - } -} - -fn bwexpander_32(ar: &mut [i32], mut chirp_q16: i32) { - let d = ar.len(); - let chirp_minus_one = chirp_q16 - 65536; - for v in ar.iter_mut().take(d - 1) { - *v = smulww(chirp_q16, *v); - chirp_q16 += rshift_round(chirp_q16.wrapping_mul(chirp_minus_one), 16); - } - ar[d - 1] = smulww(chirp_q16, ar[d - 1]); -} - -fn lpc_inverse_pred_gain(a_q12: &[i32]) -> i32 { - const QA: u32 = 24; - const A_LIMIT: i32 = 16_773_022; - let order = a_q12.len(); - let mut a = [0i32; MAX_LPC_ORDER]; - let mut dc = 0; - for k in 0..order { - dc += a_q12[k]; - a[k] = a_q12[k] << (QA - 12); - } - if dc >= 4096 { - return 0; - } - let mut inv_gain: i32 = 1 << 30; - let mul32_frac_q31 = |x: i32, y: i32| rshift_round64(x as i64 * y as i64, 31) as i32; - for k in (1..order).rev() { - if a[k] > A_LIMIT || a[k] < -A_LIMIT { - return 0; - } - let rc_q31 = -(a[k] << (31 - QA)); - let rc_mult1 = (1i32 << 30) - smmul(rc_q31, rc_q31); - inv_gain = smmul(inv_gain, rc_mult1) << 2; - if inv_gain < 107_374 { - return 0; - } - let mult2q = 32 - rc_mult1.unsigned_abs().leading_zeros() as i32; - let rc_mult2 = inverse32_varq(rc_mult1, mult2q + 30); - for n in 0..(k + 1) >> 1 { - let t1 = a[n]; - let t2 = a[k - n - 1]; - let v1 = rshift_round64(t1.saturating_sub(mul32_frac_q31(t2, rc_q31)) as i64 * rc_mult2 as i64, mult2q as u32); - if v1 > i32::MAX as i64 || v1 < i32::MIN as i64 { - return 0; - } - let v2 = rshift_round64(t2.saturating_sub(mul32_frac_q31(t1, rc_q31)) as i64 * rc_mult2 as i64, mult2q as u32); - if v2 > i32::MAX as i64 || v2 < i32::MIN as i64 { - return 0; - } - a[n] = v1 as i32; - a[k - n - 1] = v2 as i32; - } - } - if a[0] > A_LIMIT || a[0] < -A_LIMIT { - return 0; - } - let rc_q31 = -(a[0] << (31 - QA)); - let rc_mult1 = (1i32 << 30) - smmul(rc_q31, rc_q31); - inv_gain = smmul(inv_gain, rc_mult1) << 2; - if inv_gain < 107_374 { - return 0; - } - inv_gain -} - -/// Converts NLSFs (Q15) to stable Q12 LPC coefficients (`silk_NLSF2A`). -pub fn nlsf2a(nlsf: &[i32]) -> [i32; MAX_LPC_ORDER] { - let d = nlsf.len(); - let ordering: &[usize] = if d == 16 { &LSF_ORDER_WB } else { &LSF_ORDER_NBMB }; - let mut c_q17 = [0i32; MAX_LPC_ORDER]; - for k in 0..d { - let i = (nlsf[k] >> 8) as usize; - let f = nlsf[k] & 255; - let c0 = COS_Q12[i]; - let c1 = COS_Q12[(i + 1).min(128)]; - c_q17[ordering[k]] = (c0 * 256 + (c1 - c0) * f + 4) >> 3; - } - let d2 = d / 2; - let find_poly = |off: usize| -> [i64; 10] { - let mut out = [0i64; 10]; - out[0] = 1 << 16; - out[1] = -(c_q17[off] as i64); - for k in 1..d2 { - let ftmp = c_q17[2 * k + off] as i64; - out[k + 1] = 2 * out[k - 1] - ((ftmp * out[k] + 32768) >> 16); - for n in (2..=k).rev() { - out[n] += out[n - 2] - ((ftmp * out[n - 1] + 32768) >> 16); - } - out[1] -= ftmp; - } - out - }; - let p = find_poly(0); - let q = find_poly(1); - let mut a32 = [0i32; MAX_LPC_ORDER]; - for k in 0..d2 { - let ptmp = p[k + 1] + p[k]; - let qtmp = q[k + 1] - q[k]; - a32[k] = (-qtmp - ptmp) as i32; - a32[d - k - 1] = (qtmp - ptmp) as i32; - } - let a32 = &mut a32[..d]; - // Limit the dynamic range (silk_LPC_fit with QIN = 17, QOUT = 12). - let mut a_q12 = [0i32; MAX_LPC_ORDER]; - let mut i = 0; - while i < 10 { - let mut maxabs = 0i32; - let mut idx = 0; - for (k, &v) in a32.iter().enumerate() { - let av = v.saturating_abs(); - if av > maxabs { - maxabs = av; - idx = k; - } - } - let maxabs = rshift_round(maxabs, 5); - if maxabs > 32767 { - let maxabs = maxabs.min(163_838); - let chirp = 65470 - ((maxabs - 32767) << 14) / ((maxabs * (idx as i32 + 1)) >> 2); - bwexpander_32(a32, chirp); - } else { - break; - } - i += 1; - } - if i == 10 { - for k in 0..d { - a_q12[k] = sat16(rshift_round(a32[k], 5)); - a32[k] = a_q12[k] << 5; - } - } else { - for k in 0..d { - a_q12[k] = rshift_round(a32[k], 5); - } - } - for i in 0..16 { - if lpc_inverse_pred_gain(&a_q12[..d]) == 0 { - bwexpander_32(a32, 65536 - (2 << i)); - for k in 0..d { - a_q12[k] = rshift_round(a32[k], 5); - } - } else { - break; - } - } - a_q12 -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn flat_nlsf_gives_small_lpc() { - // Uniformly spaced NLSFs correspond to an (almost) flat spectrum. - let nlsf: Vec = (1..=16).map(|k| k * 32768 / 17).collect(); - let a = nlsf2a(&nlsf); - assert!(a.iter().all(|v| v.abs() < 600), "{a:?}"); - let nlsf: Vec = (1..=10).map(|k| k * 32768 / 11).collect(); - let a = nlsf2a(&nlsf); - assert!(a[..10].iter().all(|v| v.abs() < 600), "{a:?}"); - } - - #[test] - fn stabilize_enforces_spacing() { - let mut v = [100, 90, 80, 30000, 30001, 30002, 31000, 32000, 32700, 32760]; - nlsf_stabilize(&mut v, &NLSF_MIN_SPACING_NBMB); - assert!(v[0] >= NLSF_MIN_SPACING_NBMB[0]); - for i in 1..10 { - assert!(v[i] - v[i - 1] >= NLSF_MIN_SPACING_NBMB[i], "{v:?}"); - } - assert!(32768 - v[9] >= NLSF_MIN_SPACING_NBMB[10]); - } - - #[test] - fn inverse_approximations() { - for &b in &[65536, 100_000, 1 << 20, 81920, 1_686_110_208] { - let inv = inverse32_varq(b, 47) as f64; - let exact = 2f64.powi(47) / b as f64; - assert!((inv - exact).abs() / exact < 1e-3, "{b}"); - } - let q = div32_varq(65536, 131072, 16) as f64; - assert!((q - 32768.0).abs() < 2.0); - } -} diff --git a/crates/opusenc/src/silk/nlsf.rs b/crates/opusenc/src/silk/nlsf.rs deleted file mode 100644 index 4695152ff..000000000 --- a/crates/opusenc/src/silk/nlsf.rs +++ /dev/null @@ -1,130 +0,0 @@ -//! NLSF quantisation (encoder side of RFC 6716 §4.2.7.5): stage-1 vector codebook preselection -//! and a backwards-predictive stage-2 scalar quantiser that reproduces the decoder's residual -//! dequantisation exactly. The search strategy is our own. - -use super::lpc::{MAX_LPC_ORDER, nlsf_decode, smlawb, sqrt_approx}; -use super::tables::{ - NLSF_CB_NBMB, NLSF_CB_WB, NLSF_EXT, NLSF_PRED_NBMB, NLSF_PRED_WB, NLSF_PSEL_NBMB, NLSF_PSEL_WB, NLSF_SEL_NBMB, NLSF_SEL_WB, NLSF_STAGE1, NLSF_STAGE2, -}; - -/// Number of stage-1 candidates refined with stage 2. -const SURVIVORS: usize = 8; -/// Rate weight (weighted squared Q15 error per bit). -const LAMBDA: f64 = 60.0; - -fn icdf_bits(icdf: &[u8], s: usize) -> f64 { - let hi = if s == 0 { 256 } else { icdf[s - 1] as u32 }; - let p = (hi - icdf[s] as u32).max(1) as f64 / 256.0; - -p.log2() -} - -/// Bits of a stage-2 index `q` (-10..=10) with stage-2 table `tab`. -fn stage2_bits(tab: &[u8], q: i32) -> f64 { - let v = q + 4; - if v <= 0 { - icdf_bits(tab, 0) + icdf_bits(&NLSF_EXT, (-v) as usize) - } else if v >= 8 { - icdf_bits(tab, 8) + icdf_bits(&NLSF_EXT, (v - 8) as usize) - } else { - icdf_bits(tab, v as usize) - } -} - -/// Quantises target NLSFs (`target`, Q15 as f64, ascending) and returns the 1 + order indices -/// in the decoder's layout (`[stage1, stage2...]`) together with the reconstructed NLSFs. -pub fn quantize(target: &[f64], signal_type: usize, wb: bool) -> ([i32; 17], [i32; MAX_LPC_ORDER]) { - let order = target.len(); - // Laroia-style weights. - let w: Vec = (0..order) - .map(|k| { - let prev = if k == 0 { 0.0 } else { target[k - 1] }; - let next = if k + 1 == order { 32768.0 } else { target[k + 1] }; - 1.0 / (target[k] - prev).max(50.0) + 1.0 / (next - target[k]).max(50.0) - }) - .collect(); - let s1_tab = NLSF_STAGE1[(signal_type >> 1) + if wb { 2 } else { 0 }]; - let n_cb = 32; - let mut cands: Vec<(f64, usize)> = (0..n_cb) - .map(|i1| { - let cb: &[i32] = if wb { &NLSF_CB_WB[i1] } else { &NLSF_CB_NBMB[i1] }; - let d: f64 = (0..order).map(|k| w[k] * ((cb[k] << 7) as f64 - target[k]).powi(2)).sum(); - (d + LAMBDA * icdf_bits(s1_tab, i1), i1) - }) - .collect(); - cands.sort_by(|a, b| a.0.total_cmp(&b.0)); - let qstep = if wb { 9830 } else { 11796 }; - let mut best = (f64::MAX, [0i32; 17], [0i32; MAX_LPC_ORDER]); - for &(_, i1) in cands.iter().take(SURVIVORS) { - let cb1: &[i32] = if wb { &NLSF_CB_WB[i1] } else { &NLSF_CB_NBMB[i1] }; - let mut ix = [0i32; 17]; - ix[0] = i1 as i32; - let mut bits = icdf_bits(s1_tab, i1); - // Exact decoder weights per coefficient. - let w_q9: Vec = (0..order) - .map(|k| { - let prev = if k == 0 { 0 } else { cb1[k - 1] }; - let next = if k + 1 == order { 256 } else { cb1[k + 1] }; - let ww = (1024 / (cb1[k] - prev).max(1) + 1024 / (next - cb1[k]).max(1)).min(32767); - sqrt_approx(ww << 16).max(1) - }) - .collect(); - let mut out_q10 = 0i32; - for i in (0..order).rev() { - let pred = if i + 1 < order { - let sel = if wb { NLSF_PSEL_WB[i1][i] } else { NLSF_PSEL_NBMB[i1][i] } as usize; - let wp = if wb { NLSF_PRED_WB[sel][i] } else { NLSF_PRED_NBMB[sel][i] }; - (out_q10 * wp) >> 8 - } else { - 0 - }; - let cb = if wb { 8 + NLSF_SEL_WB[i1][i] as usize } else { NLSF_SEL_NBMB[i1][i] as usize }; - let tab = NLSF_STAGE2[cb]; - let want_q10 = (target[i] - (cb1[i] << 7) as f64) * w_q9[i] as f64 / 16384.0; - let step = qstep as f64 * 1024.0 / 65536.0; - let q0 = ((want_q10 - pred as f64) / step).round() as i32; - let mut bq = (f64::MAX, 0i32, 0i32); - for q in (q0 - 1).max(-10)..=(q0 + 1).min(10) { - let mut v = q << 10; - if v > 0 { - v -= 102; - } else if v < 0 { - v += 102; - } - let o = smlawb(pred, v, qstep); - let nl = (cb1[i] << 7) as f64 + ((o << 14) / w_q9[i]) as f64; - let cost = w[i] * (nl - target[i]).powi(2) + LAMBDA * stage2_bits(tab, q); - if cost < bq.0 { - bq = (cost, q, o); - } - } - ix[i + 1] = bq.1; - out_q10 = bq.2; - bits += stage2_bits(tab, bq.1); - } - let nlsf = nlsf_decode(&ix, wb); - let d: f64 = (0..order).map(|k| w[k] * (nlsf[k] as f64 - target[k]).powi(2)).sum(); - let cost = d + LAMBDA * bits; - if cost < best.0 { - best = (cost, ix, nlsf); - } - } - (best.1, best.2) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn quantised_nlsfs_track_the_target() { - for wb in [false, true] { - let order = if wb { 16 } else { 10 }; - // A smooth, plausible NLSF vector. - let target: Vec = (0..order).map(|k| 32768.0 * (k as f64 + 0.8 + 0.3 * (k as f64).sin()) / (order as f64 + 1.0)).collect(); - let (ix, nlsf) = quantize(&target, 1, wb); - assert!(ix[1..=order].iter().all(|v| (-10..=10).contains(v))); - let max_err = (0..order).map(|k| (nlsf[k] as f64 - target[k]).abs()).fold(0.0, f64::max); - assert!(max_err < 1200.0, "wb={wb} max err {max_err}: {:?} vs {target:?}", &nlsf[..order]); - } - } -} diff --git a/crates/opusenc/src/silk/pulses.rs b/crates/opusenc/src/silk/pulses.rs deleted file mode 100644 index ba22b5ec5..000000000 --- a/crates/opusenc/src/silk/pulses.rs +++ /dev/null @@ -1,113 +0,0 @@ -//! Excitation coding (encoder side of RFC 6716 §4.2.7.8): rate level, per-block pulse counts -//! with LSB escapes, the recursive shell code, LSBs and signs, written in exactly the order the -//! decoder reads them. - -use super::tables::{EXC_LSB, EXC_SIGN, PULSE_COUNT, RATE_LEVEL, SHELL_2, SHELL_4, SHELL_8, SHELL_16}; -use crate::range::RangeEncoder; - -/// Largest pulse magnitude the quantiser produces (keeps every 16-sample block codable). -pub const MAX_PULSE: i32 = 500; - -pub fn icdf_bits(icdf: &[u8], s: usize) -> f32 { - let hi = if s == 0 { 256 } else { icdf[s - 1] as u32 }; - let p = (hi - icdf[s] as u32).max(1) as f32 / 256.0; - -p.log2() -} - -fn count_table(nls: usize) -> &'static [u8] { - if nls == 10 { PULSE_COUNT[10] } else { PULSE_COUNT[9] } -} - -fn shell(enc: &mut RangeEncoder, v: &[i32], count: i32) { - let n = v.len(); - if n == 1 || count == 0 { - return; - } - let tab = match n { - 16 => SHELL_16[(count - 1) as usize], - 8 => SHELL_8[(count - 1) as usize], - 4 => SHELL_4[(count - 1) as usize], - _ => SHELL_2[(count - 1) as usize], - }; - let (a, b) = v.split_at(n / 2); - let left: i32 = a.iter().sum(); - enc.icdf(left as usize, tab, 8); - shell(enc, a, left); - shell(enc, b, count - left); -} - -/// Codes the frame's pulses (`len` a multiple of 16). -pub fn encode(enc: &mut RangeEncoder, pulses: &[i32], signal_type: usize, quant_offset_type: usize) { - let nblk = pulses.len() / 16; - let mut nls = vec![0usize; nblk]; - let mut sums = vec![0i32; nblk]; - let mut hi = vec![0i32; pulses.len()]; - for b in 0..nblk { - let blk = &pulses[b * 16..(b + 1) * 16]; - let mut s = 0usize; - loop { - let sum: i32 = blk.iter().map(|p| p.abs() >> s).sum(); - if sum <= 16 || s == 10 { - sums[b] = sum.min(16); - break; - } - s += 1; - } - nls[b] = s; - for (h, p) in hi[b * 16..(b + 1) * 16].iter_mut().zip(blk) { - *h = p.abs() >> s; - } - } - // Rate level with the cheapest pulse-count symbols. - let rl_tab = RATE_LEVEL[signal_type >> 1]; - let mut best = (f32::MAX, 0usize); - for rl in 0..9 { - let mut bits = icdf_bits(rl_tab, rl); - for b in 0..nblk { - bits += if nls[b] == 0 { icdf_bits(PULSE_COUNT[rl], sums[b] as usize) } else { icdf_bits(PULSE_COUNT[rl], 17) }; - } - if bits < best.0 { - best = (bits, rl); - } - } - let rl = best.1; - enc.icdf(rl, rl_tab, 8); - for b in 0..nblk { - if nls[b] == 0 { - enc.icdf(sums[b] as usize, PULSE_COUNT[rl], 8); - } else { - enc.icdf(17, PULSE_COUNT[rl], 8); - for j in 1..nls[b] { - enc.icdf(17, count_table(j), 8); - } - enc.icdf(sums[b] as usize, count_table(nls[b]), 8); - } - } - for b in 0..nblk { - if sums[b] > 0 { - shell(enc, &hi[b * 16..(b + 1) * 16], sums[b]); - } - } - for b in 0..nblk { - if nls[b] > 0 { - for p in &pulses[b * 16..(b + 1) * 16] { - let a = p.abs(); - for j in (0..nls[b]).rev() { - enc.icdf(((a >> j) & 1) as usize, &EXC_LSB, 8); - } - } - } - } - let base = 7 * (quant_offset_type + (signal_type << 1)); - for b in 0..nblk { - let p = sums[b] | ((nls[b] as i32) << 5); - if p > 0 { - let tab = EXC_SIGN[base + ((p & 0x1F) as usize).min(6)]; - for &q in &pulses[b * 16..(b + 1) * 16] { - if q != 0 { - enc.icdf((q > 0) as usize, tab, 8); - } - } - } - } -} diff --git a/crates/opusenc/src/silk/tables.rs b/crates/opusenc/src/silk/tables.rs deleted file mode 100644 index 8b4727268..000000000 --- a/crates/opusenc/src/silk/tables.rs +++ /dev/null @@ -1,540 +0,0 @@ -//! SILK probability tables and codebooks, transcribed from RFC 6716 §4.2 (Tables 4–53). -//! -//! PDFs are written as in the RFC (`{...}/256`) and converted at compile time to the inverse-CDF -//! form consumed by the range coder. -//! -//! Copied from FilmCraft's first-party, spec-derived `filmcraft-opus` decoder (MIT OR -//! Apache-2.0) so encoder and decoder share exactly the same values. - -/// Converts a PDF (summing to 256) into an inverse CDF (`256 - cdf[i+1]`). -pub const fn icdf(pdf: &[u8; N]) -> [u8; N] { - let mut out = [0u8; N]; - let mut acc: u32 = 0; - let mut i = 0; - while i < N { - acc += pdf[i] as u32; - out[i] = (256 - acc) as u8; - i += 1; - } - out -} - -pub const STEREO_PRED_JOINT: [u8; 25] = icdf(&[7, 2, 1, 1, 1, 10, 24, 8, 1, 1, 3, 23, 92, 23, 3, 1, 1, 8, 24, 10, 1, 1, 1, 2, 7]); -pub const UNIFORM3: [u8; 3] = icdf(&[85, 86, 85]); -pub const UNIFORM5: [u8; 5] = icdf(&[51, 51, 52, 51, 51]); -pub const STEREO_WEIGHTS_Q13: [i32; 16] = [-13732, -10050, -8266, -7526, -6500, -5000, -2950, -820, 820, 2950, 5000, 6500, 7526, 8266, 10050, 13732]; -pub const MID_ONLY: [u8; 2] = icdf(&[192, 64]); -pub const TYPE_INACTIVE: [u8; 2] = icdf(&[26, 230]); -pub const TYPE_ACTIVE: [u8; 4] = icdf(&[24, 74, 148, 10]); -pub const GAIN_MSB: [&[u8]; 3] = - [&icdf::<8>(&[32, 112, 68, 29, 12, 1, 1, 1]), &icdf::<8>(&[2, 17, 45, 60, 62, 47, 19, 4]), &icdf::<8>(&[1, 3, 26, 71, 94, 50, 9, 2])]; -pub const UNIFORM8: [u8; 8] = icdf(&[32, 32, 32, 32, 32, 32, 32, 32]); -pub const DELTA_GAIN: [u8; 41] = - icdf(&[6, 5, 11, 31, 132, 21, 8, 4, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); -pub const NLSF_STAGE1: [&[u8]; 4] = [ - &icdf::<32>(&[44, 34, 30, 19, 21, 12, 11, 3, 3, 2, 16, 2, 2, 1, 5, 2, 1, 3, 3, 1, 1, 2, 2, 2, 3, 1, 9, 9, 2, 7, 2, 1]), - &icdf::<32>(&[1, 10, 1, 8, 3, 8, 8, 14, 13, 14, 1, 14, 12, 13, 11, 11, 12, 11, 10, 10, 11, 8, 9, 8, 7, 8, 1, 1, 6, 1, 6, 5]), - &icdf::<32>(&[31, 21, 3, 17, 1, 8, 17, 4, 1, 18, 16, 4, 2, 3, 1, 10, 1, 3, 16, 11, 16, 2, 2, 3, 2, 11, 1, 4, 9, 8, 7, 3]), - &icdf::<32>(&[1, 4, 16, 5, 18, 11, 5, 14, 15, 1, 3, 12, 13, 14, 14, 6, 14, 12, 2, 6, 1, 12, 12, 11, 10, 3, 10, 5, 1, 1, 1, 3]), -]; -pub const NLSF_STAGE2: [&[u8]; 16] = [ - &icdf::<9>(&[1, 1, 1, 15, 224, 11, 1, 1, 1]), - &icdf::<9>(&[1, 1, 2, 34, 183, 32, 1, 1, 1]), - &icdf::<9>(&[1, 1, 4, 42, 149, 55, 2, 1, 1]), - &icdf::<9>(&[1, 1, 8, 52, 123, 61, 8, 1, 1]), - &icdf::<9>(&[1, 3, 16, 53, 101, 74, 6, 1, 1]), - &icdf::<9>(&[1, 3, 17, 55, 90, 73, 15, 1, 1]), - &icdf::<9>(&[1, 7, 24, 53, 74, 67, 26, 3, 1]), - &icdf::<9>(&[1, 1, 18, 63, 78, 58, 30, 6, 1]), - &icdf::<9>(&[1, 1, 1, 9, 232, 9, 1, 1, 1]), - &icdf::<9>(&[1, 1, 2, 28, 186, 35, 1, 1, 1]), - &icdf::<9>(&[1, 1, 3, 42, 152, 53, 2, 1, 1]), - &icdf::<9>(&[1, 1, 10, 49, 126, 65, 2, 1, 1]), - &icdf::<9>(&[1, 4, 19, 48, 100, 77, 5, 1, 1]), - &icdf::<9>(&[1, 1, 14, 54, 100, 72, 12, 1, 1]), - &icdf::<9>(&[1, 1, 15, 61, 87, 61, 25, 4, 1]), - &icdf::<9>(&[1, 7, 21, 50, 77, 81, 17, 1, 1]), -]; -pub const NLSF_SEL_NBMB: [[u8; 10]; 32] = [ - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [1, 3, 1, 2, 2, 1, 2, 1, 1, 1], - [2, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 2, 2, 2, 2, 1, 2, 1, 1, 1], - [2, 3, 3, 3, 3, 2, 2, 2, 2, 2], - [0, 5, 3, 3, 2, 2, 2, 2, 1, 1], - [0, 2, 2, 2, 2, 2, 2, 2, 2, 1], - [2, 3, 6, 4, 4, 4, 5, 4, 5, 5], - [2, 4, 5, 5, 4, 5, 4, 6, 4, 4], - [2, 4, 4, 7, 4, 5, 4, 5, 5, 4], - [4, 3, 3, 3, 2, 3, 2, 2, 2, 2], - [1, 5, 5, 6, 4, 5, 4, 5, 5, 5], - [2, 7, 4, 6, 5, 5, 5, 5, 5, 5], - [2, 7, 5, 5, 5, 5, 5, 6, 5, 4], - [3, 3, 5, 4, 4, 5, 4, 5, 4, 4], - [2, 3, 3, 5, 5, 4, 4, 4, 4, 4], - [2, 4, 4, 6, 4, 5, 4, 5, 5, 5], - [2, 5, 4, 6, 5, 5, 5, 4, 5, 4], - [2, 7, 4, 5, 4, 5, 4, 5, 5, 5], - [2, 5, 4, 6, 7, 6, 5, 6, 5, 4], - [3, 6, 7, 4, 6, 5, 5, 6, 4, 5], - [2, 7, 6, 4, 4, 4, 5, 4, 5, 5], - [4, 5, 5, 4, 6, 6, 5, 6, 5, 4], - [2, 5, 5, 6, 5, 6, 4, 6, 4, 4], - [4, 5, 5, 5, 3, 7, 4, 5, 5, 4], - [2, 3, 4, 5, 5, 6, 4, 5, 5, 4], - [2, 3, 2, 3, 3, 4, 2, 3, 3, 3], - [1, 1, 2, 2, 2, 2, 2, 3, 2, 2], - [4, 5, 5, 6, 6, 6, 5, 6, 4, 5], - [3, 5, 5, 4, 4, 4, 4, 3, 3, 2], - [2, 5, 3, 7, 5, 5, 4, 4, 5, 4], - [4, 4, 5, 4, 5, 6, 5, 6, 5, 4], -]; -pub const NLSF_SEL_WB: [[u8; 16]; 32] = [ - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 0, 3], - [2, 5, 5, 3, 7, 4, 4, 5, 2, 5, 4, 5, 5, 4, 3, 3], - [0, 2, 1, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1], - [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 3], - [0, 6, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 6, 6, 3, 5, 2, 5, 5, 3, 4, 4, 7, 7, 4, 4, 4], - [3, 3, 7, 3, 5, 4, 3, 3, 3, 2, 2, 3, 3, 3, 2, 3], - [0, 0, 1, 0, 0, 0, 2, 1, 2, 1, 1, 2, 2, 2, 1, 1], - [0, 3, 2, 5, 3, 3, 2, 3, 2, 1, 0, 0, 1, 0, 0, 1], - [3, 5, 5, 4, 7, 5, 3, 3, 2, 3, 2, 2, 1, 0, 1, 0], - [2, 3, 5, 3, 4, 3, 3, 3, 2, 1, 2, 6, 4, 0, 0, 0], -]; -pub const NLSF_EXT: [u8; 7] = icdf(&[156, 60, 24, 9, 4, 2, 1]); -pub const NLSF_PRED_NBMB: [[i32; 9]; 2] = [[179, 138, 140, 148, 151, 149, 153, 151, 163], [116, 67, 82, 59, 92, 72, 100, 89, 92]]; -pub const NLSF_PRED_WB: [[i32; 15]; 2] = - [[175, 148, 160, 176, 178, 173, 174, 164, 177, 174, 196, 182, 198, 192, 182], [68, 62, 66, 60, 72, 117, 85, 90, 118, 136, 151, 142, 160, 142, 155]]; -pub const NLSF_PSEL_NBMB: [[u8; 9]; 32] = [ - [0, 1, 0, 0, 0, 0, 0, 0, 0], - [1, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [1, 1, 1, 0, 0, 0, 0, 1, 0], - [0, 1, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0, 0], - [1, 0, 1, 1, 0, 0, 0, 1, 0], - [0, 1, 1, 0, 0, 1, 1, 0, 0], - [0, 0, 1, 1, 0, 1, 0, 1, 1], - [0, 0, 1, 1, 0, 0, 1, 1, 1], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 1, 1, 1, 1, 1, 0], - [0, 1, 0, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1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]; 32] = [ - [12, 35, 60, 83, 108, 132, 157, 180, 206, 228], - [15, 32, 55, 77, 101, 125, 151, 175, 201, 225], - [19, 42, 66, 89, 114, 137, 162, 184, 209, 230], - [12, 25, 50, 72, 97, 120, 147, 172, 200, 223], - [26, 44, 69, 90, 114, 135, 159, 180, 205, 225], - [13, 22, 53, 80, 106, 130, 156, 180, 205, 228], - [15, 25, 44, 64, 90, 115, 142, 168, 196, 222], - [19, 24, 62, 82, 100, 120, 145, 168, 190, 214], - [22, 31, 50, 79, 103, 120, 151, 170, 203, 227], - [21, 29, 45, 65, 106, 124, 150, 171, 196, 224], - [30, 49, 75, 97, 121, 142, 165, 186, 209, 229], - [19, 25, 52, 70, 93, 116, 143, 166, 192, 219], - [26, 34, 62, 75, 97, 118, 145, 167, 194, 217], - [25, 33, 56, 70, 91, 113, 143, 165, 196, 223], - [21, 34, 51, 72, 97, 117, 145, 171, 196, 222], - [20, 29, 50, 67, 90, 117, 144, 168, 197, 221], - [22, 31, 48, 66, 95, 117, 146, 168, 196, 222], - [24, 33, 51, 77, 116, 134, 158, 180, 200, 224], - [21, 28, 70, 87, 106, 124, 149, 170, 194, 217], - [26, 33, 53, 64, 83, 117, 152, 173, 204, 225], - [27, 34, 65, 95, 108, 129, 155, 174, 210, 225], - [20, 26, 72, 99, 113, 131, 154, 176, 200, 219], - [34, 43, 61, 78, 93, 114, 155, 177, 205, 229], - [23, 29, 54, 97, 124, 138, 163, 179, 209, 229], - [30, 38, 56, 89, 118, 129, 158, 178, 200, 231], - [21, 29, 49, 63, 85, 111, 142, 163, 193, 222], - [27, 48, 77, 103, 133, 158, 179, 196, 215, 232], - [29, 47, 74, 99, 124, 151, 176, 198, 220, 237], - [33, 42, 61, 76, 93, 121, 155, 174, 207, 225], - [29, 53, 87, 112, 136, 154, 170, 188, 208, 227], - [24, 30, 52, 84, 131, 150, 166, 186, 203, 229], - [37, 48, 64, 84, 104, 118, 156, 177, 201, 230], -]; -pub const NLSF_CB_WB: [[i32; 16]; 32] = [ - [7, 23, 38, 54, 69, 85, 100, 116, 131, 147, 162, 178, 193, 208, 223, 239], - [13, 25, 41, 55, 69, 83, 98, 112, 127, 142, 157, 171, 187, 203, 220, 236], - [15, 21, 34, 51, 61, 78, 92, 106, 126, 136, 152, 167, 185, 205, 225, 240], - [10, 21, 36, 50, 63, 79, 95, 110, 126, 141, 157, 173, 189, 205, 221, 237], - [17, 20, 37, 51, 59, 78, 89, 107, 123, 134, 150, 164, 184, 205, 224, 240], - [10, 15, 32, 51, 67, 81, 96, 112, 129, 142, 158, 173, 189, 204, 220, 236], - [8, 21, 37, 51, 65, 79, 98, 113, 126, 138, 155, 168, 179, 192, 209, 218], - [12, 15, 34, 55, 63, 78, 87, 108, 118, 131, 148, 167, 185, 203, 219, 236], - [16, 19, 32, 36, 56, 79, 91, 108, 118, 136, 154, 171, 186, 204, 220, 237], - [11, 28, 43, 58, 74, 89, 105, 120, 135, 150, 165, 180, 196, 211, 226, 241], - [6, 16, 33, 46, 60, 75, 92, 107, 123, 137, 156, 169, 185, 199, 214, 225], - [11, 19, 30, 44, 57, 74, 89, 105, 121, 135, 152, 169, 186, 202, 218, 234], - [12, 19, 29, 46, 57, 71, 88, 100, 120, 132, 148, 165, 182, 199, 216, 233], - [17, 23, 35, 46, 56, 77, 92, 106, 123, 134, 152, 167, 185, 204, 222, 237], - [14, 17, 45, 53, 63, 75, 89, 107, 115, 132, 151, 171, 188, 206, 221, 240], - [9, 16, 29, 40, 56, 71, 88, 103, 119, 137, 154, 171, 189, 205, 222, 237], - [16, 19, 36, 48, 57, 76, 87, 105, 118, 132, 150, 167, 185, 202, 218, 236], - [12, 17, 29, 54, 71, 81, 94, 104, 126, 136, 149, 164, 182, 201, 221, 237], - [15, 28, 47, 62, 79, 97, 115, 129, 142, 155, 168, 180, 194, 208, 223, 238], - [8, 14, 30, 45, 62, 78, 94, 111, 127, 143, 159, 175, 192, 207, 223, 239], - [17, 30, 49, 62, 79, 92, 107, 119, 132, 145, 160, 174, 190, 204, 220, 235], - [14, 19, 36, 45, 61, 76, 91, 108, 121, 138, 154, 172, 189, 205, 222, 238], - [12, 18, 31, 45, 60, 76, 91, 107, 123, 138, 154, 171, 187, 204, 221, 236], - [13, 17, 31, 43, 53, 70, 83, 103, 114, 131, 149, 167, 185, 203, 220, 237], - [17, 22, 35, 42, 58, 78, 93, 110, 125, 139, 155, 170, 188, 206, 224, 240], - [8, 15, 34, 50, 67, 83, 99, 115, 131, 146, 162, 178, 193, 209, 224, 239], - [13, 16, 41, 66, 73, 86, 95, 111, 128, 137, 150, 163, 183, 206, 225, 241], - [17, 25, 37, 52, 63, 75, 92, 102, 119, 132, 144, 160, 175, 191, 212, 231], - [19, 31, 49, 65, 83, 100, 117, 133, 147, 161, 174, 187, 200, 213, 227, 242], - [18, 31, 52, 68, 88, 103, 117, 126, 138, 149, 163, 177, 192, 207, 223, 239], - [16, 29, 47, 61, 76, 90, 106, 119, 133, 147, 161, 176, 193, 209, 224, 240], - [15, 21, 35, 50, 61, 73, 86, 97, 110, 119, 129, 141, 175, 198, 218, 237], -]; -pub const NLSF_MIN_SPACING_NBMB: [i32; 11] = [250, 3, 6, 3, 3, 3, 4, 3, 3, 3, 461]; -pub const NLSF_MIN_SPACING_WB: [i32; 17] = [100, 3, 40, 3, 3, 3, 5, 14, 14, 10, 11, 3, 8, 9, 7, 3, 347]; -pub const NLSF_INTERP: [u8; 5] = icdf(&[13, 22, 29, 11, 181]); -pub const LSF_ORDER_NBMB: [usize; 10] = [0, 9, 6, 3, 4, 5, 8, 1, 2, 7]; -pub const LSF_ORDER_WB: [usize; 16] = [0, 15, 8, 7, 4, 11, 12, 3, 2, 13, 10, 5, 6, 9, 14, 1]; -pub const COS_Q12: [i32; 129] = [ - 4096, 4095, 4091, 4085, 4076, 4065, 4052, 4036, 4017, 3997, 3973, 3948, 3920, 3889, 3857, 3822, 3784, 3745, 3703, 3659, 3613, 3564, 3513, 3461, 3406, 3349, - 3290, 3229, 3166, 3102, 3035, 2967, 2896, 2824, 2751, 2676, 2599, 2520, 2440, 2359, 2276, 2191, 2106, 2019, 1931, 1842, 1751, 1660, 1568, 1474, 1380, 1285, - 1189, 1093, 995, 897, 799, 700, 601, 501, 401, 301, 201, 101, 0, -101, -201, -301, -401, -501, -601, -700, -799, -897, -995, -1093, -1189, -1285, -1380, - -1474, -1568, -1660, -1751, -1842, -1931, -2019, -2106, -2191, -2276, -2359, -2440, -2520, -2599, -2676, -2751, -2824, -2896, -2967, -3035, -3102, -3166, - -3229, -3290, -3349, -3406, -3461, -3513, -3564, -3613, -3659, -3703, -3745, -3784, -3822, -3857, -3889, -3920, -3948, -3973, -3997, -4017, -4036, -4052, - -4065, -4076, -4085, -4091, -4095, -4096, -]; -pub const PITCH_HIGH: [u8; 32] = icdf(&[3, 3, 6, 11, 21, 30, 32, 19, 11, 10, 12, 13, 13, 12, 11, 9, 8, 7, 6, 4, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]); -pub const PITCH_LOW: [&[u8]; 3] = [&icdf::<4>(&[64, 64, 64, 64]), &icdf::<6>(&[43, 42, 43, 43, 42, 43]), &icdf::<8>(&[32, 32, 32, 32, 32, 32, 32, 32])]; -pub const PITCH_DELTA: [u8; 21] = icdf(&[46, 2, 2, 3, 4, 6, 10, 15, 26, 38, 30, 22, 15, 10, 7, 6, 4, 4, 2, 2, 2]); -pub const PITCH_CONTOUR: [&[u8]; 4] = [ - &icdf::<3>(&[143, 50, 63]), - &icdf::<11>(&[68, 12, 21, 17, 19, 22, 30, 24, 17, 16, 10]), - &icdf::<12>(&[91, 46, 39, 19, 14, 12, 8, 7, 6, 5, 5, 4]), - &icdf::<34>(&[33, 22, 18, 16, 15, 14, 14, 13, 13, 10, 9, 9, 8, 6, 6, 6, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1]), -]; -pub const CB_NB_10: [[i32; 2]; 3] = [[0, 0], [1, 0], [0, 1]]; -pub const CB_NB_20: [[i32; 4]; 11] = [ - [0, 0, 0, 0], - [2, 1, 0, -1], - [-1, 0, 1, 2], - [-1, 0, 0, 1], - [-1, 0, 0, 0], - [0, 0, 0, 1], - [0, 0, 1, 1], - [1, 1, 0, 0], - [1, 0, 0, 0], - [0, 0, 0, -1], - [1, 0, 0, -1], -]; -pub const CB_WB_10: [[i32; 2]; 12] = [[0, 0], [0, 1], [1, 0], [-1, 1], [1, -1], [-1, 2], [2, -1], [-2, 2], [2, -2], [-2, 3], [3, -2], [-3, 3]]; -pub const CB_WB_20: [[i32; 4]; 34] = [ - [0, 0, 0, 0], - [0, 0, 1, 1], - [1, 1, 0, 0], - [-1, 0, 0, 0], - [0, 0, 0, 1], - [1, 0, 0, 0], - [-1, 0, 0, 1], - [0, 0, 0, -1], - [-1, 0, 1, 2], - [1, 0, 0, -1], - [-2, -1, 1, 2], - [2, 1, 0, -1], - [-2, 0, 0, 2], - [-2, 0, 1, 3], - [2, 1, -1, -2], - [-3, -1, 1, 3], - [2, 0, 0, -2], - [3, 1, 0, -2], - [-3, -1, 2, 4], - [-4, -1, 1, 4], - [3, 1, -1, -3], - [-4, -1, 2, 5], - [4, 2, -1, -3], - [4, 1, -1, -4], - [-5, -1, 2, 6], - [5, 2, -1, -4], - [-6, -2, 2, 6], - [-5, -2, 2, 5], - [6, 2, -1, -5], - [-7, -2, 3, 8], - [6, 2, -2, -6], - [5, 2, -2, -5], - [8, 3, -2, -7], - [-9, -3, 3, 9], -]; -pub const LTP_PERIODICITY: [u8; 3] = icdf(&[77, 80, 99]); -pub const LTP_FILTER: [&[u8]; 3] = [ - &icdf::<8>(&[185, 15, 13, 13, 9, 9, 6, 6]), - &icdf::<16>(&[57, 34, 21, 20, 15, 13, 12, 13, 10, 10, 9, 10, 9, 8, 7, 8]), - &icdf::<32>(&[15, 16, 14, 12, 12, 12, 11, 11, 11, 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 5, 4, 4, 4, 3, 4, 3, 2]), -]; -pub const LTP_TAPS_0: [[i32; 5]; 8] = [ - [4, 6, 24, 7, 5], - [0, 0, 2, 0, 0], - [12, 28, 41, 13, -4], - [-9, 15, 42, 25, 14], - [1, -2, 62, 41, -9], - [-10, 37, 65, -4, 3], - [-6, 4, 66, 7, -8], - [16, 14, 38, -3, 33], -]; -pub const LTP_TAPS_1: [[i32; 5]; 16] = [ - [13, 22, 39, 23, 12], - [-1, 36, 64, 27, -6], - [-7, 10, 55, 43, 17], - [1, 1, 8, 1, 1], - [6, -11, 74, 53, -9], - [-12, 55, 76, -12, 8], - [-3, 3, 93, 27, -4], - [26, 39, 59, 3, -8], - [2, 0, 77, 11, 9], - [-8, 22, 44, -6, 7], - [40, 9, 26, 3, 9], - [-7, 20, 101, -7, 4], - [3, -8, 42, 26, 0], - [-15, 33, 68, 2, 23], - [-2, 55, 46, -2, 15], - [3, -1, 21, 16, 41], -]; -pub const LTP_TAPS_2: [[i32; 5]; 32] = [ - [-6, 27, 61, 39, 5], - [-11, 42, 88, 4, 1], - [-2, 60, 65, 6, -4], - [-1, -5, 73, 56, 1], - [-9, 19, 94, 29, -9], - [0, 12, 99, 6, 4], - [8, -19, 102, 46, -13], - [3, 2, 13, 3, 2], - [9, -21, 84, 72, -18], - [-11, 46, 104, -22, 8], - [18, 38, 48, 23, 0], - [-16, 70, 83, -21, 11], - [5, -11, 117, 22, -8], - [-6, 23, 117, -12, 3], - [3, -8, 95, 28, 4], - [-10, 15, 77, 60, -15], - [-1, 4, 124, 2, -4], - [3, 38, 84, 24, -25], - [2, 13, 42, 13, 31], - [21, -4, 56, 46, -1], - [-1, 35, 79, -13, 19], - [-7, 65, 88, -9, -14], - [20, 4, 81, 49, -29], - [20, 0, 75, 3, -17], - [5, -9, 44, 92, -8], - [1, -3, 22, 69, 31], - [-6, 95, 41, -12, 5], - [39, 67, 16, -4, 1], - [0, -6, 120, 55, -36], - [-13, 44, 122, 4, -24], - [81, 5, 11, 3, 7], - [2, 0, 9, 10, 88], -]; -pub const LTP_SCALE: [u8; 3] = icdf(&[128, 64, 64]); -pub const UNIFORM4: [u8; 4] = icdf(&[64, 64, 64, 64]); -pub const RATE_LEVEL: [&[u8]; 2] = [&icdf::<9>(&[15, 51, 12, 46, 45, 13, 33, 27, 14]), &icdf::<9>(&[33, 30, 36, 17, 34, 49, 18, 21, 18])]; -pub const PULSE_COUNT: [&[u8]; 11] = [ - &icdf::<18>(&[131, 74, 25, 8, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), - &icdf::<18>(&[58, 93, 60, 23, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), - &icdf::<18>(&[43, 51, 46, 33, 24, 16, 11, 8, 6, 3, 3, 3, 2, 1, 1, 2, 1, 2]), - &icdf::<18>(&[17, 52, 71, 57, 31, 12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), - &icdf::<18>(&[6, 21, 41, 53, 49, 35, 21, 11, 6, 3, 2, 2, 1, 1, 1, 1, 1, 1]), - &icdf::<18>(&[7, 14, 22, 28, 29, 28, 25, 20, 17, 13, 11, 9, 7, 5, 4, 4, 3, 10]), - &icdf::<18>(&[2, 5, 14, 29, 42, 46, 41, 31, 19, 11, 6, 3, 2, 1, 1, 1, 1, 1]), - &icdf::<18>(&[1, 2, 4, 10, 19, 29, 35, 37, 34, 28, 20, 14, 8, 5, 4, 2, 2, 2]), - &icdf::<18>(&[1, 2, 2, 5, 9, 14, 20, 24, 27, 28, 26, 23, 20, 15, 11, 8, 6, 15]), - &icdf::<18>(&[1, 1, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2]), - &icdf::<18>(&[2, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2, 0]), -]; -pub const SHELL_16: [&[u8]; 16] = [ - &icdf::<2>(&[126, 130]), - &icdf::<3>(&[56, 142, 58]), - &icdf::<4>(&[25, 101, 104, 26]), - &icdf::<5>(&[12, 60, 108, 64, 12]), - &icdf::<6>(&[7, 35, 84, 87, 37, 6]), - &icdf::<7>(&[4, 20, 59, 86, 63, 21, 3]), - &icdf::<8>(&[3, 12, 38, 72, 75, 42, 12, 2]), - &icdf::<9>(&[2, 8, 25, 54, 73, 59, 27, 7, 1]), - &icdf::<10>(&[2, 5, 17, 39, 63, 65, 42, 18, 4, 1]), - &icdf::<11>(&[1, 4, 12, 28, 49, 63, 54, 30, 11, 3, 1]), - &icdf::<12>(&[1, 4, 8, 20, 37, 55, 57, 41, 22, 8, 2, 1]), - &icdf::<13>(&[1, 3, 7, 15, 28, 44, 53, 48, 33, 16, 6, 1, 1]), - &icdf::<14>(&[1, 2, 6, 12, 21, 35, 47, 48, 40, 25, 12, 5, 1, 1]), - &icdf::<15>(&[1, 1, 4, 10, 17, 27, 37, 47, 43, 33, 21, 9, 4, 1, 1]), - &icdf::<16>(&[1, 1, 1, 8, 14, 22, 33, 40, 43, 38, 28, 16, 8, 1, 1, 1]), - &icdf::<17>(&[1, 1, 1, 1, 13, 18, 27, 36, 41, 41, 34, 24, 14, 1, 1, 1, 1]), -]; -pub const SHELL_8: [&[u8]; 16] = [ - &icdf::<2>(&[127, 129]), - &icdf::<3>(&[53, 149, 54]), - &icdf::<4>(&[22, 105, 106, 23]), - &icdf::<5>(&[11, 61, 111, 63, 10]), - &icdf::<6>(&[6, 35, 86, 88, 36, 5]), - &icdf::<7>(&[4, 20, 59, 87, 62, 21, 3]), - &icdf::<8>(&[3, 13, 40, 71, 73, 41, 13, 2]), - &icdf::<9>(&[3, 9, 27, 53, 70, 56, 28, 9, 1]), - &icdf::<10>(&[3, 8, 19, 37, 57, 61, 44, 20, 6, 1]), - &icdf::<11>(&[3, 7, 15, 28, 44, 54, 49, 33, 17, 5, 1]), - &icdf::<12>(&[1, 7, 13, 22, 34, 46, 48, 38, 28, 14, 4, 1]), - &icdf::<13>(&[1, 1, 11, 22, 27, 35, 42, 47, 33, 25, 10, 1, 1]), - &icdf::<14>(&[1, 1, 6, 14, 26, 37, 43, 43, 37, 26, 14, 6, 1, 1]), - &icdf::<15>(&[1, 1, 4, 10, 20, 31, 40, 42, 40, 31, 20, 10, 4, 1, 1]), - &icdf::<16>(&[1, 1, 3, 8, 16, 26, 35, 38, 38, 35, 26, 16, 8, 3, 1, 1]), - &icdf::<17>(&[1, 1, 2, 6, 12, 21, 30, 36, 38, 36, 30, 21, 12, 6, 2, 1, 1]), -]; -pub const SHELL_4: [&[u8]; 16] = [ - &icdf::<2>(&[127, 129]), - &icdf::<3>(&[49, 157, 50]), - &icdf::<4>(&[20, 107, 109, 20]), - &icdf::<5>(&[11, 60, 113, 62, 10]), - &icdf::<6>(&[7, 36, 84, 87, 36, 6]), - &icdf::<7>(&[6, 24, 57, 82, 60, 23, 4]), - &icdf::<8>(&[5, 18, 39, 64, 68, 42, 16, 4]), - &icdf::<9>(&[6, 14, 29, 47, 61, 52, 30, 14, 3]), - &icdf::<10>(&[1, 15, 23, 35, 51, 50, 40, 30, 10, 1]), - &icdf::<11>(&[1, 1, 21, 32, 42, 52, 46, 41, 18, 1, 1]), - &icdf::<12>(&[1, 6, 16, 27, 36, 42, 42, 36, 27, 16, 6, 1]), - &icdf::<13>(&[1, 5, 12, 21, 31, 38, 40, 38, 31, 21, 12, 5, 1]), - &icdf::<14>(&[1, 3, 9, 17, 26, 34, 38, 38, 34, 26, 17, 9, 3, 1]), - &icdf::<15>(&[1, 3, 7, 14, 22, 29, 34, 36, 34, 29, 22, 14, 7, 3, 1]), - &icdf::<16>(&[1, 2, 5, 11, 18, 25, 31, 35, 35, 31, 25, 18, 11, 5, 2, 1]), - &icdf::<17>(&[1, 1, 4, 9, 15, 21, 28, 32, 34, 32, 28, 21, 15, 9, 4, 1, 1]), -]; -pub const SHELL_2: [&[u8]; 16] = [ - &icdf::<2>(&[128, 128]), - &icdf::<3>(&[42, 172, 42]), - &icdf::<4>(&[21, 107, 107, 21]), - &icdf::<5>(&[12, 60, 112, 61, 11]), - &icdf::<6>(&[8, 34, 86, 86, 35, 7]), - &icdf::<7>(&[8, 23, 55, 90, 55, 20, 5]), - &icdf::<8>(&[5, 15, 38, 72, 72, 36, 15, 3]), - &icdf::<9>(&[6, 12, 27, 52, 77, 47, 20, 10, 5]), - &icdf::<10>(&[6, 19, 28, 35, 40, 40, 35, 28, 19, 6]), - &icdf::<11>(&[4, 14, 22, 31, 37, 40, 37, 31, 22, 14, 4]), - &icdf::<12>(&[3, 10, 18, 26, 33, 38, 38, 33, 26, 18, 10, 3]), - &icdf::<13>(&[2, 8, 13, 21, 29, 36, 38, 36, 29, 21, 13, 8, 2]), - &icdf::<14>(&[1, 5, 10, 17, 25, 32, 38, 38, 32, 25, 17, 10, 5, 1]), - &icdf::<15>(&[1, 4, 7, 13, 21, 29, 35, 36, 35, 29, 21, 13, 7, 4, 1]), - &icdf::<16>(&[1, 2, 5, 10, 17, 25, 32, 36, 36, 32, 25, 17, 10, 5, 2, 1]), - &icdf::<17>(&[1, 2, 4, 7, 13, 21, 28, 34, 36, 34, 28, 21, 13, 7, 4, 2, 1]), -]; -pub const EXC_LSB: [u8; 2] = icdf(&[136, 120]); -pub const EXC_SIGN: [&[u8]; 42] = [ - &icdf::<2>(&[2, 254]), - &icdf::<2>(&[207, 49]), - &icdf::<2>(&[189, 67]), - &icdf::<2>(&[179, 77]), - &icdf::<2>(&[174, 82]), - &icdf::<2>(&[163, 93]), - &icdf::<2>(&[157, 99]), - &icdf::<2>(&[58, 198]), - &icdf::<2>(&[245, 11]), - &icdf::<2>(&[238, 18]), - &icdf::<2>(&[232, 24]), - &icdf::<2>(&[225, 31]), - &icdf::<2>(&[220, 36]), - &icdf::<2>(&[211, 45]), - &icdf::<2>(&[1, 255]), - &icdf::<2>(&[210, 46]), - &icdf::<2>(&[190, 66]), - &icdf::<2>(&[178, 78]), - &icdf::<2>(&[169, 87]), - &icdf::<2>(&[162, 94]), - &icdf::<2>(&[152, 104]), - &icdf::<2>(&[48, 208]), - &icdf::<2>(&[242, 14]), - &icdf::<2>(&[235, 21]), - &icdf::<2>(&[224, 32]), - &icdf::<2>(&[214, 42]), - &icdf::<2>(&[205, 51]), - &icdf::<2>(&[190, 66]), - &icdf::<2>(&[1, 255]), - &icdf::<2>(&[162, 94]), - &icdf::<2>(&[152, 104]), - &icdf::<2>(&[147, 109]), - &icdf::<2>(&[144, 112]), - &icdf::<2>(&[141, 115]), - &icdf::<2>(&[138, 118]), - &icdf::<2>(&[8, 248]), - &icdf::<2>(&[203, 53]), - &icdf::<2>(&[187, 69]), - &icdf::<2>(&[176, 80]), - &icdf::<2>(&[168, 88]), - &icdf::<2>(&[161, 95]), - &icdf::<2>(&[154, 102]), -]; -pub const LBRR_FLAGS: [&[u8]; 2] = [&icdf::<3>(&[53, 53, 150]), &icdf::<7>(&[41, 20, 29, 41, 15, 28, 82])]; diff --git a/crates/opusenc/src/tables.rs b/crates/opusenc/src/tables.rs deleted file mode 100644 index 00d623af0..000000000 --- a/crates/opusenc/src/tables.rs +++ /dev/null @@ -1,122 +0,0 @@ -//! Constant tables of the 48 kHz CELT mode (RFC 6716 §4.3, Tables 55–58 and §4.3.2). -//! -//! Transcribed from RFC 6716; copied from FilmCraft's spec-derived `filmcraft-opus` decoder -//! (first-party, MIT OR Apache-2.0) so both sides share the exact same values. - -/// Number of energy bands. -pub const NB_EBANDS: usize = 21; -/// Band edges in units of 2.5 ms MDCT bins (Table 55). -pub const EBANDS: [i32; NB_EBANDS + 1] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100]; -/// Overlap of the low-overlap window (samples at 48 kHz). -pub const OVERLAP: usize = 120; -/// Largest LM (20 ms frames). -pub const MAX_LM: usize = 3; -/// Pre-emphasis coefficient. -pub const PREEMPH: f32 = 0.850_006_1; - -/// Static allocation table (Table 57), indexed `[quality][band]`, in 1/32 bit per MDCT bin. -pub const ALLOC: [[u8; NB_EBANDS]; 11] = transpose([ - [0, 90, 110, 118, 126, 134, 144, 152, 162, 172, 200], - [0, 80, 100, 110, 119, 127, 137, 145, 155, 165, 200], - [0, 75, 90, 103, 112, 120, 130, 138, 148, 158, 200], - [0, 69, 84, 93, 104, 114, 124, 132, 142, 152, 200], - [0, 63, 78, 86, 95, 103, 113, 123, 133, 143, 200], - [0, 56, 71, 80, 89, 97, 107, 117, 127, 137, 200], - [0, 49, 65, 75, 83, 91, 101, 111, 121, 131, 200], - [0, 40, 58, 70, 78, 85, 95, 105, 115, 125, 200], - [0, 34, 51, 65, 72, 78, 88, 98, 108, 118, 198], - [0, 29, 45, 59, 66, 72, 82, 92, 102, 112, 193], - [0, 20, 39, 53, 60, 66, 76, 86, 96, 106, 188], - [0, 18, 32, 47, 54, 60, 70, 80, 90, 100, 183], - [0, 10, 26, 40, 47, 54, 64, 74, 84, 94, 178], - [0, 0, 20, 31, 39, 47, 57, 67, 77, 87, 173], - [0, 0, 12, 23, 32, 41, 51, 61, 71, 81, 168], - [0, 0, 0, 15, 25, 35, 45, 55, 65, 75, 163], - [0, 0, 0, 4, 17, 29, 39, 49, 59, 69, 158], - [0, 0, 0, 0, 12, 23, 33, 43, 53, 63, 153], - [0, 0, 0, 0, 1, 16, 26, 36, 46, 56, 148], - [0, 0, 0, 0, 0, 10, 15, 20, 30, 45, 129], - [0, 0, 0, 0, 0, 1, 1, 1, 1, 20, 104], -]); - -const fn transpose(t: [[u8; 11]; NB_EBANDS]) -> [[u8; NB_EBANDS]; 11] { - let mut out = [[0u8; NB_EBANDS]; 11]; - let mut b = 0; - while b < NB_EBANDS { - let mut q = 0; - while q < 11 { - out[q][b] = t[b][q]; - q += 1; - } - b += 1; - } - out -} - -/// Mean band energy (log2 domain) removed before coarse quantisation. -pub const E_MEANS: [f32; 25] = [ - 6.4375, 6.25, 5.75, 5.3125, 5.0625, 4.8125, 4.5, 4.375, 4.875, 4.6875, 4.5625, 4.4375, 4.875, 4.625, 4.3125, 4.5, 4.375, 4.625, 4.75, 4.4375, 3.75, 3.75, - 3.75, 3.75, 3.75, -]; - -/// Inter-frame prediction coefficient (alpha) per LM, Q15. -pub const PRED_COEF: [f32; 4] = [29440.0 / 32768.0, 26112.0 / 32768.0, 21248.0 / 32768.0, 16384.0 / 32768.0]; -/// Inter-band prediction coefficient (beta) per LM for inter frames, Q15. -pub const BETA_COEF: [f32; 4] = [30147.0 / 32768.0, 22282.0 / 32768.0, 12124.0 / 32768.0, 6554.0 / 32768.0]; -/// Beta for intra frames. -pub const BETA_INTRA: f32 = 4915.0 / 32768.0; - -/// Laplace model parameters for coarse energy: `[LM][intra][2*band + {0: prob, 1: decay}]`. -pub const E_PROB_MODEL: [[[u8; 42]; 2]; 4] = [ - [ - [ - 72, 127, 65, 129, 66, 128, 65, 128, 64, 128, 62, 128, 64, 128, 64, 128, 92, 78, 92, 79, 92, 78, 90, 79, 116, 41, 115, 40, 114, 40, 132, 26, 132, - 26, 145, 17, 161, 12, 176, 10, 177, 11, - ], - [ - 24, 179, 48, 138, 54, 135, 54, 132, 53, 134, 56, 133, 55, 132, 55, 132, 61, 114, 70, 96, 74, 88, 75, 88, 87, 74, 89, 66, 91, 67, 100, 59, 108, 50, - 120, 40, 122, 37, 97, 43, 78, 50, - ], - ], - [ - [ - 83, 78, 84, 81, 88, 75, 86, 74, 87, 71, 90, 73, 93, 74, 93, 74, 109, 40, 114, 36, 117, 34, 117, 34, 143, 17, 145, 18, 146, 19, 162, 12, 165, 10, - 178, 7, 189, 6, 190, 8, 177, 9, - ], - [ - 23, 178, 54, 115, 63, 102, 66, 98, 69, 99, 74, 89, 71, 91, 73, 91, 78, 89, 86, 80, 92, 66, 93, 64, 102, 59, 103, 60, 104, 60, 117, 52, 123, 44, - 138, 35, 133, 31, 97, 38, 77, 45, - ], - ], - [ - [ - 61, 90, 93, 60, 105, 42, 107, 41, 110, 45, 116, 38, 113, 38, 112, 38, 124, 26, 132, 27, 136, 19, 140, 20, 155, 14, 159, 16, 158, 18, 170, 13, 177, - 10, 187, 8, 192, 6, 175, 9, 159, 10, - ], - [ - 21, 178, 59, 110, 71, 86, 75, 85, 84, 83, 91, 66, 88, 73, 87, 72, 92, 75, 98, 72, 105, 58, 107, 54, 115, 52, 114, 55, 112, 56, 129, 51, 132, 40, - 150, 33, 140, 29, 98, 35, 77, 42, - ], - ], - [ - [ - 42, 121, 96, 66, 108, 43, 111, 40, 117, 44, 123, 32, 120, 36, 119, 33, 127, 33, 134, 34, 139, 21, 147, 23, 152, 20, 158, 25, 154, 26, 166, 21, 173, - 16, 184, 13, 184, 10, 150, 13, 139, 15, - ], - [ - 22, 178, 63, 114, 74, 82, 84, 83, 92, 82, 103, 62, 96, 72, 96, 67, 101, 73, 107, 72, 113, 55, 118, 52, 125, 52, 118, 52, 117, 55, 135, 49, 137, 39, - 157, 32, 145, 29, 97, 33, 77, 40, - ], - ], -]; - -/// Inverse CDF for coarse energy when only a few bits remain. -pub const SMALL_ENERGY_ICDF: [u8; 3] = [2, 1, 0]; -/// Conservative log2 in 1/8 bits of the number of coded bands (intensity reservation). -pub const LOG2_FRAC_TABLE: [i32; 24] = [0, 8, 13, 16, 19, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32, 32, 33, 34, 34, 35, 36, 36, 37, 37]; -/// TF resolution changes: `[LM][4*transient + 2*tf_select + tf_flag]`. -pub const TF_SELECT_TABLE: [[i8; 8]; 4] = [[0, -1, 0, -1, 0, -1, 0, -1], [0, -1, 0, -2, 1, 0, 1, -1], [0, -2, 0, -3, 2, 0, 1, -1], [0, -2, 0, -3, 3, 0, 1, -1]]; -/// Spreading decision `{7, 2, 21, 2}/32`. -pub const SPREAD_ICDF: [u8; 4] = [25, 23, 2, 0]; -/// Allocation trim (Table 58). -pub const TRIM_ICDF: [u8; 11] = [126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0]; diff --git a/crates/opusenc/tests/it/common/mod.rs b/crates/opusenc/tests/it/common/mod.rs deleted file mode 100644 index 8f00b88e9..000000000 --- a/crates/opusenc/tests/it/common/mod.rs +++ /dev/null @@ -1,285 +0,0 @@ -//! Shared helpers for the SILK/hybrid round-trip tests: synthetic signals, encoding, decoding -//! with FilmCraft's spec-derived decoder, delay-searched SNR and an Ogg Opus writer for ffmpeg. -#![allow(dead_code)] - -use effectcraft_opusenc::OpusEncoder; - -pub const SR: f64 = 48_000.0; -pub const FRAME: usize = OpusEncoder::FRAME_SIZE; - -/// Two-pole resonator state. -struct Reson { - y1: f64, - y2: f64, -} - -impl Reson { - fn run(&mut self, x: f64, f: f64, bw: f64) -> f64 { - let r = (-std::f64::consts::PI * bw / SR).exp(); - let a1 = 2.0 * r * (2.0 * std::f64::consts::PI * f / SR).cos(); - let a2 = -r * r; - let g = 1.0 - r; - let y = g * x + a1 * self.y1 + a2 * self.y2; - self.y2 = self.y1; - self.y1 = y; - y - } -} - -/// Speech-like test signal: a glottal pulse train (100–200 Hz, gliding pitch) through three -/// formant resonators whose frequencies change per syllable, with syllable envelopes, short -/// pauses and a little aspiration noise. -pub fn speech(len: usize, seed: u32) -> Vec { - let vowels: [[f64; 3]; 5] = [[730.0, 1090.0, 2440.0], [270.0, 2290.0, 3010.0], [530.0, 1840.0, 2480.0], [570.0, 840.0, 2410.0], [300.0, 870.0, 2240.0]]; - let syl = (0.24 * SR) as usize; - let mut out = Vec::with_capacity(len); - let mut res = [Reson { y1: 0.0, y2: 0.0 }, Reson { y1: 0.0, y2: 0.0 }, Reson { y1: 0.0, y2: 0.0 }]; - let mut phase = 0.0f64; - let mut s = seed; - let mut prev_glottal = 0.0; - for n in 0..len { - let t = n as f64 / SR; - let k = n / syl; - let pos = (n % syl) as f64 / syl as f64; - // Every fourth syllable is a pause. - let pause = k % 4 == 3; - let env = if pause { 0.0 } else { (std::f64::consts::PI * pos).sin().powf(0.7) }; - let f0 = 100.0 + 50.0 * (1.0 + (2.0 * std::f64::consts::PI * 0.9 * t).sin()) + 15.0 * ((k * 7) % 5) as f64 - 30.0 * pos; - phase += f0 / SR; - if phase >= 1.0 { - phase -= 1.0; - } - // Rosenberg-like glottal flow; its derivative excites the vocal tract. - let g = if phase < 0.4 { - 0.5 * (1.0 - (std::f64::consts::PI * phase / 0.4).cos()) - } else if phase < 0.56 { - (std::f64::consts::FRAC_PI_2 * (phase - 0.4) / 0.16).cos() - } else { - 0.0 - }; - let dg = (g - prev_glottal) * 40.0; - prev_glottal = g; - s = s.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); - let noise = ((s >> 8) as f64 / (1u32 << 24) as f64 - 0.5) * 0.02; - let v = vowels[(k * 3 + 1) % 5]; - let w = vowels[(k * 3 + 4) % 5]; - let mix = pos; - let mut x = dg + noise; - let mut y = 0.0; - for (i, r) in res.iter_mut().enumerate() { - let f = v[i] * (1.0 - mix) + w[i] * mix; - y += r.run(x, f, 60.0 + 40.0 * i as f64) * [1.0, 0.6, 0.3][i]; - } - x = y * env * 1.2; - out.push(x as f32); - } - let peak = out.iter().fold(0f32, |m, v| m.max(v.abs())); - let g = 0.5 / peak.max(1e-9); - out.iter().map(|v| v * g).collect() -} - -/// Music-like test signal: three-note chords of harmonic tones (six partials each), changing -/// every half second with soft attacks and releases. -pub fn music(len: usize) -> Vec { - let chords: [[f64; 3]; 4] = [[261.63, 329.63, 392.0], [220.0, 277.18, 329.63], [174.61, 220.0, 261.63], [196.0, 246.94, 293.66]]; - let seg = (0.5 * SR) as usize; - (0..len) - .map(|n| { - let t = n as f64 / SR; - let k = n / seg; - let pos = (n % seg) as f64 / seg as f64; - let env = (pos * 20.0).min(1.0) * ((1.0 - pos) * 10.0).min(1.0); - let mut x = 0.0; - for (j, &f) in chords[k % 4].iter().enumerate() { - for h in 1..=6 { - x += (2.0 * std::f64::consts::PI * f * h as f64 * t + j as f64).sin() / h as f64; - } - } - (0.12 * env * x) as f32 - }) - .collect() -} - -pub fn interleave(planar: &[Vec]) -> Vec { - let c = planar.len(); - let len = planar[0].len(); - let mut pcm = vec![0f32; len * c]; - for (ch, p) in planar.iter().enumerate() { - for (i, &v) in p.iter().enumerate() { - pcm[i * c + ch] = v; - } - } - pcm -} - -/// Encodes planar input (padding the tail so the encoder delay is flushed). -pub fn encode(mut enc: OpusEncoder, planar: &[Vec]) -> (OpusEncoder, Vec>) { - let c = planar.len(); - let len = planar[0].len(); - let total = len + enc.pre_skip() as usize + 16; - let frames = total.div_ceil(FRAME); - let mut pcm = interleave(planar); - pcm.resize(frames * FRAME * c, 0.0); - let packets = pcm.chunks(FRAME * c).map(|f| enc.encode_float(f)).collect(); - (enc, packets) -} - -/// Decodes with craft-audio, drops the pre-skip and returns planar channels (full length). -pub fn decode(head: &[u8], packets: &[Vec]) -> Vec> { - let mut dec = craft_audio::opus::Decoder::new(head).expect("OpusHead"); - dec.set_trim_pre_skip(true); - let mut out: Vec> = vec![Vec::new(); dec.channels()]; - for p in packets { - let planes = dec.decode(Some(p)).expect("decode"); - for (o, p) in out.iter_mut().zip(planes) { - o.extend_from_slice(&p); - } - } - out -} - -/// Waveform SNR (dB) of `dec[i + shift]` against `orig[i]`, excluding the first and last 20 ms. -pub fn snr_at(orig: &[f32], dec: &[f32], shift: isize) -> f64 { - let (mut s, mut e) = (0f64, 0f64); - for i in FRAME..orig.len() - FRAME { - let j = i as isize + shift; - let d = if j >= 0 && (j as usize) < dec.len() { dec[j as usize] as f64 } else { 0.0 }; - s += (orig[i] as f64).powi(2); - e += (orig[i] as f64 - d).powi(2); - } - 10.0 * (s / e.max(1e-30)).log10() -} - -/// Best SNR over residual delays of ±`range` samples: (SNR dB, delay). -pub fn snr_search(orig: &[f32], dec: &[f32], range: isize) -> (f64, isize) { - (-range..=range).map(|d| (snr_at(orig, dec, d), d)).fold((f64::MIN, 0), |a, b| if b.0 > a.0 { b } else { a }) -} - -/// Segmental SNR (dB): mean over 20 ms segments holding signal (each clamped to [-10, 40]). -pub fn seg_snr(orig: &[f32], dec: &[f32], shift: isize) -> f64 { - let mut acc = 0f64; - let mut n = 0; - let mut i = FRAME; - while i + FRAME <= orig.len() - FRAME { - let (mut s, mut e) = (0f64, 0f64); - for k in i..i + FRAME { - let j = k as isize + shift; - let d = if j >= 0 && (j as usize) < dec.len() { dec[j as usize] as f64 } else { 0.0 }; - s += (orig[k] as f64).powi(2); - e += (orig[k] as f64 - d).powi(2); - } - if s / FRAME as f64 > 1e-5 { - acc += (10.0 * (s / e.max(1e-30)).log10()).clamp(-10.0, 40.0); - n += 1; - } - i += FRAME; - } - acc / n.max(1) as f64 -} - -/// Average bitrate (bits per second) of a packet sequence of 20 ms packets. -pub fn bitrate(packets: &[Vec]) -> f64 { - packets.iter().map(|p| p.len() * 8).sum::() as f64 / (packets.len() as f64 * 0.02) -} - -/// Low-pass filtered copy (FFT brick wall) used to compare band-limited modes fairly. -pub fn lowpass(x: &[f32], fc: f64) -> Vec { - let n = x.len().next_power_of_two(); - let mut re: Vec = x.iter().map(|&v| v as f64).collect(); - re.resize(n, 0.0); - let mut im = vec![0f64; n]; - fft(&mut re, &mut im, false); - for k in 0..n { - let f = (k.min(n - k)) as f64 * SR / n as f64; - if f > fc { - re[k] = 0.0; - im[k] = 0.0; - } - } - fft(&mut re, &mut im, true); - re[..x.len()].iter().map(|&v| (v / n as f64) as f32).collect() -} - -pub fn fft(re: &mut [f64], im: &mut [f64], inverse: bool) { - let n = re.len(); - let mut j = 0; - for i in 1..n { - let mut bit = n >> 1; - while j & bit != 0 { - j ^= bit; - bit >>= 1; - } - j |= bit; - if i < j { - re.swap(i, j); - im.swap(i, j); - } - } - let mut len = 2; - while len <= n { - let ang = if inverse { 2.0 } else { -2.0 } * std::f64::consts::PI / len as f64; - for s in (0..n).step_by(len) { - for k in 0..len / 2 { - let (wr, wi) = ((ang * k as f64).cos(), (ang * k as f64).sin()); - let (a, b) = (s + k, s + k + len / 2); - let tr = re[b] * wr - im[b] * wi; - let ti = re[b] * wi + im[b] * wr; - re[b] = re[a] - tr; - im[b] = im[a] - ti; - re[a] += tr; - im[a] += ti; - } - } - len <<= 1; - } -} - -// ---- Ogg Opus (RFC 3533 + RFC 7845) for the ffmpeg oracle ---- - -fn ogg_crc(data: &[u8]) -> u32 { - let mut crc = 0u32; - for &b in data { - crc ^= (b as u32) << 24; - for _ in 0..8 { - crc = if crc & 0x8000_0000 != 0 { (crc << 1) ^ 0x04C1_1DB7 } else { crc << 1 }; - } - } - crc -} - -fn ogg_page(out: &mut Vec, packet: &[u8], header_type: u8, granule: u64, seq: u32) { - let mut lacing = vec![255u8; packet.len() / 255]; - lacing.push((packet.len() % 255) as u8); - let start = out.len(); - out.extend_from_slice(b"OggS"); - out.push(0); - out.push(header_type); - out.extend_from_slice(&granule.to_le_bytes()); - out.extend_from_slice(&0x4543_4F50u32.to_le_bytes()); - out.extend_from_slice(&seq.to_le_bytes()); - out.extend_from_slice(&0u32.to_le_bytes()); - out.push(lacing.len() as u8); - out.extend_from_slice(&lacing); - out.extend_from_slice(packet); - let crc = ogg_crc(&out[start..]); - out[start + 22..start + 26].copy_from_slice(&crc.to_le_bytes()); -} - -/// An Ogg Opus file holding `packets` for `len` samples of audio. -pub fn ogg_opus(enc: &OpusEncoder, packets: &[Vec], len: usize) -> Vec { - let mut out = Vec::new(); - ogg_page(&mut out, &enc.opus_head(), 0x02, 0, 0); - let vendor = b"effectcraft-opusenc"; - let mut tags = b"OpusTags".to_vec(); - tags.extend_from_slice(&(vendor.len() as u32).to_le_bytes()); - tags.extend_from_slice(vendor); - tags.extend_from_slice(&0u32.to_le_bytes()); - ogg_page(&mut out, &tags, 0, 0, 1); - let pre_skip = enc.pre_skip() as u64; - for (i, p) in packets.iter().enumerate() { - let last = i + 1 == packets.len(); - let granule = if last { pre_skip + len as u64 } else { ((i + 1) * FRAME) as u64 }; - ogg_page(&mut out, p, if last { 0x04 } else { 0 }, granule, i as u32 + 2); - } - out -} diff --git a/crates/opusenc/tests/it/ffmpeg.rs b/crates/opusenc/tests/it/ffmpeg.rs deleted file mode 100644 index 1294ed348..000000000 --- a/crates/opusenc/tests/it/ffmpeg.rs +++ /dev/null @@ -1,81 +0,0 @@ -//! ffmpeg as a second, external oracle: every mode/bandwidth written as Ogg Opus must decode -//! without errors with both ffmpeg's native `opus` decoder and `libopus`, honour the pre-skip -//! and end granule, and reproduce the input. Skipped when ffmpeg is not installed. - -use crate::common; - -use std::process::Command; - -use common::*; -use effectcraft_opusenc::{Bandwidth, Mode, OpusEncoder}; - -const FFMPEG: &str = "/opt/homebrew/bin/ffmpeg"; - -fn ffmpeg() -> Option<&'static str> { - [FFMPEG, "ffmpeg"].into_iter().find(|exe| Command::new(exe).arg("-version").output().is_ok_and(|o| o.status.success())) -} - -/// Decodes an Ogg Opus file with ffmpeg's decoder `codec`; returns interleaved f32 output. -fn ffmpeg_decode(exe: &str, codec: &str, file: &[u8], channels: usize, tag: &str) -> Option> { - let has = Command::new(exe).args(["-hide_banner", "-decoders"]).output().ok()?; - if !String::from_utf8_lossy(&has.stdout).lines().any(|l| l.split_whitespace().nth(1) == Some(codec)) { - eprintln!("ffmpeg has no {codec} decoder; skipping it"); - return None; - } - let path = std::env::temp_dir().join(format!("effectcraft-opusenc-{}-{tag}.opus", std::process::id())); - std::fs::write(&path, file).unwrap(); - let out = Command::new(exe) - .args(["-v", "error", "-c:a", codec, "-i"]) - .arg(&path) - .args(["-f", "f32le", "-ac", &channels.to_string(), "-ar", "48000", "-"]) - .output() - .expect("run ffmpeg"); - let _ = std::fs::remove_file(&path); - let stderr = String::from_utf8_lossy(&out.stderr); - assert!(out.status.success(), "ffmpeg ({codec}) failed: {stderr}"); - // ffmpeg's native decoder also makes its raw-PCM muxer print a timestamp complaint for - // narrowband SILK streams written by libopus itself; that line is about ffmpeg's own - // timestamping, not the bitstream, so it is the one message tolerated. - let errors: Vec<&str> = stderr.lines().filter(|l| !l.trim().is_empty() && !l.contains("non monotonically increasing dts to muxer")).collect(); - assert!(errors.is_empty(), "ffmpeg ({codec}) reported errors: {errors:?}"); - Some(out.stdout.as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()) -} - -#[test] -fn ffmpeg_decodes_every_mode() { - let Some(exe) = ffmpeg() else { - eprintln!("ffmpeg not installed; skipping the oracle test"); - return; - }; - let len = 48_000; - let sp = speech(len + 30_000, 3); - let left = sp[..len].to_vec(); - let right: Vec = sp[30_000..].iter().map(|v| v * 0.7).collect(); - let cases = [ - (1usize, Mode::Silk, Bandwidth::Narrowband, 8_000u32, 3_400.0, 8.0), - (1, Mode::Silk, Bandwidth::Mediumband, 11_000, 5_000.0, 10.0), - (1, Mode::Silk, Bandwidth::Wideband, 16_000, 7_000.0, 12.0), - (2, Mode::Silk, Bandwidth::Wideband, 32_000, 7_000.0, 12.0), - (1, Mode::Hybrid, Bandwidth::SuperWideband, 24_000, 24_000.0, 10.0), - (1, Mode::Hybrid, Bandwidth::Fullband, 32_000, 24_000.0, 10.0), - (2, Mode::Hybrid, Bandwidth::Fullband, 64_000, 24_000.0, 10.0), - (2, Mode::Celt, Bandwidth::Fullband, 96_000, 24_000.0, 10.0), - ]; - for (c, mode, bw, rate, fc, min_snr) in cases { - let planar: Vec> = if c == 1 { vec![left.clone()] } else { vec![left.clone(), right.clone()] }; - let (enc, packets) = encode(OpusEncoder::with_mode(c as u8, rate, mode, bw), &planar); - let file = ogg_opus(&enc, &packets, len); - for codec in ["opus", "libopus"] { - let Some(dec) = ffmpeg_decode(exe, codec, &file, c, &format!("{mode:?}{bw:?}{c}{codec}")) else { - continue; - }; - assert_eq!(dec.len(), len * c, "{codec}: pre-skip and end granule must be honoured"); - for (ch, x) in planar.iter().enumerate() { - let d: Vec = (0..len).map(|i| dec[i * c + ch]).collect(); - let (snr, delay) = snr_search(&lowpass(x, fc), &d, 6); - eprintln!("ffmpeg {codec:7} {mode:?}/{bw:?} {c} ch @ {} kb/s, channel {ch}: SNR {snr:.1} dB (residual delay {delay})", rate / 1000); - assert!(snr > min_snr, "{codec} {mode:?}/{bw:?}: SNR {snr:.1} dB"); - } - } - } -} diff --git a/crates/opusenc/tests/it/main.rs b/crates/opusenc/tests/it/main.rs deleted file mode 100644 index ba6a7895d..000000000 --- a/crates/opusenc/tests/it/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -//! The crate's integration tests, one binary (each module is a former `tests/.rs`). - -mod common; -mod ffmpeg; -mod modes; diff --git a/crates/opusenc/tests/it/modes.rs b/crates/opusenc/tests/it/modes.rs deleted file mode 100644 index c01f64e69..000000000 --- a/crates/opusenc/tests/it/modes.rs +++ /dev/null @@ -1,272 +0,0 @@ -//! SILK, hybrid and CELT round trips through FilmCraft's spec-derived Opus decoder: every -//! mode/bandwidth decodes, waveform quality on speech-like and music-like signals, bitrate -//! tracking, stereo, the application tables and delay alignment. - -use crate::common; - -use common::*; -use effectcraft_opusenc::{Application, Bandwidth, Mode, OpusEncoder}; - -struct Run { - snr: f64, - seg: f64, - delay: isize, - kbps: f64, - packets: Vec>, -} - -/// Encodes `planar`, decodes, and measures each channel against `reference` (searching a -/// residual delay of up to ±6 samples). -fn run(enc: OpusEncoder, planar: &[Vec], reference: &[Vec]) -> Vec { - let (enc, packets) = encode(enc, planar); - let dec = decode(&enc.opus_head(), &packets); - let kbps = bitrate(&packets) / 1000.0; - reference - .iter() - .zip(&dec) - .map(|(r, d)| { - assert!(d.len() >= r.len(), "decoded {} < {}", d.len(), r.len()); - assert!(d.iter().all(|v| v.is_finite())); - let (snr, delay) = snr_search(r, d, 6); - Run { snr, seg: seg_snr(r, d, delay), delay, kbps, packets: packets.clone() } - }) - .collect() -} - -fn mono(mode: Mode, bw: Bandwidth, rate: u32, x: &[f32], fc: f64) -> Run { - let reference = if fc < 20_000.0 { lowpass(x, fc) } else { x.to_vec() }; - run(OpusEncoder::with_mode(1, rate, mode, bw), &[x.to_vec()], &[reference]).remove(0) -} - -/// Upper edge of the band a SILK bandwidth keeps (for band-limited references). -fn band_edge(bw: Bandwidth) -> f64 { - match bw { - Bandwidth::Narrowband => 3_400.0, - Bandwidth::Mediumband => 5_000.0, - Bandwidth::Wideband => 7_000.0, - _ => 24_000.0, - } -} - -const LEN: usize = 96_000; - -#[test] -fn every_mode_and_bandwidth_decodes() { - let sp = speech(LEN + 40_000, 11); - let left = sp[..LEN].to_vec(); - let right: Vec = sp[40_000..].iter().map(|v| v * 0.6).collect(); - for (mode, bw, config, rate) in [ - (Mode::Silk, Bandwidth::Narrowband, 1u8, 8_000u32), - (Mode::Silk, Bandwidth::Mediumband, 5, 11_000), - (Mode::Silk, Bandwidth::Wideband, 9, 16_000), - (Mode::Hybrid, Bandwidth::SuperWideband, 13, 24_000), - (Mode::Hybrid, Bandwidth::Fullband, 15, 32_000), - (Mode::Celt, Bandwidth::Fullband, 31, 64_000), - ] { - for c in [1usize, 2] { - let planar = if c == 1 { vec![left.clone()] } else { vec![left.clone(), right.clone()] }; - let reference: Vec> = planar.iter().map(|x| lowpass(x, band_edge(bw))).collect(); - let enc = OpusEncoder::with_mode(c as u8, rate * c as u32, mode, bw); - assert_eq!((enc.mode(), enc.bandwidth()), (mode, bw)); - let res = run(enc, &planar, &reference); - for p in &res[0].packets { - assert_eq!(p[0], (config << 3) | if c == 2 { 4 } else { 0 }, "TOC of {mode:?}/{bw:?}"); - assert!(p.len() >= 3 && p.len() <= 1276); - } - for (ch, r) in res.iter().enumerate() { - eprintln!( - "{mode:?}/{bw:?} {c} ch @ {} kb/s: {:.1} kb/s, channel {ch} SNR {:.1} dB, segSNR {:.1} dB, residual delay {}", - rate * c as u32 / 1000, - r.kbps, - r.snr, - r.seg, - r.delay - ); - assert!(r.snr > 8.0, "{mode:?}/{bw:?} {c} ch channel {ch}: SNR {:.1} dB", r.snr); - assert!(r.delay.abs() <= 1, "{mode:?}/{bw:?}: residual delay {} (pre-skip mismatch)", r.delay); - } - } - } -} - -#[test] -fn silk_speech_quality() { - let x = speech(LEN, 7); - for (bw, rate, min_snr) in [ - (Bandwidth::Narrowband, 8_000u32, 10.0), - (Bandwidth::Mediumband, 11_000, 14.0), - (Bandwidth::Wideband, 12_000, 14.0), - (Bandwidth::Wideband, 16_000, 18.0), - (Bandwidth::Wideband, 24_000, 24.0), - ] { - let r = mono(Mode::Silk, bw, rate, &x, band_edge(bw)); - eprintln!("SILK {bw:?} speech @ {} kb/s: {:.1} kb/s, SNR {:.1} dB, segSNR {:.1} dB", rate / 1000, r.kbps, r.snr, r.seg); - assert!(r.snr > min_snr && r.seg > min_snr - 3.0, "SILK {bw:?} @ {rate}: SNR {:.1} / seg {:.1}", r.snr, r.seg); - } -} - -#[test] -fn silk_beats_celt_on_speech_at_low_rate() { - let x = speech(LEN, 5); - // Both measured against the full-band input. - let silk = mono(Mode::Silk, Bandwidth::Wideband, 12_000, &x, 24_000.0); - let celt = mono(Mode::Celt, Bandwidth::Fullband, 12_000, &x, 24_000.0); - eprintln!( - "12 kb/s mono speech: SILK WB {:.1} dB (seg {:.1}) at {:.1} kb/s vs CELT {:.1} dB (seg {:.1}) at {:.1} kb/s", - silk.snr, silk.seg, silk.kbps, celt.snr, celt.seg, celt.kbps - ); - assert!(silk.snr > celt.snr + 3.0, "SILK {:.1} dB vs CELT {:.1} dB", silk.snr, celt.snr); - assert!(silk.seg > celt.seg + 3.0, "SILK seg {:.1} dB vs CELT seg {:.1} dB", silk.seg, celt.seg); -} - -#[test] -fn hybrid_quality() { - let sp = speech(LEN, 9); - let mu = music(LEN); - for (name, x, bw, rate, min_snr) in [ - ("speech", &sp, Bandwidth::SuperWideband, 24_000u32, 18.0), - ("speech", &sp, Bandwidth::Fullband, 32_000, 20.0), - ("music", &mu, Bandwidth::SuperWideband, 24_000, 9.0), - ("music", &mu, Bandwidth::Fullband, 32_000, 10.0), - ] { - let r = mono(Mode::Hybrid, bw, rate, x, 24_000.0); - eprintln!("hybrid {bw:?} {name} @ {} kb/s: {:.1} kb/s, SNR {:.1} dB, segSNR {:.1} dB", rate / 1000, r.kbps, r.snr, r.seg); - assert!(r.snr > min_snr, "hybrid {bw:?} {name}: SNR {:.1} dB", r.snr); - // Constant packet size. - assert!(r.packets.iter().all(|p| p.len() == rate as usize / 400)); - } -} - -#[test] -fn silk_music_quality() { - let x = music(LEN); - for (rate, min_snr) in [(12_000u32, 5.0), (16_000, 8.0), (24_000, 13.0)] { - let r = mono(Mode::Silk, Bandwidth::Wideband, rate, &x, 7_000.0); - eprintln!("SILK WB music @ {} kb/s: {:.1} kb/s, SNR {:.1} dB", rate / 1000, r.kbps, r.snr); - assert!(r.snr > min_snr, "SILK music @ {rate}: SNR {:.1} dB", r.snr); - } -} - -#[test] -fn bitrate_tracking() { - let sp = speech(LEN, 13); - let mu = music(LEN); - for (name, x) in [("speech", &sp), ("music", &mu)] { - for (mode, bw, rate) in [ - (Mode::Silk, Bandwidth::Narrowband, 6_000u32), - (Mode::Silk, Bandwidth::Narrowband, 9_000), - (Mode::Silk, Bandwidth::Mediumband, 11_000), - (Mode::Silk, Bandwidth::Wideband, 12_000), - (Mode::Silk, Bandwidth::Wideband, 20_000), - (Mode::Silk, Bandwidth::Wideband, 32_000), - (Mode::Hybrid, Bandwidth::SuperWideband, 20_000), - (Mode::Hybrid, Bandwidth::Fullband, 36_000), - ] { - let r = mono(mode, bw, rate, x, band_edge(bw)); - let ratio = r.kbps * 1000.0 / rate as f64; - eprintln!("{name} {mode:?}/{bw:?} target {} kb/s: actual {:.2} kb/s ({:+.0} %), SNR {:.1} dB", rate / 1000, r.kbps, (ratio - 1.0) * 100.0, r.snr); - assert!((0.75..=1.25).contains(&ratio), "{name} {mode:?}/{bw:?} @ {rate}: {:.2} kb/s", r.kbps); - } - } -} - -#[test] -fn stereo_silk_and_hybrid() { - let sp = speech(LEN + 40_000, 21); - let a = sp[..LEN].to_vec(); - let b: Vec = sp[40_000..].iter().map(|v| v * 0.7).collect(); - let mu = music(LEN); - let cases: Vec<(&str, Vec, Vec)> = vec![ - ("dual mono", a.clone(), a.clone()), - ("panned", a.iter().map(|v| v * 0.9).collect(), a.iter().map(|v| v * 0.35).collect()), - ("independent", a.clone(), b), - ("speech+music", a.iter().zip(&mu).map(|(x, y)| 0.8 * x + 0.3 * y).collect(), a.iter().zip(&mu).map(|(x, y)| 0.3 * x + 0.8 * y).collect()), - ]; - for (name, l, r) in &cases { - for (mode, bw, rate, min_snr) in [(Mode::Silk, Bandwidth::Wideband, 32_000u32, 9.0), (Mode::Hybrid, Bandwidth::Fullband, 64_000, 9.0)] { - let fc = band_edge(bw); - let res = run(OpusEncoder::with_mode(2, rate, mode, bw), &[l.clone(), r.clone()], &[lowpass(l, fc), lowpass(r, fc)]); - eprintln!("stereo {name} {mode:?}/{bw:?} @ {} kb/s: {:.1} kb/s, L {:.1} dB, R {:.1} dB", rate / 1000, res[0].kbps, res[0].snr, res[1].snr); - assert!(res[0].snr > min_snr && res[1].snr > min_snr, "stereo {name} {mode:?}: L {:.1} R {:.1}", res[0].snr, res[1].snr); - } - } -} - -#[test] -fn application_tables_and_pre_skip() { - let cases = [ - (Application::Voip, 1u8, 8_000u32, Mode::Silk, Bandwidth::Narrowband), - (Application::Voip, 1, 11_000, Mode::Silk, Bandwidth::Mediumband), - (Application::Voip, 1, 16_000, Mode::Silk, Bandwidth::Wideband), - (Application::Voip, 1, 24_000, Mode::Hybrid, Bandwidth::SuperWideband), - (Application::Voip, 1, 32_000, Mode::Hybrid, Bandwidth::Fullband), - (Application::Voip, 1, 48_000, Mode::Celt, Bandwidth::Fullband), - (Application::Voip, 2, 32_000, Mode::Silk, Bandwidth::Wideband), - (Application::Audio, 1, 12_000, Mode::Silk, Bandwidth::Wideband), - (Application::Audio, 1, 24_000, Mode::Hybrid, Bandwidth::Fullband), - (Application::Audio, 2, 48_000, Mode::Hybrid, Bandwidth::Fullband), - (Application::Audio, 1, 64_000, Mode::Celt, Bandwidth::Fullband), - (Application::Audio, 2, 128_000, Mode::Celt, Bandwidth::Fullband), - ]; - for (app, c, rate, mode, bw) in cases { - let e = OpusEncoder::with_application(c, rate, app); - assert_eq!((e.mode(), e.bandwidth(), e.application()), (mode, bw, app), "{app:?} {c} ch @ {rate}"); - assert_eq!(e.pre_skip(), 120, "every mode is aligned to a 120-sample delay"); - } - assert_eq!(OpusEncoder::new(2, 128_000).mode(), Mode::Celt); - assert_eq!(OpusEncoder::new(1, 12_000).application(), Application::Audio); -} - -#[test] -#[should_panic(expected = "unsupported mode/bandwidth")] -fn invalid_mode_bandwidth_panics() { - let _ = OpusEncoder::with_mode(1, 16_000, Mode::Silk, Bandwidth::Fullband); -} - -#[test] -fn extreme_inputs_stay_decodable() { - let len = 24_000; - let mut s = 1u32; - let noise: Vec = (0..len) - .map(|_| { - s = s.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); - (s >> 8) as f32 / (1u32 << 23) as f32 - 1.0 - }) - .collect(); - let square: Vec = (0..len).map(|i| if (i / 60) % 2 == 0 { 0.999 } else { -0.999 }).collect(); - let clicks: Vec = (0..len).map(|i| if i % 4_801 == 0 { 1.0 } else { 0.0 }).collect(); - let dc = vec![0.7f32; len]; - let nan: Vec = (0..len).map(|i| if i % 1000 == 0 { f32::NAN } else { 0.1 * (i as f32 * 0.01).sin() }).collect(); - for (name, x) in [("noise", &noise), ("square", &square), ("clicks", &clicks), ("dc", &dc), ("nan", &nan)] { - for (mode, bw, rate) in - [(Mode::Silk, Bandwidth::Narrowband, 6_000u32), (Mode::Silk, Bandwidth::Wideband, 40_000), (Mode::Hybrid, Bandwidth::Fullband, 24_000)] - { - for c in [1usize, 2] { - let planar: Vec> = if c == 1 { vec![x.clone()] } else { vec![x.clone(), x.iter().map(|v| -0.5 * v).collect()] }; - let (enc, packets) = encode(OpusEncoder::with_mode(c as u8, rate * c as u32, mode, bw), &planar); - assert!(packets.iter().all(|p| p.len() >= 3 && p.len() <= 1276), "{name} {mode:?}: packet sizes"); - let dec = decode(&enc.opus_head(), &packets); - let peak = dec.iter().flatten().fold(0f32, |m, v| m.max(v.abs())); - let snr = if name == "nan" { f64::NAN } else { snr_search(&planar[0], &dec[0], 2).0 }; - eprintln!("{name} {mode:?}/{bw:?} {c} ch: peak {peak:.2}, SNR {snr:.1} dB, {:.1} kb/s", bitrate(&packets) / 1000.0); - assert!(dec.iter().all(|ch| ch.iter().all(|v| v.is_finite() && v.abs() <= 4.0)), "{name} {mode:?}/{bw:?} {c} ch: bad output"); - } - } - } -} - -#[test] -fn silk_and_hybrid_silence() { - for (mode, bw, rate) in [(Mode::Silk, Bandwidth::Wideband, 16_000u32), (Mode::Hybrid, Bandwidth::Fullband, 32_000)] { - let x = vec![0f32; 48_000]; - let (enc, packets) = encode(OpusEncoder::with_mode(1, rate, mode, bw), std::slice::from_ref(&x)); - let dec = decode(&enc.opus_head(), &packets); - let peak = dec[0].iter().fold(0f32, |m, v| m.max(v.abs())); - let kbps = bitrate(&packets) / 1000.0; - eprintln!("{mode:?} silence: {kbps:.2} kb/s, decoded peak {peak:.2e}"); - assert!(peak < 1e-3, "{mode:?} silence decodes to peak {peak}"); - if mode == Mode::Silk { - assert!(kbps < 4.0, "SILK silence costs {kbps:.2} kb/s"); - } - } -} diff --git a/docs/architecture.md b/docs/architecture.md index 87a8b7233..5caaba19b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -18,7 +18,6 @@ cpal or muda. Everything in L0 to L4, the egui UI and the web app also build for | L0 | `time` | `Tick` (254 016 000 000 per second), rational frame rates incl. NTSC, SMPTE and drop-frame timecode | | L0 | `geom` | Vectors, matrices, quaternions, the layer transform (anchor, position, scale, orientation, rotation) | | L0 | `color` | sRGB and linear, HSL/HSV, luminance, the 38 blend modes, label colors | -| L0 | `opusenc` | Opus encoder: RFC 6716 SILK (NB/MB/WB), hybrid (SWB/FB) and CELT (FB) modes chosen by bitrate and application (audio / voice), 48 kHz 20 ms packets, mono/stereo, and the RFC 7845 `OpusHead`, for WebM export audio | | L1 | `raster` | Premultiplied float images, sampling, affine and projective warps, blurs, compositing (parallel with rayon) | | L1 | `keyframe` | Animated values, keyframes with temporal ease and spatial Bezier, roving, hold, velocity | | L1 | `segment` | Swappable trained models for Roto Brush and face tracking: the `MaskModel` and `FaceModel` interfaces, a registry of open-licensed models (authors, licence, URL, size, SHA-256), PyTorch checkpoint and TensorFlow Lite readers (with an interpreter), SHA-256, MobileSAM (TinyViT + Segment Anything decoder) and MediaPipe Face Landmarker (BlazeFace + Face Mesh V2) on rayon and ndarray's safe GEMM | diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e346ca897..5210f4433 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -37,7 +37,6 @@ const LAYERS: &[(&str, u8)] = &[ ("geom", 0), ("color", 0), ("testkit", 0), - ("opusenc", 0), ("raster", 1), ("keyframe", 1), ("path", 1), diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index a4ed9d6dd..6219c5253 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "47107f660191de2f0b425569506f4daa4faadac9"; +const REV: &str = "b850981f835f39859077cf62ff4e76462e76167c"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From ac1c1d9202ac8cb53ab7410e4060b7740431cd9d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 13:19:05 -0500 Subject: [PATCH 56/99] encoding: reuse shared Base64 writers across four consumers --- Cargo.lock | 19 +++++++++++++++++++ Cargo.toml | 1 + crates/aep/Cargo.toml | 1 + crates/aep/src/export/icc.rs | 14 +------------- crates/automation/Cargo.toml | 1 + crates/automation/src/base64.rs | 23 +++++++++++++---------- crates/track/Cargo.toml | 1 + crates/track/src/roto/rle.rs | 13 +------------ crates/ui-egui/Cargo.toml | 1 + crates/ui-egui/src/control.rs | 14 +------------- 10 files changed, 40 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7af09affa..4f94415c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1103,6 +1103,11 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-codepage" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" + [[package]] name = "craft-doc" version = "0.1.0" @@ -1220,6 +1225,16 @@ dependencies = [ "serde_json", ] +[[package]] +name = "craft-mime" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +dependencies = [ + "chrono", + "craft-codepage", + "encoding_rs", +] + [[package]] name = "craft-pcraft-format" version = "0.1.0" @@ -1604,6 +1619,7 @@ name = "effectcraft-aep" version = "0.24.1" dependencies = [ "craft-aep", + "craft-mime", "effectcraft-color", "effectcraft-effects", "effectcraft-keyframe", @@ -1619,6 +1635,7 @@ dependencies = [ name = "effectcraft-automation" version = "0.24.1" dependencies = [ + "craft-mime", "effectcraft-engine", "effectcraft-host", "effectcraft-model", @@ -2116,6 +2133,7 @@ dependencies = [ name = "effectcraft-track" version = "0.24.1" dependencies = [ + "craft-mime", "effectcraft-raster", "effectcraft-segment", "rayon", @@ -2130,6 +2148,7 @@ version = "0.24.1" dependencies = [ "bytemuck", "chrono", + "craft-mime", "craft-quit", "craft-ui", "craft-update", diff --git a/Cargo.toml b/Cargo.toml index ae0fd3d09..292069b97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] +craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } diff --git a/crates/aep/Cargo.toml b/crates/aep/Cargo.toml index 0523edb9b..1189df8dc 100644 --- a/crates/aep/Cargo.toml +++ b/crates/aep/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } craft-aep = { workspace = true } effectcraft-time = { workspace = true } effectcraft-color = { workspace = true } diff --git a/crates/aep/src/export/icc.rs b/crates/aep/src/export/icc.rs index ae6db7893..04a900d00 100644 --- a/crates/aep/src/export/icc.rs +++ b/crates/aep/src/export/icc.rs @@ -224,19 +224,7 @@ pub(crate) fn profile_json(icc: &[u8], name: &str) -> String { /// Standard base64 with padding. pub(crate) fn base64(data: &[u8]) -> String { - const T: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut out = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (u32::from(c[0]) << 16) | (u32::from(c.get(1).copied().unwrap_or(0)) << 8) | u32::from(c.get(2).copied().unwrap_or(0)); - for (i, shift) in [18u32, 12, 6, 0].iter().enumerate() { - if i <= c.len() { - out.push(char::from(T[((n >> shift) & 63) as usize])); - } else { - out.push('='); - } - } - } - out + craft_mime::base64::STANDARD.encode(data) } #[cfg(test)] diff --git a/crates/automation/Cargo.toml b/crates/automation/Cargo.toml index e0caf3218..23cff63c8 100644 --- a/crates/automation/Cargo.toml +++ b/crates/automation/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } effectcraft-engine = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } diff --git a/crates/automation/src/base64.rs b/crates/automation/src/base64.rs index 90002c600..21dd66d7e 100644 --- a/crates/automation/src/base64.rs +++ b/crates/automation/src/base64.rs @@ -1,16 +1,7 @@ //! Standard base64 (RFC 4648 §4, padded): MCP image content and the control channel's inline PNGs. -const A: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - pub fn encode(data: &[u8]) -> String { - let mut s = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (c[0] as u32) << 16 | (*c.get(1).unwrap_or(&0) as u32) << 8 | *c.get(2).unwrap_or(&0) as u32; - for i in 0..4 { - s.push(if i <= c.len() { A[(n >> (18 - 6 * i) & 63) as usize] as char } else { '=' }); - } - } - s + craft_mime::base64::STANDARD.encode(data) } /// Decode, ignoring ASCII whitespace; `None` on any other invalid input. @@ -48,6 +39,18 @@ pub fn decode(s: &str) -> Option> { #[cfg(test)] mod tests { + #[test] + fn shared_encoder_round_trips_every_byte_and_remainder() { + let all: Vec = (0..=255).cycle().take(513).collect(); + for length in 0..=all.len() { + let input = &all[..length]; + let encoded = super::encode(input); + assert_eq!(encoded.len(), length.div_ceil(3) * 4); + assert_eq!(super::decode(&encoded).as_deref(), Some(input)); + assert_eq!(encoded.bytes().rev().take_while(|b| *b == b'=').count(), (3 - length % 3) % 3); + } + } + #[test] fn rfc4648_vectors() { for (i, o) in [("", ""), ("f", "Zg=="), ("fo", "Zm8="), ("foo", "Zm9v"), ("foob", "Zm9vYg=="), ("fooba", "Zm9vYmE="), ("foobar", "Zm9vYmFy")] { diff --git a/crates/track/Cargo.toml b/crates/track/Cargo.toml index cd9daae36..f374a81f8 100644 --- a/crates/track/Cargo.toml +++ b/crates/track/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } effectcraft-raster = { workspace = true } effectcraft-segment = { workspace = true } rayon = { workspace = true } diff --git a/crates/track/src/roto/rle.rs b/crates/track/src/roto/rle.rs index 914bcad83..4a4152d82 100644 --- a/crates/track/src/roto/rle.rs +++ b/crates/track/src/roto/rle.rs @@ -1,19 +1,8 @@ //! Compact text encodings of mattes for project storage: run-length coding (LEB128 varints) //! wrapped in standard base64 (RFC 4648 §4). -const B64: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - pub fn base64_encode(data: &[u8]) -> String { - let mut out = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let b = [c[0], *c.get(1).unwrap_or(&0), *c.get(2).unwrap_or(&0)]; - let n = (b[0] as u32) << 16 | (b[1] as u32) << 8 | b[2] as u32; - out.push(B64[(n >> 18) as usize & 63] as char); - out.push(B64[(n >> 12) as usize & 63] as char); - out.push(if c.len() > 1 { B64[(n >> 6) as usize & 63] as char } else { '=' }); - out.push(if c.len() > 2 { B64[n as usize & 63] as char } else { '=' }); - } - out + craft_mime::base64::STANDARD.encode(data) } pub fn base64_decode(s: &str) -> Option> { diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 3c5862594..81f2023c4 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } craft-ui = { workspace = true } craft-quit = { workspace = true, features = ["egui"] } effectcraft-time = { workspace = true } diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 9f86c7ace..b1717d55e 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -803,19 +803,7 @@ fn render_frame(app: &EffectcraftApp, p: &Value) -> Outcome { /// Standard base64 (RFC 4648, padded). pub fn base64(data: &[u8]) -> String { - const A: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut s = String::with_capacity(data.len().div_ceil(3) * 4); - for c in data.chunks(3) { - let n = (c[0] as u32) << 16 | (*c.get(1).unwrap_or(&0) as u32) << 8 | *c.get(2).unwrap_or(&0) as u32; - for i in 0..4 { - if i <= c.len() { - s.push(A[(n >> (18 - 6 * i) & 63) as usize] as char); - } else { - s.push('='); - } - } - } - s + craft_mime::base64::STANDARD.encode(data) } /// Builds the `ui.inspect` reply: window size and pixels per point, fps, UI state with the From d7d6007970a7476d90250ed499a54c0a68db91cc Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 13:49:50 -0500 Subject: [PATCH 57/99] effects: use shared SPI1D table reader --- Cargo.lock | 20 ++++++++++++++++++ crates/effects/Cargo.toml | 1 + crates/effects/src/ocio/lut.rs | 35 ++------------------------------ crates/effects/src/ocio/tests.rs | 7 +++++++ 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7af09affa..6366af909 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1103,6 +1103,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-cms" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=9fd926dc93be7d4723e6eb4f484c7233d91d3e94#9fd926dc93be7d4723e6eb4f484c7233d91d3e94" +dependencies = [ + "md-5", + "rayon", +] + [[package]] name = "craft-doc" version = "0.1.0" @@ -1661,6 +1670,7 @@ name = "effectcraft-effects" version = "0.24.1" dependencies = [ "chrono", + "craft-cms", "effectcraft-color", "effectcraft-geom", "effectcraft-keyframe", @@ -4063,6 +4073,16 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.8.3" diff --git a/crates/effects/Cargo.toml b/crates/effects/Cargo.toml index bb26d3127..c486ceece 100644 --- a/crates/effects/Cargo.toml +++ b/crates/effects/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9fd926dc93be7d4723e6eb4f484c7233d91d3e94" } effectcraft-geom = { workspace = true } effectcraft-color = { workspace = true } effectcraft-keyframe = { workspace = true } diff --git a/crates/effects/src/ocio/lut.rs b/crates/effects/src/ocio/lut.rs index daa584278..186209fbc 100644 --- a/crates/effects/src/ocio/lut.rs +++ b/crates/effects/src/ocio/lut.rs @@ -35,39 +35,8 @@ pub fn parse_spimtx(text: &str) -> Option { /// Parse a Sony Imageworks `.spi1d` 1D LUT: `From `, `Length `, `Components /// <1 | 3>`, then `{` the values `}`. pub fn parse_spi1d(text: &str) -> Option { - let (mut from, mut len, mut comps) = ([0.0f32, 1.0], 0usize, 1usize); - let mut values: Vec = vec![]; - let mut body = false; - for line in text.lines().map(str::trim).filter(|l| !l.is_empty()) { - if body { - if line.starts_with('}') { - break; - } - for t in line.split_whitespace() { - values.push(t.parse().ok()?); - } - continue; - } - let mut t = line.split_whitespace(); - match t.next()? { - "{" => body = true, - "From" => from = [t.next()?.parse().ok()?, t.next()?.parse().ok()?], - "Length" => len = t.next()?.parse().ok()?, - "Components" => comps = t.next()?.parse().ok()?, - _ => {} - } - } - // A 1D table is interpolated by index, so cap it like the lattices (2²⁴ entries). - if !(2..=MAX_1D).contains(&len) - || !matches!(comps, 1 | 3) - || values.len() != len.checked_mul(comps)? - || from[1] <= from[0] - || from.iter().any(|v| !v.is_finite()) - { - return None; - } - let d1 = values.chunks_exact(comps).map(|c| if comps == 3 { [c[0], c[1], c[2]] } else { [c[0]; 3] }).collect(); - Some(Lut { n1: len, d1, n3: 0, d3: vec![], dmin: [from[0]; 3], dmax: [from[1]; 3] }) + let table = craft_cms::spi1d::parse(text)?; + Some(Lut { n1: table.values.len(), d1: table.values, n3: 0, d3: vec![], dmin: [table.domain[0]; 3], dmax: [table.domain[1]; 3] }) } /// Parse a Sony Imageworks `.spi3d` lattice: `SPILUT 1.0`, `3 3`, the sizes, then one diff --git a/crates/effects/src/ocio/tests.rs b/crates/effects/src/ocio/tests.rs index ea2423043..d9b50505f 100644 --- a/crates/effects/src/ocio/tests.rs +++ b/crates/effects/src/ocio/tests.rs @@ -116,6 +116,13 @@ fn spi_files_parse() { assert!((back[0] - 1.0).abs() < 1e-5 && (back[2] - 2.0).abs() < 1e-5, "{back:?}"); let three = parse_spi1d("Version 1\nFrom 0 1\nLength 2\nComponents 3\n{\n0 0 0\n1 0.5 2\n}\n").unwrap(); assert_eq!(three.d1, vec![[0.0; 3], [1.0, 0.5, 2.0]]); + let eof = parse_spi1d("Length 2\nFrom -1 2\n{\n0 1").unwrap(); + assert_eq!(eof.n1, 2); + assert_eq!(eof.dmin, [-1.0; 3]); + assert_eq!(eof.dmax, [2.0; 3]); + assert_eq!(eof.n3, 0); + assert!(eof.d3.is_empty()); + assert!(parse_spi1d("Length 2\n{\n0 1 2").is_none()); let mut spi3d = String::from("SPILUT 1.0\n3 3\n2 2 2\n"); for (r, g, b) in (0..8).map(|i| (i & 1, (i >> 1) & 1, i >> 2)) { spi3d += &format!("{r} {g} {b} {} {} {}\n", r as f32 * 0.5, g, b); From 414cddf4fe998b071ca2506b2a6c9a5b19485b3a Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 14:03:12 -0500 Subject: [PATCH 58/99] effects: use shared SPI3D and SPIMTX readers --- Cargo.lock | 20 ++++++++++++++++ crates/effects/Cargo.toml | 1 + crates/effects/src/ocio/lut.rs | 40 ++++---------------------------- crates/effects/src/ocio/tests.rs | 7 ++++++ 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7af09affa..8468dfdc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1103,6 +1103,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-cms" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=5c0fc062b4ae518fc2736a7f489a4c4e8222e883#5c0fc062b4ae518fc2736a7f489a4c4e8222e883" +dependencies = [ + "md-5", + "rayon", +] + [[package]] name = "craft-doc" version = "0.1.0" @@ -1661,6 +1670,7 @@ name = "effectcraft-effects" version = "0.24.1" dependencies = [ "chrono", + "craft-cms", "effectcraft-color", "effectcraft-geom", "effectcraft-keyframe", @@ -4063,6 +4073,16 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.8.3" diff --git a/crates/effects/Cargo.toml b/crates/effects/Cargo.toml index bb26d3127..14b062e5f 100644 --- a/crates/effects/Cargo.toml +++ b/crates/effects/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5c0fc062b4ae518fc2736a7f489a4c4e8222e883" } effectcraft-geom = { workspace = true } effectcraft-color = { workspace = true } effectcraft-keyframe = { workspace = true } diff --git a/crates/effects/src/ocio/lut.rs b/crates/effects/src/ocio/lut.rs index daa584278..15018ccd2 100644 --- a/crates/effects/src/ocio/lut.rs +++ b/crates/effects/src/ocio/lut.rs @@ -18,18 +18,8 @@ pub enum FileXform { /// Parse a Sony Imageworks `.spimtx` matrix: three rows of four numbers, three matrix columns /// and an offset in 16-bit code values (÷ 65535). pub fn parse_spimtx(text: &str) -> Option { - let v: Vec = text.split_whitespace().map(|t| t.parse().ok()).collect::>()?; - if v.len() != 12 || v.iter().any(|x| !x.is_finite()) { - return None; - } - let mut m = [0.0; 16]; - let mut offset = [0.0; 4]; - for (r, row) in v.as_chunks::<4>().0.iter().enumerate() { - m[r * 4..r * 4 + 3].copy_from_slice(&row[..3]); - offset[r] = row[3] / 65535.0; - } - m[15] = 1.0; - Some(FileXform::Matrix { m, offset }) + let value = craft_cms::sony_lut::parse_spimtx(text)?; + Some(FileXform::Matrix { m: value.matrix, offset: value.offset }) } /// Parse a Sony Imageworks `.spi1d` 1D LUT: `From `, `Length `, `Components @@ -73,30 +63,8 @@ pub fn parse_spi1d(text: &str) -> Option { /// Parse a Sony Imageworks `.spi3d` lattice: `SPILUT 1.0`, `3 3`, the sizes, then one /// `r g b R G B` line per lattice point (indices, then the colour). pub fn parse_spi3d(text: &str) -> Option { - let mut lines = text.lines().map(str::trim).filter(|l| !l.is_empty()); - if !lines.next()?.starts_with("SPILUT") { - return None; - } - lines.next()?; - let size: Vec = lines.next()?.split_whitespace().map(|t| t.parse().ok()).collect::>()?; - let n = *size.first()?; - if size.len() != 3 || size.iter().any(|s| *s != n) || !(2..=MAX_LATTICE).contains(&n) { - return None; - } - let mut d3 = vec![[0.0f32; 3]; n * n * n]; - let mut seen = 0usize; - for line in lines { - let v: Vec<&str> = line.split_whitespace().collect(); - let [r, g, b, cr, cg, cb] = v.as_slice() else { return None }; - let (r, g, b): (usize, usize, usize) = (r.parse().ok()?, g.parse().ok()?, b.parse().ok()?); - if r >= n || g >= n || b >= n { - return None; - } - // Our lattice is red fastest. - *d3.get_mut(r + g * n + b * n * n)? = [cr.parse().ok()?, cg.parse().ok()?, cb.parse().ok()?]; - seen += 1; - } - (seen == n * n * n).then_some(Lut { n1: 0, d1: vec![], n3: n, d3, dmin: [0.0; 3], dmax: [1.0; 3] }) + let value = craft_cms::sony_lut::parse_spi3d(text)?; + Some(Lut { n1: 0, d1: vec![], n3: value.size, d3: value.values, dmin: [0.0; 3], dmax: [1.0; 3] }) } /// Parse an Autodesk `.3dl` lattice (integers, blue fastest; an optional input-mesh line). diff --git a/crates/effects/src/ocio/tests.rs b/crates/effects/src/ocio/tests.rs index ea2423043..177108735 100644 --- a/crates/effects/src/ocio/tests.rs +++ b/crates/effects/src/ocio/tests.rs @@ -120,6 +120,13 @@ fn spi_files_parse() { for (r, g, b) in (0..8).map(|i| (i & 1, (i >> 1) & 1, i >> 2)) { spi3d += &format!("{r} {g} {b} {} {} {}\n", r as f32 * 0.5, g, b); } + let lattice = parse_spi3d(&spi3d).unwrap(); + assert_eq!(lattice.n1, 0); + assert!(lattice.d1.is_empty()); + assert_eq!(lattice.n3, 2); + assert_eq!(lattice.dmin, [0.0; 3]); + assert_eq!(lattice.dmax, [1.0; 3]); + assert!(parse_spimtx("1 0 0 0 0 1 0 0 0 0 1 0 extra").is_none()); let x = parse_file(&spi3d, "spi3d").unwrap(); let o = x.apply([1.0, 0.5, 0.25], 1, false, ""); assert!((o[0] - 0.5).abs() < 1e-6 && (o[1] - 0.5).abs() < 1e-6 && (o[2] - 0.25).abs() < 1e-6, "{o:?}"); From 85903800ddbd9d1d4160b902e8b45f8060b39c4c Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 14:46:37 -0500 Subject: [PATCH 59/99] Account selected EXR planes per part and skip unused parts --- crates/media/src/exr_channels.rs | 42 +++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index ebd77f855..13e3c9d93 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -88,16 +88,19 @@ enum Refused { TooLarge(String), } -/// Bytes the selected channels occupy in the first part's display window. The channel cache +/// Bytes the selected channels occupy in each part's own display window. The channel cache /// reserves this before decoding so concurrent imports cannot exceed its soft budget. fn planes_bytes(infos: &[craft_exr::decode::PartInfo], keep: &dyn Fn(&str) -> bool) -> Option { - let display = infos.first()?.display_window; - let pixels = u64::from(display.width).checked_mul(u64::from(display.height))?; - let selected = infos.iter().try_fold(0u64, |total, part| { + infos.first()?; + let total = infos.iter().try_fold(0u64, |total, part| { let count = part.channels.iter().filter(|channel| keep(&channel_name(part.name.as_deref(), &channel.name))).count() as u64; - total.checked_add(count) + if count == 0 { + return Some(total); + } + let pixels = u64::from(part.display_window.width).checked_mul(u64::from(part.display_window.height))?; + total.checked_add(pixels.checked_mul(count)?.checked_mul(4)?) })?; - usize::try_from(pixels.checked_mul(selected)?.checked_mul(4)?).ok() + usize::try_from(total).ok() } /// Decode selected EXR channels through craft-exr, which places each selected block directly @@ -151,6 +154,14 @@ fn decode(bytes: &[u8], keep: &dyn Fn(&str) -> bool) -> Result let rgb_indices = ["R", "G", "B"].map(|wanted| info.channels.iter().position(|channel| channel.name == wanted)); let has_rgb = rgb_indices.iter().all(Option::is_some); let alpha_index = info.channels.iter().position(|channel| channel.name == "A"); + // Metadata above still belongs to the file, but an ignored part must not allocate or + // impose its pixel/deep-data limits on the selected picture channels. + if !info.channels.iter().any(|channel| keep(&channel_name(prefix, &channel.name))) { + if rgb == Rgb::None && has_rgb { + rgb = Rgb::Unsupported; + } + continue; + } let mut part = decode::decode_display_part( bytes, info.index, @@ -1172,6 +1183,25 @@ mod tests { assert_eq!(planes_bytes(&parts, &|name| name == "Beauty.R"), Some(3 * 2 * 4)); assert_eq!(planes_bytes(&parts, &|_| false), Some(0)); + // Different display windows must not reserve every part at the first part's size. + let mut varied = parts.clone(); + varied[0].display_window.width = 1; + varied[0].display_window.height = 1; + varied[1].display_window.width = 10; + varied[1].display_window.height = 20; + assert_eq!(planes_bytes(&varied, &|_| true), Some(4 + 10 * 20 * 3 * 4)); + assert_eq!(planes_bytes(&varied, &|name| name == "Beauty.R"), Some(10 * 20 * 4)); + varied[1].display_window.width = u32::MAX; + varied[1].display_window.height = u32::MAX; + assert_eq!(planes_bytes(&varied, &|_| true), None); + assert_eq!(planes_bytes(&varied, &|name| name == "Depth.Z"), Some(4)); + + // Skipping the RGB part preserves the first-RGB fallback state and depth samples. + let depth = decode(&bytes, &|name| name == "Depth.Z").unwrap(); + assert_eq!(depth.rgb, Rgb::Unsupported); + assert_eq!(depth.aux.channels.len(), 1); + assert_eq!(depth.aux.get("Depth.Z").unwrap()[0], 7.0); + let selected = decode(&bytes, &|name| name == "Beauty.R").unwrap(); assert_eq!(selected.aux.channels.iter().map(|(name, _)| name.as_str()).collect::>(), ["Beauty.R"]); assert_eq!(selected.aux.get("Beauty.R").unwrap(), [0.0, 0.0, 0.0, 0.0, 0.1, 0.1]); From df3083222a6523916ede2813b6f3c0f5dc6a7388 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 14:53:02 -0500 Subject: [PATCH 60/99] Preserve graphics state across logical text annotations --- crates/pdf/src/build.rs | 80 +++++++++++++++++++++++++++++++--- crates/pdf/src/lib.rs | 4 +- crates/pdf/src/page.rs | 45 ++++++++++++------- crates/pdf/src/tests.rs | 69 +++++++++++++++++++++++++++++ crates/pdf/src/tests/groups.rs | 37 ++++++++++++++++ 5 files changed, 212 insertions(+), 23 deletions(-) diff --git a/crates/pdf/src/build.rs b/crates/pdf/src/build.rs index 0f295a045..ad0f68216 100644 --- a/crates/pdf/src/build.rs +++ b/crates/pdf/src/build.rs @@ -19,6 +19,9 @@ enum Kind { pub(crate) struct Builder { stack: Vec<(Group, Kind)>, + /// Logical text labels never share the graphics-state group stack. + text_labels: Vec, + text_run: bool, /// Which of the finished top-level nodes are optional-content layers. pub top_layers: Vec, pub skipped: Vec, @@ -34,14 +37,14 @@ pub(crate) fn group(name: &str) -> Group { impl Builder { pub fn new() -> Builder { - Builder { stack: vec![(group("page"), Kind::Plain)], top_layers: vec![], skipped: vec![], shapes: 0, base: 0 } + Builder { stack: vec![(group("page"), Kind::Plain)], text_labels: vec![], text_run: false, top_layers: vec![], skipped: vec![], shapes: 0, base: 0 } } /// A builder for content that will be placed inside this one's open groups and `wrap` more /// groups (a pattern's `Pattern` and `Tile`, a soft mask's two), so its nesting limit counts /// them. pub fn nested(&self, wrap: usize) -> Builder { - Builder { base: self.base.saturating_add(self.stack.len()).saturating_add(wrap), ..Builder::new() } + Builder { base: self.base.saturating_add(self.stack.len()).saturating_add(self.text_labels.len()).saturating_add(wrap), ..Builder::new() } } pub fn depth(&self) -> usize { @@ -50,7 +53,7 @@ impl Builder { /// `wrap` more groups fit under the open ones within [`MAX_DEPTH`]. pub fn has_room(&self, wrap: usize) -> bool { - self.base.saturating_add(self.stack.len()).saturating_add(wrap) <= MAX_DEPTH + self.base.saturating_add(self.stack.len()).saturating_add(self.text_labels.len()).saturating_add(wrap) <= MAX_DEPTH } pub fn skip(&mut self, what: &str) { @@ -60,6 +63,7 @@ impl Builder { } fn add(&mut self, n: Node, layer: bool) { + self.text_run = false; if self.stack.len() == 1 { self.top_layers.push(layer); } @@ -70,6 +74,9 @@ impl Builder { /// Close every group opened above `depth`. pub fn close_to(&mut self, depth: usize) { + if self.stack.len() > depth.max(1) { + self.text_run = false; + } while self.stack.len() > depth.max(1) { let Some((g, k)) = self.stack.pop() else { break }; // Empty clipping groups draw nothing. @@ -83,6 +90,7 @@ impl Builder { /// Open `g` as the group drawn into from now on; past [`MAX_DEPTH`] the group is dropped /// (what would have been drawn inside it goes to the open group) and noted as skipped. fn push_group(&mut self, g: Group, kind: Kind) { + self.text_run = false; if self.base.saturating_add(self.stack.len()) >= MAX_DEPTH { self.skip("group nesting limit"); return; @@ -109,9 +117,71 @@ impl Builder { self.push_group(g, Kind::Plain); } + /// Start a bounded logical annotation independently of graphics-state nesting. + pub fn begin_text(&mut self, text: &str) -> bool { + self.text_run = false; + if self.text_labels.len() >= MAX_DEPTH { + self.skip("logical text nesting limit"); + return false; + } + self.text_labels.push(format!("Text: {text}")); + true + } + + pub fn end_text(&mut self) { + self.text_run = false; + self.text_labels.pop(); + } + /// Add a finished node (an image, pattern tiles). - pub fn push(&mut self, n: Node) { + pub fn push(&mut self, mut n: Node) { + // Marked content is metadata, not a transparency boundary. Wrap only the + // painted node, without closing, splitting or reopening any live state group. + // Finished forms may already contain groups: metadata cannot extend the cap. + fn group_depth(n: &Node, at: usize) -> usize { + match n { + Node::Group(g) => { + if at >= MAX_DEPTH { + return MAX_DEPTH; + } + 1 + g.children.iter().map(|n| group_depth(n, at + 1)).max().unwrap_or(0) + } + _ => 0, + } + } + let contained = if self.text_labels.is_empty() { 0 } else { group_depth(&n, 0) }; + let room = MAX_DEPTH.saturating_sub(self.base.saturating_add(self.stack.len()).saturating_add(contained)); + if self.text_labels.len() > room { + self.skip("group nesting limit"); + } + // Keep consecutive glyphs of one annotation together only inside the same + // graphics-state container. A knockout parent's children must stay separate. + let coalesce = !self.text_labels.is_empty() && self.text_labels.len() <= room; + if self.text_run + && coalesce + && let Some((parent, _)) = self.stack.last_mut() + && !parent.knockout + { + let mut target = parent.children.last_mut(); + for _ in 1..self.text_labels.len() { + target = match target { + Some(Node::Group(g)) => g.children.first_mut(), + _ => None, + }; + } + if let Some(Node::Group(g)) = target { + g.children.push(n); + return; + } + } + for label in self.text_labels.iter().take(room).rev() { + let mut g = group(label); + g.isolated = false; + g.children.push(n); + n = Node::Group(g); + } self.add(n, false); + self.text_run = coalesce; } pub fn fill_stroke(&mut self, path: BezPath, transform: Affine, fill: Option<(Paint, f64, FillRule)>, stroke: Option) { @@ -128,7 +198,7 @@ impl Builder { None => (None, 1.0, FillRule::NonZero), }; let s = Shape { name: name.into(), geom: Geom::Path(path), transform, fill: f, fill_opacity: fo, fill_rule: rule, stroke, opacity: 1.0 }; - self.add(Node::Shape(s), false); + self.push(Node::Shape(s)); } /// The finished top-level nodes and their layer flags. diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index 6ed92d640..4fd5d701c 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -241,10 +241,10 @@ fn eps_fallback_font(name: &[u8]) -> Option<&'static [u8]> { || name.contains("roman") { NOTO_SERIF_REGULAR - } else if name.contains("bold") || name.contains("black") || name.contains("heavy") { - INTER_BOLD } else if name.contains("semibold") || name.contains("demi") { INTER_SEMIBOLD + } else if name.contains("bold") || name.contains("black") || name.contains("heavy") { + INTER_BOLD } else if name.contains("italic") || name.contains("oblique") { INTER_ITALIC } else { diff --git a/crates/pdf/src/page.rs b/crates/pdf/src/page.rs index 21880daa0..cb8e02f88 100644 --- a/crates/pdf/src/page.rs +++ b/crates/pdf/src/page.rs @@ -209,7 +209,7 @@ pub(crate) struct Interp<'a> { cur: Option, start: Option, pending_clip: Option, - marked: Vec>, + marked: Vec, /// The page box in default user space (for `sh`). page_box: [f64; 4], budget: usize, @@ -237,6 +237,12 @@ enum TextItem { Adjust(f64), } +enum Marked { + None, + Layer(usize), + Text, +} + impl<'a> Interp<'a> { pub fn new(file: &'a File, page_box: [f64; 4]) -> Self { Interp { @@ -488,7 +494,7 @@ impl<'a> Interp<'a> { } "d1" => self.gs.lock_color = true, "BI" => self.inline_image(&mut lx, res), - "BMC" => self.marked.push(None), + "BMC" => self.marked.push(Marked::None), "BDC" => { let layer = match (args.first().and_then(Obj::name), args.get(1)) { (Some("OC"), Some(Obj::Name(prop))) => self @@ -499,30 +505,37 @@ impl<'a> Interp<'a> { (Some("OC"), Some(Obj::Dict(ocg))) => self.ocg_name(ocg), _ => None, }; - let actual_text = match (args.first().and_then(Obj::name), args.get(1)) { - (Some("Span"), Some(Obj::Dict(props))) => props.get("ActualText").and_then(|v| match self.file.resolve(v) { - Obj::Str(bytes) => Some(crate::color::text_string(bytes)), - _ => None, - }), - _ => None, + let props = match args.get(1) { + Some(Obj::Name(name)) => self.file.get_dict(res, "Properties").and_then(|p| self.file.get_dict(p, name)), + Some(obj) => self.file.resolve(obj).dict(), + None => None, }; + let actual_text = + (args.first().and_then(Obj::name) == Some("Span")).then_some(props).flatten().and_then(|p| self.file.get(p, "ActualText")).and_then( + |v| match v { + Obj::Str(bytes) => Some(text_string(bytes)), + _ => None, + }, + ); match (layer, actual_text) { (Some(name), _) => { - self.marked.push(Some(self.b.depth())); + self.marked.push(Marked::Layer(self.b.depth())); self.b.open(&name, true); } (None, Some(text)) => { - self.marked.push(Some(self.b.depth())); - self.b.open(&format!("Text: {text}"), false); + let mark = if self.b.begin_text(&text) { Marked::Text } else { Marked::None }; + self.marked.push(mark); } - (None, None) => self.marked.push(None), + (None, None) => self.marked.push(Marked::None), } } - "EMC" => { - if let Some(Some(d)) = self.marked.pop() { - self.close_to(d); + "EMC" => match self.marked.pop() { + Some(Marked::Layer(d)) => self.close_to(d), + Some(Marked::Text) => { + self.b.end_text(); } - } + _ => {} + }, _ => {} } // Colour operands set by the device-space shorthands. diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index 44d046ff2..9c606a611 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -1359,3 +1359,72 @@ fn clip_groups_nested_without_end_are_capped() { assert!(inside[2] > 0.99 && inside[3] > 0.99, "the artwork draws inside the clips: {inside:?}"); assert!(outside[3] < 0.01, "and is clipped: {outside:?}"); } + +#[test] +fn actual_text_named_properties_and_fallback_weights() { + let data = + page_pdf("/Span /P BDC 1 0 0 rg 10 10 20 20 re f EMC", "/Properties << /P 10 0 R >>", vec![(10, "<< /ActualText (Logical text) >>".into(), None)]); + assert_eq!(shape_names(&parse(&data).unwrap()), vec!["Text: Logical text"]); + use effectcraft_text::fonts::{INTER_BOLD, INTER_SEMIBOLD}; + for name in [b"Inter-Semibold".as_slice(), b"Inter-Demi"] { + assert_eq!(eps_fallback_font(name), Some(INTER_SEMIBOLD)); + } + for name in [b"Inter-Bold".as_slice(), b"Inter-Black", b"Inter-Heavy"] { + assert_eq!(eps_fallback_font(name), Some(INTER_BOLD)); + } +} + +#[test] +fn actual_text_does_not_change_graphics_state_or_compositing() { + let resources = "/ExtGState << /M << /BM /Multiply >> /N << /BM /Normal >> >>"; + // Compare every pixel to the same operators without marked content. In particular, + // Multiply and the clip survive EMC, and a later graphics-state change still works. + for (marked, plain) in [ + ( + "/Span << /ActualText (A) >> BDC /M gs 0 1 1 rg 0 0 60 100 re f EMC 50 0 60 100 re f /N gs 0 0 1 rg 150 0 50 100 re f", + "/M gs 0 1 1 rg 0 0 60 100 re f 50 0 60 100 re f /N gs 0 0 1 rg 150 0 50 100 re f", + ), + ( + "/Span << /ActualText (A) >> BDC 0 0 100 100 re W n /M gs 0 1 1 rg 0 0 60 100 re f EMC 50 0 150 100 re f", + "0 0 100 100 re W n /M gs 0 1 1 rg 0 0 60 100 re f 50 0 150 100 re f", + ), + ( + "/Span << /ActualText (A) >> BDC q /M gs 0 1 1 rg 0 0 60 100 re f Q EMC 0 0 1 rg 100 0 100 100 re f", + "q /M gs 0 1 1 rg 0 0 60 100 re f Q 0 0 1 rg 100 0 100 100 re f", + ), + ] { + let draw = |ops| render(&parse(&page_pdf(&format!("1 1 0 rg 0 0 200 100 re f {ops}"), resources, vec![])).unwrap()); + let (a, b) = (draw(marked), draw(plain)); + for y in 0..100 { + for x in 0..200 { + assert_eq!(a.get(x, y), b.get(x, y), "pixel {x},{y}"); + } + } + } +} + +#[test] +fn logical_text_cannot_extend_finished_node_depth_limit() { + use crate::build::Builder; + use effectcraft_svg::Group; + let mut b = Builder::new(); + assert!(b.begin_text("label")); + assert!(!b.nested(0).has_room(254)); + let mut node = Node::Group(Group::new("leaf")); + for _ in 1..255 { + let mut parent = Group::new("nested"); + parent.children.push(node); + node = Node::Group(parent); + } + b.push(node); + b.end_text(); + let (nodes, _, skipped) = b.finish(); + assert!(skipped.iter().any(|s| s == "group nesting limit")); + let mut current = nodes.first(); + let mut depth = 1; + while let Some(Node::Group(g)) = current { + depth += 1; + current = g.children.first(); + } + assert_eq!(depth, 256); +} diff --git a/crates/pdf/src/tests/groups.rs b/crates/pdf/src/tests/groups.rs index 14b6a4b09..d39f7f4db 100644 --- a/crates/pdf/src/tests/groups.rs +++ b/crates/pdf/src/tests/groups.rs @@ -151,3 +151,40 @@ fn vertical_metrics_w2_and_dw2() { let dw2 = doc("/DW2 [780 -1000]"); assert!(((base.1 - dw2.1) - 2).abs() <= 1, "vy 780 → 2 pt higher: {base:?} {dw2:?}"); } + +#[test] +fn actual_text_does_not_combine_knockout_children() { + let plain = "1 0 0 rg 0 0 100 100 re f /H gs 0 0 1 rg 50 0 100 100 re f"; + let marked = format!("/Span << /ActualText (Label) >> BDC {plain} EMC"); + let a = render(&group_page("/Fm Do", "", "/Group << /S /Transparency /I true /K true >>", plain)); + let b = render(&group_page("/Fm Do", "", "/Group << /S /Transparency /I true /K true >>", &marked)); + for y in 0..100 { + for x in 0..200 { + assert!(near(a.get(x, y), b.get(x, y)), "pixel {x},{y}"); + } + } +} + +#[test] +fn actual_text_end_keeps_soft_mask_and_overlapping_paints() { + let plain = "/GS1 gs 1 0 0 rg 0 0 100 100 re f 0 0 1 rg 50 0 100 100 re f"; + let marked = "/Span << /ActualText (Label) >> BDC /GS1 gs 1 0 0 rg 0 0 100 100 re f EMC 0 0 1 rg 50 0 100 100 re f"; + let draw = |ops| { + let bytes = page_pdf( + ops, + "/ExtGState << /GS1 << /SMask << /S /Luminosity /G 10 0 R >> >> >>", + vec![( + 10, + "<< /Type /XObject /Subtype /Form /BBox [0 0 200 100] /Group << /S /Transparency /CS /DeviceGray >> >>".into(), + Some(b"0.5 g 0 0 200 100 re f".to_vec()), + )], + ); + render(&parse(&bytes).unwrap()) + }; + let (a, b) = (draw(plain), draw(marked)); + for y in 0..100 { + for x in 0..200 { + assert!(near(a.get(x, y), b.get(x, y)), "pixel {x},{y}"); + } + } +} From de68d5c300b340f9903235c574fac42896129961 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 14:59:50 -0500 Subject: [PATCH 61/99] Pin shared reencoded glyph fallback and test accented EPS --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/pdf/src/tests/import.rs | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f4279ea6..cc0ecca7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1143,7 +1143,7 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +source = "git+https://github.com/storytold/craft-libs?rev=808730f49b9637b7909fe2ae56f9d63fdb100cae#808730f49b9637b7909fe2ae56f9d63fdb100cae" [[package]] name = "craft-exr" @@ -1242,7 +1242,7 @@ dependencies = [ [[package]] name = "craft-ps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c" +source = "git+https://github.com/storytold/craft-libs?rev=808730f49b9637b7909fe2ae56f9d63fdb100cae#808730f49b9637b7909fe2ae56f9d63fdb100cae" dependencies = [ "craft-eps", "kurbo", diff --git a/Cargo.toml b/Cargo.toml index c3fce93e4..6df05760c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["read"] } +craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } diff --git a/crates/pdf/src/tests/import.rs b/crates/pdf/src/tests/import.rs index f8c6509c2..80be350f6 100644 --- a/crates/pdf/src/tests/import.rs +++ b/crates/pdf/src/tests/import.rs @@ -627,3 +627,19 @@ fn postscript_idiv_and_mod_of_i64_min_by_minus_one_give_zero() { assert_eq!(shape_names(&doc).len(), 1, "{prog}"); } } + +#[test] +fn eps_unembedded_reencoded_accent_uses_bundled_glyph() { + let doc = eps(b"/Helvetica findfont dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall /Encoding 256 array def 0 1 255 {Encoding exch /.notdef put} for Encoding 65 /eacute put currentdict end /Accent exch definefont 40 scalefont setfont 10 30 moveto (A) show\n"); + assert_eq!(shape_names(&doc), vec!["Text: é"]); + let reference = parse(&page_pdf( + "BT /F1 40 Tf 10 30 Td Tj ET", + "/Font << /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> >>", + vec![], + )) + .unwrap(); + let (a, b) = (render(&doc), render(&reference)); + let (ia, ib) = (coverage(&a, 0, 0, 200, 100), coverage(&b, 0, 0, 200, 100)); + assert!(ia > 50.0 && (ia - ib).abs() < 1.0, "EPS accent {ia} vs PDF accent {ib}"); + assert_eq!(ink_x(&a), ink_x(&b)); +} From 3b4f35eba40dda453fe0a980fa8ab63b0f29c1bb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 22:13:24 -0500 Subject: [PATCH 62/99] Keep dotLottie cutover separate from coverage PR 3654 --- .github/workflows/sonarcloud.yml | 4 ---- crates/ui-egui/tests/it/ui_crypto_pick.rs | 1 - 2 files changed, 5 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 6adc57765..8f1aa5ad5 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -20,9 +20,5 @@ jobs: uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main with: timeout-minutes: 120 - # GPU tests share a process-local lock; separate coverage shards create independent - # software Vulkan devices, bypassing that lock and potentially contending on llvmpipe. - shards: 1 - rust-test-threads: "1" fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 secrets: inherit diff --git a/crates/ui-egui/tests/it/ui_crypto_pick.rs b/crates/ui-egui/tests/it/ui_crypto_pick.rs index c9ed63ef3..5aa923698 100644 --- a/crates/ui-egui/tests/it/ui_crypto_pick.rs +++ b/crates/ui-egui/tests/it/ui_crypto_pick.rs @@ -635,7 +635,6 @@ fn clicks_wait_for_the_probe_and_edits_popups_dialogs_and_comp_switches_end_or_b /// each Resolution. Skips without a GPU adapter. #[test] fn picks_on_the_gpu_viewer() { - let _gpu = crate::gpu_test::lock(); let Some(probe) = effectcraft_gpu::Gpu::headless() else { eprintln!("no GPU adapter: skipping"); return; From 5a7b4e903f586f84ece9b7babe5448544f74f5e4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 23:03:51 -0500 Subject: [PATCH 63/99] test(gpu): isolate inverse LUT and profile readbacks --- crates/gpu/src/tests/fx_lut.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/gpu/src/tests/fx_lut.rs b/crates/gpu/src/tests/fx_lut.rs index b74e90f09..f4bac9f7d 100644 --- a/crates/gpu/src/tests/fx_lut.rs +++ b/crates/gpu/src/tests/fx_lut.rs @@ -97,6 +97,21 @@ fn apply_color_lut() { effect_case("ec.utility.applylut", &[("lut", s("/nonexistent/grade.cube"))]); } +// Keep this separate so Nextest runs the inverse lookup in a fresh process/device, +// without the preceding 3D LUT submissions in `ocio_file_transform`. The combined +// test stays intact to cover ordering and shared-device state as well. +#[test] +fn inverse_1d_lut_on_a_fresh_device_matches_cpu() { + effect_direct("ec.color.ociofile", &[("file", s(&cube_1d())), ("direction", e(1))], false); +} + +// Isolate the first profile conversion that failed in hosted llvmpipe coverage. +// This retains the same oracle and tolerance as the broader profile test. +#[test] +fn profile_conversion_on_a_fresh_device_matches_cpu() { + effect_direct("ec.utility.colorprofileconverter", &[("inputProfile", e(1)), ("outputProfile", e(3)), ("intent", e(0))], false); +} + #[test] fn ocio_file_transform() { for interp in 1..4 { From 3678cc9bec4e09f91482d9738f79b4c22c2a28d0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 23:25:31 -0500 Subject: [PATCH 64/99] fix(gpu): bound inverse LUT search and write transfer components explicitly --- crates/gpu/src/shaders/fx_lut.wgsl | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/gpu/src/shaders/fx_lut.wgsl b/crates/gpu/src/shaders/fx_lut.wgsl index 87966df7d..96f325642 100644 --- a/crates/gpu/src/shaders/fx_lut.wgsl +++ b/crates/gpu/src/shaders/fx_lut.wgsl @@ -176,12 +176,16 @@ fn fxl_inv_1d(o: u32, i: u32, y: f32) -> f32 { // partition_point over the table's values. var lo = 0u; var hi = n; - while (lo < hi) { - let mid = (lo + hi) / 2u; - if (data[b1 + mid * 3u + i] < y) { - lo = mid + 1u; - } else { - hi = mid; + // A u32 interval needs at most 32 halvings. A fixed trip count avoids + // a divergent data-dependent loop on software Vulkan without changing lookup. + for (var step = 0u; step < 32u; step++) { + if (lo < hi) { + let mid = lo + (hi - lo) / 2u; + if (data[b1 + mid * 3u + i] < y) { + lo = mid + 1u; + } else { + hi = mid; + } } } let k = clamp(lo, 1u, n - 1u); @@ -444,12 +448,11 @@ fn fxl_run(c0: vec3) -> vec3 { case 1u, 2u: { let tf = u32(data[pc + 1u]); let g = data[pc + 2u]; - for (var i = 0u; i < 3u; i++) { - if (op == 1u) { - c[i] = fxl_decode(tf, g, c[i]); - } else { - c[i] = fxl_encode(tf, g, c[i]); - } + // Explicit components avoid llvmpipe's dynamically indexed vector writes. + if (op == 1u) { + c = vec3(fxl_decode(tf, g, c.x), fxl_decode(tf, g, c.y), fxl_decode(tf, g, c.z)); + } else { + c = vec3(fxl_encode(tf, g, c.x), fxl_encode(tf, g, c.y), fxl_encode(tf, g, c.z)); } pc += 3u; } From f0a5783a821c4fe4d438c3758b2fb4a762ef4254 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 23:56:13 -0500 Subject: [PATCH 65/99] fix(gpu): preserve CSP shaper channels on software Vulkan --- crates/gpu/src/shaders/fx_lut.wgsl | 37 +++++++++++++++++++----------- crates/gpu/src/tests/fx_lut.rs | 14 +++++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/crates/gpu/src/shaders/fx_lut.wgsl b/crates/gpu/src/shaders/fx_lut.wgsl index 96f325642..f9081f834 100644 --- a/crates/gpu/src/shaders/fx_lut.wgsl +++ b/crates/gpu/src/shaders/fx_lut.wgsl @@ -130,12 +130,15 @@ fn fxl_shape(at: u32, n: u32, x: f32, flip: bool) -> f32 { // partition_point(|p| p.x < x). var lo = 0u; var hi = n; - while (lo < hi) { - let mid = (lo + hi) / 2u; - if (data[at + mid * 2u + kx] < x) { - lo = mid + 1u; - } else { - hi = mid; + // Bound the partition search as for inverse 1D LUTs below. + for (var step = 0u; step < 32u; step++) { + if (lo < hi) { + let mid = lo + (hi - lo) / 2u; + if (data[at + mid * 2u + kx] < x) { + lo = mid + 1u; + } else { + hi = mid; + } } } let i = clamp(lo, 1u, n - 1u); @@ -156,13 +159,22 @@ fn fxl_shaper_at(s: u32, k: u32) -> vec2 { return vec2(at, u32(data[s + k])); } +// Evaluate independent shaper channels without dynamically writing vector lanes. +fn fxl_shaper_apply(sh: u32, c: vec3, flip: bool) -> vec3 { + let r = fxl_shaper_at(sh, 0u); + let g = fxl_shaper_at(sh, 1u); + let b = fxl_shaper_at(sh, 2u); + return vec3( + fxl_shape(r.x, r.y, c.x, flip), + fxl_shape(g.x, g.y, c.y, flip), + fxl_shape(b.x, b.y, c.z, flip) + ); +} + fn fxl_file_fwd(o: u32, sh: i32, c0: vec3, interp: u32) -> vec3 { var c = c0; if (sh >= 0) { - for (var k = 0u; k < 3u; k++) { - let a = fxl_shaper_at(u32(sh), k); - c[k] = fxl_shape(a.x, a.y, c[k], false); - } + c = fxl_shaper_apply(u32(sh), c, false); } return fxl_lut_apply(o, c, interp); } @@ -209,10 +221,7 @@ fn fxl_file(o: u32, sh: i32, c: vec3, interp: u32, inverse: bool) -> vec3(fxl_inv_1d(o, 0u, c.x), fxl_inv_1d(o, 1u, c.y), fxl_inv_1d(o, 2u, c.z)); } if (sh >= 0) { - for (var k = 0u; k < 3u; k++) { - let a = fxl_shaper_at(u32(sh), k); - x[k] = fxl_shape(a.x, a.y, x[k], true); - } + x = fxl_shaper_apply(u32(sh), x, true); } return x; } diff --git a/crates/gpu/src/tests/fx_lut.rs b/crates/gpu/src/tests/fx_lut.rs index f4bac9f7d..acac88835 100644 --- a/crates/gpu/src/tests/fx_lut.rs +++ b/crates/gpu/src/tests/fx_lut.rs @@ -112,6 +112,20 @@ fn profile_conversion_on_a_fresh_device_matches_cpu() { effect_direct("ec.utility.colorprofileconverter", &[("inputProfile", e(1)), ("outputProfile", e(3)), ("intent", e(0))], false); } +// Unequal CSP channel point counts exercise shaper offsets on a fresh device. +#[test] +fn csp_shaper_on_a_fresh_device_matches_cpu() { + effect_direct("ec.color.ociofile", &[("file", s(&csp())), ("interpolation", e(1))], false); + effect_direct("ec.color.ociofile", &[("file", s(&csp())), ("direction", e(1))], false); +} + +// A 1D CSP takes the direct inverse-shaper path (flip=true), unlike a 3D CSP. +#[test] +fn inverse_1d_csp_shaper_on_a_fresh_device_matches_cpu() { + let lut = "CSPLUTV100\n1D\n3\n0 0.5 1\n0 0.3 1\n2\n0 1\n0 1\n4\n0 0.2 0.6 1\n0 0.4 0.7 1\n2\n0 0 0\n1 1 1\n"; + effect_direct("ec.color.ociofile", &[("file", s(lut)), ("direction", e(1))], false); +} + #[test] fn ocio_file_transform() { for interp in 1..4 { From 218b94224abdbf73b5fc2eca0c6069b82f28b90a Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 20:00:53 +0000 Subject: [PATCH 66/99] test(ui): serialize GPU picker integration --- crates/ui-egui/tests/it/ui_crypto_pick.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/tests/it/ui_crypto_pick.rs b/crates/ui-egui/tests/it/ui_crypto_pick.rs index 5aa923698..c9ed63ef3 100644 --- a/crates/ui-egui/tests/it/ui_crypto_pick.rs +++ b/crates/ui-egui/tests/it/ui_crypto_pick.rs @@ -635,6 +635,7 @@ fn clicks_wait_for_the_probe_and_edits_popups_dialogs_and_comp_switches_end_or_b /// each Resolution. Skips without a GPU adapter. #[test] fn picks_on_the_gpu_viewer() { + let _gpu = crate::gpu_test::lock(); let Some(probe) = effectcraft_gpu::Gpu::headless() else { eprintln!("no GPU adapter: skipping"); return; From 234273d9b86cfd447b73732efd36698d092d2c0f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:44:53 +0100 Subject: [PATCH 67/99] docs(exr): note the shared decoder's all-channel data-window bound --- crates/media/src/exr_channels.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index 13e3c9d93..3463cf663 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -112,7 +112,10 @@ fn decode(bytes: &[u8], keep: &dyn Fn(&str) -> bool) -> Result limits.max_pixels = MAX_DISPLAY_PIXELS as u64; limits.max_bytes = MAX_DECODE_BYTES as u64; // Header-only checks must not charge channels this caller does not decode. The shared display - // decoder independently checks the exact selected display planes before allocating them. + // decoder independently checks the exact selected display planes before allocating them. It + // also bounds a selected part's data window across all of its channels (decoded blocks carry + // every channel before the unused ones are dropped), so a part whose full channel set exceeds + // `max_bytes` is refused even when the kept planes alone would fit. let mut header_limits = limits; header_limits.max_width = u32::MAX; header_limits.max_height = u32::MAX; From 07250580e250c0eeb7465790a39823826101b046 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:07:56 +0100 Subject: [PATCH 68/99] test(export): share the GIF render and decode setup between the GIF tests Split the byte-parity check against the former gif 0.13 encoder into its own test, with the reference encode in a helper. --- crates/export/tests/it/roundtrip.rs | 94 +++++++++++++++-------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/crates/export/tests/it/roundtrip.rs b/crates/export/tests/it/roundtrip.rs index 1abed1983..224cbfc43 100644 --- a/crates/export/tests/it/roundtrip.rs +++ b/crates/export/tests/it/roundtrip.rs @@ -543,16 +543,40 @@ fn exr_sequence_values_at_or_below_one_are_unchanged() { assert!((c[0] - 1.0).abs() < 1e-4 && (c[1] - lin(0.4)).abs() < 1e-4 && c[2].abs() < 1e-6, "{channels:?}: {c:?}"); } } -#[test] -fn gif_roundtrip() { +/// Render the test project as a GIF with `om` into `out_dir(name)`, and open it for RGBA decoding. +fn render_gif(name: &str, om: &OutputModule) -> (PathBuf, gif::Decoder) { let (p, cid) = project(None); - let d = out_dir("gif"); - let om = OutputModule::for_format(OutputFormat::Gif); - let path = d.join("anim.gif"); - run(&p, cid, &NoFootage, &om, &path); + let path = out_dir(name).join("anim.gif"); + run(&p, cid, &NoFootage, om, &path); let mut opts = gif::DecodeOptions::new(); opts.set_color_output(gif::ColorOutput::RGBA); - let mut dec = opts.read_info(std::fs::File::open(&path).expect("open")).expect("gif header"); + let dec = opts.read_info(std::fs::File::open(&path).expect("open")).expect("gif header"); + (path, dec) +} + +/// The test project's frames, rendered as PNGs, re-encoded through the former app-local gif 0.13 +/// path (`Frame::from_rgba_speed` at speed 10, 1/10 s per frame, looping). +fn reference_gif() -> Vec { + let (p, cid) = project(None); + let png_pattern = out_dir("gif-byte-parity").join("frame_[#####].png"); + run(&p, cid, &NoFootage, &OutputModule::for_format(OutputFormat::PngSequence), &png_pattern); + let png_pattern = png_pattern.to_string_lossy(); + let mut expected = Vec::new(); + let mut encoder = gif::Encoder::new(&mut expected, W as u16, H as u16, &[]).expect("reference GIF encoder"); + encoder.set_repeat(gif::Repeat::Infinite).expect("reference GIF repeat"); + for frame_number in 0..FRAMES { + let mut rgba = image::open(sequence_path(&png_pattern, frame_number as i64)).expect("reference PNG").to_rgba8().into_raw(); + let mut frame = gif::Frame::from_rgba_speed(W as u16, H as u16, &mut rgba, 10); + frame.delay = 10; + encoder.write_frame(&frame).expect("reference GIF frame"); + } + drop(encoder); + expected +} + +#[test] +fn gif_roundtrip() { + let (path, mut dec) = render_gif("gif", &OutputModule::for_format(OutputFormat::Gif)); assert_eq!((dec.width() as u32, dec.height() as u32), (W, H)); assert_eq!(dec.repeat(), gif::Repeat::Infinite); let mut k = 0; @@ -567,52 +591,30 @@ fn gif_roundtrip() { } assert_eq!(k, FRAMES); assert_eq!(total_delay, 120, "1.2 s in centiseconds"); - - // Re-encode the same rendered RGB pixels through the former app-local gif 0.13 path. The - // shared writer must preserve the complete output bytes, including quantization and LZW data. - let reference_dir = out_dir("gif-byte-parity"); - let png_pattern = reference_dir.join("frame_[#####].png"); - let png_module = OutputModule::for_format(OutputFormat::PngSequence); - run(&p, cid, &NoFootage, &png_module, &png_pattern); - let png_pattern = png_pattern.to_string_lossy(); - let mut expected = Vec::new(); - { - let mut encoder = gif::Encoder::new(&mut expected, W as u16, H as u16, &[]).expect("reference GIF encoder"); - encoder.set_repeat(gif::Repeat::Infinite).expect("reference GIF repeat"); - for frame_number in 0..FRAMES { - let png_path = sequence_path(&png_pattern, frame_number as i64); - let mut rgba = image::open(png_path).expect("reference PNG").to_rgba8().into_raw(); - let mut frame = gif::Frame::from_rgba_speed(W as u16, H as u16, &mut rgba, 10); - frame.delay = 10; - encoder.write_frame(&frame).expect("reference GIF frame"); - } - } - let actual = std::fs::read(&path).expect("GIF bytes"); - assert_eq!(actual.len(), expected.len(), "GIF byte length differs: actual {}, reference {}", actual.len(), expected.len()); - let difference = actual.iter().zip(&expected).position(|(a, b)| a != b); - assert!( - difference.is_none(), - "GIF bytes differ at offset {:?}: actual {:#04x}, reference {:#04x}", - difference, - difference.map_or(0, |i| actual[i]), - difference.map_or(0, |i| expected[i]) - ); if let Some(s) = ffprobe(&path) { assert!(s.starts_with("gif|64|48"), "{s}"); } } #[test] -fn gif_rgba_keeps_background_disposal_and_non_looping() { - let (p, cid) = project(None); - let d = out_dir("gif-rgba"); - let om = OutputModule { channels: Channels::Rgba, gif_loop: false, ..OutputModule::for_format(OutputFormat::Gif) }; - let path = d.join("anim.gif"); - run(&p, cid, &NoFootage, &om, &path); +fn gif_matches_the_former_encoder_byte_for_byte() { + // The shared writer must keep the complete output, quantization and LZW data included. + let (path, _) = render_gif("gif-parity", &OutputModule::for_format(OutputFormat::Gif)); + let actual = std::fs::read(&path).expect("GIF bytes"); + let expected = reference_gif(); + let difference = actual.iter().zip(&expected).position(|(a, b)| a != b); + assert!( + actual.len() == expected.len() && difference.is_none(), + "GIF bytes differ: {} vs {} bytes, first difference at {difference:?}", + actual.len(), + expected.len() + ); +} - let mut opts = gif::DecodeOptions::new(); - opts.set_color_output(gif::ColorOutput::RGBA); - let mut dec = opts.read_info(std::fs::File::open(&path).expect("open")).expect("gif header"); +#[test] +fn gif_rgba_keeps_background_disposal_and_non_looping() { + let om = OutputModule { channels: Channels::Rgba, gif_loop: false, ..OutputModule::for_format(OutputFormat::Gif) }; + let (_, mut dec) = render_gif("gif-rgba", &om); assert_eq!(dec.repeat(), gif::Repeat::Finite(0)); let first = dec.read_next_frame().expect("frame").expect("first frame"); assert_eq!(first.dispose, gif::DisposalMethod::Background); From 186661829a677a7555e72f26b212d771eb2e81a6 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 08:18:00 +0100 Subject: [PATCH 69/99] media: decode animated GIF and WebP through craft-gif and craft-webp frames Carved out of #3649. craft_gif::frames and craft_webp::frames replace the image crate's animation decoders in gif_anim and webp_anim, with the same frame, byte and canvas limits and the same damaged-tail behaviour (frames decoded before the damage are kept). craft-gif and craft-webp are pinned to craft-libs main 948b5c23 with the frames feature. --- Cargo.lock | 9 ++- Cargo.toml | 4 +- crates/media/Cargo.toml | 4 +- crates/media/src/gif_anim.rs | 147 ++++++++++++++++++++++++++-------- crates/media/src/webp_anim.rs | 119 +++++++++++++++++++++------ 5 files changed, 219 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f68689a2..b95410306 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1166,7 +1166,11 @@ source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b4255 [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" +dependencies = [ + "gif", + "image", +] [[package]] name = "craft-i18n" @@ -1361,8 +1365,9 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ + "image", "thiserror 2.0.21", ] diff --git a/Cargo.toml b/Cargo.toml index 13e062ee6..eb297bd7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,10 @@ craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/c craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2284a6bf76b3d629b5e5bb2ca71e1c319d8dae5f" } craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index f744c684c..2922a1a7c 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -24,8 +24,8 @@ filmcraft-codecs = { workspace = true } filmcraft-media = { workspace = true } craft-dpx = { workspace = true } craft-exr = { workspace = true } -craft-gif = { workspace = true } -craft-webp = { workspace = true } +craft-gif = { workspace = true, features = ["frames"] } +craft-webp = { workspace = true, features = ["frames"] } craft-audio = { workspace = true } craft-media = { workspace = true } filmcraft-mpegts = { workspace = true } diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index 8453b50ac..e2cac5aa8 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -5,11 +5,9 @@ //! delays), so uneven timing is kept exactly; [`Anim::frame_at`] looks the frame up by time. //! Animated WebP ([`crate::webp_anim`]) shares [`Anim`] and this decode path. -use std::io::Cursor; - use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; -use image::{AnimationDecoder, DynamicImage, codecs::gif::GifDecoder}; +use image::DynamicImage; use crate::{MediaError, Result}; @@ -86,39 +84,39 @@ impl Anim { if crate::webp_anim::is_webp(bytes) { return crate::webp_anim::load(bytes); } - let mut dec = GifDecoder::new(Cursor::new(bytes)).map_err(|e| MediaError::Decode(format!("GIF: {e}")))?; - // A frame may be far larger than the canvas, and the decoder allocates its buffer before - // decoding it: no single buffer may pass what all the frames may hold. - let mut limits = image::Limits::no_limits(); - limits.max_alloc = Some(MAX_BYTES as u64); - image::ImageDecoder::set_limits(&mut dec, limits).map_err(|e| MediaError::Decode(format!("GIF: {e}")))?; - // The decoder allocates the full logical canvas for the first frame, however small the - // frames themselves are: check it before decoding any. - let (w, h) = image::ImageDecoder::dimensions(&dec); - if u64::from(w) * u64::from(h) * 4 > MAX_BYTES as u64 { - return Err(MediaError::Unsupported(format!("GIF canvas of {w}×{h} is too large to hold in memory"))); - } - let (mut frames, mut starts) = (Vec::new(), Vec::new()); - let (mut at, mut size) = (0i64, 0usize); - for frame in dec.into_frames() { - let frame = match frame { - Ok(f) => f, - Err(e) if frames.is_empty() => return Err(MediaError::Decode(format!("GIF: {e}"))), - Err(e) => { - log::warn!("media: GIF stops after {} frames: {e}", frames.len()); - break; - } - }; - let (numer, denom) = frame.delay().numer_denom_ms(); - let cs = delay_cs(numer.checked_div(denom).unwrap_or(0) / 10); - let buf = frame.into_buffer(); - size = size.saturating_add(buf.as_raw().len()); - if size > MAX_BYTES { - return Err(MediaError::Unsupported("GIF is too large to hold in memory".into())); + let mut limits = craft_gif::frames::FrameLimits::default(); + limits.max_frames = MAX_FRAMES; + limits.max_bytes = MAX_BYTES as u64; + limits.max_canvas_bytes = MAX_BYTES as u64; + limits.max_decode_bytes = Some(MAX_BYTES as u64); + let decoded = craft_gif::frames::read_frames(bytes, &limits).map_err(|e| match e { + craft_gif::frames::FrameError::Malformed(m) => MediaError::Decode(format!("GIF: {m}")), + craft_gif::frames::FrameError::LimitExceeded(m) + if m.contains("cannot hold") || m.contains("decode-allocation limit") || m.to_ascii_lowercase().contains("memory limit") => + { + MediaError::Unsupported("GIF is too large to hold in memory".into()) } + craft_gif::frames::FrameError::LimitExceeded(m) if m.contains("canvas is over") => { + MediaError::Unsupported("GIF canvas is too large to hold in memory".into()) + } + craft_gif::frames::FrameError::LimitExceeded(m) => MediaError::Unsupported(format!("GIF: {m}")), + })?; + if matches!(&decoded.stop, craft_gif::frames::Stop::ByteLimit | craft_gif::frames::Stop::FrameLimit) { + return Err(MediaError::Unsupported("GIF is too large to hold in memory".into())); + } + if let craft_gif::frames::Stop::Damaged(ref e) = decoded.stop { + log::warn!("media: GIF stops after {} frames: {e}", decoded.frames.len()); + } + let mut frames = Vec::with_capacity(decoded.frames.len()); + let mut starts = Vec::with_capacity(decoded.frames.len()); + let mut at = 0i64; + for frame in decoded.frames { + let cs = delay_cs(frame.delay_ms / 10); + let image = image::RgbaImage::from_raw(decoded.width, decoded.height, frame.rgba) + .ok_or_else(|| MediaError::Decode("GIF: invalid decoded frame dimensions".into()))?; starts.push(Tick::from_units(at, 100)); at = at.saturating_add(i64::from(cs)); - frames.push(DynamicImage::ImageRgba8(buf)); + frames.push(DynamicImage::ImageRgba8(image)); } Anim::new(frames, starts).ok_or_else(|| MediaError::Decode("GIF: no frames".into())) } @@ -133,9 +131,13 @@ impl Anim { #[cfg(test)] mod tests { + use std::io::Cursor; + use effectcraft_project::{Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; + use image::AnimationDecoder; + use super::MAX_FRAMES; use crate::{MediaPool, probe_bytes}; /// A 2×2 GIF with one solid-colour frame per `(rgb, delay)`. @@ -152,6 +154,15 @@ mod tests { out } + /// Preserve the old consumer path as a test oracle while the frame API is shared. + fn legacy_gif_frames(bytes: &[u8]) -> Vec { + image::codecs::gif::GifDecoder::new(Cursor::new(bytes)).unwrap().into_frames().map(|frame| frame.unwrap().into_buffer()).collect() + } + + fn legacy_gif_frames_until_error(bytes: &[u8]) -> Vec { + image::codecs::gif::GifDecoder::new(Cursor::new(bytes)).unwrap().into_frames().map_while(|frame| frame.ok()).map(|frame| frame.into_buffer()).collect() + } + const RED: [u8; 3] = [255, 0, 0]; const GREEN: [u8; 3] = [0, 255, 0]; const BLUE: [u8; 3] = [0, 0, 255]; @@ -201,6 +212,62 @@ mod tests { assert_eq!(f.duration, Tick::from_units(20, 100)); } + #[test] + fn shared_gif_frames_match_legacy_compositing_and_disposal() { + let mut bytes = Vec::new(); + { + let palette = [255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0]; + let mut enc = gif::Encoder::new(&mut bytes, 3, 2, &palette).unwrap(); + let first = gif::Frame { + width: 3, + height: 2, + buffer: vec![0; 6].into(), // red background + delay: 5, + dispose: gif::DisposalMethod::Keep, + ..gif::Frame::default() + }; + enc.write_frame(&first).unwrap(); + + let second = gif::Frame { + left: 1, + width: 1, + height: 1, + buffer: vec![1].into(), // green patch + delay: 7, + dispose: gif::DisposalMethod::Background, + ..gif::Frame::default() + }; + enc.write_frame(&second).unwrap(); + + let third = gif::Frame { + left: 2, + width: 1, + height: 1, + buffer: vec![2].into(), // blue patch after disposal + delay: 9, + dispose: gif::DisposalMethod::Previous, + ..gif::Frame::default() + }; + enc.write_frame(&third).unwrap(); + + let fourth = gif::Frame { + width: 1, + height: 1, + buffer: vec![3].into(), // black patch after restoring the previous canvas + delay: 11, + ..gif::Frame::default() + }; + enc.write_frame(&fourth).unwrap(); + } + let expected = legacy_gif_frames(&bytes); + let actual = super::Anim::load(&bytes).unwrap(); + assert_eq!(actual.frames.len(), expected.len()); + for (frame, old) in actual.frames.iter().zip(expected) { + assert_eq!(frame.to_rgba8(), old); + } + assert_eq!(actual.starts, vec![Tick::from_units(0, 100), Tick::from_units(5, 100), Tick::from_units(12, 100), Tick::from_units(21, 100)]); + } + #[test] fn a_single_frame_gif_stays_a_still() { let f = probe_bytes("a.gif", gif(&[(RED, 10)]).into()).unwrap(); @@ -228,6 +295,20 @@ mod tests { let _ = probe_bytes("a.gif", bytes.into()); } + #[test] + fn a_damaged_gif_tail_keeps_frames_already_decoded() { + let mut bytes = gif(&[(RED, 5), (GREEN, 5), (BLUE, 5)]); + let info = craft_gif::scan(&bytes, MAX_FRAMES).unwrap(); + assert_eq!(info.frames.len(), 3); + bytes.truncate(info.frames[1].offset); + + let legacy = legacy_gif_frames_until_error(&bytes); + assert_eq!(legacy.len(), 1); + let actual = super::Anim::load(&bytes).unwrap(); + assert_eq!(actual.frames.len(), legacy.len()); + assert_eq!(actual.frames[0].to_rgba8(), legacy[0]); + } + #[test] fn a_huge_canvas_is_refused_before_decoding() { // A 65535×65535 logical screen (16 GiB of RGBA) holding one 1×1 frame. diff --git a/crates/media/src/webp_anim.rs b/crates/media/src/webp_anim.rs index 147fe8264..dbe664fac 100644 --- a/crates/media/src/webp_anim.rs +++ b/crates/media/src/webp_anim.rs @@ -9,11 +9,9 @@ //! every delay is a whole number of frames at (1000 / the greatest common divisor of the delays), //! so it is kept exactly. A still WebP (no animation flag, or a single frame) stays a still. -use std::io::Cursor; - use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; -use image::{AnimationDecoder, DynamicImage, codecs::webp::WebPDecoder}; +use image::DynamicImage; use crate::gif_anim::{Anim, MAX_BYTES, MAX_FRAMES, gcd}; use crate::{MediaError, Result}; @@ -121,29 +119,29 @@ pub(crate) fn load(bytes: &[u8]) -> Result { if frame_bytes.saturating_mul(h.delays.len()) > MAX_BYTES { return Err(MediaError::Unsupported(format!("animated WebP of {} frames of {}×{} is too large to hold in memory", h.delays.len(), h.width, h.height))); } - let dec = WebPDecoder::new(Cursor::new(bytes)).map_err(|e| MediaError::Decode(format!("WebP: {e}")))?; - // The budget above used the canvas this file's header scan found; the decoder must agree, or - // a second VP8X header could make it allocate a far larger canvas. - if image::ImageDecoder::dimensions(&dec) != (h.width, h.height) { + let mut limits = craft_webp::frames::FrameLimits::default(); + limits.max_frames = MAX_FRAMES; + limits.max_bytes = MAX_BYTES as u64; + limits.max_canvas_bytes = MAX_BYTES as u64; + let decoded = craft_webp::frames::read_frames(bytes, &limits).map_err(|e| match e { + craft_webp::frames::FrameError::Malformed(m) => MediaError::Decode(format!("WebP: {m}")), + craft_webp::frames::FrameError::LimitExceeded(m) => MediaError::Unsupported(format!("WebP: {m}")), + })?; + if matches!(&decoded.stop, craft_webp::frames::Stop::ByteLimit | craft_webp::frames::Stop::FrameLimit) { + return Err(MediaError::Unsupported("animated WebP is too large to hold in memory".into())); + } + if let craft_webp::frames::Stop::Damaged(ref e) = decoded.stop { + log::warn!("media: WebP stops after {} frames: {e}", decoded.frames.len()); + } + if (decoded.width, decoded.height) != (h.width, h.height) { return Err(MediaError::Decode("WebP: conflicting canvas sizes".into())); } - let (mut frames, mut delays, mut size) = (Vec::new(), Vec::new(), 0usize); - for frame in dec.into_frames() { - let frame = match frame { - Ok(f) => f, - Err(e) if frames.is_empty() => return Err(MediaError::Decode(format!("WebP: {e}"))), - Err(e) => { - log::warn!("media: WebP stops after {} frames: {e}", frames.len()); - break; - } - }; - let (numer, denom) = frame.delay().numer_denom_ms(); - delays.push(numer.checked_div(denom).unwrap_or(0)); - let buf = frame.into_buffer(); - size = size.saturating_add(buf.as_raw().len()); - if size > MAX_BYTES { - return Err(MediaError::Unsupported("animated WebP is too large to hold in memory".into())); - } + let mut frames = Vec::with_capacity(decoded.frames.len()); + let mut delays = Vec::with_capacity(decoded.frames.len()); + for frame in decoded.frames { + delays.push(frame.delay_ms); + let buf = image::RgbaImage::from_raw(decoded.width, decoded.height, frame.rgba) + .ok_or_else(|| MediaError::Decode("WebP: invalid decoded frame dimensions".into()))?; frames.push(DynamicImage::ImageRgba8(buf)); } let starts = timing(&delays).starts; @@ -152,9 +150,11 @@ pub(crate) fn load(bytes: &[u8]) -> Result { #[cfg(test)] mod tests { + use std::io::Cursor; + use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; - use image::{ExtendedColorType, ImageEncoder, codecs::webp::WebPEncoder}; + use image::{AnimationDecoder, ExtendedColorType, ImageEncoder, codecs::webp::WebPDecoder, codecs::webp::WebPEncoder}; use super::timing; use crate::{MediaPool, probe_bytes}; @@ -204,6 +204,43 @@ mod tests { chunk(b"RIFF", &body) } + /// Build an animation whose frames may cover only part of the canvas. `x` and `y` are even, + /// as required by ANMF; bit 1 of `flags` selects no-blend and bit 0 selects disposal. + fn webp_subframes(canvas: (u32, u32), frames: &[(u32, u32, u32, u32, [u8; 4], u32, u8)]) -> Vec { + let (w, h) = canvas; + let mut vp8x = vec![0x12, 0, 0, 0]; + vp8x.extend_from_slice(&u24(w - 1)); + vp8x.extend_from_slice(&u24(h - 1)); + let mut body = b"WEBP".to_vec(); + body.extend(chunk(b"VP8X", &vp8x)); + body.extend(chunk(b"ANIM", &[0; 6])); + for &(x, y, fw, fh, rgba, delay, flags) in frames { + let mut anmf = Vec::new(); + anmf.extend_from_slice(&u24(x / 2)); + anmf.extend_from_slice(&u24(y / 2)); + anmf.extend_from_slice(&u24(fw - 1)); + anmf.extend_from_slice(&u24(fh - 1)); + anmf.extend_from_slice(&u24(delay)); + anmf.push(flags); + anmf.extend(vp8l(fw, fh, rgba)); + body.extend(chunk(b"ANMF", &anmf)); + } + chunk(b"RIFF", &body) + } + + fn anmf_offsets(bytes: &[u8]) -> Vec { + let mut offsets = Vec::new(); + let mut at = 12usize; + while at + 8 <= bytes.len() { + let size = u32::from_le_bytes(bytes[at + 4..at + 8].try_into().unwrap()) as usize; + if &bytes[at..at + 4] == b"ANMF" { + offsets.push(at); + } + at = at.saturating_add(8).saturating_add(size).saturating_add(size & 1); + } + offsets + } + const RED: [u8; 4] = [255, 0, 0, 255]; const GREEN: [u8; 4] = [0, 255, 0, 255]; const BLUE: [u8; 4] = [0, 0, 255, 128]; @@ -238,6 +275,38 @@ mod tests { assert_eq!(pixel_at(&pool, &f, 5.0), last); } + #[test] + fn shared_webp_frames_match_legacy_subrect_blending_and_disposal() { + // Includes a blended alpha patch, then a no-blend patch disposed to the background. + let bytes = + webp_subframes((4, 2), &[(0, 0, 4, 2, RED, 50, 0b10), (2, 0, 2, 2, BLUE, 60, 0b00), (0, 0, 2, 2, GREEN, 70, 0b11), (2, 0, 2, 2, RED, 80, 0b10)]); + let expected = WebPDecoder::new(Cursor::new(&bytes)).unwrap().into_frames().map(|frame| frame.unwrap().into_buffer()).collect::>(); + let actual = super::load(&bytes).unwrap(); + assert_eq!(expected.len(), 4); + for (index, (start_ms, old)) in [(0, &expected[0]), (50, &expected[1]), (110, &expected[2]), (180, &expected[3])].into_iter().enumerate() { + let tick = Tick::from_units(start_ms, 1000); + let frame = actual.frame_at(tick).unwrap().to_rgba8(); + assert_eq!(frame, *old, "frame {index} at {start_ms} ms"); + } + } + + #[test] + fn a_damaged_webp_tail_keeps_frames_already_decoded() { + let mut bytes = webp(4, 2, &[(RED, 50), (GREEN, 60), (BLUE, 70)]); + let offsets = anmf_offsets(&bytes); + assert_eq!(offsets.len(), 3); + bytes.truncate(offsets[2]); + + let legacy = + WebPDecoder::new(Cursor::new(&bytes)).unwrap().into_frames().map_while(|frame| frame.ok()).map(|frame| frame.into_buffer()).collect::>(); + assert_eq!(legacy.len(), 2); + let actual = super::load(&bytes).unwrap(); + for (index, old) in legacy.iter().enumerate() { + let tick = Tick::from_units(if index == 0 { 0 } else { 50 }, 1000); + assert_eq!(actual.frame_at(tick).unwrap().to_rgba8(), *old); + } + } + #[test] fn delays_rounded_to_milliseconds_read_as_the_standard_rate() { // 24 frames a second rounded to whole milliseconds, as ffmpeg writes them. From 843deea4d6bdd38c4a1edbc3b5ff677eb7a0967f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:30:38 +0100 Subject: [PATCH 70/99] pdf: decode PDFDocEncoding text strings and bound logical text labels text_string decoded strings without a byte-order mark as Latin-1, so an /ActualText with byte 0x80 became U+0080 instead of a bullet. It now maps PDFDocEncoding's 0x18-0x1F and 0x80-0xA0. Each paint inside an annotation carries its own copy of the label, so begin_text keeps at most 256 characters of it. --- crates/pdf/src/build.rs | 20 ++++++++++++++++++++ crates/pdf/src/color.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/crates/pdf/src/build.rs b/crates/pdf/src/build.rs index ad0f68216..3310bd9e0 100644 --- a/crates/pdf/src/build.rs +++ b/crates/pdf/src/build.rs @@ -10,6 +10,9 @@ pub(crate) const MAX_PATH: usize = 1 << 20; /// The deepest the open groups nest (the render tree and its consumers recurse through them). const MAX_DEPTH: usize = 256; +/// The most characters of a logical text label kept in a group name. +pub(crate) const MAX_LABEL: usize = 256; + #[derive(Clone, Copy, PartialEq, Eq)] enum Kind { Plain, @@ -124,6 +127,9 @@ impl Builder { self.skip("logical text nesting limit"); return false; } + // Every paint wrapped by the annotation carries its own copy of the label, so a long + // /ActualText is cut to MAX_LABEL characters rather than copied whole into each. + let text: String = text.chars().take(MAX_LABEL).collect(); self.text_labels.push(format!("Text: {text}")); true } @@ -209,3 +215,17 @@ impl Builder { (root, flags, self.skipped) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_long_logical_label_is_cut_once_at_begin_text() { + let mut b = Builder::new(); + assert!(b.begin_text(&"é".repeat(MAX_LABEL * 4))); + assert_eq!(b.text_labels[0].chars().count(), "Text: ".len() + MAX_LABEL); + assert!(b.begin_text("short")); + assert_eq!(b.text_labels[1], "Text: short"); + } +} diff --git a/crates/pdf/src/color.rs b/crates/pdf/src/color.rs index 5a7e9af86..8b150f907 100644 --- a/crates/pdf/src/color.rs +++ b/crates/pdf/src/color.rs @@ -779,7 +779,24 @@ impl Func { } } -/// PDF text string → Rust string (UTF-16BE with a byte-order mark, else PDFDocEncoding ≈ Latin-1). +/// PDFDocEncoding (ISO 32000-2 Annex D) where it differs from Latin-1: bytes 0x18–0x1F and +/// 0x80–0xA0 (0x9F is undefined). +const PDFDOC_LOW: [char; 8] = ['˘', 'ˇ', 'ˆ', '˙', '˝', '˛', '˚', '˜']; +const PDFDOC_HIGH: [char; 33] = [ + '•', '†', '‡', '…', '—', '–', 'ƒ', '⁄', '‹', '›', '−', '‰', '„', '“', '”', '‘', '’', '‚', '™', 'fi', 'fl', 'Ł', 'Œ', 'Š', 'Ÿ', 'Ž', 'ı', 'ł', 'œ', 'š', 'ž', + '\u{FFFD}', '€', +]; + +fn pdfdoc_char(c: u8) -> char { + match c { + 0x18..=0x1F => PDFDOC_LOW[usize::from(c - 0x18)], + 0x80..=0xA0 => PDFDOC_HIGH[usize::from(c - 0x80)], + _ => char::from(c), + } +} + +/// PDF text string → Rust string (UTF-16BE with a byte-order mark, UTF-8 with one, else +/// PDFDocEncoding). pub fn text_string(b: &[u8]) -> String { if b.starts_with(&[0xFE, 0xFF]) { let u: Vec = b[2..].as_chunks::<2>().0.iter().map(|c| u16::from_be_bytes([c[0], c[1]])).collect(); @@ -788,13 +805,19 @@ pub fn text_string(b: &[u8]) -> String { if let Some(rest) = b.strip_prefix(&[0xEF, 0xBB, 0xBF]) { return String::from_utf8_lossy(rest).into_owned(); } - b.iter().map(|&c| c as char).collect() + b.iter().map(|&c| pdfdoc_char(c)).collect() } #[cfg(test)] mod tests { use super::*; + #[test] + fn text_strings_without_a_bom_are_pdfdocencoding() { + assert_eq!(text_string(b"a\x80b\x92\xa0\x18\xe9"), "a•b™€˘é"); + assert_eq!(text_string(b"\xfe\xff\x00A\x20\x22"), "A•"); + } + #[test] fn sample_count_at_and_over_the_cap() { // 4 Mi entries × 4 outputs fill the cap exactly; a fifth output passes it. From 089c35759b1301441dd07002c3e3443c2746f1fc Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:04:07 +0100 Subject: [PATCH 71/99] test(export): share write_tone between the export integration tests --- crates/export/tests/it/hevc_av1_roundtrip.rs | 28 +----------------- crates/export/tests/it/main.rs | 1 + crates/export/tests/it/roundtrip.rs | 28 +----------------- crates/export/tests/it/support.rs | 30 ++++++++++++++++++++ crates/export/tests/it/uncompressed_mov.rs | 28 +----------------- 5 files changed, 34 insertions(+), 81 deletions(-) create mode 100644 crates/export/tests/it/support.rs diff --git a/crates/export/tests/it/hevc_av1_roundtrip.rs b/crates/export/tests/it/hevc_av1_roundtrip.rs index 4022da1ca..1cfbc41a9 100644 --- a/crates/export/tests/it/hevc_av1_roundtrip.rs +++ b/crates/export/tests/it/hevc_av1_roundtrip.rs @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; +use crate::support::write_tone; use effectcraft_color::Label; use effectcraft_export::render_queue::{ AudioOutput, CodecProfile, OpusApplication, OutputFormat, OutputModule, RateControlMode, RenderSettings, TimeSpan, WebmVideoCodec, @@ -299,30 +300,3 @@ fn rms(v: impl Iterator) -> f32 { let (s, n) = v.fold((0.0f64, 0usize), |(s, n), x| (s + (x as f64) * (x as f64), n + 1)); (s / n.max(1) as f64).sqrt() as f32 } - -/// 16-bit stereo WAV with a 440 Hz sine at amplitude 0.5 (left) and silence (right). -fn write_tone(path: &Path, secs: f64) { - let sr = 48_000u32; - let n = (secs * sr as f64) as usize; - let mut data = Vec::with_capacity(n * 4); - for i in 0..n { - let s = (0.5 * (2.0 * std::f64::consts::PI * 440.0 * i as f64 / sr as f64).sin() * 32767.0).round() as i16; - data.extend_from_slice(&s.to_le_bytes()); - data.extend_from_slice(&0i16.to_le_bytes()); - } - let mut w = Vec::new(); - w.extend_from_slice(b"RIFF"); - w.extend_from_slice(&(36 + data.len() as u32).to_le_bytes()); - w.extend_from_slice(b"WAVEfmt "); - w.extend_from_slice(&16u32.to_le_bytes()); - w.extend_from_slice(&1u16.to_le_bytes()); - w.extend_from_slice(&2u16.to_le_bytes()); - w.extend_from_slice(&sr.to_le_bytes()); - w.extend_from_slice(&(sr * 4).to_le_bytes()); - w.extend_from_slice(&4u16.to_le_bytes()); - w.extend_from_slice(&16u16.to_le_bytes()); - w.extend_from_slice(b"data"); - w.extend_from_slice(&(data.len() as u32).to_le_bytes()); - w.extend_from_slice(&data); - std::fs::write(path, w).expect("write wav"); -} diff --git a/crates/export/tests/it/main.rs b/crates/export/tests/it/main.rs index 77dc22b49..545181859 100644 --- a/crates/export/tests/it/main.rs +++ b/crates/export/tests/it/main.rs @@ -18,6 +18,7 @@ mod opus_roundtrip; mod prores_color; mod render_settings; mod roundtrip; +mod support; mod targa_sequence; mod uncompressed_mov; mod vp9_roundtrip; diff --git a/crates/export/tests/it/roundtrip.rs b/crates/export/tests/it/roundtrip.rs index 224cbfc43..65644f071 100644 --- a/crates/export/tests/it/roundtrip.rs +++ b/crates/export/tests/it/roundtrip.rs @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; +use crate::support::write_tone; use effectcraft_color::Label; use effectcraft_export::render_queue::{AlphaMode, AudioOutput, Channels, OutputFormat, OutputModule, ProResProfile, RenderSettings, TimeSpan, sequence_path}; use effectcraft_export::{Job, Progress, export}; @@ -646,33 +647,6 @@ fn cancel_stops_early() { assert_eq!(written, 0, "cancelled before the first batch"); } -/// 16-bit stereo WAV with a 440 Hz sine at amplitude 0.5 (left) and silence (right). -fn write_tone(path: &Path, secs: f64) { - let sr = 48_000u32; - let n = (secs * sr as f64) as usize; - let mut data = Vec::with_capacity(n * 4); - for i in 0..n { - let s = (0.5 * (2.0 * std::f64::consts::PI * 440.0 * i as f64 / sr as f64).sin() * 32767.0).round() as i16; - data.extend_from_slice(&s.to_le_bytes()); - data.extend_from_slice(&0i16.to_le_bytes()); - } - let mut w = Vec::new(); - w.extend_from_slice(b"RIFF"); - w.extend_from_slice(&(36 + data.len() as u32).to_le_bytes()); - w.extend_from_slice(b"WAVEfmt "); - w.extend_from_slice(&16u32.to_le_bytes()); - w.extend_from_slice(&1u16.to_le_bytes()); - w.extend_from_slice(&2u16.to_le_bytes()); - w.extend_from_slice(&sr.to_le_bytes()); - w.extend_from_slice(&(sr * 4).to_le_bytes()); - w.extend_from_slice(&4u16.to_le_bytes()); - w.extend_from_slice(&16u16.to_le_bytes()); - w.extend_from_slice(b"data"); - w.extend_from_slice(&(data.len() as u32).to_le_bytes()); - w.extend_from_slice(&data); - std::fs::write(path, w).expect("write wav"); -} - fn rms(v: impl Iterator) -> f32 { let (s, n) = v.fold((0.0f64, 0usize), |(s, n), x| (s + (x as f64) * (x as f64), n + 1)); (s / n.max(1) as f64).sqrt() as f32 diff --git a/crates/export/tests/it/support.rs b/crates/export/tests/it/support.rs new file mode 100644 index 000000000..aa5c11098 --- /dev/null +++ b/crates/export/tests/it/support.rs @@ -0,0 +1,30 @@ +//! Helpers shared by the integration test modules. + +use std::path::Path; + +/// 16-bit stereo 48 kHz WAV: a 440 Hz sine at 0.5 on the left, silence on the right. +pub(crate) fn write_tone(path: &Path, secs: f64) { + let sr = 48_000u32; + let n = (secs * sr as f64) as usize; + let mut data = Vec::with_capacity(n * 4); + for i in 0..n { + let s = (0.5 * (2.0 * std::f64::consts::PI * 440.0 * i as f64 / sr as f64).sin() * 32767.0).round() as i16; + data.extend_from_slice(&s.to_le_bytes()); + data.extend_from_slice(&0i16.to_le_bytes()); + } + let mut w = Vec::new(); + w.extend_from_slice(b"RIFF"); + w.extend_from_slice(&(36 + data.len() as u32).to_le_bytes()); + w.extend_from_slice(b"WAVEfmt "); + w.extend_from_slice(&16u32.to_le_bytes()); + w.extend_from_slice(&1u16.to_le_bytes()); + w.extend_from_slice(&2u16.to_le_bytes()); + w.extend_from_slice(&sr.to_le_bytes()); + w.extend_from_slice(&(sr * 4).to_le_bytes()); + w.extend_from_slice(&4u16.to_le_bytes()); + w.extend_from_slice(&16u16.to_le_bytes()); + w.extend_from_slice(b"data"); + w.extend_from_slice(&(data.len() as u32).to_le_bytes()); + w.extend_from_slice(&data); + std::fs::write(path, w).expect("write wav"); +} diff --git a/crates/export/tests/it/uncompressed_mov.rs b/crates/export/tests/it/uncompressed_mov.rs index 200d3116a..1242dbfb4 100644 --- a/crates/export/tests/it/uncompressed_mov.rs +++ b/crates/export/tests/it/uncompressed_mov.rs @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; +use crate::support::write_tone; use craft_media::isobmff::TrackKind; use effectcraft_color::Label; use effectcraft_export::render_queue::{AudioFormat, AudioOutput, Channels, OutputFormat, OutputModule, RenderSettings, TimeSpan, sequence_path}; @@ -28,33 +29,6 @@ fn out_dir(name: &str) -> PathBuf { d } -/// 16-bit stereo 48 kHz WAV: a 440 Hz sine at 0.5 on the left, silence on the right. -fn write_tone(path: &Path, secs: f64) { - let sr = 48_000u32; - let n = (secs * sr as f64) as usize; - let mut data = Vec::with_capacity(n * 4); - for i in 0..n { - let s = (0.5 * (2.0 * std::f64::consts::PI * 440.0 * i as f64 / sr as f64).sin() * 32767.0).round() as i16; - data.extend_from_slice(&s.to_le_bytes()); - data.extend_from_slice(&0i16.to_le_bytes()); - } - let mut w = Vec::new(); - w.extend_from_slice(b"RIFF"); - w.extend_from_slice(&(36 + data.len() as u32).to_le_bytes()); - w.extend_from_slice(b"WAVEfmt "); - w.extend_from_slice(&16u32.to_le_bytes()); - w.extend_from_slice(&1u16.to_le_bytes()); - w.extend_from_slice(&2u16.to_le_bytes()); - w.extend_from_slice(&sr.to_le_bytes()); - w.extend_from_slice(&(sr * 4).to_le_bytes()); - w.extend_from_slice(&4u16.to_le_bytes()); - w.extend_from_slice(&16u16.to_le_bytes()); - w.extend_from_slice(b"data"); - w.extend_from_slice(&(data.len() as u32).to_le_bytes()); - w.extend_from_slice(&data); - std::fs::write(path, w).expect("write wav"); -} - fn project(audio: Option<&Path>) -> (Project, ItemId) { let mut p = Project::default(); let mut comp = Comp::new(W, H, FrameRate::new(10, 1), Tick::from_seconds_f64(FRAMES as f64 / 10.0)); From 9e27d5a0a5e6a87b3a7fef3f1665e21f4268ab17 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:14:28 +0100 Subject: [PATCH 72/99] fix(media): keep every decoded GIF and WebP frame past the probe frame count --- crates/media/src/gif_anim.rs | 34 +++++++++++++++++++++++++++++++++- crates/media/src/webp_anim.rs | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index e2cac5aa8..117f85d9b 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -24,6 +24,10 @@ pub(crate) const MAX_BYTES: usize = 256 << 20; /// Frames read from a GIF's or animated WebP's headers when probing. pub(crate) const MAX_FRAMES: usize = 100_000; +/// Frames kept when decoding a GIF or animated WebP: all of them. Only [`MAX_BYTES`] and the +/// canvas budget bound decoding, as before the shared frame readers; [`MAX_FRAMES`] bounds probing. +pub(crate) const DECODE_FRAMES: usize = usize::MAX; + /// Whether `f` is an animated GIF or WebP imported by [`probe`] or [`crate::webp_anim::probe`]: /// its frames come from an [`Anim`]. pub(crate) fn is_animated(f: &Footage) -> bool { @@ -85,7 +89,7 @@ impl Anim { return crate::webp_anim::load(bytes); } let mut limits = craft_gif::frames::FrameLimits::default(); - limits.max_frames = MAX_FRAMES; + limits.max_frames = DECODE_FRAMES; limits.max_bytes = MAX_BYTES as u64; limits.max_canvas_bytes = MAX_BYTES as u64; limits.max_decode_bytes = Some(MAX_BYTES as u64); @@ -121,6 +125,12 @@ impl Anim { Anim::new(frames, starts).ok_or_else(|| MediaError::Decode("GIF: no frames".into())) } + /// How many frames were decoded. + #[cfg(test)] + pub(crate) fn len(&self) -> usize { + self.frames.len() + } + /// The frame shown at source time `t` (the first one before the start, the last one past the /// end). pub(crate) fn frame_at(&self, t: Tick) -> Option<&DynamicImage> { @@ -322,4 +332,26 @@ mod tests { let e = super::Anim::load(&out).err().unwrap(); assert!(e.to_string().contains("too large"), "{e}"); } + + /// A 1×1 GIF of `n` frames. + fn tiny_gif(n: usize) -> Vec { + let mut out = Vec::new(); + { + let mut enc = gif::Encoder::new(&mut out, 1, 1, &[]).unwrap(); + let frame = gif::Frame::from_rgb(1, 1, &RED); + for _ in 0..n { + enc.write_frame(&frame).unwrap(); + } + } + out + } + + #[test] + fn decoding_keeps_every_frame_past_the_probe_frame_count() { + // 1×1 frames fit the byte budget however many there are: the frame count refuses none. + for n in [MAX_FRAMES, MAX_FRAMES + 1] { + let anim = super::Anim::load(&tiny_gif(n)).unwrap(); + assert_eq!(anim.len(), n); + } + } } diff --git a/crates/media/src/webp_anim.rs b/crates/media/src/webp_anim.rs index dbe664fac..bb2fdcc69 100644 --- a/crates/media/src/webp_anim.rs +++ b/crates/media/src/webp_anim.rs @@ -13,7 +13,7 @@ use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; use image::DynamicImage; -use crate::gif_anim::{Anim, MAX_BYTES, MAX_FRAMES, gcd}; +use crate::gif_anim::{Anim, DECODE_FRAMES, MAX_BYTES, MAX_FRAMES, gcd}; use crate::{MediaError, Result}; /// The `Footage::codec` of an animated WebP. @@ -120,7 +120,7 @@ pub(crate) fn load(bytes: &[u8]) -> Result { return Err(MediaError::Unsupported(format!("animated WebP of {} frames of {}×{} is too large to hold in memory", h.delays.len(), h.width, h.height))); } let mut limits = craft_webp::frames::FrameLimits::default(); - limits.max_frames = MAX_FRAMES; + limits.max_frames = DECODE_FRAMES; limits.max_bytes = MAX_BYTES as u64; limits.max_canvas_bytes = MAX_BYTES as u64; let decoded = craft_webp::frames::read_frames(bytes, &limits).map_err(|e| match e { @@ -381,4 +381,34 @@ mod tests { bytes[4..8].copy_from_slice(&riff.to_le_bytes()); assert!(super::load(&bytes).is_err()); } + + /// A 1×1 animated WebP of `n` identical frames. + fn tiny_webp(n: usize) -> Vec { + let mut anmf = vec![0; 6]; + anmf.extend_from_slice(&u24(0)); + anmf.extend_from_slice(&u24(0)); + anmf.extend_from_slice(&u24(50)); + anmf.push(0b10); + anmf.extend(vp8l(1, 1, RED)); + let frame = chunk(b"ANMF", &anmf); + let mut vp8x = vec![0x12, 0, 0, 0]; + vp8x.extend_from_slice(&u24(0)); + vp8x.extend_from_slice(&u24(0)); + let mut body = b"WEBP".to_vec(); + body.extend(chunk(b"VP8X", &vp8x)); + body.extend(chunk(b"ANIM", &[0; 6])); + for _ in 0..n { + body.extend_from_slice(&frame); + } + chunk(b"RIFF", &body) + } + + #[test] + fn decoding_keeps_every_frame_past_the_probe_frame_count() { + // 1×1 frames fit the byte budget however many there are: the frame count refuses none. + for n in [crate::gif_anim::MAX_FRAMES, crate::gif_anim::MAX_FRAMES + 1] { + let anim = super::load(&tiny_webp(n)).unwrap(); + assert_eq!(anim.len(), n); + } + } } From 3f27fbe21746992c6d09d59c4d26e1012f7b94cb Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:18:04 +0100 Subject: [PATCH 73/99] test(pdf): check the PDFDocEncoding ActualText label end to end --- crates/pdf/src/tests.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index 9c606a611..c1f519595 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -98,6 +98,13 @@ fn pdf_actual_text_is_exposed_as_a_logical_group() { assert_eq!(shape_names(&doc), vec!["Text: Logical text"]); } +#[test] +fn pdf_actual_text_without_a_bom_is_pdfdocencoding_in_the_label() { + // 0x80 is a bullet in PDFDocEncoding, 0x92 a trade mark sign, not C1 control characters. + let data = page_pdf("/Span << /ActualText <80204192> >> BDC 1 0 0 rg 10 10 20 20 re f EMC", "", vec![]); + assert_eq!(shape_names(&parse(&data).unwrap()), vec!["Text: \u{2022} A\u{2122}"]); +} + #[test] fn pdf_forms_rotation_cmyk_and_alpha() { let content = "q 2 0 0 2 0 0 cm /Fm0 Do Q\n/GS0 gs 0 0 0 1 k 0 0 10 10 re f\n"; From da6e5b874c231f74e458378ebbb8cf802dee8b1f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:45:16 +0100 Subject: [PATCH 74/99] fix(media): refuse an oversized GIF canvas before scanning its frames --- crates/media/src/gif_anim.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index 117f85d9b..dc5f55e27 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -88,6 +88,14 @@ impl Anim { if crate::webp_anim::is_webp(bytes) { return crate::webp_anim::load(bytes); } + // The frame reader scans every image descriptor before it checks the canvas: refuse a + // logical screen too large to hold first, as the former decoder did. + if let Some(&[w0, w1, h0, h1]) = bytes.get(6..10).filter(|_| bytes.starts_with(b"GIF8")) { + let (w, h) = (u16::from_le_bytes([w0, w1]), u16::from_le_bytes([h0, h1])); + if u64::from(w) * u64::from(h) * 4 > MAX_BYTES as u64 { + return Err(MediaError::Unsupported(format!("GIF canvas of {w}×{h} is too large to hold in memory"))); + } + } let mut limits = craft_gif::frames::FrameLimits::default(); limits.max_frames = DECODE_FRAMES; limits.max_bytes = MAX_BYTES as u64; @@ -330,7 +338,7 @@ mod tests { } } let e = super::Anim::load(&out).err().unwrap(); - assert!(e.to_string().contains("too large"), "{e}"); + assert!(e.to_string().contains("GIF canvas of 65535×65535 is too large"), "{e}"); } /// A 1×1 GIF of `n` frames. From 3570d59d437f75abea6bc60259ed31e2f4cd84a6 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:18:56 +0100 Subject: [PATCH 75/99] media, export: read MPEG TS AAC config and check encoders with craft-libs, drop four filmcraft pins crates/media reads the MPEG TS/PS stream FilmCraft's source plays with craft_media::mpegts and LATM configuration with craft_audio::aac::latm_config. The VP9, HEVC and AV1 encoder round-trip tests decode with craft-video's decoders. filmcraft-mpegts, filmcraft-vp9, filmcraft-hevc and filmcraft-av1 are no longer direct dependencies (storytold/craft-libs#781). --- Cargo.lock | 4 --- Cargo.toml | 8 ------ crates/export/Cargo.toml | 5 ++-- crates/export/tests/it/av1_encoder/common.rs | 4 +-- crates/export/tests/it/av1_encoder/mod.rs | 2 +- crates/export/tests/it/hevc_encoder.rs | 26 ++++++++++---------- crates/export/tests/it/vp9_roundtrip.rs | 8 +++--- crates/media/Cargo.toml | 5 ++-- crates/media/src/aac.rs | 19 ++++---------- 9 files changed, 29 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b012bda16..bb1d89cf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1875,9 +1875,6 @@ dependencies = [ "effectcraft-render", "effectcraft-time", "exr", - "filmcraft-av1", - "filmcraft-hevc", - "filmcraft-vp9", "gif", "image", "log", @@ -2050,7 +2047,6 @@ dependencies = [ "filmcraft-color", "filmcraft-frame", "filmcraft-media", - "filmcraft-mpegts", "filmcraft-time", "gif", "image", diff --git a/Cargo.toml b/Cargo.toml index af6b39861..21f47439c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,13 +103,6 @@ filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "d5ead filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -# MPEG TS / PS headers read for AAC channel layouts (crates/media); craft-media has no MPEG TS reader -filmcraft-mpegts = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -# decoders used as the round-trip oracles of craft-video's VP9, HEVC and AV1 encoders (crates/export -# dev-dependencies only); craft-video has no decoder for them -filmcraft-vp9 = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-hevc = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-av1 = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } # timeline interchange (EDL, FCP7 XML, FCPXML, OTIO) for Premiere Pro interop (crates/interchange only) filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } @@ -144,7 +137,6 @@ sys-locale = "0.3" # filmcraft-frame = { path = "../filmcraft/crates/frame" } # filmcraft-color = { path = "../filmcraft/crates/color" } # filmcraft-time = { path = "../filmcraft/crates/time" } -# filmcraft-mpegts = { path = "../filmcraft/crates/mpegts" } [workspace.lints.rust] unsafe_code = "forbid" diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index c84efc6ee..1bf883df3 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -31,7 +31,6 @@ tempfile = { workspace = true } effectcraft-media = { workspace = true } effectcraft-effects = { workspace = true } effectcraft-color = { workspace = true } -filmcraft-hevc = { workspace = true } -filmcraft-av1 = { workspace = true } -filmcraft-vp9 = { workspace = true } +# The decoders that check the VP9, HEVC and AV1 encoders round-trip (av1 is already on). +craft-video = { workspace = true, features = ["vp9-decode", "hevc-decode"] } effectcraft-keyframe = { workspace = true } diff --git a/crates/export/tests/it/av1_encoder/common.rs b/crates/export/tests/it/av1_encoder/common.rs index 3cd42a584..7e78adda6 100644 --- a/crates/export/tests/it/av1_encoder/common.rs +++ b/crates/export/tests/it/av1_encoder/common.rs @@ -86,13 +86,13 @@ pub struct Run { pub lf_levels: Vec, } -/// Encodes `pics`, checks every packet decodes (filmcraft-av1) to exactly the encoder's +/// Encodes `pics`, checks every packet decodes (craft-video's AV1 decoder) to exactly the encoder's /// reconstruction and returns packets, reconstructions and luma PSNRs. pub fn encode_and_check(cfg: EncoderConfig, pics: &[Pic]) -> Run { let bd = cfg.bit_depth as u32; let mut enc = Encoder::new(cfg).expect("config"); // single-threaded: each packet's picture comes out of its own decode call - let mut dec = filmcraft_av1::Decoder::with_threads(1); + let mut dec = craft_video::av1::decode::Decoder::with_threads(1); let mut run = Run { packets: Vec::new(), recons: Vec::new(), psnr_y: Vec::new(), lf_levels: Vec::new() }; for (i, p) in pics.iter().enumerate() { let pkt = enc.encode(&p.frame()).expect("encode"); diff --git a/crates/export/tests/it/av1_encoder/mod.rs b/crates/export/tests/it/av1_encoder/mod.rs index d33ea0c55..be7476d43 100644 --- a/crates/export/tests/it/av1_encoder/mod.rs +++ b/crates/export/tests/it/av1_encoder/mod.rs @@ -1,4 +1,4 @@ -//! craft-video's AV1 encoder against the filmcraft-av1 decoder and ffmpeg's libdav1d. +//! craft-video's AV1 encoder against craft-video's AV1 decoder and ffmpeg's libdav1d. mod bench; mod common; diff --git a/crates/export/tests/it/hevc_encoder.rs b/crates/export/tests/it/hevc_encoder.rs index c19ff9cbd..383183ec0 100644 --- a/crates/export/tests/it/hevc_encoder.rs +++ b/crates/export/tests/it/hevc_encoder.rs @@ -1,4 +1,4 @@ -//! Round trips through the filmcraft-hevc decoder and (when installed) ffmpeg: decoded pictures must +//! Round trips through the craft-video HEVC decoder and (when installed) ffmpeg: decoded pictures must //! equal the encoder's own reconstruction bit-exactly. use craft_video::hevc::{Encoder, EncoderConfig, Frame, Profile, RateControl}; @@ -84,9 +84,9 @@ fn encode(cfg: EncoderConfig, pics: &[Pic]) -> Run { run } -/// Decode with filmcraft-hevc and compare with the reconstructions. -fn check_filmcraft(run: &Run, w: usize, h: usize) { - let mut dec = filmcraft_hevc::Decoder::from_hvcc(&run.hvcc).unwrap(); +/// Decode with craft-video's HEVC decoder and compare with the reconstructions. +fn check_decoder(run: &Run, w: usize, h: usize) { + let mut dec = craft_video::hevc::decode::Decoder::from_hvcc(&run.hvcc).unwrap(); let mut pics = Vec::new(); for (i, p) in run.packets.iter().enumerate() { pics.extend(dec.decode(p, i as i64).unwrap()); @@ -211,7 +211,7 @@ fn intra_8bit_quality_and_decoders() { let run = encode(cfg(w as u32, h as u32, 22, 1, Profile::Main), &pics); eprintln!("intra QP22: {} bytes, PSNR-Y {:.2}", run.packets[0].len(), run.psnr_y[0]); assert!(run.psnr_y[0] > 35.0, "PSNR {}", run.psnr_y[0]); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, "intra8"); } @@ -267,7 +267,7 @@ fn inter_8bit_moving_pattern() { let p_avg = sizes[1..].iter().sum::() as f64 / 5.0; assert!(p_avg < sizes[0] as f64 * 0.6, "P frames {p_avg} vs I {}", sizes[0]); assert!(run.psnr_y.iter().all(|&p| p > 33.0)); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, "inter8"); } @@ -276,7 +276,7 @@ fn odd_multiple_sizes_and_cropping() { for (w, h) in [(34usize, 18usize), (66, 38), (8, 8), (130, 72), (2, 2), (2, 70), (264, 6)] { let pics: Vec = (0..3).map(|i| synth(w, h, 8, i, 2 * i)).collect(); let run = encode(cfg(w as u32, h as u32, 30, 2, Profile::Main), &pics); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, &format!("size{w}x{h}")); } } @@ -305,7 +305,7 @@ fn noise_low_qp() { .collect(); let run = encode(cfg(w as u32, h as u32, 0, 2, profile), &pics); assert!(run.psnr_y.iter().all(|&p| p > 45.0), "{:?}", run.psnr_y); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, bd, &format!("noise{bd}")); } } @@ -317,7 +317,7 @@ fn high_qp_deblocking() { for (qp, profile, bd) in [(38u8, Profile::Main, 8u32), (44, Profile::Main, 8), (37, Profile::Main10, 10)] { let pics: Vec = (0..5).map(|i| synth(w, h, bd, 2 * i, i)).collect(); let run = encode(cfg(w as u32, h as u32, qp, 4, profile), &pics); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, bd, &format!("hq{qp}")); } } @@ -329,7 +329,7 @@ fn long_gop_poc_wrap() { let pics: Vec = (0..300).map(|i| synth(w, h, 8, i % 7, i % 5)).collect(); let run = encode(cfg(w as u32, h as u32, 30, 0, Profile::Main), &pics); assert_eq!(run.keys.iter().filter(|&&k| k).count(), 1); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, "pocwrap"); let run = encode(cfg(w as u32, h as u32, 30, 260, Profile::Main), &pics); assert_eq!(run.keys.iter().filter(|&&k| k).count(), 2); @@ -348,7 +348,7 @@ fn main10_round_trip() { let run = encode(cfg(w as u32, h as u32, 24, 3, Profile::Main10), &pics); eprintln!("main10 psnr {:?}", run.psnr_y); assert!(run.psnr_y[0] > 35.0); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 10, "main10"); } @@ -358,7 +358,7 @@ fn qp_extremes() { for qp in [0u8, 51] { let pics: Vec = (0..2).map(|i| synth(w, h, 8, i, i)).collect(); let run = encode(cfg(w as u32, h as u32, qp, 30, Profile::Main), &pics); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, &format!("qp{qp}")); } } @@ -375,7 +375,7 @@ fn bitrate_mode_hits_target() { let kbps = bits as f64 / (pics.len() as f64 / 30.0) / 1000.0; eprintln!("bitrate mode: {kbps:.1} kbit/s for a 400 kbit/s target"); assert!(kbps > 400.0 / 2.0 && kbps < 400.0 * 2.0, "{kbps}"); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); } #[test] diff --git a/crates/export/tests/it/vp9_roundtrip.rs b/crates/export/tests/it/vp9_roundtrip.rs index f9d36770d..cb6fbfa0c 100644 --- a/crates/export/tests/it/vp9_roundtrip.rs +++ b/crates/export/tests/it/vp9_roundtrip.rs @@ -1,8 +1,8 @@ -//! The VP9 intra encoder (`craft_video::vp9`) round-trips through FilmCraft's VP9 decoder (and +//! The VP9 intra encoder (`craft_video::vp9`) round-trips through craft-video's VP9 decoder (and //! ffmpeg as an external oracle when installed): sizes, lossless exactness, PSNR. +use craft_video::vp9::decode::{Decoder, Picture, Plane}; use craft_video::vp9::{EncoderConfig, Vp9Encoder}; -use filmcraft_vp9::{Decoder, Plane}; fn plane_u8(p: &Plane) -> Vec { match p { @@ -40,7 +40,7 @@ fn source(w: usize, h: usize, kind: u32) -> (Vec, Vec, Vec) { (y, u, v) } -fn decode(frame: &[u8]) -> filmcraft_vp9::Picture { +fn decode(frame: &[u8]) -> Picture { let mut d = Decoder::with_threads(1); let mut pics = d.decode(frame, 0).expect("decode"); assert_eq!(pics.len(), 1); @@ -179,7 +179,7 @@ fn moving(w: usize, h: usize, t: usize, kind: u32) -> (Vec, Vec, Vec (y, u, v) } -fn planes_of(p: &filmcraft_vp9::Picture, w: usize, h: usize) -> [Vec; 3] { +fn planes_of(p: &Picture, w: usize, h: usize) -> [Vec; 3] { let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); [crop(&plane_u8(&p.y), p.y_stride, w, h), crop(&plane_u8(&p.u), p.uv_stride, cw, ch), crop(&plane_u8(&p.v), p.uv_stride, cw, ch)] } diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index c236cf294..ff98229cb 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -26,9 +26,8 @@ craft-dpx = { workspace = true } craft-exr = { workspace = true, features = ["decode"] } craft-gif = { workspace = true, features = ["frames"] } craft-webp = { workspace = true, features = ["frames"] } -craft-audio = { workspace = true } -craft-media = { workspace = true } -filmcraft-mpegts = { workspace = true } +craft-audio = { workspace = true, features = ["aac-decode"] } +craft-media = { workspace = true, features = ["mpegts"] } filmcraft-frame = { workspace = true } filmcraft-color = { workspace = true } filmcraft-time = { workspace = true } diff --git a/crates/media/src/aac.rs b/crates/media/src/aac.rs index a1793b7af..356a8dff5 100644 --- a/crates/media/src/aac.rs +++ b/crates/media/src/aac.rs @@ -62,15 +62,15 @@ fn matroska(file: &dyn ByteReader) -> Option> { /// first unit it can read. Only AAC is asked about, so the streams before that one were refused /// whatever their codec, and an ADTS stream played has no configuration outside its frames. fn latm(file: &dyn ByteReader) -> Option> { - use filmcraft_mpegts::Codec; + use craft_media::mpegts::{self, Codec}; let head = Head(file, file.len().min(MPEG_HEAD)); - let mpeg = filmcraft_mpegts::open(&head).ok()?; - let audio = mpeg.streams.iter().enumerate().filter(|(_, s)| s.kind() == filmcraft_mpegts::Kind::Audio && !s.units.is_empty()); + let mpeg = mpegts::open(&head).ok()?; + let audio = mpeg.streams.iter().enumerate().filter(|(_, s)| s.kind() == mpegts::Kind::Audio && !s.units.is_empty()); let played = audio.take(filmcraft_media::MAX_AUDIO_STREAMS).find_map(|(i, s)| { let first = mpeg.read_unit(&head, i, 0).ok()?; match s.codec { - Codec::AacAdts => filmcraft_mpegts::frame_info(&s.codec, &first).map(|_| None), - Codec::AacLatm => filmcraft_codecs::audio::latm_config(&first).map(|c| Some(c.asc)), + Codec::AacAdts => mpegts::frame_info(&s.codec, &first).map(|_| None), + Codec::AacLatm => craft_audio::aac::latm_config(&first).map(|c| Some(c.asc)), _ => None, } }); @@ -97,12 +97,3 @@ impl craft_media::ByteSource for Head<'_> { self.read(offset, buf) } } - -impl filmcraft_mpegts::ByteSource for Head<'_> { - fn len(&self) -> u64 { - self.1 - } - fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> { - self.read(offset, buf) - } -} From 1cc80e7443c6d11b42ff2b0f46d9f800db1ada0f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:33:33 +0100 Subject: [PATCH 76/99] psd: read the document structure with craft_psd Psd::parse reads the header, colour mode data, layer records with their additional information and the global blocks with craft_psd::PsdFile::from_source. Channel data and the merged image stay in the document as ranges, and the linked-file blocks are left in the source. A damaged layer section still opens as the merged image. The local 8BPS section, record and block walkers are removed (storytold/craft-libs#786). --- crates/psd/Cargo.toml | 3 + crates/psd/src/lib.rs | 4 +- crates/psd/src/parse.rs | 291 ++++++++++---------------- crates/psd/src/read.rs | 2 +- crates/psd/src/tests.rs | 1 + crates/psd/src/tests/shared_corpus.rs | 61 ++++++ 6 files changed, 174 insertions(+), 188 deletions(-) create mode 100644 crates/psd/src/tests/shared_corpus.rs diff --git a/crates/psd/Cargo.toml b/crates/psd/Cargo.toml index 46ad240d7..818331cce 100644 --- a/crates/psd/Cargo.toml +++ b/crates/psd/Cargo.toml @@ -12,3 +12,6 @@ workspace = true [dependencies] craft-psd = { workspace = true } miniz_oxide = "0.9" + +[dev-dependencies] +craft-psd = { workspace = true, features = ["testgen"] } diff --git a/crates/psd/src/lib.rs b/crates/psd/src/lib.rs index 91792a837..b476a5e2d 100644 --- a/crates/psd/src/lib.rs +++ b/crates/psd/src/lib.rs @@ -1,8 +1,8 @@ //! Photoshop document (PSD / PSB) reader, implemented from Adobe's public *Photoshop File Formats //! Specification* (see README.md), and a minimal writer ([`mod@write`]) for fixtures. //! -//! [`Psd::parse`] reads the structure (header, layer records and their additional information, -//! the layer tree) without decoding pixels; [`Psd::composite`] decodes the merged image and +//! [`Psd::parse`] reads the structure with `craft_psd` (header, layer records and their +//! additional information, the layer tree) without decoding pixels; [`Psd::composite`] decodes the merged image and //! [`Psd::layer_pixels`] one layer (with its layer mask applied to alpha) on demand. Pixels come //! out as straight (unpremultiplied) RGBA `f32` in 0..1, display-encoded (32-bit documents, //! which are linear, are encoded to sRGB). diff --git a/crates/psd/src/parse.rs b/crates/psd/src/parse.rs index 6357b0024..6ed618a47 100644 --- a/crates/psd/src/parse.rs +++ b/crates/psd/src/parse.rs @@ -11,102 +11,106 @@ pub fn is_psd(bytes: &[u8]) -> bool { } impl Psd { + /// Reads the structure with [`craft_psd::PsdFile::from_source`]: header, colour mode data, + /// layer records with their additional information and the global blocks. Channel data and + /// the merged image stay in `data` (as ranges), decoded on demand. pub fn parse(data: impl Into>) -> Result { let data: Arc<[u8]> = data.into(); - let mut r = Reader::new(&data); - if r.bytes(4).ok() != Some(b"8BPS") { + if !is_psd(&data) { return Err(Error::NotPsd); } - let version = r.u16()?; - let psb = match version { - 1 => false, - 2 => true, - _ => return Err(Error::NotPsd), + let source = craft_psd::source::Source::new(data.clone()); + // Linked-file blocks can be most of a file: leave them in the source, read in place. + let linked = |key: &[u8; 4], _len: u64| matches!(key, b"lnk2" | b"lnkD" | b"lnk3" | b"lnkE"); + let (head, file, warnings) = match craft_psd::PsdFile::from_source_deferring(source, linked, |_| Ok(false), |_| false) { + Ok((file, _)) => { + // The compression field before the merged image's data. + let merged = file.image_data.stored.as_ref().map_or(data.len(), |s| (s.offset as usize).saturating_sub(2)); + ((file.header.clone(), file.color_mode_data.clone(), merged), Some(file), vec![]) + } + // A damaged layer section must not discard the document: keep the header and the + // merged image, drop the layers and say so. Without a merged image there is nothing to + // fall back to, so the original error stands. + Err(e) => match flattened(&data) { + Some(head) => (head, None, vec![format!("Layers could not be read ({}); only the flattened image is available", error(&e))]), + None => return Err(error(&e)), + }, }; - r.skip(6)?; - let channels = r.u16()?; - let height = r.u32()?; - let width = r.u32()?; - let depth = r.u16()?; - let mode_v = r.u16()?; + let (h, palette, merged_offset) = head; + let mode_v = h.color_mode.as_u16(); let mode = ColorMode::from_u16(mode_v).ok_or_else(|| Error::Unsupported(format!("colour mode {mode_v}")))?; - if !matches!(depth, 1 | 8 | 16 | 32) { - return Err(Error::Unsupported(format!("{depth}-bit"))); + if !matches!(h.depth, 1 | 8 | 16 | 32) { + return Err(Error::Unsupported(format!("{}-bit", h.depth))); } - if width == 0 || height == 0 || width > 300_000 || height > 300_000 { - return Err(Error::Invalid(format!("size {width}x{height}"))); + if h.width == 0 || h.height == 0 || h.width > 300_000 || h.height > 300_000 { + return Err(Error::Invalid(format!("size {}x{}", h.width, h.height))); } - // Colour mode data. - let n = r.u32()? as usize; - let palette = r.bytes(n)?.to_vec(); - // Image resources. - let n = r.u32()? as usize; - r.skip(n)?; - // Layer and mask information. let mut psd = Psd { - psb, - width, - height, - channels, - depth, + psb: h.version.is_psb(), + width: h.width, + height: h.height, + channels: h.channels, + depth: h.depth, mode, layers: vec![], merged_alpha: false, palette, linked: vec![], - warnings: vec![], + warnings, data: data.clone(), - merged_offset: 0, + merged_offset, }; - let lm_len = r.length(psb)?; - let lm_end = r.pos.checked_add(lm_len).filter(|&e| e <= data.len()).ok_or(Error::Truncated)?; - if lm_len > 0 { - let li_len = r.length(psb)?; - let li_end = r.pos.checked_add(li_len).filter(|&e| e <= lm_end).ok_or(Error::Truncated)?; - if li_len > 0 - && let Err(e) = psd.layer_info(&data, r.pos, li_end) - { - // A damaged layer section must not discard the document: keep the header and the - // merged image, drop the layers and say so. Without a merged image there is - // nothing to fall back to, so the original error stands. - if lm_end.checked_add(2).is_none_or(|n| n > data.len()) { - return Err(e); - } - psd.layers.clear(); - psd.warnings.push(format!("Layers could not be read ({e}); only the flattened image is available")); - } - r.pos = li_end; - if r.pos + 4 <= lm_end { - let g = r.u32()? as usize; - r.pos = (r.pos + g).min(lm_end); - } - // Global additional layer information (16/32-bit layer info lives here). - while let Some((key, start, end)) = next_block(&data, &mut r.pos, lm_end, psb) { - if matches!(&key, b"lnk2" | b"lnkD" | b"lnk3" | b"lnkE") { - psd.linked_files(&data, start, end); - } - if matches!(&key, b"Lr16" | b"Lr32" | b"Layr") && psd.layers.is_empty() && end > start { - // The block holds the layer info, normally without its length field; accept - // both layouts. - if psd.layer_info(&data, start, end).is_err() || psd.layers.is_empty() { - psd.layers.clear(); - let skip = if psb { 8 } else { 4 }; - if start + skip < end && psd.layer_info(&data, start + skip, end).is_err() { - psd.layers.clear(); - } - } - } - r.pos = end; + let Some(file) = file else { return Ok(psd) }; + if let Some(info) = &file.layer_info { + psd.merged_alpha = info.merged_alpha; + psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i)).collect(); + } + for b in &file.global_blocks { + if let Some(stored) = b.stored.as_ref().filter(|_| linked(&b.key, 0)) { + let start = stored.offset as usize; + psd.linked_files(&data, start, start.saturating_add(stored.len as usize).min(data.len())); } } - if !psd.layers.is_empty() { - // A 16/32-bit layer block recovered the layers. - psd.warnings.clear(); - } - psd.merged_offset = lm_end; Ok(psd) } + /// One layer record of the model, its additional information read into [`Layer`]. + fn layer(&self, rec: &craft_psd::LayerRecord, index: usize) -> Layer { + let channels = rec + .channels + .iter() + .map(|c| match &c.stored { + // `ChannelInfo` covers the compression field and the data after it. + Some(s) => ChannelInfo { id: c.id, offset: (s.offset as usize).saturating_sub(2), len: s.len as usize + 2 }, + None => ChannelInfo { id: c.id, offset: 0, len: 0 }, + }) + .collect(); + let r = rec.rect; + let mut l = Layer { + index, + rect: Rect { top: r.top, left: r.left, bottom: r.bottom, right: r.right }, + blend: rec.blend_mode.key(), + opacity: rec.opacity, + fill_opacity: 255, + clipping: rec.clipping != 0, + hidden: rec.flags.hidden(), + protect_transparency: rec.flags.transparency_protected(), + channels, + name: mac_roman_string(&rec.name), + ..Default::default() + }; + if let craft_psd::MaskData::Mask(m) = &rec.mask { + let rect = Rect { top: m.rect.top, left: m.rect.left, bottom: m.rect.bottom, right: m.rect.right }; + l.mask = Some(LayerMask { rect, default_color: m.default_color, disabled: m.flags & 2 != 0, inverted: m.flags & 4 != 0 }); + } + for b in &rec.blocks { + l.keys.push(b.key); + // A malformed block only loses that block's information. + let _ = self.layer_block(&mut l, &b.key, &b.data); + } + l + } + /// The embedded bytes of linked file `uuid`. pub fn linked_data(&self, uuid: &str) -> Option<&[u8]> { let f = self.linked.iter().find(|f| f.uuid == uuid)?; @@ -168,88 +172,6 @@ impl Psd { } } - fn layer_info(&mut self, data: &[u8], start: usize, end: usize) -> Result<()> { - let mut r = Reader::at(&data[..end], start); - let count = r.i16()?; - self.merged_alpha = count < 0; - let n = count.unsigned_abs() as usize; - let mut layers = Vec::with_capacity(n); - for i in 0..n { - layers.push(self.layer_record(&mut r, i)?); - } - // Channel image data follows in record order. - for l in &mut layers { - for c in &mut l.channels { - c.offset = r.pos; - r.skip(c.len)?; - } - } - self.layers = layers; - Ok(()) - } - - fn layer_record(&self, r: &mut Reader, index: usize) -> Result { - let psb = self.psb; - let (top, left, bottom, right) = (r.i32()?, r.i32()?, r.i32()?, r.i32()?); - let nch = r.u16()? as usize; - if nch > 64 { - return Err(Error::Invalid("channel count".into())); - } - let mut channels = Vec::with_capacity(nch); - for _ in 0..nch { - let id = r.i16()?; - let len = r.length(psb)?; - channels.push(ChannelInfo { id, offset: 0, len }); - } - if r.bytes(4)? != b"8BIM" { - return Err(Error::Invalid("layer record signature".into())); - } - let blend = r.tag()?; - let opacity = r.u8()?; - let clipping = r.u8()? != 0; - let flags = r.u8()?; - r.skip(1)?; - let extra = r.u32()? as usize; - let extra_end = r.pos.checked_add(extra).filter(|&e| e <= r.data.len()).ok_or(Error::Truncated)?; - let mut l = Layer { - index, - rect: Rect { top, left, bottom, right }, - blend, - opacity, - fill_opacity: 255, - clipping, - hidden: flags & 2 != 0, - protect_transparency: flags & 1 != 0, - channels, - ..Default::default() - }; - // Layer mask data. - let mlen = r.u32()? as usize; - let mstart = r.pos; - if mlen >= 18 { - let rect = Rect { top: r.i32()?, left: r.i32()?, bottom: r.i32()?, right: r.i32()? }; - let default_color = r.u8()?; - let mflags = r.u8()?; - l.mask = Some(LayerMask { rect, default_color, disabled: mflags & 2 != 0, inverted: mflags & 4 != 0 }); - } - r.pos = mstart + mlen; - // Blending ranges. - let blen = r.u32()? as usize; - r.skip(blen)?; - l.name = r.pascal(4)?; - let mut pos = r.pos; - let data = r.data; - while let Some((key, start, end)) = next_block(data, &mut pos, extra_end, psb) { - l.keys.push(key); - let block = &data[start..end]; - // A malformed block only loses that block's information. - let _ = self.layer_block(&mut l, &key, block); - pos = end; - } - r.pos = extra_end; - Ok(l) - } - fn layer_block(&self, l: &mut Layer, key: &[u8; 4], b: &[u8]) -> Result<()> { let mut r = Reader::new(b); match key { @@ -482,33 +404,32 @@ impl Psd { } } -/// The next additional-information block at `*pos` (signature `8BIM`/`8B64`, key, length): -/// returns (key, data start, data end). Skips up to 3 padding bytes before a signature. -fn next_block(data: &[u8], pos: &mut usize, end: usize, psb: bool) -> Option<([u8; 4], usize, usize)> { - let mut p = *pos; - for _ in 0..4 { - if p + 12 > end { - return None; - } - if &data[p..p + 4] == b"8BIM" || &data[p..p + 4] == b"8B64" { - break; - } - p += 1; +/// The header, colour mode data and merged image offset of a document whose layer and mask +/// section cannot be read: `None` when the merged image cannot be reached either. +fn flattened(data: &[u8]) -> Option<(craft_psd::Header, Vec, usize)> { + let head = craft_psd::head::HeadView::from_bytes(data).ok()?; + let at = usize::try_from(head.layer_section_offset).ok()?; + let len = if head.header.version.is_psb() { + u64::from_be_bytes(data.get(at..at + 8)?.try_into().ok()?) + } else { + u64::from(u32::from_be_bytes(data.get(at..at + 4)?.try_into().ok()?)) + }; + let field = if head.header.version.is_psb() { 8 } else { 4 }; + let merged = at.checked_add(field)?.checked_add(usize::try_from(len).ok()?)?; + (merged.checked_add(2)? <= data.len()).then(|| (head.header.clone(), head.color_mode_data.to_vec(), merged)) +} + +/// This crate's error for one from craft-psd. +fn error(e: &craft_psd::PsdError) -> Error { + match e { + craft_psd::PsdError::UnexpectedEof { .. } => Error::Truncated, + craft_psd::PsdError::InvalidSignature { .. } | craft_psd::PsdError::UnsupportedVersion(_) => Error::NotPsd, + craft_psd::PsdError::Unsupported(s) => Error::Unsupported(s.clone()), + other => Error::Invalid(other.to_string()), } - if p + 12 > end || !(&data[p..p + 4] == b"8BIM" || &data[p..p + 4] == b"8B64") { - return None; - } - let mut key = [0u8; 4]; - key.copy_from_slice(&data[p + 4..p + 8]); - let wide = - psb && matches!(&key, b"LMsk" | b"Lr16" | b"Lr32" | b"Layr" | b"Mt16" | b"Mt32" | b"Mtrn" | b"Alph" | b"FMsk" | b"lnk2" | b"FEid" | b"FXid" | b"PxSD"); - let mut r = Reader::at(&data[..end], p + 8); - let len = r.length(wide).ok()?; - let start = r.pos; - let stop = start.checked_add(len)?; - if stop > end { - return None; - } - *pos = stop; - Some((key, start, stop)) +} + +/// A Pascal string's bytes in the system (Mac Roman) encoding; ASCII covers the common case. +fn mac_roman_string(b: &[u8]) -> String { + b.iter().map(|&b| if b < 0x80 { b as char } else { super::read::mac_roman(b) }).collect() } diff --git a/crates/psd/src/read.rs b/crates/psd/src/read.rs index 9df7d8b63..307998066 100644 --- a/crates/psd/src/read.rs +++ b/crates/psd/src/read.rs @@ -85,7 +85,7 @@ impl<'a> Reader<'a> { } /// Mac OS Roman upper half (0x80..=0xFF), as published by the Unicode Consortium mapping table. -fn mac_roman(b: u8) -> char { +pub(crate) fn mac_roman(b: u8) -> char { const T: &str = "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔ\u{F8FF}ÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ"; T.chars().nth((b - 0x80) as usize).unwrap_or('?') } diff --git a/crates/psd/src/tests.rs b/crates/psd/src/tests.rs index fd041138a..22c575154 100644 --- a/crates/psd/src/tests.rs +++ b/crates/psd/src/tests.rs @@ -3,6 +3,7 @@ use super::*; mod integration; mod opt; +mod shared_corpus; fn gradient(w: u32, h: u32) -> Vec<[f32; 4]> { (0..w * h).map(|i| [(i % w) as f32 / (w - 1).max(1) as f32, (i / w) as f32 / (h - 1).max(1) as f32, 0.25, 1.0]).collect() diff --git a/crates/psd/src/tests/shared_corpus.rs b/crates/psd/src/tests/shared_corpus.rs new file mode 100644 index 000000000..c6a6814d5 --- /dev/null +++ b/crates/psd/src/tests/shared_corpus.rs @@ -0,0 +1,61 @@ +//! The reader over craft-psd's generated corpus (every colour mode, depth, compression and PSB): +//! the model matches the shared reader's records and its channel ranges hold the stored bytes. + +use crate::*; + +#[test] +fn every_generated_case_reads_like_craft_psd() { + let mut decoded = 0; + for (i, case) in craft_psd::testgen::all_cases().into_iter().enumerate() { + let bytes = case.file.to_bytes().expect("write"); + let shared = craft_psd::PsdFile::from_bytes(&bytes).expect("shared parse"); + let p = match Psd::parse(bytes.clone()) { + Ok(p) => p, + // Modes this reader does not show are refused cleanly, never half-read. + Err(Error::Unsupported(_)) => continue, + Err(e) => panic!("case {i}: {e}"), + }; + assert_eq!( + (p.width, p.height, p.depth, p.psb), + (shared.header.width, shared.header.height, shared.header.depth, shared.header.version.is_psb()), + "case {i}" + ); + let records = shared.layer_info.as_ref().map_or(&[][..], |l| &l.layers[..]); + assert_eq!(p.layers.len(), records.len(), "case {i}"); + for (l, rec) in p.layers.iter().zip(records) { + assert_eq!(l.blend, rec.blend_mode.key(), "case {i}"); + assert_eq!(l.channels.len(), rec.channels.len(), "case {i}"); + for (c, rc) in l.channels.iter().zip(&rec.channels) { + assert_eq!(c.id, rc.id, "case {i}"); + // The range covers the compression field and the stored bytes after it. + assert!(c.len == 0 || c.len == rc.data.len() + 2, "case {i}"); + assert!(c.len == 0 || bytes[c.offset + 2..c.offset + c.len] == rc.data[..], "case {i}"); + } + } + // Decoding reads those ranges: it ends in pixels or a clean error, as before the cutover. + if p.composite().is_ok() { + decoded += 1; + } + for li in 0..p.layers.len() { + let _ = p.layer_pixels(li, false); + } + } + assert!(decoded > 100, "{decoded} composites decoded"); +} + +#[test] +fn a_damaged_layer_section_keeps_the_merged_image() { + let case = craft_psd::testgen::all_cases().into_iter().find(|c| c.file.layer_info.as_ref().is_some_and(|l| !l.layers.is_empty())).expect("a layered case"); + let mut bytes = case.file.to_bytes().expect("write"); + let head = craft_psd::head::HeadView::from_bytes(&bytes).expect("head"); + // Overwrite the first layer record's signature. + let at = head.layer_section_offset as usize + if head.header.version.is_psb() { 16 } else { 8 } + 2 + 16; + let channels = usize::from(u16::from_be_bytes([bytes[at], bytes[at + 1]])); + let sig = at + 2 + channels * if head.header.version.is_psb() { 10 } else { 6 }; + assert_eq!(&bytes[sig..sig + 4], b"8BIM"); + bytes[sig..sig + 4].copy_from_slice(b"XXXX"); + let p = Psd::parse(bytes).expect("flattened"); + assert!(p.layers.is_empty()); + assert!(p.warnings.iter().any(|w| w.contains("Layers could not be read")), "{:?}", p.warnings); + assert!(p.composite().is_ok()); +} From 59671cfd292dddbe2a7a66c344a133088ce81964 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:41:54 +0100 Subject: [PATCH 77/99] psd: keep layers past a damaged resource, report an unreadable Lr16 block --- crates/psd/src/parse.rs | 68 ++++++++++++++++++++++----- crates/psd/src/tests/shared_corpus.rs | 48 +++++++++++++++++++ 2 files changed, 105 insertions(+), 11 deletions(-) diff --git a/crates/psd/src/parse.rs b/crates/psd/src/parse.rs index 6ed618a47..b1f8b6b6d 100644 --- a/crates/psd/src/parse.rs +++ b/crates/psd/src/parse.rs @@ -19,13 +19,11 @@ impl Psd { if !is_psd(&data) { return Err(Error::NotPsd); } - let source = craft_psd::source::Source::new(data.clone()); - // Linked-file blocks can be most of a file: leave them in the source, read in place. - let linked = |key: &[u8; 4], _len: u64| matches!(key, b"lnk2" | b"lnkD" | b"lnk3" | b"lnkE"); - let (head, file, warnings) = match craft_psd::PsdFile::from_source_deferring(source, linked, |_| Ok(false), |_| false) { - Ok((file, _)) => { + let (read, shift) = read_file(&data); + let (head, file, warnings) = match read { + Ok(file) => { // The compression field before the merged image's data. - let merged = file.image_data.stored.as_ref().map_or(data.len(), |s| (s.offset as usize).saturating_sub(2)); + let merged = file.image_data.stored.as_ref().map_or(data.len(), |s| ((s.offset + shift) as usize).saturating_sub(2)); ((file.header.clone(), file.color_mode_data.clone(), merged), Some(file), vec![]) } // A damaged layer section must not discard the document: keep the header and the @@ -60,14 +58,23 @@ impl Psd { data: data.clone(), merged_offset, }; - let Some(file) = file else { return Ok(psd) }; + let Some(file) = file else { + psd.merged_alpha = section_merged_alpha(&data); + return Ok(psd); + }; + if let Some((block, e)) = file.unreadable_layer_block() { + // A 16/32-bit file's layers live in a global block; when it is damaged the file reads + // as flattened. Its layer count still says whether the merged image has alpha. + psd.merged_alpha = block.data.get(..2).is_some_and(|c| i16::from_be_bytes([c[0], c[1]]) < 0); + psd.warnings.push(format!("Layers could not be read ({}); only the flattened image is available", error(&e))); + } if let Some(info) = &file.layer_info { psd.merged_alpha = info.merged_alpha; - psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i)).collect(); + psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i, shift)).collect(); } for b in &file.global_blocks { if let Some(stored) = b.stored.as_ref().filter(|_| linked(&b.key, 0)) { - let start = stored.offset as usize; + let start = (stored.offset + shift) as usize; psd.linked_files(&data, start, start.saturating_add(stored.len as usize).min(data.len())); } } @@ -75,13 +82,14 @@ impl Psd { } /// One layer record of the model, its additional information read into [`Layer`]. - fn layer(&self, rec: &craft_psd::LayerRecord, index: usize) -> Layer { + /// `shift` moves craft-psd's offsets back into `self.data` (see [`read_file`]). + fn layer(&self, rec: &craft_psd::LayerRecord, index: usize, shift: u64) -> Layer { let channels = rec .channels .iter() .map(|c| match &c.stored { // `ChannelInfo` covers the compression field and the data after it. - Some(s) => ChannelInfo { id: c.id, offset: (s.offset as usize).saturating_sub(2), len: s.len as usize + 2 }, + Some(s) => ChannelInfo { id: c.id, offset: ((s.offset + shift) as usize).saturating_sub(2), len: s.len as usize + 2 }, None => ChannelInfo { id: c.id, offset: 0, len: 0 }, }) .collect(); @@ -419,6 +427,44 @@ fn flattened(data: &[u8]) -> Option<(craft_psd::Header, Vec, usize)> { (merged.checked_add(2)? <= data.len()).then(|| (head.header.clone(), head.color_mode_data.to_vec(), merged)) } +/// Linked-file blocks can be most of a file: leave them in the source, read in place. +fn linked(key: &[u8; 4], _len: u64) -> bool { + matches!(key, b"lnk2" | b"lnkD" | b"lnk3" | b"lnkE") +} + +/// Reads `data` with craft-psd. The image resources are not part of the model, so when the file +/// does not read, it is read again with an empty resource section: a damaged resource must not +/// cost the layers. The second value is how far that copy's offsets sit before `data`'s. +fn read_file(data: &Arc<[u8]>) -> (std::result::Result, u64) { + let read = |d: Arc<[u8]>| craft_psd::PsdFile::from_source_deferring(craft_psd::source::Source::new(d), linked, |_| Ok(false), |_| false).map(|(f, _)| f); + let first = read(data.clone()); + let be32 = |at: usize| data.get(at..at.checked_add(4)?).map(|b| u32::from_be_bytes([b[0], b[1], b[2], b[3]]) as usize); + if first.is_ok() { + return (first, 0); + } + let Some(res_at) = be32(26).and_then(|cmd| cmd.checked_add(30)) else { return (first, 0) }; + let Some(res_len) = be32(res_at).filter(|&n| n > 0) else { return (first, 0) }; + let Some(rest) = res_at.checked_add(4 + res_len).and_then(|end| data.get(end..)) else { return (first, 0) }; + let mut copy = Vec::with_capacity(res_at + 4 + rest.len()); + copy.extend_from_slice(&data[..res_at]); + copy.extend_from_slice(&[0; 4]); + copy.extend_from_slice(rest); + match read(copy.into()) { + Ok(file) => (Ok(file), res_len as u64), + Err(_) => (first, 0), + } +} + +/// Whether the layer section's (unreadable) layer count is negative, which marks the merged +/// image's first extra channel as its transparency. +fn section_merged_alpha(data: &[u8]) -> bool { + let Ok(head) = craft_psd::head::HeadView::from_bytes(data) else { return false }; + let field = if head.header.version.is_psb() { 8 } else { 4 }; + let Some(at) = usize::try_from(head.layer_section_offset).ok().and_then(|a| a.checked_add(2 * field)) else { return false }; + let has_info = data.get(at - field..at).is_some_and(|l| l.iter().any(|&b| b != 0)); + has_info && data.get(at..at + 2).is_some_and(|c| i16::from_be_bytes([c[0], c[1]]) < 0) +} + /// This crate's error for one from craft-psd. fn error(e: &craft_psd::PsdError) -> Error { match e { diff --git a/crates/psd/src/tests/shared_corpus.rs b/crates/psd/src/tests/shared_corpus.rs index c6a6814d5..59d05271e 100644 --- a/crates/psd/src/tests/shared_corpus.rs +++ b/crates/psd/src/tests/shared_corpus.rs @@ -59,3 +59,51 @@ fn a_damaged_layer_section_keeps_the_merged_image() { assert!(p.warnings.iter().any(|w| w.contains("Layers could not be read")), "{:?}", p.warnings); assert!(p.composite().is_ok()); } + +/// The first generated case that is layered and passes `keep`, with its bytes. +fn layered(keep: impl Fn(&craft_psd::PsdFile) -> bool) -> Vec { + let case = craft_psd::testgen::all_cases() + .into_iter() + .find(|c| c.file.layer_info.as_ref().is_some_and(|l| !l.layers.is_empty()) && keep(&c.file)) + .expect("a layered case"); + case.file.to_bytes().expect("write") +} + +#[test] +fn a_damaged_resource_keeps_the_layers() { + let intact = layered(|f| f.header.depth == 8 && !f.resources.is_empty()); + let want = Psd::parse(intact.clone()).expect("intact"); + let mut bytes = intact; + // The first resource: signature, id, padded Pascal name, then its length, made to run off the end. + let res_at = 30 + u32::from_be_bytes(bytes[26..30].try_into().unwrap()) as usize; + let name = 1 + usize::from(bytes[res_at + 4 + 6]); + let len_at = res_at + 4 + 6 + name + name % 2; + bytes[len_at..len_at + 4].copy_from_slice(&0x7fff_fff0u32.to_be_bytes()); + let p = Psd::parse(bytes).expect("parse"); + assert!(p.warnings.is_empty(), "{:?}", p.warnings); + assert_eq!(p.layers.len(), want.layers.len()); + assert_eq!(p.merged_alpha, want.merged_alpha); + assert_eq!(p.composite().expect("composite").data, want.composite().expect("composite").data); + for i in 0..p.layers.len() { + assert_eq!(p.layers[i].name, want.layers[i].name); + assert_eq!(p.layer_pixels(i, false).map(|l| l.data).ok(), want.layer_pixels(i, false).map(|l| l.data).ok(), "layer {i}"); + } +} + +#[test] +fn a_damaged_16_bit_layer_block_is_reported() { + let intact = layered(|f| f.header.depth == 16 && matches!(f.layer_info_placement, craft_psd::LayerInfoPlacement::GlobalBlock { .. })); + let want = Psd::parse(intact.clone()).expect("intact"); + assert!(want.merged_alpha, "the generated 16-bit cases carry merged alpha"); + let mut bytes = intact; + let at = bytes.windows(8).position(|w| w == b"8BIMLr16").expect("Lr16 block"); + let psb = want.psb; + // Block header, then the layer count and the first record's rect: its channel count follows. + let channels = at + 8 + if psb { 8 } else { 4 } + 2 + 16; + bytes[channels..channels + 2].copy_from_slice(&u16::MAX.to_be_bytes()); + let p = Psd::parse(bytes).expect("flattened"); + assert!(p.layers.is_empty()); + assert!(p.warnings.iter().any(|w| w.contains("Layers could not be read")), "{:?}", p.warnings); + assert_eq!(p.merged_alpha, want.merged_alpha); + assert_eq!(p.composite().expect("composite").data, want.composite().expect("composite").data); +} From 50f8cc339770ebc648ba29f0ac45e0b986c37dd6 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:45:48 +0100 Subject: [PATCH 78/99] psd: write fixtures with craft_psd --- crates/psd/src/lib.rs | 1 - crates/psd/src/pixels.rs | 36 ----- crates/psd/src/tests.rs | 15 +- crates/psd/src/tests/opt.rs | 2 +- crates/psd/src/write.rs | 303 +++++++++++++----------------------- 5 files changed, 125 insertions(+), 232 deletions(-) diff --git a/crates/psd/src/lib.rs b/crates/psd/src/lib.rs index 91792a837..07f5f0359 100644 --- a/crates/psd/src/lib.rs +++ b/crates/psd/src/lib.rs @@ -32,7 +32,6 @@ pub use model::{ Adjustment, ChannelInfo, ColorMode, Layer, LayerMask, LinkedFile, MAX_GROUP_DEPTH, Node, Pixels, Rect, Section, SmartObject, SubPath, TextInfo, VectorMask, }; pub use parse::is_psd; -pub(crate) use pixels::pack_bits; #[cfg(test)] use pixels::{lab_to_rgb, srgb_encode, unpack_bits}; diff --git a/crates/psd/src/pixels.rs b/crates/psd/src/pixels.rs index 290a7b6f4..4907e21f7 100644 --- a/crates/psd/src/pixels.rs +++ b/crates/psd/src/pixels.rs @@ -505,42 +505,6 @@ pub(crate) fn unpack_bits(src: &[u8], row: usize, out: &mut Vec) -> Result<( Ok(()) } -/// PackBits encoding of one row. -pub(crate) fn pack_bits(src: &[u8]) -> Vec { - let mut out = vec![]; - let mut i = 0; - while i < src.len() { - // run of identical bytes - let mut run = 1; - while i + run < src.len() && src[i + run] == src[i] && run < 128 { - run += 1; - } - if run >= 2 { - out.push((1 - run as isize) as i8 as u8); - out.push(src[i]); - i += run; - continue; - } - // literal run - let start = i; - let mut n = 0; - while i < src.len() && n < 128 { - if i + 1 < src.len() && src[i + 1] == src[i] { - break; - } - i += 1; - n += 1; - } - if n == 0 { - i += 1; - n = 1; - } - out.push((n - 1) as u8); - out.extend_from_slice(&src[start..start + n]); - } - out -} - pub(crate) fn srgb_encode(v: f32) -> f32 { if v <= 0.003_130_8 { v * 12.92 } else { 1.055 * v.powf(1.0 / 2.4) - 0.055 } } diff --git a/crates/psd/src/tests.rs b/crates/psd/src/tests.rs index fd041138a..36470ba9b 100644 --- a/crates/psd/src/tests.rs +++ b/crates/psd/src/tests.rs @@ -171,7 +171,7 @@ fn text_effects_fill_and_adjustments() { #[test] fn packbits_round_trip() { for src in [vec![], vec![1u8], vec![5; 300], (0..=255).collect::>(), vec![1, 1, 2, 3, 3, 3, 4, 5, 5]] { - let enc = pack_bits(&src); + let enc = craft_psd::compression::packbits::encode_vec(&src); let mut out = vec![]; unpack_bits(&enc, src.len(), &mut out).unwrap(); assert_eq!(out, src); @@ -519,3 +519,16 @@ fn a_failed_inflate_reports_its_status_not_its_output() { let Err(Error::Invalid(msg)) = crate::limits::inflate(&z, 1 << 21) else { panic!("the checksum fails") }; assert!(msg.len() < 100, "{} bytes", msg.len()); } + +#[test] +fn written_32_bit_documents_decode() { + // 32-bit samples are written as floats, raw or RLE, so both read back whole. + for rle in [true, false] { + let p = Psd::parse(write(&doc_with_layers(32, ColorMode::Rgb, rle))).expect("parse"); + assert_eq!(p.depth, 32); + assert!(p.composite().is_ok(), "rle={rle}"); + for i in 0..p.layers.len() { + assert!(p.layer_pixels(i, false).is_ok(), "rle={rle} layer {i}"); + } + } +} diff --git a/crates/psd/src/tests/opt.rs b/crates/psd/src/tests/opt.rs index 44bcec071..241af0069 100644 --- a/crates/psd/src/tests/opt.rs +++ b/crates/psd/src/tests/opt.rs @@ -385,7 +385,7 @@ fn stream(planes: &[Vec], w: usize, h: usize, depth: u16, comp: u16) -> Vec< match comp { 0 => planes.iter().for_each(|p| out.extend(p)), 1 => { - let rows: Vec> = planes.iter().flat_map(|p| p.chunks(rowb.max(1)).map(pack_bits)).collect(); + let rows: Vec> = planes.iter().flat_map(|p| p.chunks(rowb.max(1)).map(craft_psd::compression::packbits::encode_vec)).collect(); rows.iter().for_each(|r| out.extend((r.len() as u16).to_be_bytes())); rows.iter().for_each(|r| out.extend(r)); } diff --git a/crates/psd/src/write.rs b/crates/psd/src/write.rs index a92e76dcd..e46576467 100644 --- a/crates/psd/src/write.rs +++ b/crates/psd/src/write.rs @@ -1,10 +1,17 @@ //! A minimal Photoshop document writer, per the same specification as the reader: RGB, CMYK or //! Grayscale, 8 or 16 bits, raw or RLE channels, pixel layers with layer masks, groups and any //! additional-information blocks (helpers below build text, effects, fill and adjustment -//! blocks). Used to generate test fixtures; not a full exporter. +//! blocks). Used to generate test fixtures; not a full exporter. The file itself is laid out and +//! encoded by craft-psd ([`craft_psd::PsdFile::to_bytes`]). + +use craft_psd::layer::{LayerInfo, LayerRecord}; +use craft_psd::tagged::{SectionType, TaggedBlock}; +use craft_psd::{ + BlendMode, BlendingRanges, ChannelData, Compression, GlobalLayerMask, Header, ImageData, LayerFlags, LayerInfoPlacement, MaskData, PsdFile, Version, +}; use crate::descriptor::{self, DValue, Descriptor, put_u16, put_u32, put_utf16}; -use crate::{ColorMode, Rect, Section, engine_data, pack_bits}; +use crate::{ColorMode, Rect, Section, engine_data}; /// A layer mask for [`WLayer`]. #[derive(Clone, Debug)] @@ -93,7 +100,7 @@ impl WLayer { pub struct WDoc { pub width: u32, pub height: u32, - /// 8 or 16. + /// 8, 16 or 32 (32-bit samples are written as floats). pub depth: u16, /// Rgb, Cmyk or Grayscale. pub mode: ColorMode, @@ -128,10 +135,12 @@ fn mode_channels(mode: ColorMode, p: [f32; 4]) -> Vec { } fn encode_samples(v: &[f32], depth: u16) -> Vec { - let mut out = Vec::with_capacity(v.len() * if depth == 16 { 2 } else { 1 }); + let mut out = Vec::with_capacity(v.len() * usize::from(depth.div_ceil(8))); for &x in v { let x = x.clamp(0.0, 1.0); - if depth == 16 { + if depth == 32 { + out.extend_from_slice(&x.to_be_bytes()); + } else if depth == 16 { put_u16(&mut out, (x * 65535.0).round() as u16); } else { out.push((x * 255.0).round() as u8); @@ -140,139 +149,69 @@ fn encode_samples(v: &[f32], depth: u16) -> Vec { out } -/// One channel's data (compression field + data) for a `w`×`h` plane. -fn channel_data(v: &[f32], w: usize, h: usize, depth: u16, rle: bool) -> Vec { - let raw = encode_samples(v, depth); - let mut out = vec![]; - let rowb = raw.len() / h.max(1); - if !rle || w == 0 || h == 0 { - put_u16(&mut out, 0); - out.extend_from_slice(&raw); - return out; - } - put_u16(&mut out, 1); - let rows: Vec> = raw.chunks(rowb.max(1)).map(pack_bits).collect(); - for r in &rows { - put_u16(&mut out, r.len() as u16); - } - for r in rows { - out.extend_from_slice(&r); - } - out +/// The layer and merged-image compression of `doc`. +fn compression(doc: &WDoc) -> Compression { + if doc.rle { Compression::Rle } else { Compression::Raw } } -fn pascal4(out: &mut Vec, s: &str) { - let b: Vec = s.bytes().map(|c| if c < 0x80 { c } else { b'?' }).take(255).collect(); - out.push(b.len() as u8); - out.extend_from_slice(&b); - let total = 1 + b.len(); - out.resize(out.len() + total.div_ceil(4) * 4 - total, 0); +/// One channel of a `w`×`h` plane, encoded by craft-psd. An empty plane is written raw. +fn channel(id: i16, v: &[f32], w: usize, h: usize, doc: &WDoc) -> craft_psd::Result { + let c = if w == 0 || h == 0 { Compression::Raw } else { compression(doc) }; + ChannelData::encode(id, c, &encode_samples(v, doc.depth), w, h, doc.depth, Version::Psd) } -fn block(out: &mut Vec, key: &[u8; 4], data: &[u8]) { - out.extend_from_slice(b"8BIM"); - out.extend_from_slice(key); - let padded = data.len().div_ceil(2) * 2; - put_u32(out, padded as u32); - out.extend_from_slice(data); - out.resize(out.len() + padded - data.len(), 0); +/// A legacy Pascal name: ASCII, anything else as `?`, at most 255 bytes. +fn legacy_name(s: &str) -> Vec { + s.bytes().map(|c| if c < 0x80 { c } else { b'?' }).take(255).collect() } -fn layer_info(doc: &WDoc) -> Vec { - let mut out = vec![]; - out.extend_from_slice(&(-(doc.layers.len() as i16)).to_be_bytes()); - let mut chan_data: Vec)>> = vec![]; - for l in &doc.layers { - let (w, h) = (l.rect.width() as usize, l.rect.height() as usize); - let mut chans: Vec<(i16, Vec)> = vec![]; - let n = w * h; - let alpha: Vec = l.pixels.iter().take(n).map(|p| p[3]).collect(); - chans.push((-1, channel_data(&alpha, w, h, doc.depth, doc.rle))); - let cc = doc.mode.color_channels(); - let planes: Vec> = l.pixels.iter().take(n).map(|p| mode_channels(doc.mode, *p)).collect(); - for c in 0..cc { - let plane: Vec = planes.iter().map(|v| v[c]).collect(); - chans.push((c as i16, channel_data(&plane, w, h, doc.depth, doc.rle))); - } - if let Some(m) = &l.mask { - chans.push((-2, channel_data(&m.data, m.rect.width() as usize, m.rect.height() as usize, doc.depth, doc.rle))); - } - // record - for v in [l.rect.top, l.rect.left, l.rect.bottom, l.rect.right] { - out.extend_from_slice(&v.to_be_bytes()); - } - put_u16(&mut out, chans.len() as u16); - for (id, d) in &chans { - out.extend_from_slice(&id.to_be_bytes()); - put_u32(&mut out, d.len() as u32); - } - out.extend_from_slice(b"8BIM"); - out.extend_from_slice(&l.blend); - out.push(l.opacity); - out.push(l.clipping as u8); - let mut flags = 8u8; - if l.hidden { - flags |= 2; - } - out.push(flags); - out.push(0); - let mut extra = vec![]; - match &l.mask { - Some(m) => { - put_u32(&mut extra, 20); - for v in [m.rect.top, m.rect.left, m.rect.bottom, m.rect.right] { - extra.extend_from_slice(&v.to_be_bytes()); - } - extra.push(m.default_color); - extra.push(if m.disabled { 2 } else { 0 }); - extra.extend_from_slice(&[0, 0]); - } - None => put_u32(&mut extra, 0), - } - put_u32(&mut extra, 0); // blending ranges - pascal4(&mut extra, &l.name); - let luni = unicode_plain(&l.name); - block(&mut extra, b"luni", &luni); - match l.section { - Section::Layer => {} - s => { - let mut d = vec![]; - put_u32( - &mut d, - match s { - Section::OpenFolder => 1, - Section::ClosedFolder => 2, - _ => 3, - }, - ); - d.extend_from_slice(b"8BIM"); - d.extend_from_slice(&l.blend); - block(&mut extra, b"lsct", &d); - } - } - for (k, d) in &l.blocks { - block(&mut extra, k, d); - } - put_u32(&mut out, extra.len() as u32); - out.extend_from_slice(&extra); - chan_data.push(chans); - } - for chans in chan_data { - for (_, d) in chans { - out.extend_from_slice(&d); - } - } - if out.len() % 2 == 1 { - out.push(0); - } - out +fn psd_rect(r: Rect) -> craft_psd::Rect { + craft_psd::Rect { top: r.top, left: r.left, bottom: r.bottom, right: r.right } } -/// A Unicode string without the terminating NUL (the layer-name `luni` form). -fn unicode_plain(s: &str) -> Vec { - let mut out = vec![]; - put_utf16(&mut out, s, false); - out +/// The layer record of `l`: pixels, mask, name, section and blocks. +fn record(l: &WLayer, doc: &WDoc) -> craft_psd::Result { + let (w, h) = (l.rect.width() as usize, l.rect.height() as usize); + let n = w * h; + let alpha: Vec = l.pixels.iter().take(n).map(|p| p[3]).collect(); + let mut channels = vec![channel(-1, &alpha, w, h, doc)?]; + let planes: Vec> = l.pixels.iter().take(n).map(|p| mode_channels(doc.mode, *p)).collect(); + for c in 0..doc.mode.color_channels() { + let plane: Vec = planes.iter().map(|v| v[c]).collect(); + channels.push(channel(c as i16, &plane, w, h, doc)?); + } + let mut mask = MaskData::None; + if let Some(m) = &l.mask { + channels.push(channel(-2, &m.data, m.rect.width() as usize, m.rect.height() as usize, doc)?); + mask = MaskData::Mask(craft_psd::LayerMask::new(psd_rect(m.rect), m.default_color, if m.disabled { 2 } else { 0 })); + } + let mut flags = LayerFlags(8); + flags.set_hidden(l.hidden); + let mut blocks = vec![TaggedBlock::unicode_name(&l.name)]; + let kind = match l.section { + Section::Layer => None, + Section::OpenFolder => Some(SectionType::OpenFolder), + Section::ClosedFolder => Some(SectionType::ClosedFolder), + Section::Divider => Some(SectionType::BoundingDivider), + }; + if let Some(kind) = kind { + blocks.push(TaggedBlock::section_divider(kind, Some(BlendMode::from_key(l.blend)), None)); + } + blocks.extend(l.blocks.iter().map(|(k, d)| TaggedBlock::new(*k, d.clone()))); + Ok(LayerRecord { + rect: psd_rect(l.rect), + channels, + blend_mode: BlendMode::from_key(l.blend), + opacity: l.opacity, + clipping: u8::from(l.clipping), + flags, + filler: 0, + mask, + blending_ranges: BlendingRanges::default(), + name: legacy_name(&l.name), + blocks, + extra_trailing: vec![], + }) } /// Normal "over" of the visible pixel layers (groups ignored), straight alpha. @@ -298,76 +237,54 @@ fn flatten(doc: &WDoc) -> Vec<[f32; 4]> { acc } -/// Serialise a document. +/// Serialise a document with craft-psd. pub fn write(doc: &WDoc) -> Vec { + // Every input `WDoc` describes is in range for the writer; a failure is a bug in the caller. + #[allow(clippy::expect_used)] + build(doc).and_then(|f| f.to_bytes()).expect("a WDoc is always writable") +} + +fn build(doc: &WDoc) -> craft_psd::Result { let cc = doc.mode.color_channels(); - let mut out = vec![]; - out.extend_from_slice(b"8BPS"); - put_u16(&mut out, 1); - out.extend_from_slice(&[0; 6]); - put_u16(&mut out, (cc + 1) as u16); - put_u32(&mut out, doc.height); - put_u32(&mut out, doc.width); - put_u16(&mut out, doc.depth); - put_u16(&mut out, doc.mode.to_u16()); - put_u32(&mut out, 0); // colour mode data - put_u32(&mut out, 0); // image resources - // Layer and mask information. - let mut lm = vec![]; - if !doc.layers.is_empty() { - let li = layer_info(doc); - if doc.depth == 16 { - put_u32(&mut lm, 0); - put_u32(&mut lm, 0); // global layer mask info - let mut padded = li; - while !padded.len().is_multiple_of(4) { - padded.push(0); - } - lm.extend_from_slice(b"8BIM"); - lm.extend_from_slice(b"Lr16"); - put_u32(&mut lm, padded.len() as u32); - lm.extend_from_slice(&padded); - } else { - put_u32(&mut lm, li.len() as u32); - lm.extend_from_slice(&li); - put_u32(&mut lm, 0); - } - if !doc.linked.is_empty() { - let d = linked_block(&doc.linked); - lm.extend_from_slice(b"8BIM"); - lm.extend_from_slice(b"lnk2"); - put_u32(&mut lm, d.len() as u32); - lm.extend_from_slice(&d); - } + let header = Header::new(Version::Psd, doc.width, doc.height, (cc + 1) as u16, doc.depth, craft_psd::ColorMode::from_u16(doc.mode.to_u16())); + let layers = doc.layers.iter().map(|l| record(l, doc)).collect::>>()?; + let has_layers = !layers.is_empty(); + let mut global_blocks = vec![]; + if has_layers && !doc.linked.is_empty() { + global_blocks.push(TaggedBlock::new(*b"lnk2", linked_block(&doc.linked))); } - put_u32(&mut out, lm.len() as u32); - out.extend_from_slice(&lm); // Merged image. let comp = doc.composite.clone().unwrap_or_else(|| flatten(doc)); - let w = doc.width as usize; let planes: Vec> = comp.iter().map(|p| mode_channels(doc.mode, *p)).collect(); - let mut chans: Vec> = (0..cc).map(|c| planes.iter().map(|v| v[c]).collect()).collect(); - chans.push(comp.iter().map(|p| p[3]).collect()); - if doc.rle { - put_u16(&mut out, 1); - let rows: Vec>> = - chans.iter().map(|c| encode_samples(c, doc.depth).chunks((w * if doc.depth == 16 { 2 } else { 1 }).max(1)).map(pack_bits).collect()).collect(); - for c in &rows { - for r in c { - put_u16(&mut out, r.len() as u16); - } - } - for c in rows { - for r in c { - out.extend_from_slice(&r); - } - } - } else { - put_u16(&mut out, 0); - for c in &chans { - out.extend_from_slice(&encode_samples(c, doc.depth)); - } + let mut merged = vec![]; + for c in 0..cc { + merged.extend(encode_samples(&planes.iter().map(|v| v[c]).collect::>(), doc.depth)); } + merged.extend(encode_samples(&comp.iter().map(|p| p[3]).collect::>(), doc.depth)); + let image_data = ImageData::encode(compression(doc), &merged, &header)?; + Ok(PsdFile { + header, + color_mode_data: vec![], + resources: vec![], + layer_info: has_layers.then_some(LayerInfo { merged_alpha: true, layers, padding: None }), + // 16-bit layers go in an `Lr16` block, as Photoshop writes them. + layer_info_placement: if has_layers && doc.depth == 16 { + LayerInfoPlacement::GlobalBlock { index: 0, signature: *b"8BIM", key: *b"Lr16", padding: None } + } else { + LayerInfoPlacement::Section + }, + global_layer_mask: has_layers.then(GlobalLayerMask::default), + global_blocks, + layer_mask_trailing: vec![], + image_data, + write_as_psb: false, + }) +} + +/// A Unicode string without the terminating NUL (the layer-name `luni` form). +fn unicode_plain(s: &str) -> Vec { + let mut out = vec![]; + put_utf16(&mut out, s, false); out } From 49abf0b402d7f151a6f8e6f6829d900a070ebfa7 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:57:54 +0100 Subject: [PATCH 79/99] psd: write 32-bit layers in Lr32, wide RLE rows raw --- crates/psd/src/tests.rs | 32 ++++++++++++++++++++++++++++++++ crates/psd/src/write.rs | 18 +++++++++++------- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/crates/psd/src/tests.rs b/crates/psd/src/tests.rs index 36470ba9b..f70ebaf5f 100644 --- a/crates/psd/src/tests.rs +++ b/crates/psd/src/tests.rs @@ -532,3 +532,35 @@ fn written_32_bit_documents_decode() { } } } + +#[test] +fn deep_layers_go_in_their_global_block() { + for (depth, key) in [(16, b"Lr16"), (32, b"Lr32")] { + let bytes = write(&doc_with_layers(depth, ColorMode::Rgb, true)); + let file = craft_psd::PsdFile::from_bytes(&bytes).expect("parse"); + assert!( + matches!(file.layer_info_placement, craft_psd::LayerInfoPlacement::GlobalBlock { key: k, .. } if &k == key), + "{depth}-bit: {:?}", + file.layer_info_placement + ); + assert_eq!(Psd::parse(bytes).expect("parse").layers.len(), doc_with_layers(depth, ColorMode::Rgb, true).layers.len()); + } +} + +#[test] +fn rows_too_wide_for_rle_are_written_raw() { + // 20000 32-bit samples are 80000 bytes per row, past the 65535 an RLE row count holds. + let doc = |w: u32| { + let mut d = WDoc::new(w, 1); + d.depth = 32; + d.composite = Some(vec![[0.5, 0.25, 0.75, 1.0]; w as usize]); + d.layers.push(WLayer::solid("Wide", Rect::new(0, 0, w as i32, 1), [0.5, 0.25, 0.75, 1.0])); + d + }; + let want = Psd::parse(write(&doc(100))).expect("narrow").composite().expect("composite").data[0]; + let p = Psd::parse(write(&doc(20_000))).expect("parse"); + let c = p.composite().expect("composite"); + assert_eq!(c.data.len(), 20_000); + assert!(c.data.iter().all(|px| *px == want), "{:?} vs {want:?}", c.data[0]); + assert!(p.layer_pixels(0, false).is_ok()); +} diff --git a/crates/psd/src/write.rs b/crates/psd/src/write.rs index e46576467..bd55b566e 100644 --- a/crates/psd/src/write.rs +++ b/crates/psd/src/write.rs @@ -157,7 +157,10 @@ fn compression(doc: &WDoc) -> Compression { /// One channel of a `w`×`h` plane, encoded by craft-psd. An empty plane is written raw. fn channel(id: i16, v: &[f32], w: usize, h: usize, doc: &WDoc) -> craft_psd::Result { let c = if w == 0 || h == 0 { Compression::Raw } else { compression(doc) }; - ChannelData::encode(id, c, &encode_samples(v, doc.depth), w, h, doc.depth, Version::Psd) + let samples = encode_samples(v, doc.depth); + // A PSD RLE row holds at most 65535 bytes; a wider plane is written raw. + ChannelData::encode(id, c, &samples, w, h, doc.depth, Version::Psd) + .or_else(|_| ChannelData::encode(id, Compression::Raw, &samples, w, h, doc.depth, Version::Psd)) } /// A legacy Pascal name: ASCII, anything else as `?`, at most 255 bytes. @@ -261,17 +264,18 @@ fn build(doc: &WDoc) -> craft_psd::Result { merged.extend(encode_samples(&planes.iter().map(|v| v[c]).collect::>(), doc.depth)); } merged.extend(encode_samples(&comp.iter().map(|p| p[3]).collect::>(), doc.depth)); - let image_data = ImageData::encode(compression(doc), &merged, &header)?; + let image_data = ImageData::encode(compression(doc), &merged, &header).or_else(|_| ImageData::encode(Compression::Raw, &merged, &header))?; Ok(PsdFile { header, color_mode_data: vec![], resources: vec![], layer_info: has_layers.then_some(LayerInfo { merged_alpha: true, layers, padding: None }), - // 16-bit layers go in an `Lr16` block, as Photoshop writes them. - layer_info_placement: if has_layers && doc.depth == 16 { - LayerInfoPlacement::GlobalBlock { index: 0, signature: *b"8BIM", key: *b"Lr16", padding: None } - } else { - LayerInfoPlacement::Section + // 16- and 32-bit layers go in an `Lr16` / `Lr32` block, as Photoshop writes them. + layer_info_placement: match doc.depth { + 16 | 32 if has_layers => { + LayerInfoPlacement::GlobalBlock { index: 0, signature: *b"8BIM", key: craft_psd::tiff::layer_info_key(doc.depth), padding: None } + } + _ => LayerInfoPlacement::Section, }, global_layer_mask: has_layers.then(GlobalLayerMask::default), global_blocks, From e51a805f4ef9485bc092aafd97ce1029e33c1f3a Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:04:22 +0100 Subject: [PATCH 80/99] psd: recover layers from a length-prefixed or fallback Lr16/Lr32 block --- crates/psd/src/parse.rs | 119 ++++++++++++++++++++------ crates/psd/src/tests/shared_corpus.rs | 54 ++++++++++++ 2 files changed, 149 insertions(+), 24 deletions(-) diff --git a/crates/psd/src/parse.rs b/crates/psd/src/parse.rs index b1f8b6b6d..d669b969b 100644 --- a/crates/psd/src/parse.rs +++ b/crates/psd/src/parse.rs @@ -19,11 +19,11 @@ impl Psd { if !is_psd(&data) { return Err(Error::NotPsd); } - let (read, shift) = read_file(&data); + let (read, splice) = read_file(&data); let (head, file, warnings) = match read { Ok(file) => { // The compression field before the merged image's data. - let merged = file.image_data.stored.as_ref().map_or(data.len(), |s| ((s.offset + shift) as usize).saturating_sub(2)); + let merged = file.image_data.stored.as_ref().map_or(data.len(), |s| (splice.map(s.offset) as usize).saturating_sub(2)); ((file.header.clone(), file.color_mode_data.clone(), merged), Some(file), vec![]) } // A damaged layer section must not discard the document: keep the header and the @@ -70,11 +70,11 @@ impl Psd { } if let Some(info) = &file.layer_info { psd.merged_alpha = info.merged_alpha; - psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i, shift)).collect(); + psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i, splice)).collect(); } for b in &file.global_blocks { if let Some(stored) = b.stored.as_ref().filter(|_| linked(&b.key, 0)) { - let start = (stored.offset + shift) as usize; + let start = splice.map(stored.offset) as usize; psd.linked_files(&data, start, start.saturating_add(stored.len as usize).min(data.len())); } } @@ -82,14 +82,14 @@ impl Psd { } /// One layer record of the model, its additional information read into [`Layer`]. - /// `shift` moves craft-psd's offsets back into `self.data` (see [`read_file`]). - fn layer(&self, rec: &craft_psd::LayerRecord, index: usize, shift: u64) -> Layer { + /// `splice` maps craft-psd's offsets back into `self.data` (see [`read_file`]). + fn layer(&self, rec: &craft_psd::LayerRecord, index: usize, splice: Splice) -> Layer { let channels = rec .channels .iter() .map(|c| match &c.stored { // `ChannelInfo` covers the compression field and the data after it. - Some(s) => ChannelInfo { id: c.id, offset: ((s.offset + shift) as usize).saturating_sub(2), len: s.len as usize + 2 }, + Some(s) => ChannelInfo { id: c.id, offset: (splice.map(s.offset) as usize).saturating_sub(2), len: s.len as usize + 2 }, None => ChannelInfo { id: c.id, offset: 0, len: 0 }, }) .collect(); @@ -432,26 +432,97 @@ fn linked(key: &[u8; 4], _len: u64) -> bool { matches!(key, b"lnk2" | b"lnkD" | b"lnk3" | b"lnkE") } -/// Reads `data` with craft-psd. The image resources are not part of the model, so when the file -/// does not read, it is read again with an empty resource section: a damaged resource must not -/// cost the layers. The second value is how far that copy's offsets sit before `data`'s. -fn read_file(data: &Arc<[u8]>) -> (std::result::Result, u64) { +/// Reads `data` with craft-psd. Where that loses what the old reader kept, it reads a copy with +/// the obstacle taken out, and the [`Splice`] maps the copy's offsets back into `data`: +/// - a damaged image resource (resources are not part of the model): no resources; +/// - damaged layer records in the section: none there, so a global `Lr16`/`Lr32`/`Layr` block +/// can still give the layers; +/// - a global layer block that starts with its own length (both layouts are accepted): the +/// block without it. +fn read_file(data: &Arc<[u8]>) -> (std::result::Result, Splice) { let read = |d: Arc<[u8]>| craft_psd::PsdFile::from_source_deferring(craft_psd::source::Source::new(d), linked, |_| Ok(false), |_| false).map(|(f, _)| f); + let layered = |f: &craft_psd::PsdFile| f.layer_info.as_ref().is_some_and(|i| !i.layers.is_empty()); + let retry = |copy: Option<(Vec, Splice)>, accept: &dyn Fn(&craft_psd::PsdFile) -> bool| { + let (copy, splice) = copy?; + read(copy.into()).ok().filter(|f| accept(f)).map(|f| (f, splice)) + }; let first = read(data.clone()); - let be32 = |at: usize| data.get(at..at.checked_add(4)?).map(|b| u32::from_be_bytes([b[0], b[1], b[2], b[3]]) as usize); - if first.is_ok() { - return (first, 0); + let got = match &first { + Ok(f) if layered(f) => None, + Ok(_) => retry(prefixed_layer_block(data), &layered), + Err(_) => retry(without_resources(data), &|_| true).or_else(|| retry(without_section_layers(data), &layered)), + }; + match got { + Some((file, splice)) => (Ok(file), splice), + None => (first, Splice::default()), } - let Some(res_at) = be32(26).and_then(|cmd| cmd.checked_add(30)) else { return (first, 0) }; - let Some(res_len) = be32(res_at).filter(|&n| n > 0) else { return (first, 0) }; - let Some(rest) = res_at.checked_add(4 + res_len).and_then(|end| data.get(end..)) else { return (first, 0) }; - let mut copy = Vec::with_capacity(res_at + 4 + rest.len()); - copy.extend_from_slice(&data[..res_at]); - copy.extend_from_slice(&[0; 4]); - copy.extend_from_slice(rest); - match read(copy.into()) { - Ok(file) => (Ok(file), res_len as u64), - Err(_) => (first, 0), +} + +/// A big-endian unsigned field of `width` bytes at `at`. +fn be(data: &[u8], at: usize, width: usize) -> Option { + let b = data.get(at..at.checked_add(width)?)?; + usize::try_from(b.iter().fold(0u64, |v, &b| v << 8 | u64::from(b))).ok() +} + +/// The length-field width of the layer section and its long blocks. +fn field(data: &[u8]) -> usize { + if data.get(4..6) == Some(&[0, 2]) { 8 } else { 4 } +} + +fn without_resources(data: &[u8]) -> Option<(Vec, Splice)> { + let res_at = be(data, 26, 4)?.checked_add(30)?; + let res_len = be(data, res_at, 4).filter(|&n| n > 0)?; + Splice::apply(data, res_at + 4, res_len, &[(res_at, 4)]) +} + +fn without_section_layers(data: &[u8]) -> Option<(Vec, Splice)> { + let head = craft_psd::head::HeadView::from_bytes(data).ok()?; + let ls = usize::try_from(head.layer_section_offset).ok()?; + let w = field(data); + let li_at = ls.checked_add(w)?; + let li_len = be(data, li_at, w).filter(|&n| n > 0)?; + Splice::apply(data, li_at + w, li_len, &[(li_at, w), (ls, w)]) +} + +fn prefixed_layer_block(data: &[u8]) -> Option<(Vec, Splice)> { + let head = craft_psd::head::HeadView::from_bytes(data).ok()?; + let ls = usize::try_from(head.layer_section_offset).ok()?; + let w = field(data); + let end = be(data, ls, w)?.checked_add(ls + w)?.min(data.len()); + // The block (signature, key, length), whose own first field reads as a length that fits in it. + let at = (ls..end.saturating_sub(8 + 2 * w)).find(|&i| { + matches!(&data[i..i + 4], b"8BIM" | b"8B64") + && matches!(&data[i + 4..i + 8], b"Lr16" | b"Lr32" | b"Layr") + && be(data, i + 8, w).zip(be(data, i + 8 + w, w)).is_some_and(|(len, inner)| inner > 0 && inner.checked_add(w).is_some_and(|e| e <= len)) + })?; + Splice::apply(data, at + 8 + w, w, &[(at + 8, w), (ls, w)]) +} + +/// A copy of the file with one range taken out, and the way from the copy's offsets back to the +/// original's. +#[derive(Debug, Clone, Copy, Default)] +struct Splice { + at: u64, + removed: u64, +} + +impl Splice { + fn map(self, offset: u64) -> u64 { + if offset >= self.at { offset + self.removed } else { offset } + } + + /// `data` without the `removed` bytes at `at`, the length fields at `fixes` (offset, width; + /// all before `at`) shortened to match. + fn apply(data: &[u8], at: usize, removed: usize, fixes: &[(usize, usize)]) -> Option<(Vec, Splice)> { + let tail = data.get(at.checked_add(removed)?..)?; + let mut copy = Vec::with_capacity(at + tail.len()); + copy.extend_from_slice(data.get(..at)?); + copy.extend_from_slice(tail); + for &(f, width) in fixes { + let v = (be(©, f, width)?.checked_sub(removed)? as u64).to_be_bytes(); + copy.get_mut(f..f + width)?.copy_from_slice(&v[8 - width..]); + } + Some((copy, Splice { at: at as u64, removed: removed as u64 })) } } diff --git a/crates/psd/src/tests/shared_corpus.rs b/crates/psd/src/tests/shared_corpus.rs index 59d05271e..2c90cb481 100644 --- a/crates/psd/src/tests/shared_corpus.rs +++ b/crates/psd/src/tests/shared_corpus.rs @@ -107,3 +107,57 @@ fn a_damaged_16_bit_layer_block_is_reported() { assert_eq!(p.merged_alpha, want.merged_alpha); assert_eq!(p.composite().expect("composite").data, want.composite().expect("composite").data); } + +/// `bytes` with `insert` put at `at`, the length fields at `fixes` (offset, width) grown to match. +fn insert(bytes: &[u8], at: usize, insert: &[u8], fixes: &[(usize, usize)]) -> Vec { + let mut out = [&bytes[..at], insert, &bytes[at..]].concat(); + for &(f, w) in fixes { + let v = out[f..f + w].iter().fold(0u64, |v, &b| v << 8 | u64::from(b)) + insert.len() as u64; + out[f..f + w].copy_from_slice(&v.to_be_bytes()[8 - w..]); + } + out +} + +/// A 16-bit layered case (layers in `Lr16`), its parse, the layer section offset, the length +/// field width and the `Lr16` block's offset. +fn deep() -> (Vec, Psd, usize, usize, usize) { + let bytes = layered(|f| f.header.depth == 16 && matches!(f.layer_info_placement, craft_psd::LayerInfoPlacement::GlobalBlock { .. })); + let want = Psd::parse(bytes.clone()).expect("intact"); + let ls = craft_psd::head::HeadView::from_bytes(&bytes).expect("head").layer_section_offset as usize; + let w = if want.psb { 8 } else { 4 }; + let at = bytes.windows(8).position(|x| x[4..] == *b"Lr16" && matches!(&x[..4], b"8BIM" | b"8B64")).expect("Lr16"); + (bytes, want, ls, w, at) +} + +fn same_layers(p: &Psd, want: &Psd) { + assert!(p.warnings.is_empty(), "{:?}", p.warnings); + assert_eq!(p.layers.len(), want.layers.len()); + assert_eq!(p.merged_alpha, want.merged_alpha); + assert_eq!(p.composite().expect("composite").data, want.composite().expect("composite").data); + for i in 0..p.layers.len() { + assert_eq!(p.layers[i].name, want.layers[i].name); + assert_eq!(p.layer_pixels(i, false).map(|l| l.data).ok(), want.layer_pixels(i, false).map(|l| l.data).ok(), "layer {i}"); + } +} + +#[test] +fn a_length_prefixed_16_bit_layer_block_reads() { + let (bytes, want, ls, w, at) = deep(); + let body = at + 8 + w; + let len = u64::try_from(bytes.len()).unwrap().min(u64::from(u32::MAX)); + let block_len = bytes[at + 8..body].iter().fold(0u64, |v, &b| v << 8 | u64::from(b)); + assert!(block_len < len); + let prefix = &block_len.to_be_bytes()[8 - w..]; + let p = Psd::parse(insert(&bytes, body, prefix, &[(at + 8, w), (ls, w)])).expect("parse"); + same_layers(&p, &want); +} + +#[test] +fn damaged_section_records_fall_back_to_the_16_bit_block() { + let (bytes, want, ls, w, _) = deep(); + // A section layer info claiming one record that is cut short. + let li_at = ls + w; + assert!(bytes[li_at..li_at + w].iter().all(|&b| b == 0), "the generated file keeps its layers only in Lr16"); + let p = Psd::parse(insert(&bytes, li_at + w, &[0, 1, 0, 0, 0, 0], &[(li_at, w), (ls, w)])).expect("parse"); + same_layers(&p, &want); +} From e9690b2c027c08b7c82fab8769f67ca7664a5862 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:17:28 +0100 Subject: [PATCH 81/99] psd: walk top-level global blocks for the layer block repair --- crates/psd/src/parse.rs | 44 +++++++++++++++++++++------ crates/psd/src/tests/shared_corpus.rs | 12 ++++++++ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/crates/psd/src/parse.rs b/crates/psd/src/parse.rs index d669b969b..2713394e0 100644 --- a/crates/psd/src/parse.rs +++ b/crates/psd/src/parse.rs @@ -437,8 +437,8 @@ fn linked(key: &[u8; 4], _len: u64) -> bool { /// - a damaged image resource (resources are not part of the model): no resources; /// - damaged layer records in the section: none there, so a global `Lr16`/`Lr32`/`Layr` block /// can still give the layers; -/// - a global layer block that starts with its own length (both layouts are accepted): the -/// block without it. +/// - a global layer block that starts with its own length (both layouts are accepted), or +/// that follows up to three stray bytes: the block without them. fn read_file(data: &Arc<[u8]>) -> (std::result::Result, Splice) { let read = |d: Arc<[u8]>| craft_psd::PsdFile::from_source_deferring(craft_psd::source::Source::new(d), linked, |_| Ok(false), |_| false).map(|(f, _)| f); let layered = |f: &craft_psd::PsdFile| f.layer_info.as_ref().is_some_and(|i| !i.layers.is_empty()); @@ -484,20 +484,46 @@ fn without_section_layers(data: &[u8]) -> Option<(Vec, Splice)> { Splice::apply(data, li_at + w, li_len, &[(li_at, w), (ls, w)]) } +/// The global layer block's repair, found by walking the top-level global blocks by their +/// declared lengths (so a linked file's payload is never searched): up to three stray bytes +/// before the first block, or the block's payload starting with its own length. fn prefixed_layer_block(data: &[u8]) -> Option<(Vec, Splice)> { let head = craft_psd::head::HeadView::from_bytes(data).ok()?; let ls = usize::try_from(head.layer_section_offset).ok()?; let w = field(data); let end = be(data, ls, w)?.checked_add(ls + w)?.min(data.len()); - // The block (signature, key, length), whose own first field reads as a length that fits in it. - let at = (ls..end.saturating_sub(8 + 2 * w)).find(|&i| { - matches!(&data[i..i + 4], b"8BIM" | b"8B64") - && matches!(&data[i + 4..i + 8], b"Lr16" | b"Lr32" | b"Layr") - && be(data, i + 8, w).zip(be(data, i + 8 + w, w)).is_some_and(|(len, inner)| inner > 0 && inner.checked_add(w).is_some_and(|e| e <= len)) - })?; - Splice::apply(data, at + 8 + w, w, &[(at + 8, w), (ls, w)]) + let li_at = ls + w; + let gm_at = be(data, li_at, w)?.checked_add(li_at + w)?; + let mut pos = be(data, gm_at, 4)?.checked_add(gm_at + 4)?; + let is_sig = |i: usize| matches!(data.get(i..i + 4), Some(b"8BIM" | b"8B64")); + // Stray bytes before the first block hide every block from craft-psd. + let mut lead = None; + while pos < end { + let skip = (0..=3).find(|&k| is_sig(pos + k))?; + let at = pos + skip; + let key = data.get(at + 4..at + 8)?; + let width = if w == 8 && PSB_LONG_KEYS.iter().any(|k| k[..] == *key) { 8 } else { 4 }; + let len = be(data, at + 8, width)?; + let body = at + 8 + width; + if matches!(key, b"Lr16" | b"Lr32" | b"Layr") { + if let Some((at, n)) = lead { + return Splice::apply(data, at, n, &[(ls, w)]); + } + // The payload's first field reads as a length that fits in it. + be(data, body, w).filter(|&n| n > 0 && n.checked_add(w).is_some_and(|e| e <= len))?; + return Splice::apply(data, body, w, &[(at + 8, width), (ls, w)]); + } + if pos == gm_at + 4 + be(data, gm_at, 4)? && skip > 0 { + lead = Some((pos, skip)); + } + pos = body.checked_add(len)?; + } + None } +/// Keys whose block length is 8 bytes in a PSB. +const PSB_LONG_KEYS: [&[u8; 4]; 13] = [b"LMsk", b"Lr16", b"Lr32", b"Layr", b"Mt16", b"Mt32", b"Mtrn", b"Alph", b"FMsk", b"lnk2", b"FEid", b"FXid", b"PxSD"]; + /// A copy of the file with one range taken out, and the way from the copy's offsets back to the /// original's. #[derive(Debug, Clone, Copy, Default)] diff --git a/crates/psd/src/tests/shared_corpus.rs b/crates/psd/src/tests/shared_corpus.rs index 2c90cb481..af8e0870f 100644 --- a/crates/psd/src/tests/shared_corpus.rs +++ b/crates/psd/src/tests/shared_corpus.rs @@ -161,3 +161,15 @@ fn damaged_section_records_fall_back_to_the_16_bit_block() { let p = Psd::parse(insert(&bytes, li_at + w, &[0, 1, 0, 0, 0, 0], &[(li_at, w), (ls, w)])).expect("parse"); same_layers(&p, &want); } + +#[test] +fn a_stray_byte_before_the_global_blocks_is_skipped() { + let (bytes, want, ls, w, _) = deep(); + // Section layer info (empty) and global mask, then the first global block. + let li_at = ls + w; + let gm_at = li_at + w + bytes[li_at..li_at + w].iter().fold(0usize, |v, &b| v << 8 | usize::from(b)); + let first = gm_at + 4 + u32::from_be_bytes(bytes[gm_at..gm_at + 4].try_into().unwrap()) as usize; + assert_eq!(&bytes[first..first + 4], b"8BIM"); + let p = Psd::parse(insert(&bytes, first, &[0], &[(ls, w)])).expect("parse"); + same_layers(&p, &want); +} From 00bf6a06c9a556947b17955ed0cee1ea816a9369 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:30:10 +0100 Subject: [PATCH 82/99] psd: keep the luni block's bytes so exported files are unchanged --- crates/psd/src/write.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/psd/src/write.rs b/crates/psd/src/write.rs index bd55b566e..e67862470 100644 --- a/crates/psd/src/write.rs +++ b/crates/psd/src/write.rs @@ -163,6 +163,15 @@ fn channel(id: i16, v: &[f32], w: usize, h: usize, doc: &WDoc) -> craft_psd::Res .or_else(|_| ChannelData::encode(id, Compression::Raw, &samples, w, h, doc.depth, Version::Psd)) } +/// The `luni` block: the UTF-16 length and code units, unpadded, as this writer has always +/// written it (`TaggedBlock::unicode_name` adds a terminator, which would change exported files). +fn unicode_name(name: &str) -> TaggedBlock { + let units: Vec = name.encode_utf16().collect(); + let mut data = (units.len() as u32).to_be_bytes().to_vec(); + data.extend(units.iter().flat_map(|u| u.to_be_bytes())); + TaggedBlock::new(*b"luni", data) +} + /// A legacy Pascal name: ASCII, anything else as `?`, at most 255 bytes. fn legacy_name(s: &str) -> Vec { s.bytes().map(|c| if c < 0x80 { c } else { b'?' }).take(255).collect() @@ -190,7 +199,7 @@ fn record(l: &WLayer, doc: &WDoc) -> craft_psd::Result { } let mut flags = LayerFlags(8); flags.set_hidden(l.hidden); - let mut blocks = vec![TaggedBlock::unicode_name(&l.name)]; + let mut blocks = vec![unicode_name(&l.name)]; let kind = match l.section { Section::Layer => None, Section::OpenFolder => Some(SectionType::OpenFolder), From 7f9f0bc489bf493657e778b4ba9f9886ed82e06b Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:31:10 +0100 Subject: [PATCH 83/99] psd: record stray leading bytes before the layer block check, use craft-psd's long-length keys --- crates/psd/src/parse.rs | 19 +++++++++---------- crates/psd/src/tests/shared_corpus.rs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/psd/src/parse.rs b/crates/psd/src/parse.rs index 2713394e0..39b9ea989 100644 --- a/crates/psd/src/parse.rs +++ b/crates/psd/src/parse.rs @@ -494,18 +494,23 @@ fn prefixed_layer_block(data: &[u8]) -> Option<(Vec, Splice)> { let end = be(data, ls, w)?.checked_add(ls + w)?.min(data.len()); let li_at = ls + w; let gm_at = be(data, li_at, w)?.checked_add(li_at + w)?; - let mut pos = be(data, gm_at, 4)?.checked_add(gm_at + 4)?; + let blocks = be(data, gm_at, 4)?.checked_add(gm_at + 4)?; + let mut pos = blocks; let is_sig = |i: usize| matches!(data.get(i..i + 4), Some(b"8BIM" | b"8B64")); // Stray bytes before the first block hide every block from craft-psd. let mut lead = None; while pos < end { let skip = (0..=3).find(|&k| is_sig(pos + k))?; let at = pos + skip; - let key = data.get(at + 4..at + 8)?; - let width = if w == 8 && PSB_LONG_KEYS.iter().any(|k| k[..] == *key) { 8 } else { 4 }; + // Leading bytes before the first block are recorded before its key is looked at. + if lead.is_none() && pos == blocks && skip > 0 { + lead = Some((pos, skip)); + } + let key: [u8; 4] = data.get(at + 4..at + 8)?.try_into().ok()?; + let width = if craft_psd::tagged::uses_long_length(head.header.version, &key) { 8 } else { 4 }; let len = be(data, at + 8, width)?; let body = at + 8 + width; - if matches!(key, b"Lr16" | b"Lr32" | b"Layr") { + if matches!(&key, b"Lr16" | b"Lr32" | b"Layr") { if let Some((at, n)) = lead { return Splice::apply(data, at, n, &[(ls, w)]); } @@ -513,17 +518,11 @@ fn prefixed_layer_block(data: &[u8]) -> Option<(Vec, Splice)> { be(data, body, w).filter(|&n| n > 0 && n.checked_add(w).is_some_and(|e| e <= len))?; return Splice::apply(data, body, w, &[(at + 8, width), (ls, w)]); } - if pos == gm_at + 4 + be(data, gm_at, 4)? && skip > 0 { - lead = Some((pos, skip)); - } pos = body.checked_add(len)?; } None } -/// Keys whose block length is 8 bytes in a PSB. -const PSB_LONG_KEYS: [&[u8; 4]; 13] = [b"LMsk", b"Lr16", b"Lr32", b"Layr", b"Mt16", b"Mt32", b"Mtrn", b"Alph", b"FMsk", b"lnk2", b"FEid", b"FXid", b"PxSD"]; - /// A copy of the file with one range taken out, and the way from the copy's offsets back to the /// original's. #[derive(Debug, Clone, Copy, Default)] diff --git a/crates/psd/src/tests/shared_corpus.rs b/crates/psd/src/tests/shared_corpus.rs index af8e0870f..1f5659187 100644 --- a/crates/psd/src/tests/shared_corpus.rs +++ b/crates/psd/src/tests/shared_corpus.rs @@ -173,3 +173,20 @@ fn a_stray_byte_before_the_global_blocks_is_skipped() { let p = Psd::parse(insert(&bytes, first, &[0], &[(ls, w)])).expect("parse"); same_layers(&p, &want); } + +#[test] +fn stray_bytes_before_a_leading_16_bit_block_are_skipped() { + let (bytes, want, ls, w, at) = deep(); + let li_at = ls + w; + let gm_at = li_at + w + bytes[li_at..li_at + w].iter().fold(0usize, |v, &b| v << 8 | usize::from(b)); + let first = gm_at + 4 + u32::from_be_bytes(bytes[gm_at..gm_at + 4].try_into().unwrap()) as usize; + // Drop the blocks before `Lr16` so it comes first, then put 1 to 3 stray bytes before it. + let mut lead = [&bytes[..first], &bytes[at..]].concat(); + let lm = lead[ls..ls + w].iter().fold(0u64, |v, &b| v << 8 | u64::from(b)) - (at - first) as u64; + lead[ls..ls + w].copy_from_slice(&lm.to_be_bytes()[8 - w..]); + assert_eq!(&lead[first + 4..first + 8], b"Lr16"); + for n in 1..=3 { + let p = Psd::parse(insert(&lead, first, &vec![0; n], &[(ls, w)])).expect("parse"); + same_layers(&p, &want); + } +} From 952918aa02bde6a6aece0360cee1df55ccd0a275 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:59:44 +0100 Subject: [PATCH 84/99] psd: keep finite 32-bit color samples outside 0..1 Integer depths are still clamped. NaN and infinities use the same mapping as the reader. --- crates/psd/src/tests.rs | 30 ++++++++++++++++++++++++++++++ crates/psd/src/write.rs | 21 ++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/crates/psd/src/tests.rs b/crates/psd/src/tests.rs index f70ebaf5f..7bc88006b 100644 --- a/crates/psd/src/tests.rs +++ b/crates/psd/src/tests.rs @@ -1,5 +1,6 @@ use super::write::*; use super::*; +use crate::pixels::srgb_encode; mod integration; mod opt; @@ -564,3 +565,32 @@ fn rows_too_wide_for_rle_are_written_raw() { assert!(c.data.iter().all(|px| *px == want), "{:?} vs {want:?}", c.data[0]); assert!(p.layer_pixels(0, false).is_ok()); } + +#[test] +fn written_32_bit_color_samples_keep_their_range() { + // The reader keeps finite 32-bit samples outside 0..1; the writer must be able to + // produce those fixtures. Integer depths stay clamped. A layer is present so the + // merged transparency flag is set and alpha is read back. + let want = [2.0, -0.5, 0.25, 1.5]; + let mut d = WDoc::new(1, 1); + d.depth = 32; + d.rle = false; + d.composite = Some(vec![want]); + d.layers.push(WLayer::solid("HDR", Rect::new(0, 0, 1, 1), want)); + let bytes = write(&d); + for v in want { + assert!(bytes.windows(4).any(|w| w == v.to_be_bytes()), "missing the {v} sample"); + } + let p = Psd::parse(bytes).expect("parse"); + assert!(p.merged_alpha); + let c = p.composite().expect("composite"); + assert_eq!(c.data[0], [srgb_encode(2.0), srgb_encode(-0.5), srgb_encode(0.25), 1.5]); + assert_eq!(p.layer_pixels(0, false).expect("layer").data[0], c.data[0]); + + let mut d8 = WDoc::new(1, 1); + d8.composite = Some(vec![want]); + d8.layers.push(WLayer::solid("HDR", Rect::new(0, 0, 1, 1), want)); + let p8 = Psd::parse(write(&d8)).expect("parse 8-bit"); + let q = |x: f32| (x.clamp(0.0, 1.0) * 255.0).round() / 255.0; + assert_eq!(p8.composite().expect("composite").data[0], [q(2.0), q(-0.5), q(0.25), q(1.5)]); +} diff --git a/crates/psd/src/write.rs b/crates/psd/src/write.rs index e67862470..6f77ad438 100644 --- a/crates/psd/src/write.rs +++ b/crates/psd/src/write.rs @@ -10,8 +10,9 @@ use craft_psd::{ BlendMode, BlendingRanges, ChannelData, Compression, GlobalLayerMask, Header, ImageData, LayerFlags, LayerInfoPlacement, MaskData, PsdFile, Version, }; -use crate::descriptor::{self, DValue, Descriptor, put_u16, put_u32, put_utf16}; -use crate::{ColorMode, Rect, Section, engine_data}; +use crate::descriptor::{self, put_u16, put_u32, put_utf16, DValue, Descriptor}; +use crate::limits::finite_sample; +use crate::{engine_data, ColorMode, Rect, Section}; /// A layer mask for [`WLayer`]. #[derive(Clone, Debug)] @@ -127,7 +128,11 @@ fn mode_channels(mode: ColorMode, p: [f32; 4]) -> Vec { ColorMode::Cmyk => { // Stored values are inverted ink amounts: k = max, c = r / max (reader: r = c * k). let m = p[0].max(p[1]).max(p[2]); - if m <= 0.0 { vec![0.0, 0.0, 0.0, 0.0] } else { vec![p[0] / m, p[1] / m, p[2] / m, m] } + if m <= 0.0 { + vec![0.0, 0.0, 0.0, 0.0] + } else { + vec![p[0] / m, p[1] / m, p[2] / m, m] + } } ColorMode::Grayscale => vec![p[0]], _ => vec![p[0], p[1], p[2]], @@ -137,7 +142,9 @@ fn mode_channels(mode: ColorMode, p: [f32; 4]) -> Vec { fn encode_samples(v: &[f32], depth: u16) -> Vec { let mut out = Vec::with_capacity(v.len() * usize::from(depth.div_ceil(8))); for &x in v { - let x = x.clamp(0.0, 1.0); + // Integer depths are stored in 0..1. 32-bit documents keep finite samples + // outside that range (HDR); NaN and infinities use the reader's mapping. + let x = if depth == 32 { finite_sample(x) } else { x.clamp(0.0, 1.0) }; if depth == 32 { out.extend_from_slice(&x.to_be_bytes()); } else if depth == 16 { @@ -151,7 +158,11 @@ fn encode_samples(v: &[f32], depth: u16) -> Vec { /// The layer and merged-image compression of `doc`. fn compression(doc: &WDoc) -> Compression { - if doc.rle { Compression::Rle } else { Compression::Raw } + if doc.rle { + Compression::Rle + } else { + Compression::Raw + } } /// One channel of a `w`×`h` plane, encoded by craft-psd. An empty plane is written raw. From 7311b6574cfb9e916812bfca9b93c4472fb768b7 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:30:21 +0100 Subject: [PATCH 85/99] psd: rustfmt write.rs to the workspace style The previous commit had been formatted without rustfmt.toml (use_small_heuristics = "Max"), so cargo fmt --check failed on the gate. --- crates/psd/src/write.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/psd/src/write.rs b/crates/psd/src/write.rs index 6f77ad438..e5ec285b8 100644 --- a/crates/psd/src/write.rs +++ b/crates/psd/src/write.rs @@ -10,9 +10,9 @@ use craft_psd::{ BlendMode, BlendingRanges, ChannelData, Compression, GlobalLayerMask, Header, ImageData, LayerFlags, LayerInfoPlacement, MaskData, PsdFile, Version, }; -use crate::descriptor::{self, put_u16, put_u32, put_utf16, DValue, Descriptor}; +use crate::descriptor::{self, DValue, Descriptor, put_u16, put_u32, put_utf16}; use crate::limits::finite_sample; -use crate::{engine_data, ColorMode, Rect, Section}; +use crate::{ColorMode, Rect, Section, engine_data}; /// A layer mask for [`WLayer`]. #[derive(Clone, Debug)] @@ -128,11 +128,7 @@ fn mode_channels(mode: ColorMode, p: [f32; 4]) -> Vec { ColorMode::Cmyk => { // Stored values are inverted ink amounts: k = max, c = r / max (reader: r = c * k). let m = p[0].max(p[1]).max(p[2]); - if m <= 0.0 { - vec![0.0, 0.0, 0.0, 0.0] - } else { - vec![p[0] / m, p[1] / m, p[2] / m, m] - } + if m <= 0.0 { vec![0.0, 0.0, 0.0, 0.0] } else { vec![p[0] / m, p[1] / m, p[2] / m, m] } } ColorMode::Grayscale => vec![p[0]], _ => vec![p[0], p[1], p[2]], @@ -158,11 +154,7 @@ fn encode_samples(v: &[f32], depth: u16) -> Vec { /// The layer and merged-image compression of `doc`. fn compression(doc: &WDoc) -> Compression { - if doc.rle { - Compression::Rle - } else { - Compression::Raw - } + if doc.rle { Compression::Rle } else { Compression::Raw } } /// One channel of a `w`×`h` plane, encoded by craft-psd. An empty plane is written raw. From ddebf3d71ab90809b3617a786ee86d2448a0328e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 08:17:16 -0500 Subject: [PATCH 86/99] refactor(interchange): stage coherent Film dependency refresh for shared formats --- Cargo.lock | 979 ++++++++++++++++++++++++++++++++++++++++------------- Cargo.toml | 16 +- 2 files changed, 749 insertions(+), 246 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae7f294a7..83cba5a3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aligned" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4508988c62edf04abd8d92897fca0c2995d907ce1dfeaf369dac3716a40685" +dependencies = [ + "as-slice", +] + [[package]] name = "aligned-vec" version = "0.6.4" @@ -215,6 +224,18 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "arbitrary" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed" + [[package]] name = "arboard" version = "3.6.1" @@ -236,6 +257,17 @@ dependencies = [ "x11rb", ] +[[package]] +name = "arg_enum_proc_macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -257,6 +289,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b" +[[package]] +name = "as-slice" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516" +dependencies = [ + "stable_deref_trait", +] + [[package]] name = "ash" version = "0.38.0+1.3.281" @@ -446,6 +487,40 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "av-scenechange" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f321d77c20e19b92c39e7471cf986812cbb46659d2af674adc4331ef3f18394" +dependencies = [ + "aligned", + "anyhow", + "arg_enum_proc_macro", + "arrayvec", + "log", + "num-rational", + "num-traits", + "pastey 0.1.1", + "rayon", + "thiserror 2.0.21", + "v_frame", + "y4m", +] + +[[package]] +name = "av1-grain" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfddb07216410377231960af4fcab838eaa12e013417781b78bd95ee22077f8" +dependencies = [ + "anyhow", + "arrayvec", + "log", + "nom", + "num-rational", + "v_frame", +] + [[package]] name = "base64" version = "0.23.1" @@ -504,6 +579,15 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "bitstream-io" +version = "4.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eff00be299a18769011411c9def0d827e8f2d7bf0c3dbf53633147a8867fd1f" +dependencies = [ + "no_std_io2", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -555,7 +639,7 @@ dependencies = [ "boa_macros", "boa_string", "indexmap", - "num-bigint", + "num-bigint 0.5.1", "rustc-hash 2.1.3", "strum", ] @@ -589,13 +673,13 @@ dependencies = [ "icu_normalizer", "indexmap", "intrusive-collections", - "itertools", - "num-bigint", + "itertools 0.15.0", + "num-bigint 0.5.1", "num-integer", "num-traits", "num_enum", "oneshot", - "pastey", + "pastey 0.2.3", "portable-atomic", "rand 0.10.3", "regress", @@ -668,7 +752,7 @@ dependencies = [ "boa_macros", "fast-float2", "icu_properties", - "num-bigint", + "num-bigint 0.5.1", "num-traits", "regress", "rustc-hash 2.1.3", @@ -682,7 +766,7 @@ checksum = "30bf86c2bcff5bf2547acbfc516c5d3108ca527cb131511d749bf6fbef762c0e" dependencies = [ "fast-float2", "itoa", - "pastey", + "pastey 0.2.3", "rustc-hash 2.1.3", "ryu-js", "static_assertions", @@ -722,6 +806,12 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "built" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0e531d93d39c34eef561e929e8a7f86d77a5af08aac4f6d6e39976c51858e9" + [[package]] name = "bumpalo" version = "3.20.3" @@ -1114,6 +1204,17 @@ dependencies = [ "libc", ] +[[package]] +name = "craft-aaf" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" +dependencies = [ + "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d)", + "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d)", + "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d)", + "thiserror 2.0.21", +] + [[package]] name = "craft-aep" version = "0.1.0" @@ -1128,6 +1229,40 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-audio" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +dependencies = [ + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "log", + "rayon", + "symphonia 0.6.1", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-audio" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" +dependencies = [ + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d)", + "log", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-cfb" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=7f3fdc0dfebd03f33a241f91f916e9a78d3e5c93#7f3fdc0dfebd03f33a241f91f916e9a78d3e5c93" + +[[package]] +name = "craft-cfb" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" + [[package]] name = "craft-cms" version = "0.1.0" @@ -1169,6 +1304,14 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-dpx" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-ecproj-format" version = "0.1.0" @@ -1238,7 +1381,7 @@ name = "craft-image-codecs" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" dependencies = [ - "craft-jpeg", + "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "craft-metadata", "crc32fast", "exr", @@ -1266,6 +1409,14 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-jpeg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=937ac93c5cf3cd4b6a81e195b078fe161eb081b9#937ac93c5cf3cd4b6a81e195b078fe161eb081b9" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-lottie" version = "0.1.0" @@ -1287,7 +1438,16 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4#f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +dependencies = [ + "chrono", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-media" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" dependencies = [ "thiserror 2.0.21", ] @@ -1308,7 +1468,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c dependencies = [ "brotli-decompressor", "chrono", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "quick-xml 0.41.0", "serde", ] @@ -1378,13 +1538,24 @@ dependencies = [ "objc2-app-kit 0.3.2", ] +[[package]] +name = "craft-raw" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=7738cc6c689060475cb6947a6e3db6ed78fb3419#7738cc6c689060475cb6947a6e3db6ed78fb3419" +dependencies = [ + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7738cc6c689060475cb6947a6e3db6ed78fb3419)", + "rayon", + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-svg" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" dependencies = [ "craft-image-codecs", - "craft-xml", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "flate2", "kurbo", "quick-xml 0.41.0", @@ -1394,6 +1565,23 @@ dependencies = [ "vectorcraft-pathops", ] +[[package]] +name = "craft-tga" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +dependencies = [ + "thiserror 2.0.21", +] + +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=0eaafeb5054f2113523c8844822a830865cf45f2#0eaafeb5054f2113523c8844822a830865cf45f2" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-tiff" version = "0.1.0" @@ -1403,6 +1591,52 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=7738cc6c689060475cb6947a6e3db6ed78fb3419#7738cc6c689060475cb6947a6e3db6ed78fb3419" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-time" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-time" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-timeline" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +dependencies = [ + "craft-time 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", + "serde", + "serde_json", +] + +[[package]] +name = "craft-timeline" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" +dependencies = [ + "craft-time 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d)", +] + [[package]] name = "craft-ui" version = "0.1.0" @@ -1472,6 +1706,17 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-video" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +dependencies = [ + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "rav1e", + "rayon", + "thiserror 2.0.21", +] + [[package]] name = "craft-webp" version = "0.1.0" @@ -1481,6 +1726,16 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +dependencies = [ + "quick-xml 0.41.0", + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-xml" version = "0.1.0" @@ -1491,6 +1746,34 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +dependencies = [ + "quick-xml 0.41.0", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" +dependencies = [ + "quick-xml 0.41.0", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-y4m" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=25c7a8959cf70cf8c3f076d05baadb0990710569#25c7a8959cf70cf8c3f076d05baadb0990710569" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-zip" version = "0.1.0" @@ -1862,10 +2145,10 @@ dependencies = [ name = "effectcraft-export" version = "0.24.1" dependencies = [ - "craft-audio", + "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "craft-gif", "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", - "craft-video", + "craft-video 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "effectcraft-color", "effectcraft-effects", "effectcraft-keyframe", @@ -2025,9 +2308,9 @@ dependencies = [ name = "effectcraft-media" version = "0.24.1" dependencies = [ - "craft-audio", + "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "craft-docpath", - "craft-dpx", + "craft-dpx 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", "craft-exr", "craft-gif", "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", @@ -2370,7 +2653,7 @@ dependencies = [ "bitflags 2.13.2", "emath", "epaint", - "itertools", + "itertools 0.15.0", "log", "nohash-hasher", "profiling", @@ -2432,7 +2715,7 @@ dependencies = [ "ahash", "egui", "enum-map", - "itertools", + "itertools 0.15.0", "log", "profiling", ] @@ -2722,129 +3005,70 @@ dependencies = [ "libc", ] -[[package]] -name = "filmcraft-aac" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-ac3" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-apv" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "rayon", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-av1" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "rayon", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-avi" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" - [[package]] name = "filmcraft-bitstream" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] [[package]] name = "filmcraft-cfb" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +dependencies = [ + "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7f3fdc0dfebd03f33a241f91f916e9a78d3e5c93)", +] [[package]] name = "filmcraft-codecs" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ - "filmcraft-aac", - "filmcraft-ac3", - "filmcraft-apv", - "filmcraft-av1", - "filmcraft-avi", + "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=937ac93c5cf3cd4b6a81e195b078fe161eb081b9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-video 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-y4m", "filmcraft-bitstream", "filmcraft-color", - "filmcraft-dnx", "filmcraft-frame", - "filmcraft-h264", - "filmcraft-hevc", "filmcraft-isobmff", "filmcraft-matroska", "filmcraft-media", - "filmcraft-mpa", - "filmcraft-mpeg2v", - "filmcraft-mpegts", - "filmcraft-mxf", - "filmcraft-ogg", - "filmcraft-opus", - "filmcraft-prores", "filmcraft-time", - "filmcraft-vp8", - "filmcraft-vp9", - "image", "log", "rayon", - "symphonia", + "symphonia 0.5.5", "thiserror 2.0.21", "web-time", ] [[package]] name = "filmcraft-color" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ "serde", ] [[package]] name = "filmcraft-dng" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ - "rayon", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-dnx" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", + "craft-raw", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0eaafeb5054f2113523c8844822a830865cf45f2)", + "image", "rayon", "thiserror 2.0.21", ] [[package]] name = "filmcraft-frame" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ "filmcraft-color", "filmcraft-time", @@ -2854,44 +3078,26 @@ dependencies = [ [[package]] name = "filmcraft-geom" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ "serde", ] -[[package]] -name = "filmcraft-h264" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "rayon", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-hevc" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "rayon", - "thiserror 2.0.21", -] - [[package]] name = "filmcraft-interchange" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ + "craft-aaf", + "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", "filmcraft-cfb", "filmcraft-color", "filmcraft-geom", "filmcraft-media", "filmcraft-project", "filmcraft-time", - "roxmltree", "serde", "serde_json", "thiserror 2.0.21", @@ -2899,25 +3105,29 @@ dependencies = [ [[package]] name = "filmcraft-isobmff" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] [[package]] name = "filmcraft-matroska" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0ad6c1e1d297908915f4be315b0fcfc9be7b5d4)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] [[package]] name = "filmcraft-media" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ + "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-dpx 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", + "craft-tga", "filmcraft-color", "filmcraft-dng", "filmcraft-frame", @@ -2928,54 +3138,10 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "filmcraft-mpa" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-mpeg2v" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "rayon", - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-mpegts" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-mxf" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "chrono", -] - -[[package]] -name = "filmcraft-ogg" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" - -[[package]] -name = "filmcraft-opus" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" - [[package]] name = "filmcraft-project" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ "filmcraft-color", "filmcraft-geom", @@ -2984,42 +3150,15 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-prores" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "rayon", - "thiserror 2.0.21", + "url", ] [[package]] name = "filmcraft-time" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" +version = "0.20.1" +source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" dependencies = [ - "serde", -] - -[[package]] -name = "filmcraft-vp8" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "thiserror 2.0.21", -] - -[[package]] -name = "filmcraft-vp9" -version = "0.12.0" -source = "git+https://github.com/storytold/filmcraft?rev=d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5#d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" -dependencies = [ - "filmcraft-bitstream", - "rayon", - "thiserror 2.0.21", + "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", ] [[package]] @@ -3899,12 +4038,32 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "interpolate_name" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "intrusive-collections" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4275b20e6057cd7733fd8df8a5a31701e4fe44497dad0f3fa0e1c4fb971506be" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.15.0" @@ -4095,6 +4254,16 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +[[package]] +name = "libfuzzer-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2" +dependencies = [ + "arbitrary", + "cc", +] + [[package]] name = "libloading" version = "0.8.9" @@ -4209,6 +4378,16 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "maybe-rayon" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" +dependencies = [ + "cfg-if", + "rayon", +] + [[package]] name = "md-5" version = "0.10.6" @@ -4391,6 +4570,12 @@ dependencies = [ "jni-sys 0.3.1", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + [[package]] name = "nix" version = "0.31.3" @@ -4403,6 +4588,15 @@ dependencies = [ "libc", ] +[[package]] +name = "no_std_io2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418abd1b6d34fbf6cae440dc874771b0525a604428704c76e48b29a5e67b8003" +dependencies = [ + "memchr", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -4418,6 +4612,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "noop_proc_macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" + [[package]] name = "ntapi" version = "0.4.3" @@ -4436,6 +4636,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.5.1" @@ -4483,6 +4693,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint 0.4.8", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -4990,6 +5211,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pastey" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec" + [[package]] name = "pastey" version = "0.2.3" @@ -5271,6 +5498,19 @@ name = "profiling" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5" +dependencies = [ + "profiling-procmacros", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4488a4a36b9a4ba6b9334a32a39971f77c1436ec82c38707bce707699cc3bbcb" +dependencies = [ + "quote", + "syn 2.0.119", +] [[package]] name = "proptest" @@ -5452,6 +5692,40 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca45419789ae5a7899559e9512e58ca889e41f04f1f2445e9f4b290ceccd1d08" +[[package]] +name = "rav1e" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b6dd56e85d9483277cde964fd1bdb0428de4fec5ebba7540995639a21cb32b" +dependencies = [ + "aligned-vec", + "arbitrary", + "arg_enum_proc_macro", + "arrayvec", + "av-scenechange", + "av1-grain", + "bitstream-io", + "built", + "cfg-if", + "interpolate_name", + "itertools 0.14.0", + "libc", + "libfuzzer-sys", + "log", + "maybe-rayon", + "new_debug_unreachable", + "noop_proc_macro", + "num-derive", + "num-traits", + "paste", + "profiling", + "rand 0.9.5", + "rand_chacha", + "simd_helpers", + "thiserror 2.0.21", + "v_frame", +] + [[package]] name = "raw-cpuid" version = "11.6.0" @@ -5560,6 +5834,12 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "regex-lite" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" + [[package]] name = "regex-syntax" version = "0.8.11" @@ -5991,6 +6271,15 @@ dependencies = [ "simdutf8", ] +[[package]] +name = "simd_helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6" +dependencies = [ + "quote", +] + [[package]] name = "simdutf8" version = "0.1.5" @@ -6226,17 +6515,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5773a4c030a19d9bfaa090f49746ff35c75dfddfa700df7a5939d5e076a57039" dependencies = [ "lazy_static", - "symphonia-bundle-flac", - "symphonia-bundle-mp3", - "symphonia-codec-aac", - "symphonia-codec-alac", - "symphonia-codec-pcm", - "symphonia-codec-vorbis", - "symphonia-core", - "symphonia-format-isomp4", - "symphonia-format-ogg", - "symphonia-format-riff", - "symphonia-metadata", + "symphonia-bundle-flac 0.5.5", + "symphonia-bundle-mp3 0.5.5", + "symphonia-codec-aac 0.5.5", + "symphonia-codec-alac 0.5.5", + "symphonia-codec-pcm 0.5.5", + "symphonia-codec-vorbis 0.5.5", + "symphonia-core 0.5.5", + "symphonia-format-isomp4 0.5.5", + "symphonia-format-ogg 0.5.5", + "symphonia-format-riff 0.5.5", + "symphonia-metadata 0.5.5", +] + +[[package]] +name = "symphonia" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7edef6a96b696d4e0cab5ee9ebb7ca155ed95f30a6b45bbb8b97d2727f02424" +dependencies = [ + "lazy_static", + "symphonia-bundle-flac 0.6.1", + "symphonia-bundle-mp3 0.6.1", + "symphonia-codec-aac 0.6.1", + "symphonia-codec-adpcm", + "symphonia-codec-alac 0.6.1", + "symphonia-codec-pcm 0.6.1", + "symphonia-codec-vorbis 0.6.1", + "symphonia-core 0.6.1", + "symphonia-format-caf", + "symphonia-format-isomp4 0.6.1", + "symphonia-format-mkv", + "symphonia-format-ogg 0.6.1", + "symphonia-format-riff 0.6.1", + "symphonia-metadata 0.6.1", ] [[package]] @@ -6246,11 +6558,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c91565e180aea25d9b80a910c546802526ffd0072d0b8974e3ebe59b686c9976" dependencies = [ "log", - "symphonia-core", - "symphonia-metadata", + "symphonia-core 0.5.5", + "symphonia-metadata 0.5.5", "symphonia-utils-xiph", ] +[[package]] +name = "symphonia-bundle-flac" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6405d5c34ff6f8f7ca08a4101efe66d21e180f7322ef9359900a0e55698a7892" +dependencies = [ + "log", + "symphonia-common", + "symphonia-core 0.6.1", + "symphonia-metadata 0.6.1", +] + [[package]] name = "symphonia-bundle-mp3" version = "0.5.5" @@ -6259,8 +6583,19 @@ checksum = "4872dd6bb56bf5eac799e3e957aa1981086c3e613b27e0ac23b176054f7c57ed" dependencies = [ "lazy_static", "log", - "symphonia-core", - "symphonia-metadata", + "symphonia-core 0.5.5", + "symphonia-metadata 0.5.5", +] + +[[package]] +name = "symphonia-bundle-mp3" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98ea5ffc8716bff677dfb3b01b420c7b758de901a72b8c330bf2040ab74b4add" +dependencies = [ + "lazy_static", + "log", + "symphonia-core 0.6.1", ] [[package]] @@ -6271,7 +6606,29 @@ checksum = "4c263845aa86881416849c1729a54c7f55164f8b96111dba59de46849e73a790" dependencies = [ "lazy_static", "log", - "symphonia-core", + "symphonia-core 0.5.5", +] + +[[package]] +name = "symphonia-codec-aac" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5bf8e39552d34a3c4c98333370e62f48c92456d2e814f273b5c3ad7c4a5f45c" +dependencies = [ + "lazy_static", + "log", + "symphonia-common", + "symphonia-core 0.6.1", +] + +[[package]] +name = "symphonia-codec-adpcm" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445932ecb0c59362fde9c082dd63a75380650c5077fdb8b80b8cac850442a74c" +dependencies = [ + "log", + "symphonia-core 0.6.1", ] [[package]] @@ -6281,7 +6638,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8413fa754942ac16a73634c9dfd1500ed5c61430956b33728567f667fdd393ab" dependencies = [ "log", - "symphonia-core", + "symphonia-core 0.5.5", +] + +[[package]] +name = "symphonia-codec-alac" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "920a78f96f3cf62932d0c497959c0cc2100ef36b03c7ca1417b260f432a482d8" +dependencies = [ + "log", + "symphonia-common", + "symphonia-core 0.6.1", ] [[package]] @@ -6291,7 +6659,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e89d716c01541ad3ebe7c91ce4c8d38a7cf266a3f7b2f090b108fb0cb031d95" dependencies = [ "log", - "symphonia-core", + "symphonia-core 0.5.5", +] + +[[package]] +name = "symphonia-codec-pcm" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04ba75686acbe43542fdd374571195f0530c0b7785ca25cc6840e9c6c4b6eea" +dependencies = [ + "log", + "symphonia-core 0.6.1", ] [[package]] @@ -6301,10 +6679,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f025837c309cd69ffef572750b4a2257b59552c5399a5e49707cc5b1b85d1c73" dependencies = [ "log", - "symphonia-core", + "symphonia-core 0.5.5", "symphonia-utils-xiph", ] +[[package]] +name = "symphonia-codec-vorbis" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73d90b4fcf796137cc683c538282804ff9629f8ad9dbfd881fcbba331ac4e986" +dependencies = [ + "log", + "symphonia-common", + "symphonia-core 0.6.1", +] + +[[package]] +name = "symphonia-common" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acc3fcc18ec9b8cdd48614e259c4cf0d27b71d41e5d9b120b42c5adab12d7c4" +dependencies = [ + "log", + "symphonia-core 0.6.1", + "symphonia-metadata 0.6.1", +] + [[package]] name = "symphonia-core" version = "0.5.5" @@ -6318,6 +6718,31 @@ dependencies = [ "log", ] +[[package]] +name = "symphonia-core" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c412864d599d4750d0c3d684d7e093ec05e5309681ef5252cc1096a437f6e0" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "lazy_static", + "log", + "num-complex", + "smallvec", +] + +[[package]] +name = "symphonia-format-caf" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab64327ee1920531c5bf86cf7e9cd1a599d57013ddc30691da62683cefc65191" +dependencies = [ + "log", + "symphonia-common", + "symphonia-core 0.6.1", +] + [[package]] name = "symphonia-format-isomp4" version = "0.5.5" @@ -6326,11 +6751,35 @@ checksum = "243739585d11f81daf8dac8d9f3d18cc7898f6c09a259675fc364b382c30e0a5" dependencies = [ "encoding_rs", "log", - "symphonia-core", - "symphonia-metadata", + "symphonia-core 0.5.5", + "symphonia-metadata 0.5.5", "symphonia-utils-xiph", ] +[[package]] +name = "symphonia-format-isomp4" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e681a70e1870d34e02abf1dbc51e4267c3f1827801474e8870be8c689fc4dc3" +dependencies = [ + "log", + "symphonia-common", + "symphonia-core 0.6.1", + "symphonia-metadata 0.6.1", +] + +[[package]] +name = "symphonia-format-mkv" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d015c5c0558864665894b3f4cbd95e10abb01b9c868e751c72670f326a56360e" +dependencies = [ + "lazy_static", + "log", + "symphonia-common", + "symphonia-core 0.6.1", +] + [[package]] name = "symphonia-format-ogg" version = "0.5.5" @@ -6338,11 +6787,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b4955c67c1ed3aa8ae8428d04ca8397fbef6a19b2b051e73b5da8b1435639cb" dependencies = [ "log", - "symphonia-core", - "symphonia-metadata", + "symphonia-core 0.5.5", + "symphonia-metadata 0.5.5", "symphonia-utils-xiph", ] +[[package]] +name = "symphonia-format-ogg" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5495e7f7e3c7035328d82b6d6e377eef289bb0c4105bdeb557fc93a833f994" +dependencies = [ + "log", + "symphonia-common", + "symphonia-core 0.6.1", + "symphonia-metadata 0.6.1", +] + [[package]] name = "symphonia-format-riff" version = "0.5.5" @@ -6351,8 +6812,20 @@ checksum = "c2d7c3df0e7d94efb68401d81906eae73c02b40d5ec1a141962c592d0f11a96f" dependencies = [ "extended", "log", - "symphonia-core", - "symphonia-metadata", + "symphonia-core 0.5.5", + "symphonia-metadata 0.5.5", +] + +[[package]] +name = "symphonia-format-riff" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff70929083a8c1a5f6cd7c904b6071c7914ad04739b510c2f7239dfc9b7dabe" +dependencies = [ + "extended", + "log", + "symphonia-core 0.6.1", + "symphonia-metadata 0.6.1", ] [[package]] @@ -6364,7 +6837,20 @@ dependencies = [ "encoding_rs", "lazy_static", "log", - "symphonia-core", + "symphonia-core 0.5.5", +] + +[[package]] +name = "symphonia-metadata" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83713a97705d77bdef7cdbc0768fd6e5a54e4cd7e48d60a806ae85639e2c87c6" +dependencies = [ + "lazy_static", + "log", + "regex-lite", + "smallvec", + "symphonia-core 0.6.1", ] [[package]] @@ -6373,8 +6859,8 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27c85ab799a338446b68eec77abf42e1a6f1bb490656e121c6e27bfbab9f16" dependencies = [ - "symphonia-core", - "symphonia-metadata", + "symphonia-core 0.5.5", + "symphonia-metadata 0.5.5", ] [[package]] @@ -6928,6 +7414,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "v_frame" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "666b7727c8875d6ab5db9533418d7c764233ac9c0cff1d469aec8fa127597be2" +dependencies = [ + "aligned-vec", + "num-traits", + "wasm-bindgen", +] + [[package]] name = "vectorcraft-geom" version = "0.18.0" @@ -8209,6 +8706,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "y4m" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448" + [[package]] name = "yoke" version = "0.8.3" diff --git a/Cargo.toml b/Cargo.toml index 21f47439c..b4d81bc21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,15 +98,15 @@ craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-lib # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. -filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } +filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } # timeline interchange (EDL, FCP7 XML, FCPXML, OTIO) for Premiere Pro interop (crates/interchange only) -filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-geom = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } +filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-geom = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } # gpu (the same wgpu eframe / egui-wgpu use) wgpu = { version = "30.0.1", features = ["fragile-send-sync-non-atomic-wasm"] } From cb29f77eafbe804d8421e1d7537e5332de40ccab Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 08:42:06 -0500 Subject: [PATCH 87/99] interchange: adapt export to current Film media and marker APIs --- crates/interchange/src/export.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/interchange/src/export.rs b/crates/interchange/src/export.rs index fd396b00b..371c3a3d3 100644 --- a/crates/interchange/src/export.rs +++ b/crates/interchange/src/export.rs @@ -365,7 +365,7 @@ impl Exporter<'_> { let mut clip = media_clip(fp::MediaRef::File { path: path.clone() }, info); clip.offline = f.missing; let bin = self.bin(it.and_then(|i| i.parent)); - let id = self.fp.add_item(&name, fp::Label::Iris, fp::ItemKind::Media(clip), bin); + let id = self.fp.add_item(&name, fp::Label::Iris, fp::ItemKind::Media(Box::new(clip)), bin); self.media.insert(path, id); id } @@ -384,7 +384,7 @@ impl Exporter<'_> { Some(b) } }; - let id = self.fp.add_item(name, fp::Label::Violet, fp::ItemKind::Media(clip), bin); + let id = self.fp.add_item(name, fp::Label::Violet, fp::ItemKind::Media(Box::new(clip)), bin); self.media.insert(r.path.clone(), id); id } @@ -405,7 +405,7 @@ impl Exporter<'_> { ); let clip = media_clip(fp::MediaRef::Generator(Generator::ColorMatte { color: [color[0], color[1], color[2], 1.0] }), info); let bin = self.bin(it.and_then(|i| i.parent)); - let id = self.fp.add_item(&name, fp::Label::Rose, fp::ItemKind::Media(clip), bin); + let id = self.fp.add_item(&name, fp::Label::Rose, fp::ItemKind::Media(Box::new(clip)), bin); self.media.insert(key, id); id } @@ -540,6 +540,9 @@ impl Exporter<'_> { comment: if m.chapter.is_empty() { String::new() } else { m.comment.clone() }, kind: if m.chapter.is_empty() { fp::MarkerKind::Comment } else { fp::MarkerKind::Chapter }, color: fp::Label::Green, + custom_color: None, + author: String::new(), + url: m.url.clone(), }) .collect(); if let Some(seq) = self.fp.sequence_mut(sid) { @@ -733,6 +736,7 @@ fn media_info(name: &str, kind: MediaKind, duration: Tick, video: Option fp::MediaClip { mod tests { use super::*; + #[test] + fn synthesized_video_metadata_does_not_claim_an_inferred_color_profile() { + let info = media_info("clip", MediaKind::Video, Tick::ZERO, Some((1920, 1080, FrameRate::new(24, 1), 1.0, "raw".into(), true)), false); + let video = info.video.unwrap(); + assert_eq!((video.width, video.height), (1920, 1080)); + assert!(video.color_assumed.is_none()); + assert!(video.has_alpha); + } + /// A folder's bin is the same one each time it is asked for (a cached folder once answered /// `None`, so a folder's second item went to the project root); a non-item has no bin. #[test] From ed8811d2d8a1282b3b93ca7f113a8673749498c4 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:55:09 +0100 Subject: [PATCH 88/99] psd: parse linked files with craft-psd and pin past #1845 Repin only craft-psd to craft-libs main e836b6fd (includes #1845). lnk2 / lnkD / lnk3 / lnkE records come from craft_psd::smart::linked_files; payload ranges are shifted from the block back into the document bytes. is_linked_layer_key is the deferral predicate. Descriptors, placed objects, and pixel decode stay local until craft-libs#1887 (parse_prefix) and #1885 (PackBits recovery) are on main. --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/psd/src/parse.rs | 55 +++++------------------------------------ 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae7f294a7..1284590d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1359,7 +1359,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" +source = "git+https://github.com/storytold/craft-libs?rev=e836b6fd893eca3fbe5880f000dbf446c3a32fcc#e836b6fd893eca3fbe5880f000dbf446c3a32fcc" dependencies = [ "encoding_rs", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 21f47439c..0ed32db9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs" craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e836b6fd893eca3fbe5880f000dbf446c3a32fcc" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } diff --git a/crates/psd/src/parse.rs b/crates/psd/src/parse.rs index 39b9ea989..3f70a67b5 100644 --- a/crates/psd/src/parse.rs +++ b/crates/psd/src/parse.rs @@ -128,55 +128,12 @@ impl Psd { /// Linked layer data records (spec: "Linked Layer"): length, kind (`liFD` embedded data, /// `liFE` external file, `liFA` alias), version, unique id, original file name, type, /// creator, data length, optional descriptors, then the data. A damaged record ends the list. + /// Ranges in [`LinkedFile::data`] are in the document bytes (`self.data`); craft-psd reports + /// them relative to the block, so the block's start is added back. fn linked_files(&mut self, data: &[u8], start: usize, end: usize) { - let mut pos = start; - while pos + 8 <= end { - let mut r = Reader::at(&data[..end], pos); - let Ok(len) = r.u64() else { break }; - let body = r.pos; - let Some(rec_end) = body.checked_add(len as usize).filter(|e| *e <= end) else { break }; - let mut r = Reader::at(&data[..rec_end], body); - let rec = (|| -> Result { - let kind = r.tag()?; - let version = r.u32()?; - let n = r.u8()? as usize; - let uuid = String::from_utf8_lossy(r.bytes(n)?).into_owned(); - let name = descriptor::read_unicode(&mut r)?; - let file_type = String::from_utf8_lossy(&r.tag()?).trim().to_string(); - let _creator = r.tag()?; - let dlen = r.u64()? as usize; - if r.u8()? != 0 { - let _v = r.u32()?; - descriptor::read_descriptor(&mut r)?; - } - let mut out = LinkedFile { uuid, name, file_type, data: None }; - match &kind { - b"liFD" => { - let s = r.pos; - r.skip(dlen)?; - out.data = Some(s..s + dlen); - } - b"liFE" => { - let _v = r.u32()?; - descriptor::read_descriptor(&mut r)?; - if version > 3 { - r.skip(4 + 4 + 8)?; - } - let _size = r.u64()?; - if version > 2 && r.remaining() >= dlen && dlen > 0 { - let s = r.pos; - out.data = Some(s..s + dlen); - } - } - _ => {} - } - Ok(out) - })(); - match rec { - Ok(f) => self.linked.push(f), - Err(_) => break, - } - pos = rec_end.div_ceil(4) * 4; + let Some(block) = data.get(start..end) else { return }; + for f in craft_psd::smart::linked_files(block) { + self.linked.push(LinkedFile { uuid: f.uuid, name: f.name, file_type: f.file_type, data: f.data.map(|r| (start + r.start)..(start + r.end)) }); } } @@ -429,7 +386,7 @@ fn flattened(data: &[u8]) -> Option<(craft_psd::Header, Vec, usize)> { /// Linked-file blocks can be most of a file: leave them in the source, read in place. fn linked(key: &[u8; 4], _len: u64) -> bool { - matches!(key, b"lnk2" | b"lnkD" | b"lnk3" | b"lnkE") + craft_psd::smart::is_linked_layer_key(key) } /// Reads `data` with craft-psd. Where that loses what the old reader kept, it reads a copy with From adb120c32768637a53a519b1a6e3bfaead6bc0c4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 09:41:59 -0500 Subject: [PATCH 89/99] interchange: update test fixtures and adopt merged shared AAF route --- Cargo.lock | 46 +++++++++++------------- Cargo.toml | 16 ++++----- crates/host/tests/it/timeline_interop.rs | 3 +- crates/interchange/src/export.rs | 2 +- crates/interchange/src/tests.rs | 3 +- 5 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83cba5a3f..a38c653da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1541,12 +1541,15 @@ dependencies = [ [[package]] name = "craft-raw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=7738cc6c689060475cb6947a6e3db6ed78fb3419#7738cc6c689060475cb6947a6e3db6ed78fb3419" +source = "git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe#402dfe46ad568a97f660bcbe30e3a80429b9e1fe" dependencies = [ - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7738cc6c689060475cb6947a6e3db6ed78fb3419)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe)", + "miniz_oxide 0.9.1", "rayon", "serde", "thiserror 2.0.21", + "zune-core", + "zune-jpeg", ] [[package]] @@ -1576,7 +1579,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=0eaafeb5054f2113523c8844822a830865cf45f2#0eaafeb5054f2113523c8844822a830865cf45f2" +source = "git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe#402dfe46ad568a97f660bcbe30e3a80429b9e1fe" dependencies = [ "serde", "thiserror 2.0.21", @@ -1591,15 +1594,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-tiff" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=7738cc6c689060475cb6947a6e3db6ed78fb3419#7738cc6c689060475cb6947a6e3db6ed78fb3419" -dependencies = [ - "serde", - "thiserror 2.0.21", -] - [[package]] name = "craft-time" version = "0.1.0" @@ -3008,7 +3002,7 @@ dependencies = [ [[package]] name = "filmcraft-bitstream" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] @@ -3016,7 +3010,7 @@ dependencies = [ [[package]] name = "filmcraft-cfb" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7f3fdc0dfebd03f33a241f91f916e9a78d3e5c93)", ] @@ -3024,7 +3018,7 @@ dependencies = [ [[package]] name = "filmcraft-codecs" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=937ac93c5cf3cd4b6a81e195b078fe161eb081b9)", @@ -3048,7 +3042,7 @@ dependencies = [ [[package]] name = "filmcraft-color" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "serde", ] @@ -3056,10 +3050,10 @@ dependencies = [ [[package]] name = "filmcraft-dng" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-raw", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0eaafeb5054f2113523c8844822a830865cf45f2)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe)", "image", "rayon", "thiserror 2.0.21", @@ -3068,7 +3062,7 @@ dependencies = [ [[package]] name = "filmcraft-frame" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "filmcraft-color", "filmcraft-time", @@ -3079,7 +3073,7 @@ dependencies = [ [[package]] name = "filmcraft-geom" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "serde", ] @@ -3087,7 +3081,7 @@ dependencies = [ [[package]] name = "filmcraft-interchange" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-aaf", "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", @@ -3106,7 +3100,7 @@ dependencies = [ [[package]] name = "filmcraft-isobmff" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] @@ -3114,7 +3108,7 @@ dependencies = [ [[package]] name = "filmcraft-matroska" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] @@ -3122,7 +3116,7 @@ dependencies = [ [[package]] name = "filmcraft-media" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", "craft-dpx 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", @@ -3141,7 +3135,7 @@ dependencies = [ [[package]] name = "filmcraft-project" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "filmcraft-color", "filmcraft-geom", @@ -3156,7 +3150,7 @@ dependencies = [ [[package]] name = "filmcraft-time" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=baeca9db89e54723a86e02e0e3a550e5ea2b16d2#baeca9db89e54723a86e02e0e3a550e5ea2b16d2" +source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" dependencies = [ "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", ] diff --git a/Cargo.toml b/Cargo.toml index b4d81bc21..6c0fc585d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,15 +98,15 @@ craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-lib # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. -filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } -filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } -filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } -filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } -filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } # timeline interchange (EDL, FCP7 XML, FCPXML, OTIO) for Premiere Pro interop (crates/interchange only) -filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } -filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } -filmcraft-geom = { git = "https://github.com/storytold/filmcraft", rev = "baeca9db89e54723a86e02e0e3a550e5ea2b16d2" } +filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-geom = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } # gpu (the same wgpu eframe / egui-wgpu use) wgpu = { version = "30.0.1", features = ["fragile-send-sync-non-atomic-wasm"] } diff --git a/crates/host/tests/it/timeline_interop.rs b/crates/host/tests/it/timeline_interop.rs index 9688a409f..8cdc2a4d1 100644 --- a/crates/host/tests/it/timeline_interop.rs +++ b/crates/host/tests/it/timeline_interop.rs @@ -54,6 +54,7 @@ fn still(p: &mut fp::Project, path: &str) -> fp::ItemId { codec: "png".into(), pixel_format: String::new(), color: Default::default(), + color_assumed: None, has_alpha: false, bitrate: None, hdr: None, @@ -75,7 +76,7 @@ fn still(p: &mut fp::Project, path: &str) -> fp::ItemId { identity: None, }; let name = path.rsplit('/').next().unwrap().to_string(); - p.add_item(&name, fp::Label::Iris, fp::ItemKind::Media(clip), None) + p.add_item(&name, fp::Label::Iris, fp::ItemKind::Media(Box::new(clip)), None) } /// V1: red for 2 s; V2: blue at 50 % opacity and 50 % scale; a cross dissolve from red to green diff --git a/crates/interchange/src/export.rs b/crates/interchange/src/export.rs index 371c3a3d3..69ab38aa4 100644 --- a/crates/interchange/src/export.rs +++ b/crates/interchange/src/export.rs @@ -761,7 +761,7 @@ mod tests { #[test] fn synthesized_video_metadata_does_not_claim_an_inferred_color_profile() { - let info = media_info("clip", MediaKind::Video, Tick::ZERO, Some((1920, 1080, FrameRate::new(24, 1), 1.0, "raw".into(), true)), false); + let info = media_info("clip", MediaKind::Movie, Tick::ZERO, Some((1920, 1080, FrameRate::new(24, 1), 1.0, "raw".into(), true)), false); let video = info.video.unwrap(); assert_eq!((video.width, video.height), (1920, 1080)); assert!(video.color_assumed.is_none()); diff --git a/crates/interchange/src/tests.rs b/crates/interchange/src/tests.rs index 4ce892c15..ec61c5848 100644 --- a/crates/interchange/src/tests.rs +++ b/crates/interchange/src/tests.rs @@ -34,6 +34,7 @@ fn info(kind: filmcraft_media::MediaKind, video: bool, audio: bool) -> filmcraft codec: "png".into(), pixel_format: String::new(), color: Default::default(), + color_assumed: None, has_alpha: false, bitrate: None, hdr: None, @@ -60,7 +61,7 @@ fn media(p: &mut fp::Project, name: &str, path: &str, kind: filmcraft_media::Med proxy: None, identity: None, }; - p.add_item(name, fp::Label::Iris, fp::ItemKind::Media(clip), bin) + p.add_item(name, fp::Label::Iris, fp::ItemKind::Media(Box::new(clip)), bin) } fn rate() -> filmcraft_time::FrameRate { From 9da73e9cf3e15cda59e732401c94dfe23e4c52f9 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 09:47:19 -0500 Subject: [PATCH 90/99] psd: delegate ZIP prediction reversal with budgeted scratch --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/psd/src/pixels.rs | 68 ++++++++++++++++--------------------- crates/psd/src/tests/opt.rs | 18 ++++++++++ 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1284590d6..5d5411483 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1359,7 +1359,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e836b6fd893eca3fbe5880f000dbf446c3a32fcc#e836b6fd893eca3fbe5880f000dbf446c3a32fcc" +source = "git+https://github.com/storytold/craft-libs?rev=c864e1e8c9e0f7e2c9f24fca1faa6f298a068bca#c864e1e8c9e0f7e2c9f24fca1faa6f298a068bca" dependencies = [ "encoding_rs", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 0ed32db9a..55ba9d0c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs" craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e836b6fd893eca3fbe5880f000dbf446c3a32fcc" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c864e1e8c9e0f7e2c9f24fca1faa6f298a068bca" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } diff --git a/crates/psd/src/pixels.rs b/crates/psd/src/pixels.rs index 4907e21f7..f9b7ca6f3 100644 --- a/crates/psd/src/pixels.rs +++ b/crates/psd/src/pixels.rs @@ -134,46 +134,36 @@ impl Psd { /// Undo ZIP prediction in place; the 32-bit scratch row is charged to `budget`. pub(crate) fn unpredict(&self, v: &mut [u8], w: usize, h: usize, budget: &mut Budget) -> Result<()> { - match self.depth { - 16 => { - for row in v.chunks_exact_mut(w * 2).take(h) { - let mut prev = 0u16; - for c in row.as_chunks_mut::<2>().0 { - let x = u16::from_be_bytes([c[0], c[1]]).wrapping_add(prev); - c.copy_from_slice(&x.to_be_bytes()); - prev = x; - } - } - } - 32 => { - // One scratch row for the whole plane, charged: a wide, short layer passes the - // decode's peak check and would otherwise allocate it on top. - let mut planar = budget.filled(w.checked_mul(4).ok_or_else(|| too_large(w, h))?, 0u8)?; - #[cfg(test)] - counters::bump(&counters::SCRATCH); - for row in v.chunks_exact_mut(w * 4).take(h) { - for i in 1..row.len() { - row[i] = row[i].wrapping_add(row[i - 1]); - } - // Bytes are stored plane by plane (all first bytes, then all second bytes…). - planar.copy_from_slice(row); - for x in 0..w { - for b in 0..4 { - row[x * 4 + b] = planar[b * w + x]; - } - } - } - budget.release(planar.len() as u64); - } - _ => { - for row in v.chunks_exact_mut(w).take(h) { - for i in 1..row.len() { - row[i] = row[i].wrapping_add(row[i - 1]); - } - } - } + // Preserve the reader's recovery behavior: decode only complete rows, at most h. + // The fallback depths historically used byte-wise prediction rather than packed bits. + let depth = match self.depth { + 16 => 16, + 32 => 32, + _ => 8, + }; + let rowb = w.checked_mul(usize::from(depth / 8)).ok_or_else(|| too_large(w, h))?; + if rowb == 0 { + return Ok(()); } - Ok(()) + let rows = (v.len() / rowb).min(h); + let layout = craft_psd::compression::PlaneLayout { + planes: 1, + width: w, + height: rows, + depth, + version: if self.psb { craft_psd::Version::Psb } else { craft_psd::Version::Psd }, + }; + let mut scratch = if depth == 32 { + let scratch = budget.filled(rowb, 0u8)?; + #[cfg(test)] + counters::bump(&counters::SCRATCH); + scratch + } else { + Vec::new() + }; + let result = craft_psd::compression::unpredict_with_scratch(&mut v[..rows * rowb], &layout, &mut scratch); + budget.release(scratch.len() as u64); + result.map_err(|e| Error::Invalid(e.to_string())) } /// Hand every sample of `raw` (`w`×`h`, row-major, in order) to `f` as a float. Samples a short diff --git a/crates/psd/src/tests/opt.rs b/crates/psd/src/tests/opt.rs index 241af0069..79e05a41b 100644 --- a/crates/psd/src/tests/opt.rs +++ b/crates/psd/src/tests/opt.rs @@ -650,3 +650,21 @@ fn placed_bake_solves_the_quad_once() { so.map([1.0, 1.0], 20.0, 10.0); assert_eq!(counters::take(&QUAD), 1); } + +#[test] +fn shared_unpredict_keeps_tail_bytes_and_refuses_unbudgeted_scratch() { + for depth in [8u16, 16, 32] { + let p = Psd { depth, ..base() }; + let (w, h) = (3, 2); + let row = w * usize::from(depth / 8); + let mut actual: Vec = (0..row * 3 + 1).map(|i| (i * 31 % 251) as u8).collect(); + let mut expected = actual.clone(); + ref_unpredict(depth, &mut expected, w, h); + p.unpredict(&mut actual, w, h, &mut Budget::new(u64::MAX)).unwrap(); + assert_eq!(actual, expected, "complete extra rows and partial tails stay untouched"); + } + let p = Psd { depth: 32, ..base() }; + let mut bytes = vec![0x31; 24]; + assert!(p.unpredict(&mut bytes, 3, 2, &mut Budget::new(11)).is_err()); + assert_eq!(bytes, vec![0x31; 24], "budget refusal precedes mutation"); +} From b842402a83710367af9f9b6e6cab76f339c2d2ac Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 11:04:56 -0500 Subject: [PATCH 91/99] interchange: retain EDL guessed-path bounds with current Film metadata --- crates/interchange/src/import.rs | 8 +++++--- crates/interchange/src/tests.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/interchange/src/import.rs b/crates/interchange/src/import.rs index 6faadd91a..5dd5642ac 100644 --- a/crates/interchange/src/import.rs +++ b/crates/interchange/src/import.rs @@ -201,8 +201,8 @@ const EDL_MEDIA_TIME_NOTE: &str = "EDL source timecodes were imported as media t /// The largest start timecode, in frames, a file may have: a day at 1000 fps. const MAX_FILE_TIMECODE: i64 = 24 * 3600 * 1000; -/// The paths an EDL reader guessed (media it flags offline: a line without `SOURCE FILE` names -/// only its clip) that are not inside the list's folder: a clip name of `../x.mov` or an absolute +/// The paths an EDL reader guessed (identified by its `Tape Name` metadata: a line without +/// `SOURCE FILE` names only its clip) that are not inside the list's folder: a clip name of `../x.mov` or an absolute /// one would link a file elsewhere on the disk. They stay placeholders. A `SOURCE FILE` path is /// the list's own choice and is kept, also when another clip guesses the same path. fn guessed_outside(project: &fp::Project, base_dir: Option<&str>) -> HashSet { @@ -219,7 +219,9 @@ fn guessed_outside(project: &fp::Project, base_dir: Option<&str>) -> HashSet Date: Mon, 16 Nov 2026 11:09:24 -0500 Subject: [PATCH 92/99] test: use valid encoded PCE layout for AAC downmix parity --- ATTRIBUTION.md | 8 ++- crates/media/tests/fixtures/README.md | 31 +++++++++ .../tests/fixtures/pce61-ffmpeg.aac-fixture | Bin 0 -> 170569 bytes .../pce61-ffmpeg.aac-fixture.attribution | 7 ++ crates/media/tests/it/aac_layout.rs | 63 ++++++++++-------- 5 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 crates/media/tests/fixtures/README.md create mode 100644 crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture create mode 100644 crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture.attribution diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 2f78b6b5e..7043e6128 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -155,4 +155,10 @@ under [`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt). Forks and | `docs/brand/artcraft-mark.png` | ArtCraft Team | Original work: first-party ArtCraft brand mark (ArtCraft symbol ("A" mark), blue) | ArtCraft brand terms, not open source (`docs/brand/LICENSE-brand.txt`) | | `docs/brand/artcraft-mark.svg` | ArtCraft Team | Original work: first-party ArtCraft brand mark (ArtCraft symbol ("A" mark), blue) | ArtCraft brand terms, not open source (`docs/brand/LICENSE-brand.txt`) | -- Appearance theme previews, drawn procedurally from original shapes: `crates/ui-egui/src/panels/settings.rs` (original work, MIT OR Apache-2.0). +- Appearance theme previews, drawn procedurally from original shapes: `crates/ui-egui/src/panels/settings.rs` (original work, MIT OR Apache-2.0). + +## Synthetic test audio + +| Asset | Author | Source | Licence | +|---|---|---|---| +| `crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture` | Dylan M. Taylor | Original sine waves; reproducible recipe in `crates/media/tests/fixtures/README.md` | MIT OR Apache-2.0 | diff --git a/crates/media/tests/fixtures/README.md b/crates/media/tests/fixtures/README.md new file mode 100644 index 000000000..1e9b6bf45 --- /dev/null +++ b/crates/media/tests/fixtures/README.md @@ -0,0 +1,31 @@ +# Synthetic AAC layout fixture + +`pce61-ffmpeg.aac-fixture` contains only original mathematical sine tones generated for these tests by Dylan M. Taylor. No recorded audio or third-party source/assets were copied; the generated fixture is covered by this repository's license. FFmpeg is a generation tool, not a runtime test dependency. + +Generator: FFmpeg 7.1.5 (Debian 7.1.5-0+deb13u1, AAC encoder Lavc61.19.101). +SHA-256: `07c460636dce4aa4163df8ef35f3b76f1214c38bf217aacd23243e608d87071e`. + +The seven PCM inputs are FL500Hz, FR700Hz, FC300Hz, LFE60Hz, BC900Hz, SL1100Hz, SR1300Hz, each amplitude0.25 at48kHz for2seconds. The real encoder emits its own PCE and matching element tags; unlike the previous synthetic configuration rewrite, no LFE element is mislabeled as an unlisted SCE. + +Reproduce using FFmpeg/ffprobe and Python3: + +```sh +ffmpeg -hide_banner -loglevel error -f lavfi -i 'aevalsrc=0.25*sin(2*PI*500*t)|0.25*sin(2*PI*700*t)|0.25*sin(2*PI*300*t)|0.25*sin(2*PI*60*t)|0.25*sin(2*PI*900*t)|0.25*sin(2*PI*1100*t)|0.25*sin(2*PI*1300*t):s=48000:d=2:c=6.1' -c:a aac -b:a 672k pce61.m4a +ffprobe -v error -show_streams -show_packets -show_data -of json pce61.m4a > pce61.json +python3 - <<'PY' +import json, struct +x = json.load(open('pce61.json')) +def raw(text): + return bytes.fromhex(''.join(line.split(': ', 1)[1].split(' ', 1)[0].replace(' ', '') + for line in text.strip().splitlines())) +asc = raw(x['streams'][0]['extradata']) +units = [raw(p['data']) for p in x['packets']] +assert len(units) == 95 +output = bytearray(b'PCE1') +for record in [asc, *units]: + output += struct.pack('>I', len(record)) + record +open('pce61-ffmpeg.aac-fixture', 'wb').write(output) +PY +``` + +Envelope: ASCII `PCE1`, then a big-endian32-bit length and ASC bytes, then95 length-prefixed raw AAC access units. Container priming trim is deliberately not retained, matching the existing tests' encoder units; measurements start0.5seconds into decoded audio. Other encoder versions can yield different bytes; preserve actual PCE/AU consistency and all existing tone-gain assertions. diff --git a/crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture b/crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture new file mode 100644 index 0000000000000000000000000000000000000000..d2894ff82c3e9a2329bcae81f34447a1af78a1cf GIT binary patch literal 170569 zcmce;1zc3k_diZ4AxJBr^wOQu<$}8)-QA#oK})A}F5MyBjew*yNQaatA=1*#{x7Ic zKc8>?U%xr;J#%L6-GzI1?#!Gs?^%V1k{k#K2={P3QMw@r6bS8NSdR@IjCna&Irv#Q z*g4defupEepO6s#RE;2^8qgQRq}N~SSiL?uN6!k&HVHogJ;6cA9ikRVU|@%|W=caL zv8gv80qn}0o6{zHPE?SPM;L97y``9-d|A3U(Tb-pbaBCW3ewi5mH7^UydcO(ZdcCN_M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peg.aac-fixture.attribution b/crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture.attribution new file mode 100644 index 000000000..3f385a1e4 --- /dev/null +++ b/crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture.attribution @@ -0,0 +1,7 @@ +asset: pce61-ffmpeg.aac-fixture +title: Synthetic seven-channel AAC PCE tone fixture +author: Dylan M. Taylor +source: crates/media/tests/fixtures/README.md (reproducible generation recipe) +license: MIT OR Apache-2.0 +added: 2026-11-16 +notes: Original sine-wave signals, no recorded audio or copied assets. Encoded using FFmpeg 7.1.5. SHA-256 07c460636dce4aa4163df8ef35f3b76f1214c38bf217aacd23243e608d87071e. diff --git a/crates/media/tests/it/aac_layout.rs b/crates/media/tests/it/aac_layout.rs index 896e4f0a7..5adf762b2 100644 --- a/crates/media/tests/it/aac_layout.rs +++ b/crates/media/tests/it/aac_layout.rs @@ -1,7 +1,8 @@ //! Multichannel AAC reaches stereo by where each channel plays, whatever order its channel -//! configuration decodes in (#1701). Fixtures are tones encoded with craft-audio's AAC encoder (no -//! ffmpeg needed, so nothing is skipped), with the configuration rewritten where the coded -//! elements fit another: configurations 11 and 12 code the same elements as the encoder's 7- and +//! configuration decodes in (#1701). Fixtures are tones encoded with craft-audio's AAC encoder, +//! plus a checked-in genuine FFmpeg-generated 6.1-channel fixture (no external tool at test time, nothing skipped). +//! The configuration is rewritten only where the coded elements fit another: configurations 11 +//! and 12 code the same elements as the encoder's 7- and //! 8-channel output, and a program config element can name any of them. use std::f64::consts::PI; @@ -9,7 +10,7 @@ use std::io::Cursor; use std::path::PathBuf; use std::sync::Arc; -use craft_audio::aac::{AudioSpecificConfig, Encoder, EncoderConfig, ProgramConfig}; +use craft_audio::aac::{AudioSpecificConfig, Encoder, EncoderConfig}; use effectcraft_media::{MediaPool, probe, probe_bytes}; use effectcraft_time::Tick; @@ -59,13 +60,6 @@ fn lc(config: u8) -> Option { Some(AudioSpecificConfig::lc(3, config)) } -fn pce(front: Vec<(bool, u8)>, side: Vec<(bool, u8)>, back: Vec<(bool, u8)>, lfe: Vec, comment: &[u8]) -> Option { - let pce = ProgramConfig { object_type: 1, sf_index: 3, front, side, back, lfe, comment: comment.to_vec(), ..Default::default() }; - let mut asc = AudioSpecificConfig::lc(3, 0); - asc.pce = Some(pce); - Some(asc) -} - use Ch::*; fn cases() -> Vec { @@ -80,15 +74,9 @@ fn cases() -> Vec { Case { name: "config12", content: &[C, L, R, Ls, Rs, Ls, Rs, Lfe], asc: lc(12) }, // the encoder's own 6.1: a PCE listing the centre first Case { name: "pce61-centre-first", content: &[C, L, R, Ls, Rs, Cs, Lfe], asc: None }, - // ffmpeg's 6.1 PCE: front pair and centre, a side SCE, a back pair and SCE, no LFE - // element, its channels in ffmpeg's order L R C LFE Cs Ls Rs. The decoder places the - // encoder's SCE 0 in the front SCE, pair 0 front, pair 1 back, SCE 1 in the back SCE (tag - // 1) and the LFE in the side SCE left over (tag 5). - Case { - name: "pce61-ffmpeg", - content: &[C, L, R, Cs, Ls, Rs, Lfe], - asc: pce(vec![(true, 0), (false, 0)], vec![(false, 5)], vec![(true, 1), (false, 1)], vec![], b"Lavc62.28.102"), - }, + // A genuine FFmpeg-generated 6.1-channel PCE and matching coded elements; rewriting only the ASC of + // our encoder's LFE0 stream to claim a side SCE5 would make an invalid access unit. + Case { name: "pce61-ffmpeg", content: &[C, L, R, Cs, Ls, Rs, Lfe], asc: None }, ] } @@ -110,6 +98,32 @@ fn encode(content: &[Ch], adts: bool) -> (Vec, Vec>) { (enc.audio_specific_config(), units) } +/// Preserve the fixture's real element types/tags instead of changing only its ASC. +/// The envelope and reproducible tone-generation recipe are in `tests/fixtures/README.md`. +fn encode_case(case: &Case) -> (Vec, Vec>) { + if case.name == "pce61-ffmpeg" { + let bytes = include_bytes!("../fixtures/pce61-ffmpeg.aac-fixture"); + assert_eq!(&bytes[..4], b"PCE1"); + let mut rest = &bytes[4..]; + let mut record = || { + let len = u32::from_be_bytes(rest[..4].try_into().unwrap()) as usize; + let (data, tail) = rest[4..].split_at(len); + rest = tail; + data.to_vec() + }; + let asc = record(); + let mut units = Vec::new(); + // The generated fixture contains 95 access units (including encoder priming). + for _ in 0..95 { + units.push(record()); + } + assert!(rest.is_empty(), "fixture has no unparsed records"); + return (asc, units); + } + let (asc, units) = encode(case.content, false); + (case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC")), units) +} + fn mp4(asc: Vec, channels: u32, units: &[Vec]) -> Vec { mp4_after(None, asc, channels, units) } @@ -211,8 +225,7 @@ fn lfe_is_coded(case: &Case, bytes: Vec) { #[test] fn every_aac_layout_mixes_by_speaker_in_mp4() { for case in cases() { - let (asc, units) = encode(case.content, false); - let asc = case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC")); + let (asc, units) = encode_case(&case); let bytes = mp4(asc, case.content.len() as u32, &units); lfe_is_coded(&case, bytes.clone()); let p = write(&format!("{}.mp4", case.name), &bytes); @@ -228,8 +241,7 @@ fn every_aac_layout_mixes_by_speaker_in_mp4() { #[test] fn matroska_aac_layouts_mix_by_speaker() { for case in cases().into_iter().filter(|c| matches!(c.name, "config12" | "pce61-centre-first" | "pce61-ffmpeg")) { - let (asc, units) = encode(case.content, false); - let asc = case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC")); + let (asc, units) = encode_case(&case); let p = write(&format!("{}.mkv", case.name), &mkv(asc, case.content.len() as u32, &units)); check(case.name, case.content, &mix(&MediaPool::new(), &probe(&p).expect("probe"))); } @@ -254,8 +266,7 @@ fn an_empty_audio_track_lends_its_configuration_to_no_other() { let case = cases().into_iter().find(|c| c.name == name).expect("case"); let n = case.content.len() as u32; let empty = Some((AudioSpecificConfig::lc(3, empty).to_bytes().expect("ASC"), n)); - let (asc, units) = encode(case.content, false); - let asc = case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC")); + let (asc, units) = encode_case(&case); let p = write(&format!("{name}-after-empty.mp4"), &mp4_after(empty.clone(), asc.clone(), n, &units)); check(&format!("{name} MP4"), case.content, &mix(&MediaPool::new(), &probe(&p).expect("probe"))); let p = write(&format!("{name}-after-empty.mkv"), &mkv_after(empty, asc, n, &units)); From b6d2598b3f217b2bbeb8b6ec86302941cfe21bc5 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 11:27:30 -0500 Subject: [PATCH 93/99] interchange: delegate lexical depth preflight to craft-timeline --- Cargo.lock | 18 ++++++++ Cargo.toml | 1 + crates/interchange/Cargo.toml | 1 + crates/interchange/src/import.rs | 73 +------------------------------- 4 files changed, 21 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a38c653da..397da745e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1603,6 +1603,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-time" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76#a2560df05b4c58631f53a57e65fb05f0e0e6cf76" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-time" version = "0.1.0" @@ -1623,6 +1632,14 @@ dependencies = [ "serde_json", ] +[[package]] +name = "craft-timeline" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76#a2560df05b4c58631f53a57e65fb05f0e0e6cf76" +dependencies = [ + "craft-time 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76)", +] + [[package]] name = "craft-timeline" version = "0.1.0" @@ -2252,6 +2269,7 @@ dependencies = [ name = "effectcraft-interchange" version = "0.24.1" dependencies = [ + "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76)", "effectcraft-color", "effectcraft-keyframe", "effectcraft-project", diff --git a/Cargo.toml b/Cargo.toml index 6c0fc585d..a7441a26b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] +craft-timeline = { git = "https://github.com/storytold/craft-libs", rev = "a2560df05b4c58631f53a57e65fb05f0e0e6cf76", default-features = false } craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", version = "=0.1.0", default-features = false, features = ["read"] } craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } diff --git a/crates/interchange/Cargo.toml b/crates/interchange/Cargo.toml index 11dfec333..e2caa613d 100644 --- a/crates/interchange/Cargo.toml +++ b/crates/interchange/Cargo.toml @@ -10,6 +10,7 @@ rust-version.workspace = true workspace = true [dependencies] +craft-timeline = { workspace = true } effectcraft-time = { workspace = true } effectcraft-color = { workspace = true } effectcraft-keyframe = { workspace = true } diff --git a/crates/interchange/src/import.rs b/crates/interchange/src/import.rs index 5dd5642ac..a5336f406 100644 --- a/crates/interchange/src/import.rs +++ b/crates/interchange/src/import.rs @@ -49,78 +49,7 @@ pub struct ImportResult { /// a few levels per nested sequence; parsing several thousand levels overflowed the stack. pub const MAX_DEPTH: usize = 256; -/// The deepest element nesting of an XML document (a quick scan that skips comments, CDATA, -/// processing instructions, declarations and quoted attribute values). -pub(crate) fn xml_depth(b: &[u8]) -> usize { - let (mut i, mut depth, mut max) = (0usize, 0usize, 0usize); - let skip_to = |from: usize, end: &[u8]| b.get(from..).and_then(|r| r.windows(end.len()).position(|w| w == end)).map_or(b.len(), |p| from + p + end.len()); - while let Some(&c) = b.get(i) { - if c != b'<' { - i += 1; - continue; - } - let rest = b.get(i..).unwrap_or_default(); - if rest.starts_with(b""); - } else if rest.starts_with(b""); - } else if rest.starts_with(b""); - } else if rest.starts_with(b""); - } else if rest.starts_with(b""); - } else { - // A start tag: find its end outside quotes; `/>` closes it at once. - let mut j = i + 1; - let mut quote = None; - while let Some(&c) = b.get(j) { - match quote { - Some(q) if c == q => quote = None, - Some(_) => {} - None if c == b'"' || c == b'\'' => quote = Some(c), - None if c == b'>' => break, - None => {} - } - j += 1; - } - if b.get(j.wrapping_sub(1)) != Some(&b'/') { - depth += 1; - max = max.max(depth); - } - i = j + 1; - } - } - max -} - -/// The deepest array / object nesting of a JSON document (strings skipped). -pub(crate) fn json_depth(b: &[u8]) -> usize { - let (mut depth, mut max, mut in_str, mut esc) = (0usize, 0usize, false, false); - for &c in b { - if in_str { - if esc { - esc = false; - } else if c == b'\\' { - esc = true; - } else if c == b'"' { - in_str = false; - } - continue; - } - match c { - b'"' => in_str = true, - b'[' | b'{' => { - depth += 1; - max = max.max(depth); - } - b']' | b'}' => depth = depth.saturating_sub(1), - _ => {} - } - } - max -} +pub(crate) use craft_timeline::preflight::{json_depth, xml_depth}; pub fn import( project: &mut Project, From ee6f04c4fc7e62c79db0c1b00add1b70b4cdc356 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 11:40:58 -0500 Subject: [PATCH 94/99] refactor: pin merged PSD prediction scratch API --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d5411483..121b3b510 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1359,7 +1359,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c864e1e8c9e0f7e2c9f24fca1faa6f298a068bca#c864e1e8c9e0f7e2c9f24fca1faa6f298a068bca" +source = "git+https://github.com/storytold/craft-libs?rev=ce2ec507c2e6a6a078a5f450f641487f8931816d#ce2ec507c2e6a6a078a5f450f641487f8931816d" dependencies = [ "encoding_rs", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 55ba9d0c2..34da549e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs" craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c864e1e8c9e0f7e2c9f24fca1faa6f298a068bca" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ce2ec507c2e6a6a078a5f450f641487f8931816d" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } From de0843b193fa68708504161275f57c2eca418604 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 12:32:32 -0500 Subject: [PATCH 95/99] interchange: pin merged optional marker-color parity fix --- Cargo.lock | 36 ++++++++++++++++++------------------ Cargo.toml | 16 ++++++++-------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a38c653da..3a070ac11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1541,9 +1541,9 @@ dependencies = [ [[package]] name = "craft-raw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe#402dfe46ad568a97f660bcbe30e3a80429b9e1fe" +source = "git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac#bea91b1861eea3889bec9d26338076f2ff31c4ac" dependencies = [ - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac)", "miniz_oxide 0.9.1", "rayon", "serde", @@ -1579,7 +1579,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe#402dfe46ad568a97f660bcbe30e3a80429b9e1fe" +source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" dependencies = [ "serde", "thiserror 2.0.21", @@ -1588,7 +1588,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" +source = "git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac#bea91b1861eea3889bec9d26338076f2ff31c4ac" dependencies = [ "serde", "thiserror 2.0.21", @@ -3002,7 +3002,7 @@ dependencies = [ [[package]] name = "filmcraft-bitstream" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] @@ -3010,7 +3010,7 @@ dependencies = [ [[package]] name = "filmcraft-cfb" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7f3fdc0dfebd03f33a241f91f916e9a78d3e5c93)", ] @@ -3018,7 +3018,7 @@ dependencies = [ [[package]] name = "filmcraft-codecs" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=937ac93c5cf3cd4b6a81e195b078fe161eb081b9)", @@ -3042,7 +3042,7 @@ dependencies = [ [[package]] name = "filmcraft-color" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "serde", ] @@ -3050,10 +3050,10 @@ dependencies = [ [[package]] name = "filmcraft-dng" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-raw", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=402dfe46ad568a97f660bcbe30e3a80429b9e1fe)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac)", "image", "rayon", "thiserror 2.0.21", @@ -3062,7 +3062,7 @@ dependencies = [ [[package]] name = "filmcraft-frame" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "filmcraft-color", "filmcraft-time", @@ -3073,7 +3073,7 @@ dependencies = [ [[package]] name = "filmcraft-geom" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "serde", ] @@ -3081,7 +3081,7 @@ dependencies = [ [[package]] name = "filmcraft-interchange" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-aaf", "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", @@ -3100,7 +3100,7 @@ dependencies = [ [[package]] name = "filmcraft-isobmff" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] @@ -3108,7 +3108,7 @@ dependencies = [ [[package]] name = "filmcraft-matroska" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", ] @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "filmcraft-media" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", "craft-dpx 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", @@ -3135,7 +3135,7 @@ dependencies = [ [[package]] name = "filmcraft-project" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "filmcraft-color", "filmcraft-geom", @@ -3150,7 +3150,7 @@ dependencies = [ [[package]] name = "filmcraft-time" version = "0.20.1" -source = "git+https://github.com/storytold/filmcraft?rev=6e561687f0efc9a674c4bfb1c8251da178d1fb55#6e561687f0efc9a674c4bfb1c8251da178d1fb55" +source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0)", ] diff --git a/Cargo.toml b/Cargo.toml index 6c0fc585d..35d8d78ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,15 +98,15 @@ craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-lib # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. -filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } -filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } -filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } -filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } -filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-codecs = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } +filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } +filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } +filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } +filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } # timeline interchange (EDL, FCP7 XML, FCPXML, OTIO) for Premiere Pro interop (crates/interchange only) -filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } -filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } -filmcraft-geom = { git = "https://github.com/storytold/filmcraft", rev = "6e561687f0efc9a674c4bfb1c8251da178d1fb55" } +filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } +filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } +filmcraft-geom = { git = "https://github.com/storytold/filmcraft", rev = "3f137a7ed420cac79b32145f5243b7f98b31f71c" } # gpu (the same wgpu eframe / egui-wgpu use) wgpu = { version = "30.0.1", features = ["fragile-send-sync-non-atomic-wasm"] } From e57aa567b9fa408c7506917607eb3d2dbb0cba91 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 13:33:08 -0500 Subject: [PATCH 96/99] interchange: pin merged shared nesting preflight --- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f1bb26e5..73d74ecb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1597,7 +1597,7 @@ dependencies = [ [[package]] name = "craft-time" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" +source = "git+https://github.com/storytold/craft-libs?rev=0d6dd8bed815b8366869a800d2bf22588ca62dcb#0d6dd8bed815b8366869a800d2bf22588ca62dcb" dependencies = [ "serde", "thiserror 2.0.21", @@ -1606,7 +1606,7 @@ dependencies = [ [[package]] name = "craft-time" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76#a2560df05b4c58631f53a57e65fb05f0e0e6cf76" +source = "git+https://github.com/storytold/craft-libs?rev=57288edafdc45552e30481cc649021de446abfa0#57288edafdc45552e30481cc649021de446abfa0" dependencies = [ "serde", "thiserror 2.0.21", @@ -1621,6 +1621,14 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-timeline" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=0d6dd8bed815b8366869a800d2bf22588ca62dcb#0d6dd8bed815b8366869a800d2bf22588ca62dcb" +dependencies = [ + "craft-time 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0d6dd8bed815b8366869a800d2bf22588ca62dcb)", +] + [[package]] name = "craft-timeline" version = "0.1.0" @@ -1632,14 +1640,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "craft-timeline" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76#a2560df05b4c58631f53a57e65fb05f0e0e6cf76" -dependencies = [ - "craft-time 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76)", -] - [[package]] name = "craft-timeline" version = "0.1.0" @@ -2269,7 +2269,7 @@ dependencies = [ name = "effectcraft-interchange" version = "0.24.1" dependencies = [ - "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a2560df05b4c58631f53a57e65fb05f0e0e6cf76)", + "craft-timeline 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0d6dd8bed815b8366869a800d2bf22588ca62dcb)", "effectcraft-color", "effectcraft-keyframe", "effectcraft-project", diff --git a/Cargo.toml b/Cargo.toml index 62d4d6287..2889bdc34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-timeline = { git = "https://github.com/storytold/craft-libs", rev = "a2560df05b4c58631f53a57e65fb05f0e0e6cf76", default-features = false } +craft-timeline = { git = "https://github.com/storytold/craft-libs", rev = "0d6dd8bed815b8366869a800d2bf22588ca62dcb", default-features = false } craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", version = "=0.1.0", default-features = false, features = ["read"] } craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } From fa542829e93005433b353f5f42b6be5eb2a0649c Mon Sep 17 00:00:00 2001 From: vangel76 Date: Mon, 16 Nov 2026 22:05:56 +0100 Subject: [PATCH 97/99] #3793: build the OCIO test's expected LUT path from its parts join("luts/grade.cube") keeps the forward slash on Windows, while the code resolves the config's LUT as luts\grade.cube, so the test's text lookup in the read log missed there. The code under test is unchanged. --- crates/engine/src/tests/lut_files.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/tests/lut_files.rs b/crates/engine/src/tests/lut_files.rs index 98c95652a..6f6818b23 100644 --- a/crates/engine/src/tests/lut_files.rs +++ b/crates/engine/src/tests/lut_files.rs @@ -192,7 +192,7 @@ fn an_overridden_lut_file_renders_again() { #[test] fn ocio_files_render_again_from_warm_caches() { let dir = tempfile::tempdir().unwrap(); - let (lut, config, grade) = (dir.path().join("file.cube"), dir.path().join("config.ocio"), dir.path().join("luts/grade.cube")); + let (lut, config, grade) = (dir.path().join("file.cube"), dir.path().join("config.ocio"), dir.path().join("luts").join("grade.cube")); std::fs::create_dir_all(dir.path().join("luts")).unwrap(); write(&lut, BLACK, 1_000); write(&grade, BLACK, 1_000); From defa16a26f4e8a3ff3bed3986f6ed4ad4a30d478 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 21:58:04 -0500 Subject: [PATCH 98/99] svg: use shared bounded prefix path parsing (#3800) --- Cargo.lock | 138 ++------------ Cargo.toml | 2 +- crates/svg/src/pathdata.rs | 356 +------------------------------------ 3 files changed, 20 insertions(+), 476 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73d74ecb5..165407081 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,21 +147,6 @@ dependencies = [ "equator", ] -[[package]] -name = "alloc-no-stdlib" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2fb6cfd47bf496ff64095c20eaba0c201404ee38714d4142fcfa1dc334fcc7a" - -[[package]] -name = "alloc-stdlib" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5c1865780388bfa186411ab5f247819487fc4864c6e9c3106611fa347586e1" -dependencies = [ - "alloc-no-stdlib", -] - [[package]] name = "allocator-api2" version = "0.2.21" @@ -796,16 +781,6 @@ dependencies = [ "syn 3.0.6", ] -[[package]] -name = "brotli-decompressor" -version = "6.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc031cd87c6529082b0b65c604e86af0ed7744841b17ccfe60b1e31fa606179e" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", -] - [[package]] name = "built" version = "0.8.1" @@ -1376,39 +1351,6 @@ dependencies = [ "writeable", ] -[[package]] -name = "craft-image-codecs" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" -dependencies = [ - "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", - "craft-metadata", - "crc32fast", - "exr", - "flate2", - "half", - "hayro-jpeg2000", - "image", - "image-webp", - "jpeg-encoder", - "png", - "rayon", - "serde_json", - "thiserror 2.0.21", - "tiff", - "zune-core", - "zune-jpeg", - "zune-jpegxl", -] - -[[package]] -name = "craft-jpeg" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" -dependencies = [ - "thiserror 2.0.21", -] - [[package]] name = "craft-jpeg" version = "0.1.0" @@ -1461,18 +1403,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "craft-metadata" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" -dependencies = [ - "brotli-decompressor", - "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", - "quick-xml 0.41.0", - "serde", -] - [[package]] name = "craft-mime" version = "0.1.0" @@ -1543,7 +1473,7 @@ name = "craft-raw" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac#bea91b1861eea3889bec9d26338076f2ff31c4ac" dependencies = [ - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac)", + "craft-tiff", "miniz_oxide 0.9.1", "rayon", "serde", @@ -1555,10 +1485,9 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" +source = "git+https://github.com/storytold/craft-libs?rev=e52cd9a889adbeeda447c75a546133960cf3382d#e52cd9a889adbeeda447c75a546133960cf3382d" dependencies = [ - "craft-image-codecs", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e52cd9a889adbeeda447c75a546133960cf3382d)", "flate2", "kurbo", "quick-xml 0.41.0", @@ -1576,15 +1505,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-tiff" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" -dependencies = [ - "serde", - "thiserror 2.0.21", -] - [[package]] name = "craft-tiff" version = "0.1.0" @@ -1747,16 +1667,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" -dependencies = [ - "quick-xml 0.41.0", - "serde", - "thiserror 2.0.21", -] - [[package]] name = "craft-xml" version = "0.1.0" @@ -1777,6 +1687,16 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=e52cd9a889adbeeda447c75a546133960cf3382d#e52cd9a889adbeeda447c75a546133960cf3382d" +dependencies = [ + "quick-xml 0.41.0", + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-y4m" version = "0.1.0" @@ -3039,7 +2959,7 @@ version = "0.20.1" source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-audio 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", - "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=937ac93c5cf3cd4b6a81e195b078fe161eb081b9)", + "craft-jpeg", "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", "craft-video 0.1.0 (git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab)", "craft-y4m", @@ -3071,7 +2991,7 @@ version = "0.20.1" source = "git+https://github.com/storytold/filmcraft?rev=3f137a7ed420cac79b32145f5243b7f98b31f71c#3f137a7ed420cac79b32145f5243b7f98b31f71c" dependencies = [ "craft-raw", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bea91b1861eea3889bec9d26338076f2ff31c4ac)", + "craft-tiff", "image", "rayon", "thiserror 2.0.21", @@ -3760,9 +3680,6 @@ name = "hayro-jpeg2000" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" -dependencies = [ - "fearless_simd", -] [[package]] name = "hayro-syntax" @@ -4024,7 +3941,6 @@ dependencies = [ "moxcms", "num-traits", "png", - "qoi", "tiff", "zune-core", "zune-jpeg", @@ -4175,12 +4091,6 @@ dependencies = [ "libc", ] -[[package]] -name = "jpeg-encoder" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b454d911ac55068f53495488d8ccd0646eaa540c033a28ee15b07838afafb01f" - [[package]] name = "js-sys" version = "0.3.106" @@ -5573,15 +5483,6 @@ version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" -[[package]] -name = "qoi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" -dependencies = [ - "bytemuck", -] - [[package]] name = "quick-error" version = "1.2.3" @@ -9001,15 +8902,6 @@ dependencies = [ "zune-core", ] -[[package]] -name = "zune-jpegxl" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cba11ecd07cc23351500e840ae03841b7e4997923ec8e4832ee3ae199ea0b6b4" -dependencies = [ - "zune-core", -] - [[package]] name = "zvariant" version = "5.15.0" diff --git a/Cargo.toml b/Cargo.toml index 2889bdc34..54158cd1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ce2ec507c2e6a6a078a5f450f641487f8931816d" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e52cd9a889adbeeda447c75a546133960cf3382d" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } diff --git a/crates/svg/src/pathdata.rs b/crates/svg/src/pathdata.rs index dbc6855c5..5ceb2ab89 100644 --- a/crates/svg/src/pathdata.rs +++ b/crates/svg/src/pathdata.rs @@ -1,360 +1,12 @@ -//! SVG path data (SVG 1.1 §8.3 / SVG 2 §9.3): every command, implicit repeats, relative -//! coordinates, smooth curves and elliptical arcs (converted to cubics through kurbo's `SvgArc`). -//! Parsing stops at the first error, keeping what was read (as the specification asks). +//! Prefix-preserving SVG path and numeric-list parsing is shared with craft-svg. +//! App document budgets and geometry policy remain with the importer. -use kurbo::{BezPath, PathEl, Point, SvgArc, Vec2}; - -/// Maximum path elements retained from one SVG path or point list. -pub(crate) const MAX_PATH_ELEMENTS: usize = 100_000; - -/// Tokenizer over numbers and command letters. -struct Lex<'a> { - b: &'a [u8], - i: usize, -} - -impl Lex<'_> { - fn skip_sep(&mut self) { - while self.i < self.b.len() && (self.b[self.i].is_ascii_whitespace() || self.b[self.i] == b',') { - self.i += 1; - } - } - fn command(&mut self) -> Option { - self.skip_sep(); - let c = *self.b.get(self.i)?; - if c.is_ascii_alphabetic() && c != b'e' && c != b'E' { - self.i += 1; - Some(c) - } else { - None - } - } - fn at_number(&mut self) -> bool { - self.skip_sep(); - self.b.get(self.i).is_some_and(|c| c.is_ascii_digit() || matches!(c, b'-' | b'+' | b'.')) - } - fn number(&mut self) -> Option { - self.skip_sep(); - let start = self.i; - let b = self.b; - let mut i = self.i; - if i < b.len() && matches!(b[i], b'-' | b'+') { - i += 1; - } - let mut digits = false; - while i < b.len() && b[i].is_ascii_digit() { - i += 1; - digits = true; - } - if i < b.len() && b[i] == b'.' { - i += 1; - while i < b.len() && b[i].is_ascii_digit() { - i += 1; - digits = true; - } - } - if !digits { - return None; - } - if i < b.len() && matches!(b[i], b'e' | b'E') { - let mut j = i + 1; - if j < b.len() && matches!(b[j], b'-' | b'+') { - j += 1; - } - if j < b.len() && b[j].is_ascii_digit() { - while j < b.len() && b[j].is_ascii_digit() { - j += 1; - } - i = j; - } - } - self.i = i; - let number = std::str::from_utf8(&b[start..i]).ok()?.parse::().ok()?; - number.is_finite().then_some(number) - } - /// Arc flags may be written without separators ("a1 1 0 00 1 1"). - fn flag(&mut self) -> Option { - self.skip_sep(); - let c = *self.b.get(self.i)?; - self.i += 1; - match c { - b'0' => Some(false), - b'1' => Some(true), - _ => None, - } - } -} - -/// Parse no more than `max_values`; the flag reports whether another valid value was present. -pub(crate) fn numbers_bounded(s: &str, max_values: usize) -> (Vec, bool) { - let mut l = Lex { b: s.as_bytes(), i: 0 }; - let mut v = vec![]; - while l.at_number() { - if v.len() >= max_values { - return (v, true); - } - match l.number() { - Some(x) => v.push(x), - None => break, - } - } - (v, false) -} - -/// Parse path data into a kurbo path, retaining at most [`MAX_PATH_ELEMENTS`] elements. -/// Malformed or overlong input returns the prefix parsed before the problem. -pub fn parse_path_data(d: &str) -> BezPath { - parse_path_data_bounded(d, MAX_PATH_ELEMENTS).0 -} - -/// Pen position and reflection state while parsing path commands. -struct PathState { - /// Current point. - current: Point, - /// Start of the current subpath. - start: Point, - /// Last cubic control point, for smooth curves. - last_cubic: Option, - /// Last quadratic control point, for smooth curves. - last_quad: Option, - /// Whether a subpath is open. - open: bool, -} - -/// Cap on path elements and whether it has been hit. -struct PathLimit { - /// Maximum number of path elements. - max_elements: usize, - /// Set when the cap or a non-finite coordinate stopped output. - exceeded: bool, -} - -/// Parse at most `max_elements`, reporting when more path geometry was present. -pub(crate) fn parse_path_data_bounded(d: &str, max_elements: usize) -> (BezPath, bool) { - let mut l = Lex { b: d.as_bytes(), i: 0 }; - let mut p = BezPath::new(); - let mut state = PathState { current: Point::ZERO, start: Point::ZERO, last_cubic: None, last_quad: None, open: false }; - let mut limit = PathLimit { max_elements, exceeded: false }; - let mut cmd: Option = None; - loop { - if p.elements().len() >= limit.max_elements { - l.skip_sep(); - limit.exceeded = l.i < l.b.len(); - break; - } - let c = match l.command() { - Some(c) => c, - None => match cmd { - // Implicit repeat (a moveto repeats as lineto). Z takes no numbers, so a number - // after it is an error: repeating Z would loop forever without consuming input. - Some(c) if l.at_number() && !c.eq_ignore_ascii_case(&b'z') => match c { - b'M' => b'L', - b'm' => b'l', - other => other, - }, - _ => break, - }, - }; - let rel = c.is_ascii_lowercase(); - let base = if rel { state.current.to_vec2() } else { Vec2::ZERO }; - let pt = |l: &mut Lex| -> Option { Some(Point::new(l.number()?, l.number()?) + base) }; - let ok = (|| -> Option<()> { - match c.to_ascii_uppercase() { - b'M' => { - state.current = pt(&mut l)?; - if !push_element(&mut p, PathEl::MoveTo(state.current), &mut limit) { - return None; - } - state.start = state.current; - state.open = true; - state.last_cubic = None; - state.last_quad = None; - } - b'Z' => { - if state.open && !push_element(&mut p, PathEl::ClosePath, &mut limit) { - return None; - } - state.current = state.start; - state.last_cubic = None; - state.last_quad = None; - } - _ if !state.open => { - // A segment without a preceding moveto starts at the current point. - if !push_element(&mut p, PathEl::MoveTo(state.current), &mut limit) { - return None; - } - state.open = true; - return segment(&mut l, c, base, &mut p, &mut state, &mut limit); - } - _ => return segment(&mut l, c, base, &mut p, &mut state, &mut limit), - } - Some(()) - })(); - if ok.is_none() { - break; - } - if limit.exceeded { - break; - } - cmd = Some(c); - if c.eq_ignore_ascii_case(&b'z') { - // After Z a new segment starts from the subpath start (an unused move is dropped - // below). - if !push_element(&mut p, PathEl::MoveTo(state.start), &mut limit) { - break; - } - state.open = true; - } - } - (strip_trailing_moves(p), limit.exceeded) -} - -/// Push an element if finite and under the cap; otherwise mark the limit exceeded and return false. -fn push_element(p: &mut BezPath, element: PathEl, limit: &mut PathLimit) -> bool { - let finite = match element { - PathEl::MoveTo(point) | PathEl::LineTo(point) => point.x.is_finite() && point.y.is_finite(), - PathEl::QuadTo(control, point) => [control.x, control.y, point.x, point.y].iter().all(|value| value.is_finite()), - PathEl::CurveTo(first, second, point) => [first.x, first.y, second.x, second.y, point.x, point.y].iter().all(|value| value.is_finite()), - PathEl::ClosePath => true, - }; - if p.elements().len() >= limit.max_elements || !finite { - limit.exceeded = true; - return false; - } - p.push(element); - true -} - -/// Parse one path command's arguments into `p`, returning `None` on malformed or over-limit input. -fn segment(l: &mut Lex, c: u8, base: Vec2, p: &mut BezPath, state: &mut PathState, limit: &mut PathLimit) -> Option<()> { - let num = |l: &mut Lex| l.number(); - let pt = |l: &mut Lex| -> Option { Some(Point::new(l.number()?, l.number()?) + base) }; - match c.to_ascii_uppercase() { - b'L' => { - let current = pt(l)?; - if !push_element(p, PathEl::LineTo(current), limit) { - return None; - } - state.current = current; - state.last_cubic = None; - state.last_quad = None; - } - b'H' => { - let x = num(l)? + base.x; - let current = Point::new(x, state.current.y); - if !push_element(p, PathEl::LineTo(current), limit) { - return None; - } - state.current = current; - state.last_cubic = None; - state.last_quad = None; - } - b'V' => { - let y = num(l)? + base.y; - let current = Point::new(state.current.x, y); - if !push_element(p, PathEl::LineTo(current), limit) { - return None; - } - state.current = current; - state.last_cubic = None; - state.last_quad = None; - } - b'C' => { - let (c1, c2, e) = (pt(l)?, pt(l)?, pt(l)?); - if !push_element(p, PathEl::CurveTo(c1, c2, e), limit) { - return None; - } - state.last_cubic = Some(c2); - state.last_quad = None; - state.current = e; - } - b'S' => { - let c1 = state.last_cubic.map_or(state.current, |c| state.current + (state.current - c)); - let (c2, e) = (pt(l)?, pt(l)?); - if !push_element(p, PathEl::CurveTo(c1, c2, e), limit) { - return None; - } - state.last_cubic = Some(c2); - state.last_quad = None; - state.current = e; - } - b'Q' => { - let (q, e) = (pt(l)?, pt(l)?); - if !push_element(p, PathEl::QuadTo(q, e), limit) { - return None; - } - state.last_quad = Some(q); - state.last_cubic = None; - state.current = e; - } - b'T' => { - let q = state.last_quad.map_or(state.current, |c| state.current + (state.current - c)); - let e = pt(l)?; - if !push_element(p, PathEl::QuadTo(q, e), limit) { - return None; - } - state.last_quad = Some(q); - state.last_cubic = None; - state.current = e; - } - b'A' => { - let rx = num(l)?.abs(); - let ry = num(l)?.abs(); - let rot = num(l)?; - let large = l.flag()?; - let sweep = l.flag()?; - let e = pt(l)?; - let arc = SvgArc { from: state.current, to: e, radii: Vec2::new(rx, ry), x_rotation: rot.to_radians(), large_arc: large, sweep }; - let mut last_end = None; - if let Some(a) = kurbo::Arc::from_svg_arc(&arc) { - // Scale tolerance with the radius so the segment count stays bounded. - let tol = 0.1_f64.max(a.radii.x.max(a.radii.y) * 1e-4); - a.to_cubic_beziers(tol, |c1, c2, end| { - if limit.exceeded { - return; - } - if push_element(p, PathEl::CurveTo(c1, c2, end), limit) { - last_end = Some(end); - } - }); - } - if limit.exceeded { - return None; - } - // Degenerate arcs (e.g. huge radii) may emit nothing or stop short of the end point. - if last_end.is_none_or(|q| (q - e).hypot() > 1e-3 * (1.0 + e.to_vec2().hypot())) && !push_element(p, PathEl::LineTo(e), limit) { - return None; - } - state.current = e; - state.last_cubic = None; - state.last_quad = None; - } - _ => return None, - } - Some(()) -} - -/// Drop move-tos that start no segment (from closepath bookkeeping). -fn strip_trailing_moves(p: BezPath) -> BezPath { - use kurbo::PathEl; - let els = p.elements(); - let mut out = BezPath::new(); - for (i, e) in els.iter().enumerate() { - if let PathEl::MoveTo(_) = e { - let next_is_seg = els.get(i + 1).is_some_and(|n| !matches!(n, PathEl::MoveTo(_))); - if !next_is_seg { - continue; - } - } - out.push(*e); - } - out -} +pub use craft_svg::prefix_path::{MAX_PATH_ELEMENTS, numbers_bounded, parse_path_data, parse_path_data_bounded}; #[cfg(test)] mod tests { use super::*; - use kurbo::PathEl; + use kurbo::{PathEl, Point}; #[test] /// Huge arc radii stay bounded. From 41da144555a1c8ddbbe94876a00259832322d00c Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 21:58:09 -0500 Subject: [PATCH 99/99] Shape operators: cap each expanding operator's output (#2948) --- Cargo.lock | 1 + crates/path/Cargo.toml | 1 + crates/path/src/ops.rs | 54 +++++++++++++++++++++--- crates/path/src/ops/tests.rs | 80 ++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 165407081..f5b87bf7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2293,6 +2293,7 @@ dependencies = [ "effectcraft-raster", "kurbo", "linesweeper", + "log", "tiny-skia 0.12.0", ] diff --git a/crates/path/Cargo.toml b/crates/path/Cargo.toml index 2e9bc85d9..122c37fe0 100644 --- a/crates/path/Cargo.toml +++ b/crates/path/Cargo.toml @@ -14,5 +14,6 @@ effectcraft-geom = { workspace = true } effectcraft-keyframe = { workspace = true } effectcraft-raster = { workspace = true } kurbo = { workspace = true } +log = { workspace = true } tiny-skia = { workspace = true } linesweeper = "0.5" diff --git a/crates/path/src/ops.rs b/crates/path/src/ops.rs index ba5349312..5c89ce6bc 100644 --- a/crates/path/src/ops.rs +++ b/crates/path/src/ops.rs @@ -351,14 +351,28 @@ fn round_sub(sub: &Sub, r: f64, out: &mut BezPath) { /// join. `copies` copies are made, copy *i* (0-based) offset by `amount · (i + 1 + copy_offset)`, /// all returned in the same compound path. pub fn offset(paths: &[BezPath], amount: f64, join: Join, miter_limit: f64, copies: f64, copy_offset: f64) -> Vec { - let n = copies.round().clamp(1.0, 1000.0) as usize; + offset_within(paths, amount, join, miter_limit, copies, copy_offset, MAX_OPERATOR_SEGMENTS) +} + +/// [`offset`] with each path's result held to `max` elements (its first copy aside). +fn offset_within(paths: &[BezPath], amount: f64, join: Join, miter_limit: f64, copies: f64, copy_offset: f64, max: usize) -> Vec { + let n = pieces_within_budget(paths, copies.round().clamp(1.0, 1000.0) as usize); paths .iter() .map(|p| { let mut out = BezPath::new(); for i in 0..n { let d = amount * (i as f64 + 1.0 + copy_offset); - out.extend(crate::offset::offset_path(p, d, join, miter_limit).elements().iter().copied()); + let copy = crate::offset::offset_path(p, d, join, miter_limit); + // The budget is spent on what `offset_path` returns (an open subpath comes back as + // a closed outline of many segments; a zero offset as the path itself): the first + // copy is always kept, and a copy that would pass the budget is not made, so the + // work stays within a small multiple of it. + if i > 0 && out.elements().len().saturating_add(copy.elements().len()) > max { + log::warn!("path: Offset Paths made {i} of {n} copies; more would pass {max} segments"); + break; + } + out.extend(copy.elements().iter().copied()); } out }) @@ -387,6 +401,14 @@ pub fn twist(paths: &[BezPath], angle_deg: f64, center: [f64; 2]) -> Vec Vec usize { + if sub.closed { 2 } else { 1 } +} + +/// `want` pieces (or copies) per input segment, reduced so the whole output (segments times +/// pieces, plus per-subpath overhead) stays within [`MAX_OPERATOR_SEGMENTS`] (never below 1, so the input itself always passes through). +fn pieces_within_budget(paths: &[BezPath], want: usize) -> usize { + // Count what is subdivided (drawn segments) and keep room for each subpath's own MoveTo/Close. + let (mut segs, mut overhead) = (0usize, 0usize); + for sub in paths.iter().flat_map(subs) { + segs = segs.saturating_add(sub.segs.len()); + overhead = overhead.saturating_add(overhead_of(&sub)); + } + want.min(MAX_OPERATOR_SEGMENTS.saturating_sub(overhead) / segs.max(1)).max(1) +} + /// Split every segment into `m` pieces of equal arc length. Original vertices get the average of /// their incoming and outgoing tangents (so a corner's normal is its bisector). fn resample(sub: &Sub, m: usize) -> Vec { @@ -503,7 +547,7 @@ fn emit(samples: &[Sample], disp: &[Vec2], closed: bool, smooth: bool, handle: f /// `smooth` makes rounded waves instead of sharp zig zags. A closed path with `n` segments ends up /// with `n · (ridges + 1)` vertices (open: one more). pub fn zigzag(paths: &[BezPath], size: f64, ridges: f64, smooth: bool) -> Vec { - let m = ridges.round().clamp(0.0, 1000.0) as usize + 1; + let m = pieces_within_budget(paths, ridges.round().clamp(0.0, 1000.0) as usize + 1); paths .iter() .map(|p| { @@ -586,7 +630,7 @@ pub fn wiggle(paths: &[BezPath], w: &WiggleParams, time_s: f64) -> Vec if w.size == 0.0 { return paths.to_vec(); } - let m = w.detail.round().clamp(0.0, 1000.0) as usize + 1; + let m = pieces_within_budget(paths, w.detail.round().clamp(0.0, 1000.0) as usize + 1); let seed = w.seed.round() as i64 as u64; let t = time_s * w.speed + w.phase_deg / 360.0; let corr = (w.correlation / 100.0).clamp(0.0, 1.0); diff --git a/crates/path/src/ops/tests.rs b/crates/path/src/ops/tests.rs index 1ebdcea5b..e64a55b47 100644 --- a/crates/path/src/ops/tests.rs +++ b/crates/path/src/ops/tests.rs @@ -182,6 +182,25 @@ fn offset_copies() { assert!(close(o[0].bounding_box().width(), 140.0, 1e-3)); } +#[test] +fn offset_copies_are_budgeted_by_the_output_they_return() { + // An open one-segment subpath comes back as a closed outline of several elements, so the copies + // stop when the returned elements pass the budget, not when the input segments would. + let line = || { + let mut p = BezPath::new(); + p.move_to((0.0, 0.0)); + p.line_to((50.0, 0.0)); + p + }; + let one = offset_within(&[line()], 5.0, Join::Round, 4.0, 1.0, 0.0, usize::MAX)[0].elements().len(); + assert!(one > 4, "{one}"); + let o = offset_within(&[line()], 5.0, Join::Round, 4.0, 50.0, 0.0, one * 3); + let moves = o[0].elements().iter().filter(|e| matches!(e, PathEl::MoveTo(_))).count(); + assert!((1..50).contains(&moves) && o[0].elements().len() <= one * 4, "{moves} contours, {} elements", o[0].elements().len()); + // The first copy always comes back, however small the budget. + assert!(!offset_within(&[line()], 5.0, Join::Round, 4.0, 5.0, 0.0, 0)[0].elements().is_empty()); +} + #[test] fn offset_open_path_outlines() { let mut l = BezPath::new(); @@ -246,6 +265,22 @@ fn twist_of_centred_circle_keeps_it_round() { assert_eq!(id[0], sq(0.0, 0.0, 5.0)); } +#[test] +fn twist_keeps_requested_detail_when_the_whole_request_fits_the_budget() { + // One long segment asks for 64 pieces; 20,000 tiny ones ask for one each. Together that is + // far under the budget, so the long one is not cut to what a uniform 64 per segment would allow. + let mut long = BezPath::new(); + long.move_to((0.0, 0.0)); + long.line_to((5000.0, 0.0)); + let mut tiny = BezPath::new(); + tiny.move_to((0.0, 1.0)); + for i in 1..=20_000 { + tiny.line_to((i as f64 * 1e-3, 1.0)); + } + let t = twist(&[long, tiny], 90.0, [0.0, 0.0]); + assert_eq!(t[0].elements().len(), 1 + 64); +} + // ---------------------------------------------------------------- zig zag #[test] @@ -417,3 +452,48 @@ fn normalize_and_filled_area() { let n = crate::boolean::normalize(&p, FillRule::EvenOdd); assert!(close(n.area().abs(), 10000.0, 1e-6)); } + +// ---------------------------------------------------------------- operator budget + +#[test] +fn stacked_expanding_operators_stay_within_the_segment_budget() { + // Three Zig Zags at 1000 ridges would turn a square into 4 · 1001³ segments; each output + // is held to the budget instead, and the last operators still pass the geometry through. + let mut p = vec![sq(0.0, 0.0, 100.0)]; + for _ in 0..3 { + p = zigzag(&p, 1.0, 1000.0, false); + let n: usize = p.iter().map(|q| q.elements().len()).sum(); + assert!(n <= 2 * MAX_OPERATOR_SEGMENTS, "{n}"); + } + let w = wiggle(&p, &WiggleParams { detail: 1000.0, ..Default::default() }, 0.0); + let n: usize = w.iter().map(|q| q.elements().len()).sum(); + assert!(n <= 2 * MAX_OPERATOR_SEGMENTS, "{n}"); + let o = offset(&[sq(0.0, 0.0, 100.0)], 1.0, Join::Miter, 4.0, 1000.0, 0.0); + assert!(!o[0].elements().is_empty()); + // Within the budget nothing changes: 4 segments × 11 pieces. + assert_eq!(vertex_count(&zigzag(&[sq(0.0, 0.0, 100.0)], 1.0, 10.0, false)[0]), 44); +} + +#[test] +fn many_short_open_paths_keep_their_requested_detail_within_the_budget() { + // 1000 open lines at 1000 ridges: 1,001,000 segments fit the budget, so nothing is reduced. + let lines: Vec = (0..1000) + .map(|i| { + let mut p = BezPath::new(); + p.move_to((0.0, i as f64)); + p.line_to((100.0, i as f64)); + p + }) + .collect(); + let z = zigzag(&lines, 1.0, 1000.0, false); + assert!(z.iter().all(|q| q.elements().len() == 1 + 1001)); +} + +#[test] +fn open_subpaths_reserve_one_element_of_overhead() { + // 349,525 open lines: the move-to is the only extra element, so 2 copies fit the budget + // (a closed subpath's extra close-path would leave room for 1). + let line = BezPath::from_vec(vec![PathEl::MoveTo((0.0, 0.0).into()), PathEl::LineTo((1.0, 0.0).into())]); + let lines = vec![line; 349_525]; + assert_eq!(pieces_within_budget(&lines, 3), 2); +}