From af4a6f74f52d24e193193cae44fcff84f07ff5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 16 Nov 2026 01:22:37 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20A=20burned=20ASS/SSA=20track=20is?= =?UTF-8?q?=20drawn=20as=20libass=20draws=20it:=20styles,=20PlayRes=20scal?= =?UTF-8?q?ing,=20outline,=20shadow,=20blur,=20fades,=20colour/alpha/size/?= =?UTF-8?q?italic=20overrides,=20\an=20and=20\pos;=20burn=5Fcaptions=20nat?= =?UTF-8?q?ive:false=20keeps=20the=20caption=20look?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/engine/src/assrender.rs | 1067 ++++++++++++++++++++++++++++++++ crates/engine/src/export.rs | 106 +++- crates/engine/src/lib.rs | 1 + crates/engine/src/text.rs | 25 +- crates/mcp/src/tools/export.rs | 13 +- 5 files changed, 1186 insertions(+), 26 deletions(-) create mode 100644 crates/engine/src/assrender.rs diff --git a/crates/engine/src/assrender.rs b/crates/engine/src/assrender.rs new file mode 100644 index 0000000..65806a8 --- /dev/null +++ b/crates/engine/src/assrender.rs @@ -0,0 +1,1067 @@ +//! Advanced SubStation Alpha drawn as libass draws it: each event in its style's +//! face, scaled from `PlayRes` to the frame, with its outline, shadow, blur and +//! fade, composed onto the picture. An event's coverage is rasterised once and +//! kept while the frame size holds, so a fade is a blend, not a rasterisation. + +use std::collections::HashMap; +use std::path::Path; + +use ab_glyph::{Font, FontRef, GlyphId, OutlineCurve, point}; +use ab_glyph_rasterizer::Rasterizer; +use ec_subs::{Segment, SubtitleStyle}; + +use crate::colorspace::is_sd; +use crate::text::{self, mix, yuv}; + +const ITALIC_SHEAR: f32 = 0.2; +const DEFAULT_EVENT_FORMAT: &str = "Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text"; + +/// One event on screen: its index in the script and its span on the timeline, in microseconds. +#[derive(Clone, Copy, Debug)] +pub struct Shown { + /// The event's index in the script, in file order. + pub event: usize, + /// When the event starts on the timeline. + pub start_us: i64, + /// When the event ends on the timeline. + pub end_us: i64, +} + +/// An ASS script ready to draw: its PlayRes, styles and events, and the coverage of the events drawn. +pub struct Captions { + play: (f32, f32), + scaled: bool, + wrap: u8, + styles: Vec