Files
photocraft/crates/engine/examples/bench_art_history.rs
T
ce6b831c03 Integration: Art History Brush tolerance, source window, History source (#1610)
- Tolerance defaulted to 50 and averaged alpha into the difference, so an
  ordinary edit (e.g. #c03030 -> #d04848) was never painted back, and a stroke
  that wrote nothing still left an empty History step. Photoshop's default is
  0; the difference is now the larger of the mean colour change and the
  alpha change (the Eraser keeps colour and lowers alpha), and a stroke that
  writes nothing is an error instead of an empty step.
- Each tile copied a source window of tile +- halo per dab: a leftward stroke
  or a curl across x = 64 read empty pixels there (seam), and a size-1000 click
  copied ~5e9 floats (11.9 s). The rotated read stays inside the dab, so it now
  samples the source directly; bilinear reads at pixel centres, so an
  unrotated dab copies the history pixel instead of a 2x2 blend.
- The brush used its own history lookup (state 0 by default): it now takes
  the History Brush's source (history.setSource, snapshots, refusal after a
  canvas size change).
- TOOL-213-20 is partial (8 of 10 styles, Area scales spacing); docs follow.

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 11:11:50 +01:00

61 lines
1.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! 24 MP timing of Art History Brush on a representative stroke.
//! `cargo run --release -p photocraft-engine --example bench_art_history`
use std::time::Instant;
use photocraft_engine::Session;
use photocraft_geom::Rect;
use serde_json::json;
fn main() {
let (w, h) = (6016u32, 4000u32);
let mut s = Session::new();
s.execute("file.new", json!({"width": w, "height": h, "depth": 8, "mode": "rgb"})).unwrap();
s.edit("texture", |doc, active| {
let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap();
let fmt = surf.format();
let row: Vec<f32> = (0..w)
.flat_map(|x| {
let t = (x % 256) as f32 / 255.0;
photocraft_raster::from_rgba(&fmt, [t, 0.35, 1.0 - t, 1.0])
})
.collect();
for y in 0..h as i32 {
surf.write_region(Rect::new(0, y, w as i32, y + 1), &row);
}
Ok(())
})
.unwrap();
s.execute("edit.fill", json!({"color": "#606060"})).unwrap();
let points: Vec<[i32; 2]> = (0..200).map(|i| [2800 + i, 2000]).collect();
let run = |s: &mut Session, style: &str| {
s.execute(
"paint.artHistoryBrush",
json!({
"points": points,
"size": 40,
"hardness": 100,
"area": 50,
"tolerance": 0,
"style": style,
"state": 0
}),
)
.unwrap();
};
// Warm the allocator / tile cache.
run(&mut s, "tightMedium");
s.undo();
for style in ["tightMedium", "looseCurl"] {
let t = Instant::now();
run(&mut s, style);
let ms = t.elapsed().as_secs_f64() * 1000.0;
println!(
"artHistoryBrush document {w}×{h} ({:.1} MP) stroke 200 px size 40 area 50 style {style} {ms:.3} ms",
(w as u64 * h as u64) as f64 / 1e6
);
s.undo();
}
}