Effects: text and shape layers run their stack over the whole layer region (#659).
An authored layer's effect buffer spanned only its painted content — the glyph bounding box for text, the drawn bounds for shapes — while the size the stack measures from (effect_bounds) is the whole comp-sized layer rectangle. Tiling and displacement effects computed correct output for pixels outside the painted rectangle and then wrote them into the buffer that was too small, so CC Tiler repeated only within the text box and CC Smear lost its liquid trail at the glyph edge (#658). Buf::cover now grows the stack's input to the layer's rectangle with transparent margins — what a sized source's buffer already is — applied by run_effect_stack whenever an enabled video effect will run, and natively on the GPU by reallocating and copying the texture. The placement and the sized-source paths are unchanged; two regression tests (CC Tiler spans the region, CC Smear trails past the text bounds) fail without the growth.
This commit is contained in:
@@ -264,6 +264,21 @@ impl Buf {
|
||||
pub fn to_px(&self, p: [f64; 2]) -> (f64, f64) {
|
||||
(p[0] * self.scale + self.offset[0], p[1] * self.scale + self.offset[1])
|
||||
}
|
||||
/// Grow the buffer so it covers a `size`-layer-pixel region starting at its offset (see
|
||||
/// [`cover_plan`]): the whole layer rectangle a sized source's buffer already is. Content
|
||||
/// keeps its place; the new area is transparent. No-op when the buffer already covers it.
|
||||
pub fn cover(&mut self, size: [f64; 2]) {
|
||||
let Some((dx, dy, w, h)) = cover_plan(self.offset, self.scale, size, self.img.width, self.img.height) else { return };
|
||||
let src = std::mem::replace(&mut self.img, Image::new(w, h));
|
||||
let (sw, sh) = (src.width as usize, src.height as usize);
|
||||
for y in 0..sh {
|
||||
let s = y * sw;
|
||||
let d = (y + dy as usize) * w as usize + dx as usize;
|
||||
self.img.data[d..d + sw].copy_from_slice(&src.data[s..s + sw]);
|
||||
}
|
||||
self.offset[0] += dx as f64;
|
||||
self.offset[1] += dy as f64;
|
||||
}
|
||||
/// Measure from `origin` (in the current coordinates): a point `p` becomes `p − origin`.
|
||||
/// Moves between layer space and effect space (the renderer's `effect_bounds`).
|
||||
pub fn rebase(&mut self, origin: [f64; 2]) {
|
||||
@@ -281,6 +296,27 @@ impl Buf {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where [`Buf::cover`] would take a buffer: shift its pixels by `(dx, dy)` and resize it to
|
||||
/// `width` × `height` so it spans the `size`-layer-pixel region that starts at its offset — the
|
||||
/// whole layer rectangle, which a sized source's buffer already is. `None` when the buffer
|
||||
/// already covers that region unchanged (footage, solids, the comp below an adjustment).
|
||||
pub fn cover_plan(offset: [f64; 2], scale: f64, size: [f64; 2], width: u32, height: u32) -> Option<(u32, u32, u32, u32)> {
|
||||
if scale <= 0.0 || !scale.is_finite() || !offset[0].is_finite() || !offset[1].is_finite() || !size[0].is_finite() || !size[1].is_finite() {
|
||||
return None;
|
||||
}
|
||||
// Region and content, both as pixel ranges in the buffer's own coordinates.
|
||||
let (rw, rh) = (offset[0] + (size[0] * scale).ceil(), offset[1] + (size[1] * scale).ceil());
|
||||
let (lo_x, lo_y) = (offset[0].min(0.0).floor(), offset[1].min(0.0).floor());
|
||||
let (hi_x, hi_y) = (rw.max(width as f64).ceil(), rh.max(height as f64).ceil());
|
||||
let (nw_f, nh_f) = (hi_x - lo_x, hi_y - lo_y);
|
||||
if !(nw_f <= 16384.0 && nh_f <= 16384.0) {
|
||||
return None;
|
||||
}
|
||||
let (dx, dy) = ((-lo_x) as u32, (-lo_y) as u32);
|
||||
let (nw, nh) = (nw_f.round().max(1.0) as u32, nh_f.round().max(1.0) as u32);
|
||||
(dx != 0 || dy != 0 || nw != width || nh != height).then_some((dx, dy, nw, nh))
|
||||
}
|
||||
|
||||
/// A layer mask at the current time, flattened to a polyline in layer coordinates.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct MaskShape {
|
||||
|
||||
Reference in New Issue
Block a user