🐛 ASS \blur is sized as libass sizes it: sigma 0.849·blur in pixels of the video, not scaled from PlayRes; \be adds its box passes
Browse files at this commitbc736390285bb6800f108fbac776b3414a6504cdParent: af4a6f72 changed files +13 -3
crates/engine/src/assrender.rsmodified+12 -2
| @@ -31,6 +31,7 @@ pub struct Shown { | |||
| 31 | pub struct Captions { | 31 | pub struct Captions { |
| 32 | play: (f32, f32), | 32 | play: (f32, f32), |
| 33 | scaled: bool, | 33 | scaled: bool, |
| 34 | + storage_h: f32, | ||
| 34 | wrap: u8, | 35 | wrap: u8, |
| 35 | styles: Vec<Style>, | 36 | styles: Vec<Style>, |
| 36 | events: Vec<Event>, | 37 | events: Vec<Event>, |
| @@ -82,6 +83,7 @@ impl Captions { | |||
| 82 | Some(Captions { | 83 | Some(Captions { |
| 83 | play: (res("play_res_x", 384.0), res("play_res_y", 288.0)), | 84 | play: (res("play_res_x", 384.0), res("play_res_y", 288.0)), |
| 84 | scaled: meta("scaled_border_and_shadow").is_some_and(|v| v.eq_ignore_ascii_case("yes")), | 85 | scaled: meta("scaled_border_and_shadow").is_some_and(|v| v.eq_ignore_ascii_case("yes")), |
| 86 | + storage_h: 0.0, | ||
| 85 | wrap: meta("wrap_style").and_then(|v| v.parse().ok()).unwrap_or(0), | 87 | wrap: meta("wrap_style").and_then(|v| v.parse().ok()).unwrap_or(0), |
| 86 | styles, | 88 | styles, |
| 87 | events, | 89 | events, |
| @@ -89,6 +91,12 @@ impl Captions { | |||
| 89 | }) | 91 | }) |
| 90 | } | 92 | } |
| 91 | 93 | ||
| 94 | + /// Blur is sized in pixels of a `height`-row video, as libass sizes it against its storage size. | ||
| 95 | + pub fn for_video_height(mut self, height: u32) -> Captions { | ||
| 96 | + self.storage_h = height as f32; | ||
| 97 | + self | ||
| 98 | + } | ||
| 99 | + | ||
| 92 | /// Draws the events `shown` lists at `t_us` onto a BGRA canvas of `size` pixels. | 100 | /// Draws the events `shown` lists at `t_us` onto a BGRA canvas of `size` pixels. |
| 93 | pub fn draw_bgra(&mut self, canvas: &mut [u8], size: (u32, u32), shown: &[Shown], t_us: i64) { | 101 | pub fn draw_bgra(&mut self, canvas: &mut [u8], size: (u32, u32), shown: &[Shown], t_us: i64) { |
| 94 | let (w, h) = (size.0 as usize, size.1 as usize); | 102 | let (w, h) = (size.0 as usize, size.1 as usize); |
| @@ -248,11 +256,13 @@ impl Captions { | |||
| 248 | let y0 = top; | 256 | let y0 = top; |
| 249 | let y1 = top + block; | 257 | let y1 = top + block; |
| 250 | let bsc = if self.scaled { sy } else { 1.0 }; | 258 | let bsc = if self.scaled { sy } else { 1.0 }; |
| 259 | + let blur_px = if self.storage_h > 0.0 { hf / self.storage_h } else { 1.0 }; | ||
| 260 | + let sigma_of = |r: &Run| ((0.849 * r.blur).powi(2) + 0.5 * r.edge_blur).sqrt() * blur_px; | ||
| 251 | let reach = walk | 261 | let reach = walk |
| 252 | .runs | 262 | .runs |
| 253 | .iter() | 263 | .iter() |
| 254 | .map(|r| { | 264 | .map(|r| { |
| 255 | - let sigma = (r.blur + r.edge_blur) * bsc; | 265 | + let sigma = sigma_of(r); |
| 256 | r.border.abs() * bsc + r.shadow.abs() * bsc + 3.0 * sigma | 266 | r.border.abs() * bsc + r.shadow.abs() * bsc + 3.0 * sigma |
| 257 | }) | 267 | }) |
| 258 | .fold(0.0, f32::max); | 268 | .fold(0.0, f32::max); |
| @@ -274,7 +284,7 @@ impl Captions { | |||
| 274 | let mut fill = coverage(&glyphs, (mw, mh), (ox as f32, oy as f32)); | 284 | let mut fill = coverage(&glyphs, (mw, mh), (ox as f32, oy as f32)); |
| 275 | let border = run.border * bsc; | 285 | let border = run.border * bsc; |
| 276 | let shadow = (run.shadow * bsc).round() as i32; | 286 | let shadow = (run.shadow * bsc).round() as i32; |
| 277 | - let sigma = (run.blur + run.edge_blur) * bsc; | 287 | + let sigma = sigma_of(run); |
| 278 | let mut edge = Vec::new(); | 288 | let mut edge = Vec::new(); |
| 279 | if border > 0.0 { | 289 | if border > 0.0 { |
| 280 | edge = dilate(&fill, mw, mh, border); | 290 | edge = dilate(&fill, mw, mh, border); |
crates/engine/src/export.rsmodified+1 -1
| @@ -7055,7 +7055,7 @@ pub fn compose_at_with( | |||
| 7055 | if let Some((pick, style)) = burn { | 7055 | if let Some((pick, style)) = burn { |
| 7056 | let (sources, cues): (Vec<usize>, Vec<Cue>) = burn_cues_indexed(project, pick, meta.frame_rate)?.into_iter().unzip(); | 7056 | let (sources, cues): (Vec<usize>, Vec<Cue>) = burn_cues_indexed(project, pick, meta.frame_rate)?.into_iter().unzip(); |
| 7057 | let on = cues_on_screen(&cues, frame, meta.frame_rate); | 7057 | let on = cues_on_screen(&cues, frame, meta.frame_rate); |
| 7058 | - match native_script(project, pick, &style) { | 7058 | + match native_script(project, pick, &style).map(|c| c.for_video_height(meta.height)) { |
| 7059 | Some(mut captions) => { | 7059 | Some(mut captions) => { |
| 7060 | let shown = native_shown(&cues, &sources, &on); | 7060 | let shown = native_shown(&cues, &sources, &on); |
| 7061 | let t_us = (f64::from(frame) / meta.frame_rate * 1e6).round() as i64; | 7061 | let t_us = (f64::from(frame) / meta.frame_rate * 1e6).round() as i64; |