mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
fix(filters): Clouds size their pattern by the canvas, not the selection
Since Clouds became a filter, its cloud size came from the filter's reference bounds, which are the selection's when there is one: clouds in a selection were finer than the canvas's. Before, they were sized by the document. Clouds now take the canvas as their bounds; the selection only masks them, as before (review on #6160).
This commit is contained in:
1 parent
c6fff8a3a8
commit
875ec69fce
3 files changed
+34
-2
No files matched your search
@@ -616,6 +616,12 @@ impl FilterParams {
|
||||
matches!(self, FilterParams::Fibers { .. } | FilterParams::Clouds { difference: false, .. })
|
||||
}
|
||||
|
||||
/// Whether the filter sizes its pattern by the canvas even with a selection (Clouds): its
|
||||
/// bounds are then the canvas, and the selection only masks the result.
|
||||
pub fn sizes_by_canvas(&self) -> bool {
|
||||
matches!(self, FilterParams::Clouds { .. })
|
||||
}
|
||||
|
||||
/// Human-readable name.
|
||||
pub fn label(&self) -> &'static str {
|
||||
match self {
|
||||
|
||||
@@ -1440,6 +1440,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// A selection masks Clouds but doesn't change their size: inside it they are the canvas's
|
||||
/// clouds, as when Clouds sized itself by the document (before it became a filter).
|
||||
#[test]
|
||||
fn clouds_in_a_selection_are_the_canvas_clouds() {
|
||||
// Big enough that the canvas (cloud size 100 px) and the selection (16 px) size differently.
|
||||
let big = |depth: u32| {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth})).unwrap();
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s
|
||||
};
|
||||
for depth in [8, 16, 32] {
|
||||
let mut whole = big(depth);
|
||||
whole.execute("filter.render.clouds", json!({"seed": 4})).unwrap();
|
||||
let mut s = big(depth);
|
||||
s.execute("select.rect", json!({"x": 50, "y": 40, "width": 60, "height": 50})).unwrap();
|
||||
s.execute("filter.render.clouds", json!({"seed": 4})).unwrap();
|
||||
for (x, y) in [(50, 40), (75, 60), (100, 85), (109, 89)] {
|
||||
let (a, b) = (pixel(&s, x, y), pixel(&whole, x, y));
|
||||
assert!((0..4).all(|c| (a[c] - b[c]).abs() < 1e-3), "depth {depth} at {x},{y}: {a:?} vs {b:?}");
|
||||
}
|
||||
assert_eq!(pixel(&s, 300, 200)[3], 0.0, "outside the selection the layer stays empty");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn average_and_clouds() {
|
||||
let mut s = session(8);
|
||||
|
||||
@@ -262,9 +262,10 @@ pub(crate) fn run_filter(s: &mut Session, id: &str, p: &Value) -> Result<Value>
|
||||
};
|
||||
let selection = doc.selection.clone();
|
||||
let sel_bounds = selection.as_ref().map(photocraft_raster::Surface::content_bounds);
|
||||
// Distortions centre on the selection when there is one, else the canvas.
|
||||
// Distortions centre on the selection when there is one, else the canvas. Clouds size
|
||||
// their pattern by the canvas either way; the selection only masks them.
|
||||
let doc_bounds = doc.bounds();
|
||||
let bounds = sel_bounds.filter(|b| !b.is_empty()).unwrap_or(doc_bounds);
|
||||
let bounds = if fp.sizes_by_canvas() { doc_bounds } else { sel_bounds.filter(|b| !b.is_empty()).unwrap_or(doc_bounds) };
|
||||
// Neighbourhood filters repeat edge pixels at the canvas edge (or past it, where the
|
||||
// layer has off-canvas pixels) instead of fading in transparency, as Photoshop does.
|
||||
if let Some(surf) = crate::channel_cmds::channel_surface_for_filter(doc, Some(layer), &p)? {
|
||||
|
||||
Reference in new issue
Block a user