Preferences › Performance › Low Resolution Previews (on by default) (#1247)

Live previews of large documents (filter dialogs, adjustment dialogs that fall back to the
filter preview, zoomed-out adjustment dialogs, an adjustment layer's sliders while they drag)
render on a nearest-neighbour reduced copy: a 16 MP photo previews at every 3rd pixel, drawn
3x blocky at 100 %. Turning the setting off renders them at full resolution.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
UnemarsandClaude Opus 5.5 authored and GitHub committed 2026-10-08 19:10:02 -04:00
1 parent e2956dcf93
commit 3439d327f7
20 files changed
+226 -8

No files matched your search

+5
View File
@@ -408,6 +408,10 @@ pub struct Performance {
pub rendering_mode: Option<RenderingMode>,
/// Graphics backend (applies at next launch; see [`GpuBackend`]).
pub gpu_backend: GpuBackend,
/// Live previews of large documents (adjustment and filter dialogs, an adjustment layer's
/// sliders while they drag) render on a reduced copy: fast, but blocky when zoomed in. Off:
/// they render at full resolution.
pub low_resolution_previews: bool,
/// Memory budget of the layer-effect cache, in MB.
pub effect_cache_mb: u32,
pub legacy_compositing: bool,
@@ -436,6 +440,7 @@ impl Default for Performance {
use_gpu: true,
rendering_mode: None,
gpu_backend: GpuBackend::Auto,
low_resolution_previews: true,
effect_cache_mb: 768,
legacy_compositing: false,
}
+13
View File
@@ -187,6 +187,19 @@ fn json_round_trip_tolerates_unknown_and_missing_keys() {
assert!(u.load_prefs_json("not json").is_err());
}
#[test]
fn low_resolution_previews_default_on_and_switch_off() {
// A preferences file from before the setting keeps the fast previews.
let mut s = Session::new();
s.load_prefs_json(r#"{"performance": {"historyStates": 20}}"#).unwrap();
assert!(s.prefs().performance.low_resolution_previews);
s.execute("prefs.set", json!({"path": "performance.lowResolutionPreviews", "value": false})).unwrap();
assert!(!s.prefs().performance.low_resolution_previews);
let mut t = Session::new();
t.load_prefs_json(&s.prefs_to_json()).unwrap();
assert!(!t.prefs().performance.low_resolution_previews);
}
#[test]
fn units_convert_both_ways() {
for u in [Unit::Pixels, Unit::Inches, Unit::Centimeters, Unit::Millimeters, Unit::Points, Unit::Picas, Unit::Percent] {
+6 -2
View File
@@ -9,7 +9,8 @@
//! - over the target's area within the selection only (`switch_region`), and of that only what
//! the view shows; the rest catches up as the view moves (`uncovered`);
//! - zoomed out on a large document, on a copy reduced to about the screen's resolution, built
//! once per session ([`gpu_proxy`]).
//! once per session ([`gpu_proxy`]), unless Preferences › Performance › Low Resolution Previews
//! is off.
//!
//! OK still runs the real command (one history step); Cancel just drops the preview. The base
//! document (with the preview layer) and the region are built once per dialog session; a change
@@ -199,7 +200,7 @@ fn hash(parts: &[&[u8]]) -> u64 {
fn cheap(app: &PhotocraftApp, doc: &Document) -> bool {
match &app.gpu {
Some(g) => g.supports(doc),
None => crate::proxy::factor(doc) <= 1,
None => crate::proxy::preview_factor(doc, crate::proxy::reduced_previews(app)) <= 1,
}
}
@@ -386,6 +387,9 @@ pub struct ProxyFrame {
/// and the view is far enough out that a reduced copy shows the same detail as the full-size
/// composite: each change then composites ~1/k² of the pixels. Built once per session and factor.
pub fn gpu_proxy(app: &mut PhotocraftApp, idx: usize, zoom: f32) -> Option<ProxyFrame> {
if !crate::proxy::reduced_previews(app) {
return None;
}
let gpu = app.gpu.clone()?;
update(app, idx)?;
let p = app.adjust_preview.as_mut()?;
+6 -4
View File
@@ -704,7 +704,7 @@ pub fn ensure_texture(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize,
// a large document (taken by the GPU path) would cost a full-size CPU composite per change.
if crate::adjust_preview::shown_key(app) == Some(preview_key)
&& let Some(st) = app.session.documents().get(idx)
&& crate::proxy::factor(&st.doc) > 1
&& crate::proxy::preview_factor(&st.doc, crate::proxy::reduced_previews(app)) > 1
{
(doc, preview_key) = (st.doc.clone(), 0);
}
@@ -940,7 +940,7 @@ fn ensure_filter_preview(app: &mut PhotocraftApp, idx: usize) -> Option<(u32, u6
let st = app.session.documents().get(idx)?;
(st.doc.id, st.revision, st.doc.clone(), st.active_layer)
};
let k = crate::proxy::factor(&doc);
let k = crate::proxy::preview_factor(&doc, crate::proxy::reduced_previews(app));
let hash = format!("{cmd}{params}").bytes().fold(k as u64 ^ revision.wrapping_mul(0x9e37), |h, b| h.wrapping_mul(31).wrapping_add(b as u64));
let key = doc_id.0 ^ (1u64 << 61);
let fresh = matches!(&app.filter_preview, Some(p) if p.doc == doc_id && p.hash == hash);
@@ -992,7 +992,8 @@ fn ensure_proxy_preview(app: &mut PhotocraftApp, idx: usize) -> Option<(u32, u64
let st = app.session.documents().get(idx)?;
(st.doc.id, st.revision, st.doc.clone())
};
let k = crate::proxy::factor(&doc);
// Low-resolution previews off: k is 1 and the canvas shows `display_doc` (full size).
let k = crate::proxy::preview_factor(&doc, crate::proxy::reduced_previews(app));
if k <= 1 {
return None;
}
@@ -1755,7 +1756,8 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
let drop_shadow = border == photocraft_engine::prefs::CanvasBorder::DropShadow;
// Drop shadow, checkerboard, document image.
let img_rect = xf.doc_rect(doc.bounds());
// Live adjustment previews on big documents use a downsampled proxy (see proxy.rs).
// Live adjustment previews on big documents use a downsampled proxy (see proxy.rs), unless
// Preferences › Performance › Low Resolution Previews is off.
let mut on_gpu = false;
// A flipped view draws through the CPU path (the GPU canvas shader has no mirroring).
if app.gpu.is_some()
+1
View File
@@ -1817,6 +1817,7 @@
Maximize psd compatibility Maximalizovat kompatibilitu PSD
Medium gray Středně šedá
Memory usage mb Využití paměti (MB)
Low resolution previews Náhledy v nízkém rozlišení
Missing glyph protection Ochrana proti chybějícím glyfům
Modern Moderní
Nearest neighbor Nejbližší soused
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1794,6 +1794,7 @@
Maximize psd compatibility PSD-Kompatibilität maximieren
Medium gray Mittelgrau
Memory usage mb Speichernutzung (MB)
Low resolution previews Vorschau in niedriger Auflösung
Missing glyph protection Schutz vor fehlenden Glyphen
Modern Modern
Nearest neighbor Nächster Nachbar
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1803,6 +1803,7 @@
Maximize psd compatibility Maximizar la compatibilidad de PSD
Medium gray Gris medio
Memory usage mb Uso de memoria (MB)
Low resolution previews Previsualizaciones de baja resolución
Missing glyph protection Protección de glifos faltantes
Modern Moderno
Nearest neighbor Vecino más cercano
Can't render this file because it contains an unexpected character in line 4 and column 47.
+1
View File
@@ -1781,6 +1781,7 @@
Maximize psd compatibility Maximiser la compatibilité PSD
Medium gray Gris moyen
Memory usage mb Utilisation de la mémoire (Mo)
Low resolution previews Aperçus en basse résolution
Missing glyph protection Protection contre les glyphes manquants
Modern Moderne
Nearest neighbor Au plus proche
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1775,6 +1775,7 @@
Maximize psd compatibility Maksimalkan kompatibilitas PSD
Medium gray Abu-abu sedang
Memory usage mb Pemakaian memori MB
Low resolution previews Pratinjau resolusi rendah
Missing glyph protection Perlindungan glyph hilang
Modern Modern
Nearest neighbor Nearest neighbor
Can't render this file because it contains an unexpected character in line 4 and column 47.
+1
View File
@@ -1800,6 +1800,7 @@
Maximize psd compatibility Massimizza compatibilità PSD
Medium gray Grigio medio
Memory usage mb Uso memoria MB
Low resolution previews Anteprime a bassa risoluzione
Missing glyph protection Protezione glifi mancanti
Modern Moderno
Nearest neighbor Vicino più prossimo
1 # Italian (it) catalog. Columns, separated by a TAB: context <TAB> source <TAB> translation
1800
1801
1802
1803
1804
1805
1806
+1
View File
@@ -1808,6 +1808,7 @@
Maximize psd compatibility PSD の互換性を最大にする
Medium gray 中間グレー
Memory usage mb メモリ使用量 (MB)
Low resolution previews 低解像度プレビュー
Missing glyph protection 字形欠落の保護
Modern モダン
Nearest neighbor ニアレストネイバー
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1776,6 +1776,7 @@
Maximize psd compatibility PSD 호환성 최대화
Medium gray 중간 회색
Memory usage mb 메모리 사용량(MB)
Low resolution previews 저해상도 미리 보기
Missing glyph protection 누락된 글리프 보호
Modern 현대적
Nearest neighbor 최근접 이웃
1 # Korean (ko) catalog. UTF-8: context<TAB>English source<TAB>translation.
1776
1777
1778
1779
1780
1781
1782
+1
View File
@@ -1802,6 +1802,7 @@
Language Język
Large tabs Duże karty
Legacy compositing Starszy sposób komponowania
Low resolution previews Podglądy w niskiej rozdzielczości
Light gray Jasnoszary
Line Linia
Lines Linie
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1780,6 +1780,7 @@
Maximize psd compatibility Maximizar compatibilidade de PSD
Medium gray Cinza médio
Memory usage mb Uso de memória (MB)
Low resolution previews Visualizações em baixa resolução
Missing glyph protection Proteção de glifos ausentes
Modern Moderno
Nearest neighbor Vizinho mais próximo
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -2206,6 +2206,7 @@
Maximize psd compatibility Максимальная совместимость PSD
Medium gray Средне-серая
Memory usage mb Память (МБ)
Low resolution previews Превью в низком разрешении
Metal Metal
Missing glyph protection Защита от отсутствующих глифов
Modern Современный
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1810,6 +1810,7 @@
Maximize psd compatibility 最大化 PSD 兼容性
Medium gray 中灰色
Memory usage mb 内存使用量 (MB)
Low resolution previews 低分辨率预览
Missing glyph protection 缺失字形保护
Modern 现代
Nearest neighbor 邻近
1 # Simplified Chinese (zh-hans) catalog. UTF-8, TAB-separated columns:
1810
1811
1812
1813
1814
1815
1816
+1
View File
@@ -1803,6 +1803,7 @@
Maximize psd compatibility 最大化 PSD 相容性
Medium gray 中灰
Memory usage mb 記憶體使用量 (MB)
Low resolution previews 低解析度預覽
Missing glyph protection 缺少字符保護
Modern 現代
Nearest neighbor 最接近像素
Can't render this file because it contains an unexpected character in line 6 and column 47.
+14
View File
@@ -16,6 +16,17 @@ pub fn factor(doc: &Document) -> u32 {
((px as f64 / PREVIEW_PIXELS as f64).sqrt().ceil() as u32).max(2)
}
/// Whether live previews may run on a reduced copy (Preferences › Performance › Low Resolution
/// Previews, on by default). Off, every live preview renders at full resolution.
pub fn reduced_previews(app: &crate::PhotocraftApp) -> bool {
app.session.prefs().performance.low_resolution_previews
}
/// Downscale factor of a live preview of `doc`: [`factor`], or 1 when reduced previews are off.
pub fn preview_factor(doc: &Document, reduced: bool) -> u32 {
if reduced { factor(doc) } else { 1 }
}
pub use photocraft_compose::proxy::{downsample, proxy_document};
#[cfg(test)]
@@ -32,6 +43,9 @@ mod tests {
let k = factor(&big);
assert!((3..=5).contains(&k), "{k}");
assert!(big.size.area() / (k as u64 * k as u64) <= PREVIEW_PIXELS);
assert_eq!(preview_factor(&big, true), k);
assert_eq!(preview_factor(&big, false), 1);
assert_eq!(preview_factor(&small, true), 1);
}
#[test]
+167
View File
@@ -0,0 +1,167 @@
//! Preferences › Performance › Low Resolution Previews: on (the default) live previews of a large
//! document render on a reduced copy, off they render at full resolution.
//!
//! A 3000 × 2000 document of 1 px black and white columns: the reduced copy (every 2nd pixel at
//! this size) is all black, so its preview shows a flat colour where the full-size one shows the
//! columns at 100 % (and their mipmapped grey zoomed out). Drives the real app offscreen on wgpu;
//! skips when no GPU adapter exists (like `drag_preview_canvas.rs`).
use photocraft_color::{Color, ColorMode, SampleType};
use photocraft_doc::{Document, Size};
use photocraft_geom::Rect;
use photocraft_ui_egui::PhotocraftApp;
use photocraft_ui_egui::control::{ControlRequest, handle};
use serde_json::{Value, json};
type Harness = egui_kittest::Harness<'static, PhotocraftApp>;
const W: i32 = 3000;
const H: i32 = 2000;
fn harness() -> Option<Harness> {
let built = std::panic::catch_unwind(|| {
egui_kittest::Harness::builder().with_size(egui::vec2(1100.0, 760.0)).with_pixels_per_point(1.0).with_max_steps(64).wgpu().build_eframe(|cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
if let Some(rs) = cc.wgpu_render_state.as_ref() {
app.set_wgpu(rs.clone());
}
app
})
});
match built {
Ok(h) => Some(h),
Err(_) => {
eprintln!("skipping: no GPU adapter");
None
}
}
}
fn control(h: &mut Harness, method: &str, params: Value) {
let ctx = h.ctx.clone();
let (req, _rx) = ControlRequest::new(method, params);
handle(h.state_mut(), &ctx, &req);
h.run_steps(3);
}
fn columns_document() -> Document {
let mut doc = Document::with_background("columns", Size::new(W as u32, H as u32), ColorMode::Rgb, SampleType::U8, Color::WHITE);
let s = doc.layers[0].surface_mut().expect("background pixels");
for x in (0..W).step_by(2) {
s.fill_rect(Rect::new(x, 0, x + 1, H), &[0.0, 0.0, 0.0, 1.0]);
}
doc
}
fn setup(h: &mut Harness, zoom: f32) {
{
let app = h.state_mut();
app.session.add_document(columns_document(), None);
app.sync_views();
app.ui.extras.rulers = false;
}
control(h, "ui.set", json!({"zoom": zoom, "center": [W / 2, H / 2]}));
h.run_steps(4);
}
/// Whether the canvas draws on the GPU (the previews under test are the GPU canvas's).
fn on_gpu(h: &mut Harness) -> bool {
let _ = h.render();
let gpu = h.state().perf.gpu;
if !gpu {
eprintln!("skipping: the canvas isn't on the GPU");
}
gpu
}
fn low_res(h: &mut Harness, on: bool) {
h.state_mut().run("prefs.set", json!({"path": "performance.lowResolutionPreviews", "value": on})).expect("prefs.set");
h.run_steps(4);
}
/// Luma along a 300 px row near the canvas's top-left corner (clear of centred dialogs).
fn row(h: &mut Harness) -> Vec<i32> {
h.run_steps(4);
let canvas = {
let app = h.state();
photocraft_ui_egui::rulers::content_rect(app, app.last_canvas_rect)
};
let img = h.render().expect("render");
let (x0, y) = (canvas.min.x as u32 + 20, canvas.min.y as u32 + 40);
(x0..x0 + 300)
.map(|x| {
let p = img.get_pixel(x, y).0;
(i32::from(p[0]) * 3 + i32::from(p[1]) * 6 + i32::from(p[2])) / 10
})
.collect()
}
/// Fraction of neighbouring screen pixels that differ like black and white.
fn columns(r: &[i32]) -> f32 {
r.windows(2).filter(|w| (w[0] - w[1]).abs() > 100).count() as f32 / (r.len() - 1) as f32
}
fn mean(r: &[i32]) -> f32 {
r.iter().sum::<i32>() as f32 / r.len() as f32
}
#[test]
fn adjustment_layer_drag_previews_at_full_resolution_when_low_res_is_off() {
let Some(mut h) = harness() else { return };
setup(&mut h, 1.0);
if !on_gpu(&mut h) {
return;
}
assert!(columns(&row(&mut h)) > 0.9, "the canvas shows the 1 px columns at 100 %");
let layer = {
let app = h.state_mut();
app.run("layer.newAdjustmentLayer.invert", json!({})).expect("adjustment layer");
let id = app.session.active().and_then(|d| d.active_layer).expect("active layer");
// What the Properties panel sets while a slider drags.
app.live_adjust = Some((id, json!({})));
id
};
let reduced = row(&mut h);
assert!(columns(&reduced) < 0.1, "default: the reduced copy loses the columns ({})", columns(&reduced));
low_res(&mut h, false);
h.state_mut().live_adjust = Some((layer, json!({})));
let full = row(&mut h);
assert!(columns(&full) > 0.9, "low-res previews off: every column shows ({})", columns(&full));
}
#[test]
fn filter_dialog_previews_at_full_resolution_when_low_res_is_off() {
let Some(mut h) = harness() else { return };
setup(&mut h, 1.0);
if !on_gpu(&mut h) {
return;
}
// Offset 0, 0 leaves the pixels as they are: any change is the preview's resolution.
photocraft_ui_egui::filter_dialog::open(h.state_mut(), "filter.other.offset").expect("Offset dialog");
let reduced = row(&mut h);
assert!(columns(&reduced) < 0.1, "default: the reduced copy loses the columns ({})", columns(&reduced));
low_res(&mut h, false);
let full = row(&mut h);
assert!(columns(&full) > 0.9, "low-res previews off: every column shows ({})", columns(&full));
}
#[test]
fn adjustment_dialog_zoomed_out_skips_the_reduced_copy_when_low_res_is_off() {
let Some(mut h) = harness() else { return };
setup(&mut h, 0.5);
if !on_gpu(&mut h) {
return;
}
let committed = mean(&row(&mut h));
assert!(committed > 60.0, "zoomed out the columns average to grey ({committed})");
photocraft_ui_egui::adjust_dialog::open(h.state_mut(), "image.adjustments.levels").expect("Levels dialog");
h.run_steps(4);
assert!(photocraft_ui_egui::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).is_some(), "default: zoomed out on the reduced copy");
let reduced = mean(&row(&mut h));
assert!(reduced < 30.0, "the reduced copy keeps only the black columns ({reduced})");
low_res(&mut h, false);
assert!(photocraft_ui_egui::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).is_none(), "off: no reduced copy");
let full = mean(&row(&mut h));
assert!((full - committed).abs() < 8.0, "off: the preview matches the committed view ({full} vs {committed})");
}
+2 -2
View File
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 13 | 47 scenarios: 3 within budget, 22 over budget or failing, 15 tracked only, 6 not run, 7 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 4 | 10 | 13 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 229/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 |
| [Tools](#tools) | 7 | 14 | 9 | |
| [Workspace and UI](#workspace-and-ui) | 0 | 5 | 18 | settings that do nothing: 56 of 139 (target 0) |
| [Workspace and UI](#workspace-and-ui) | 0 | 5 | 18 | settings that do nothing: 56 of 140 (target 0) |
| [Type](#type) | 0 | 3 | 6 | |
| [Automation](#automation) | 3 | 2 | 6 | 627 of 627 menu items live (100.0%) |
| [Reliability](#reliability) | 4 | 1 | 2 | never-crash lints on 27 of 27 crates; panic_hunt present |
@@ -154,7 +154,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
**Settings that do nothing: 56 of 139** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
**Settings that do nothing: 56 of 140** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
Unread: `general.color_picker`, `general.beep_when_done`, `general.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.lowercase_extension`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `units_and_rulers.screen_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.use_esc_to_commit`, `type_.text_engine`, `type_.font_preview`, `type_.fill_new_type_layers_with_placeholder`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `enhanced_controls.rotate_view_with_trackpad`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.