mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
fix(ui): keep Clone Stamp source preview crisp when zoomed in (#5995)
This commit is contained in:
1 parent
df055f3dcb
commit
3d95193ef6
2 files changed
+35
-4
No files matched your search
@@ -9,6 +9,7 @@
|
||||
//! `--system-theme light|dark|none` supplies a deterministic OS appearance for theme captures.
|
||||
//!
|
||||
//! `--safe-gpu` draws the canvas on the CPU path, like the app's `--safe-gpu` launch.
|
||||
//! `--hardware-filtering` respects texture samplers; the default predictable renderer forces bilinear filtering.
|
||||
//! `--wayland-notice` previews the native file drag-and-drop guidance shown in Wayland sessions.
|
||||
//! `--custom-titlebar` draws the Windows/Linux title bar (caption buttons in the top bar).
|
||||
//!
|
||||
@@ -66,8 +67,15 @@ fn main() {
|
||||
let custom_titlebar = args.iter().any(|a| a == "--custom-titlebar");
|
||||
// `--settle-ms N`: keep rendering frames for N ms before the capture (e.g. mid-job).
|
||||
let settle_ms: u64 = arg(&args, "--settle-ms").and_then(|s| s.parse().ok()).unwrap_or(0);
|
||||
let mut harness =
|
||||
egui_kittest::Harness::builder().with_size(egui::vec2(w, h)).with_pixels_per_point(scale).with_max_steps(64).wgpu().build_eframe(move |cc| {
|
||||
let mut render_options = eframe::egui_wgpu::RendererOptions::PREDICTABLE;
|
||||
render_options.predictable_texture_filtering = !args.iter().any(|a| a == "--hardware-filtering");
|
||||
let mut harness = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(w, h))
|
||||
.with_pixels_per_point(scale)
|
||||
.with_max_steps(64)
|
||||
.with_render_options(render_options)
|
||||
.wgpu()
|
||||
.build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
|
||||
let mut services = services;
|
||||
services.is_wayland = wayland_notice;
|
||||
|
||||
@@ -88,10 +88,10 @@ fn draw_clone_preview(app: &mut PhotocraftApp, painter: &egui::Painter, xf: &Vie
|
||||
let image = display_image(display.as_deref(), &buf);
|
||||
match app.clone_preview.as_mut() {
|
||||
Some(cache) => {
|
||||
cache.texture.set(image, TextureOptions::LINEAR);
|
||||
cache.texture.set(image, canvas_texture_options(1));
|
||||
cache.key = key;
|
||||
}
|
||||
None => app.clone_preview = Some(ClonePreviewCache { key, texture: painter.ctx().load_texture("clone-preview", image, TextureOptions::LINEAR) }),
|
||||
None => app.clone_preview = Some(ClonePreviewCache { key, texture: painter.ctx().load_texture("clone-preview", image, canvas_texture_options(1)) }),
|
||||
}
|
||||
}
|
||||
let Some(cache) = &app.clone_preview else { return };
|
||||
@@ -6925,6 +6925,29 @@ mod tests {
|
||||
assert!(output.shapes.iter().all(|s| !matches!(s.shape, egui::Shape::Mesh(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clone_overlay_keeps_magnified_pixels_crisp_on_upload_and_refresh() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.run("cloneSource.set", json!({"source": [16, 16]})).unwrap();
|
||||
app.ui.tool = Tool::CloneStamp;
|
||||
app.session.tools.brush.size = 20.0;
|
||||
let xf =
|
||||
ViewXform { rect: Rect::from_min_size(Pos2::ZERO, vec2(200.0, 200.0)), zoom: 4.0, center: [32.0, 32.0], flip: false, rotation: 0.0, aspect: 1.0 };
|
||||
for invert in [false, true] {
|
||||
app.session.presets.clone.overlay.invert = invert;
|
||||
let mut output = ctx.run_ui(Default::default(), |ui| {
|
||||
draw_clone_preview(&mut app, ui.painter(), &xf, [32.0, 32.0], None);
|
||||
});
|
||||
let upload = output.textures_delta.set.values().flatten().find(|d| d.image.size() == [20, 20]).expect("clone overlay upload");
|
||||
let options = upload.options;
|
||||
output.textures_delta.clear();
|
||||
assert_eq!(options.magnification, egui::TextureFilter::Nearest, "invert={invert}");
|
||||
assert_eq!(options.minification, egui::TextureFilter::Linear, "zoomed-out previews remain filtered");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clone_overlay_blend_mode_mixes_with_the_image_under_the_brush() {
|
||||
let ctx = egui::Context::default();
|
||||
|
||||
Reference in new issue
Block a user