mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Warp: keep the antialiased outline outside 8/16 bit RGB (#17578)
The hard outline is measured on 8 and 16 bit RGB only; 32 bit and other colour modes keep today's antialiased outline, decided per pixel surface so group children of another format follow their own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
19b49b8ac0
commit
02a54d237e
2 files changed
+39
-4
No files matched your search
@@ -286,6 +286,11 @@ fn warp_layer(
|
||||
}
|
||||
_ => {
|
||||
if let Some(surf) = l.surface_mut() {
|
||||
// The hard outline is measured on 8 and 16 bit RGB; 32 bit and other modes keep
|
||||
// the antialiased one.
|
||||
let fmt = surf.format();
|
||||
let measured = fmt.mode == photocraft_color::ColorMode::Rgb && fmt.sample != photocraft_color::SampleType::F32;
|
||||
let outline = if measured { outline } else { Outline::Antialiased };
|
||||
*surf = match doc_sel {
|
||||
Some(sel) => {
|
||||
let (lifted, mut rest) = crate::transform_cmds::split_selected(surf, sel)?;
|
||||
@@ -297,7 +302,6 @@ fn warp_layer(
|
||||
}
|
||||
None => {
|
||||
// Content outside the warp box stays where it is.
|
||||
let fmt = surf.format();
|
||||
let warped = warp_mesh_surface_outline(surf, rect, &map, Fold::IN_PLACE, interp, outline, ctl).ok_or(EngineError::Cancelled)?;
|
||||
cancelled(ctl)?;
|
||||
// Tiles are shared, so a surface that has alpha already costs nothing to copy.
|
||||
|
||||
@@ -8,8 +8,13 @@ const H: i32 = 300;
|
||||
|
||||
/// The reference test document: a grey 200x150 layer with black lines every 10 px over white.
|
||||
fn session(pref: &str) -> Session {
|
||||
session_in(pref, "rgb", 8)
|
||||
}
|
||||
|
||||
/// [`session`] in another colour mode and depth.
|
||||
fn session_in(pref: &str, mode: &str, depth: u32) -> Session {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": W, "height": H})).unwrap();
|
||||
s.execute("file.new", json!({"width": W, "height": H, "mode": mode, "depth": depth})).unwrap();
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.edit("fill", |doc, active| {
|
||||
let surface = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap();
|
||||
@@ -43,14 +48,30 @@ fn arc() -> Value {
|
||||
|
||||
/// The layer's RGBA pixels over the canvas after `warp` sampled with `interp` under `pref`.
|
||||
fn warped(pref: &str, warp: Value, interp: &str) -> Vec<[f32; 4]> {
|
||||
let mut s = session(pref);
|
||||
warped_in(session(pref), warp, interp)
|
||||
}
|
||||
|
||||
/// [`warped`] on the document `s`; the pixels padded to four channels.
|
||||
fn warped_in(mut s: Session, warp: Value, interp: &str) -> Vec<[f32; 4]> {
|
||||
let mut p = warp;
|
||||
p["rect"] = json!([100, 75, 300, 225]);
|
||||
p["interpolation"] = json!(interp);
|
||||
s.execute("edit.transform.warp", p).unwrap();
|
||||
let st = s.active().unwrap();
|
||||
let surface = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap();
|
||||
(0..H).flat_map(|y| (0..W).map(move |x| <[f32; 4]>::try_from(surface.pixel(x, y)).unwrap())).collect()
|
||||
(0..H)
|
||||
.flat_map(|y| {
|
||||
(0..W).map(move |x| {
|
||||
let px = surface.pixel(x, y);
|
||||
let mut out = [0.0; 4];
|
||||
out[3] = px.last().copied().unwrap_or(0.0);
|
||||
for (o, v) in out.iter_mut().zip(&px[..px.len() - 1]) {
|
||||
*o = *v;
|
||||
}
|
||||
out
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether every pixel within 3 px of pixel `o` is opaque.
|
||||
@@ -101,3 +122,13 @@ fn free_transform_nearest_neighbor_stays_hard_whatever_the_preference() {
|
||||
assert_eq!(partial(&warped(pref, arc(), "nearest")), 0, "{pref}: Nearest Neighbor sampling has a hard outline");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unmeasured_formats_keep_the_antialiased_outline() {
|
||||
for (mode, depth) in [("rgb", 32), ("grayscale", 8)] {
|
||||
let soft = warped_in(session_in("bilinear", mode, depth), arc(), "bilinear");
|
||||
let pref_nearest = warped_in(session_in("nearestNeighbor", mode, depth), arc(), "bilinear");
|
||||
assert!(partial(&soft) > 0, "{mode} {depth}: the outline is antialiased");
|
||||
assert!(pref_nearest == soft, "{mode} {depth}: the Nearest Neighbor preference changes nothing");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user