Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge main into #1279; effects/lib.rs: keep the PR's Buf::grow_left_top/align beside main's budgeted Buf::pad, and put cover_plan's doc comment back on cover_plan (the PR's new items had split it off)

bflatastic56fde5c3d6e4
diff --cc crates/effects/src/lib.rs
index 21d06f503,117506807..44c8a987b
--- a/crates/effects/src/lib.rs
+++ b/crates/effects/src/lib.rs
@@@ -311,27 -312,16 +312,29 @@@ impl Buf
self.offset[0] += l as f64;
self.offset[1] += t as f64;
}
+ /// Grow by `left` and `top` transparent pixels on those sides only.
+ pub fn grow_left_top(&mut self, left: u32, top: u32) {
+ self.pad_sides([left, top, 0, 0]);
+ }
+ /// Give the buffer the pixel-grid phase (modulo [`GRID_ALIGN`]) that [`Buf::cover`] of
+ /// `size` would, by growing left/top only ([`align_plan`]). A downscaled layer is resampled
+ /// through a pyramid whose 2x2 blocks follow the buffer's grid, so a buffer that starts at
+ /// its content's corner instead of the cover's resamples to different pixels (#1205).
+ pub fn align(&mut self, size: [f64; 2]) {
+ if let Some((l, t)) = align_plan(self.offset, self.scale, size, self.img.width, self.img.height) {
+ self.grow_left_top(l, t);
+ }
+ }
- /// Grow by `pad` transparent pixels on every side.
+ /// Grow by `pad` transparent pixels on every side, within [`pad_within_budget`] and as
+ /// clamped by [`Image::effective_pad`].
pub fn pad(&mut self, pad: u32) {
- if pad == 0 {
+ let eff = self.img.effective_pad(pad_within_budget(self.img.width, self.img.height, pad));
+ if eff == 0 {
return;
}
- self.img = self.img.padded(pad);
- self.offset[0] += pad as f64;
- self.offset[1] += pad as f64;
+ self.img = self.img.padded(eff);
+ self.offset[0] += eff as f64;
+ self.offset[1] += eff as f64;
}
}
@@@ -372,37 -377,10 +390,37 @@@ pub fn adjustment_crop(offset: [f64; 2]
Some((dx as i64, dy as i64))
}
- /// 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).
+/// Effects that grow their own buffer by what they need (blur and glow margins, Repeat Edge
+/// Pixels through [`Buf::cover`], displacement through [`cover_pad`]): a stack of only these
+/// skips the renderer's cover of the whole layer rectangle (#1205).
+pub const SKIPS_COVER: &[&str] = &["ec.blur.gaussian", "ec.blur.fastbox", "ec.stylize.glow", "ec.distort.turbulentdisplace"];
+
+/// The grid phase [`Buf::align`] keeps and the step [`cover_pad`] grows in: covers the levels
+/// of the resampling pyramid used for downscaled layers.
+pub const GRID_ALIGN: u32 = 64;
+
+/// Left/top growth giving a buffer [`cover_plan`]'s grid phase modulo [`GRID_ALIGN`]; `None`
+/// when there is nothing to add.
+pub fn align_plan(offset: [f64; 2], scale: f64, size: [f64; 2], width: u32, height: u32) -> Option<(u32, u32)> {
+ let (dx, dy, _, _) = cover_plan(offset, scale, size, width, height)?;
+ let (l, t) = (dx % GRID_ALIGN, dy % GRID_ALIGN);
+ (l != 0 || t != 0).then_some((l, t))
+}
+
+/// Padding for an effect that moves pixels up to `want` past the content (not an adjustment
+/// layer): `want`, capped at what reaches the layer rectangle, in whole [`GRID_ALIGN`] steps so
+/// the grid phase stays. 0 once the buffer covers the layer.
+pub fn cover_pad(ctx: &EffectCtx, size: [u32; 2], offset: [f64; 2], scale: f64, want: u32) -> u32 {
+ if ctx.adjustment {
+ return 0;
+ }
+ want.min(util::layer_cover_pad(ctx, size, offset, scale)).div_ceil(GRID_ALIGN) * GRID_ALIGN
+}
+
+ /// 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;