From 4bbcede5725fdb8bdb4bfd501eef58b5af140834 Mon Sep 17 00:00:00 2001 From: Gert Pellin - GPE Date: Wed, 14 Oct 2026 07:59:00 +0200 Subject: [PATCH] Fibers: fill an empty layer, as Photoshop does (#5241) (#5289) Fibers renders from the foreground and background colours without reading the layer, but its output area was the layer's content grown by a zero halo: on an empty layer that is empty, so nothing was drawn (and a following transform found nothing to transform). On a partly filled layer only the content's bounding box was filled. It now writes the reference bounds (the selection's, else the canvas) like the global filters, without reading the whole layer as they do. --- crates/algo/src/lib.rs | 14 +++++++++++--- crates/algo/src/tests.rs | 4 ++++ crates/engine/src/filters_ext/tests.rs | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/algo/src/lib.rs b/crates/algo/src/lib.rs index 78dae7b06f..49ab15871c 100644 --- a/crates/algo/src/lib.rs +++ b/crates/algo/src/lib.rs @@ -600,6 +600,13 @@ impl FilterParams { self.halo() == Halo::Bounds } + /// Whether the filter renders new pixels without reading the layer's own (Fibers): it fills + /// the reference bounds even where the layer is transparent, as Photoshop's does on an + /// empty layer, while still reading no neighbourhood. + pub fn renders_from_nothing(&self) -> bool { + matches!(self, FilterParams::Fibers { .. }) + } + /// Human-readable name. pub fn label(&self) -> &'static str { match self { @@ -905,12 +912,13 @@ pub fn kernel(params: &FilterParams, src: &Image, out: Rect, ctx: &Ctx) -> Vec) -> Rect { let mut area = match params.halo_for(bounds) { Halo::Bounds => bounds, + Halo::Radius(_) if params.renders_from_nothing() => bounds, Halo::Radius(r) => { if content.is_empty() { Rect::EMPTY diff --git a/crates/algo/src/tests.rs b/crates/algo/src/tests.rs index 9a90012df9..31def5f99d 100644 --- a/crates/algo/src/tests.rs +++ b/crates/algo/src/tests.rs @@ -446,6 +446,10 @@ fn halos_and_output_area() { assert_eq!(output_area(&FilterParams::Twirl { angle: 1.0 }, content, R, None), R); assert_eq!(output_area(&FilterParams::BoxBlur { radius: 1.0 }, content, R, Some(Rect::new(0, 0, 12, 12))), Rect::new(8, 8, 12, 12)); assert!(output_area(&FilterParams::Invert, Rect::EMPTY, R, None).is_empty()); + // Fibers renders without reading the layer: an empty layer still fills the bounds (#5241). + let fibers = FilterParams::Fibers { variance: 16.0, strength: 4.0, seed: 0, foreground: [0.0; 4], background: [1.0; 4] }; + assert_eq!(output_area(&fibers, Rect::EMPTY, R, None), R); + assert_eq!(output_area(&fibers, content, R, Some(Rect::new(0, 0, 12, 12))), Rect::new(0, 0, 12, 12)); } #[test] diff --git a/crates/engine/src/filters_ext/tests.rs b/crates/engine/src/filters_ext/tests.rs index b616101f7c..0f32c5367d 100644 --- a/crates/engine/src/filters_ext/tests.rs +++ b/crates/engine/src/filters_ext/tests.rs @@ -164,6 +164,27 @@ fn colour_filters_use_and_record_tool_colours() { } } +#[test] +fn fibers_fill_an_empty_layer() { + // #5241: Fibers renders from the colours, not the layer's pixels, so an empty layer fills + // like in Photoshop (and can be transformed afterwards). + let mut s = Session::new(); + s.execute("file.new", json!({"width": 48, "height": 32})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("filter.render.fibers", json!({"seed": 3})).unwrap(); + let px = pixels(&s); + assert!(px.as_chunks::<4>().0.iter().all(|p| p[3] == 1.0), "every pixel is rendered opaque"); + s.execute("edit.transform.flipHorizontal", json!({})).unwrap(); + + // With a selection only the selection fills. + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("select.rect", json!({"x": 4, "y": 4, "width": 10, "height": 6})).unwrap(); + s.execute("filter.render.fibers", json!({"seed": 3})).unwrap(); + let d = s.active().unwrap(); + let surf = d.doc.layer(d.active_layer.unwrap()).unwrap().surface().unwrap(); + assert_eq!(surf.content_bounds(), Rect::new(4, 4, 14, 10)); +} + #[test] fn displace_reads_another_document() { let mut s = session();