fix(render): Fill keeps a scaled-up text layer's working image small (#4158) (#4159)

* fix(render): Fill keeps a scaled-up text layer's working image small (#4158)

A layer's effect stack skips the cover of the whole layer rectangle only
when every effect is in SKIPS_COVER. Fill was not, so a text layer with
Fill scaled up to ~900 % got a working image the size of the scaled layer
rectangle on every frame, and a render reached tens of GB.

Fill without Invert only recolours pixels the layer already has (masked
or not), so it now skips the cover too. Inverted, it paints the layer's
transparent area and keeps it. The check reads the instance's Invert
value, so EffectSpec gains skips_cover_for(params).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(render): a feathered Fill keeps the cover (#4158)

With a feather, a Fill mask edge outside the painted pixels still blurs
into them, so the coverage has to be computed beyond the painted bounds.
Keep the cover when either feather is set; unfeathered Fill (the default)
still skips it. Adds a covered-reference test with a feathered mask whose
edge lies just outside the painted content (fails without this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MeanTemperatureandClaude Opus 5.5 authored and GitHub committed 2026-11-28 08:52:51 +01:00
1 parent 61e4f00138
commit 1855d02c47
4 files changed
+144 -2

No files matched your search

+14
View File
@@ -670,6 +670,20 @@ impl EffectSpec {
pub fn skips_cover(&self) -> bool {
SKIPS_COVER.contains(&self.id)
}
/// [`EffectSpec::skips_cover`] for one instance, given its current parameters (evaluated only
/// when the answer depends on them). Fill without Invert or feather only recolours pixels the
/// layer already has, masked or not, so it needs no room beyond them: covering the whole layer
/// rectangle only inflated working images on scaled-up text (#4158). Inverted, it paints the
/// layer's transparent area; feathered, a mask edge outside the painted pixels still blurs into
/// them. Both keep the cover.
pub fn skips_cover_for(&self, params: impl FnOnce() -> Params) -> bool {
self.skips_cover()
|| (self.id == "ec.generate.fill" && {
let p = params();
!p.b("invert") && p.f("horizontalFeather") <= 0.0 && p.f("verticalFeather") <= 0.0
})
}
}
pub(crate) fn p(id: &'static str, name: &'static str, default: Value, ui: ParamUi) -> ParamSpec {
+4 -2
View File
@@ -829,12 +829,14 @@ impl<'a> Renderer<'a> {
// get the cover: they move content past the painted bounds without growing the buffer.
let video = || {
fx.groups().filter(|g| g.enabled).filter_map(|g| match &g.kind {
GroupKind::Effect { effect } => effectcraft_effects::find(effect).filter(|s| !effectcraft_effects::audio_fx::is_audio_effect(s.id)),
GroupKind::Effect { effect } => {
effectcraft_effects::find(effect).filter(|s| !effectcraft_effects::audio_fx::is_audio_effect(s.id)).map(|s| (s, g))
}
_ => None,
})
};
if !adjustment && video().next().is_some() {
if video().all(|s| s.skips_cover()) {
if video().all(|(s, g)| s.skips_cover_for(|| self.effect_params(ctx, layer, g))) {
target.align(layer_size);
} else {
target.cover(layer_size);
+1
View File
@@ -12,6 +12,7 @@ mod aux_channels;
mod collapse;
mod color;
mod drop_shadow_cover;
mod fill_cover;
mod footage_size;
mod frame_blend;
mod guides;
+125
View File
@@ -0,0 +1,125 @@
use super::*;
use crate::{EvalCtx, Image, NoFootage, RenderOpts, Renderer};
use effectcraft_effects::Buf;
// The same synthetic painted source as `drop_shadow_cover.rs`: no installed fonts, and none of
// the multi-gigabyte allocation from #4158, but the same text effect-stack bounds.
fn source(scale: f64) -> Buf {
let mut img = Image::new(20, 12);
for y in 2..10 {
for x in 2..18 {
img.set(x, y, [0.8, 0.2, 0.1, 1.0]);
}
}
Buf { img, offset: [7.0, -3.0], scale }
}
fn text_with_fill(fill: &[(&str, Value)], then_glow: bool) -> (Project, ItemId, Comp, effectcraft_project::Layer) {
let (mut p, cid, comp) = setup();
let mut layer = build::layer(&mut p, &comp, "Text", LayerSource::Text, (0, 0), None);
add_effect_200(&mut p, &mut layer, "ec.generate.fill", fill);
if then_glow {
add_effect_200(&mut p, &mut layer, "ec.stylize.glow", &[("radius", Value::Scalar(1.0))]);
}
(p, cid, comp, layer)
}
#[test]
fn fill_does_not_cover_the_zoomed_layer_rectangle() {
for then_glow in [false, true] {
let (p, cid, comp, layer) = text_with_fill(&[("opacity", Value::Scalar(70.0))], then_glow);
let r = Renderer::new(&p, &NoFootage, RenderOpts::default());
let ctx = EvalCtx::new(&p, cid, &comp, Tick::ZERO);
let out = r.apply_effects(&ctx, &layer, source(4.0), false);
// The cover of the layer rectangle makes this at least 800 x 400; the painted source,
// its grid alignment and Glow's margin need far less.
assert!(out.img.width < 192 && out.img.height < 192, "glow {then_glow}: {} x {}", out.img.width, out.img.height);
}
}
#[test]
fn fill_matches_the_covered_reference() {
for scale in [0.5, 1.0, 4.0] {
for opacity in [100.0, 70.0] {
for then_glow in [false, true] {
let (p, cid, comp, layer) = text_with_fill(&[("opacity", Value::Scalar(opacity))], then_glow);
let r = Renderer::new(&p, &NoFootage, RenderOpts::default());
let ctx = EvalCtx::new(&p, cid, &comp, Tick::ZERO);
let input = source(scale);
let mut covered = input.clone();
let (size, origin) = ctx.effect_bounds(&layer);
covered.rebase(origin);
covered.cover(size);
covered.rebase([-origin[0], -origin[1]]);
let actual = r.apply_effects(&ctx, &layer, input, false);
let reference = r.apply_effects(&ctx, &layer, covered, false);
// Compare the union in layer-pixel coordinates. Buffer origins differ by integral pixels.
let x0 = (-actual.offset[0]).min(-reference.offset[0]) as i32;
let y0 = (-actual.offset[1]).min(-reference.offset[1]) as i32;
let x1 = (f64::from(actual.img.width) - actual.offset[0]).max(f64::from(reference.img.width) - reference.offset[0]) as i32;
let y1 = (f64::from(actual.img.height) - actual.offset[1]).max(f64::from(reference.img.height) - reference.offset[1]) as i32;
for y in y0..y1 {
for x in x0..x1 {
let sample = |b: &Buf| b.img.sample_bilinear(f64::from(x) + b.offset[0] + 0.5, f64::from(y) + b.offset[1] + 0.5);
let (a, b) = (sample(&actual), sample(&reference));
for c in 0..4 {
assert!(
(a[c] - b[c]).abs() < 1e-5,
"scale {scale}, opacity {opacity}, glow {then_glow}, ({x}, {y}), channel {c}: {} != {}",
a[c],
b[c]
);
}
}
}
}
}
}
}
#[test]
fn inverted_fill_keeps_the_cover() {
// Inverted, Fill paints the layer's transparent area, so it still needs the whole rectangle.
let (p, cid, comp, layer) = text_with_fill(&[("invert", Value::Bool(true))], false);
let r = Renderer::new(&p, &NoFootage, RenderOpts::default());
let ctx = EvalCtx::new(&p, cid, &comp, Tick::ZERO);
let out = r.apply_effects(&ctx, &layer, source(4.0), false);
assert!(out.img.width >= 800 && out.img.height >= 400, "{} x {}", out.img.width, out.img.height);
}
#[test]
fn feathered_mask_fill_matches_the_covered_reference() {
// A feathered Fill mask whose edge lies just outside the painted content: the feather reaches
// into the painted pixels only if the coverage outside them is computed too.
for scale in [1.0, 4.0] {
let (mut p, cid, comp, mut layer) =
text_with_fill(&[("fillMask", Value::Scalar(1.0)), ("horizontalFeather", Value::Scalar(6.0)), ("verticalFeather", Value::Scalar(6.0))], false);
let mut next = p.next_id;
// Painted layer x spans about -5..11 at scale 1; the mask's right edge sits at 13.
let m = build::mask(&mut Ids(&mut next), "Mask 1", ShapePath::rect([-3.5, 5.0], 33.0, 50.0), MaskMode::None, [255, 255, 0]);
p.next_id = next;
layer.props.sub_mut("masks").unwrap().children.push(effectcraft_project::Node::Group(m));
let r = Renderer::new(&p, &NoFootage, RenderOpts::default());
let ctx = EvalCtx::new(&p, cid, &comp, Tick::ZERO);
let input = source(scale);
let mut covered = input.clone();
let (size, origin) = ctx.effect_bounds(&layer);
covered.rebase(origin);
covered.cover(size);
covered.rebase([-origin[0], -origin[1]]);
let actual = r.apply_effects(&ctx, &layer, input, false);
let reference = r.apply_effects(&ctx, &layer, covered, false);
for y in 2..10 {
for x in 2..18 {
// The painted pixels, in the input buffer's coordinates.
let lx = f64::from(x) - 7.0;
let ly = f64::from(y) + 3.0;
let sample = |b: &Buf| b.img.sample_bilinear(lx + b.offset[0] + 0.5, ly + b.offset[1] + 0.5);
let (a, b) = (sample(&actual), sample(&reference));
for c in 0..4 {
assert!((a[c] - b[c]).abs() < 1e-4, "scale {scale}, ({x}, {y}), channel {c}: {} != {}", a[c], b[c]);
}
}
}
}
}