mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-22 14:06:50 -06:00
* LR-PROF-IMPORT: import the user's own DNG camera profiles (.dcp)
profile.import (File > Import Profiles & Presets, drag & drop) now also
reads DNG Camera Profiles: the user's own .dcp files, e.g. made with a
colour-checker tool. They appear in the profile browser and menu under
Camera Profiles with dcp:<camera>-<file> ids; profiles.camera lists them
and profile.deleteCamera / profile.deleteImported remove them. A library
on disk keeps a copy in Profiles/. No profile ships with the app and the
repository holds none: tests build theirs in memory (write_dcp).
lightcraft_raw::dcp parses the file per DNG spec ch. 6 (magic RC in
place of 42; IFD 0 read through the existing DNG colour builders) and
DcpProfile::applied_to puts its matrices, illuminants and look in place
of a raw file's, keeping the shot's white balance, analog balance and
baseline exposure.
Choosing one (develop.profile) replaces the raw file's colour model when
it is decoded, before the starting colour and the white-balance scale
(WbScaleOf) are worked out, so the matrix path takes over from the fitted
JPEG look (CR3/CR2/ARW...) and white balance follows the profile. A
profile without a tone curve of its own (most chart-made ones) keeps the
photo's contrast: the DNG's tone curve, else the tone of the camera-JPEG
fit. The profile travels with SourceRef::File into FileLoader /
PairLoader (new Option<&DcpProfile> argument); a decoded source records
the profile it was made with and is not reused for another. Smart
previews and the web render worker keep the file's own colour; rendered
(non-raw) photos ignore it.
This reverses the documented "Adobe profile formats deliberately
unsupported" stance for user-supplied files only; docs updated.
Split out of #1012.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: build against upstream main (kelvin_presets, 3-arg loaders)
DcpProfile::applied_to keeps the file's white-balance presets (new
ColorData::kelvin_presets upstream): they are camera facts like as-shot
neutral. Upstream's new FileLoader test closures take the profile argument.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: hover previews and browser thumbnails develop the hovered camera profile
The loupe's hover preview (preview_job) and the profile browser's thumbnails (variant_job) took
the photo's own decoded source, so hovering an imported camera profile showed the built-in colour
(and hovering a built-in profile while one was applied kept the camera profile's). Both now decode
as the hovered settings develop: the source follows the settings' camera profile, as the main
render does, and a variant's cache key already follows its settings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: build against upstream main (face-tile test loader and render_bench take the camera profile)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI: the catalog's staging-link test module is Unix-only (unused import broke clippy on Windows)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI: same-folder export test expects the '/'-joined subfolder (failed on Windows)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI: folder-drop tests build widget ids with the Folders tree's '/' paths (failed on Windows)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: rustfmt after merging main
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a real D750 camera profile as a pinned test corpus, checked against Lightroom
dieli's CC0 Nikon D750 ColorChecker set (Calibrite PROFILER dual-illuminant DCP,
matrix-only; the two chart NEFs; Lightroom Classic 15.6 renders with the profile)
is fetched by cargo xtask corpus --download into corpus/d750-colorchecker/, pinned
to commit f37f4054 and by sha256; nothing is committed.
Tests (skip without the corpus): the profile parses as matrix-only with
Cool White Fluorescent + D55; the matrices blend by inverse temperature; the
matrix-only path inverts the colour matrix and adapts to D50; it takes over the
chart NEFs' colour; imported and applied end to end, the charts develop within
mean dE2000 3.84 (flash) / 3.35 (indoor) of Lightroom's renders.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a single .dcp file is a camera profile only, not also an unreadable LUT
profile.import read every plain file that was neither a folder nor a .zip as a .cube LUT, so importing
one .dcp imported the camera profile and also reported it as failed ("stream did not contain valid
UTF-8"). Only .cube files are read as LUTs now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: review fixes for imported camera profiles
- A library moved or restored elsewhere finds its camera profiles in its own Profiles/ folder.
- A grid thumbnail is cut from the decoded preview only when that preview used the same camera profile.
- Render and source cache keys carry a fingerprint of the profile file, so a deleted or replaced profile never
has its old renders stand in.
- Camera profiles can be favourites, and favourites/recent entries survive reopening the library.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: smart previews without the camera profile, current-profile source facts, unsupported files reported
CodeRabbit review of 4ef025d9:
- Build Smart Previews develops the proxy without the photo's imported camera profile and never takes a cached
source decoded with it (the denoised picture is kept); before, only the stale-proxy refresh left it out.
- Session::source_info reports decoder facts only from a cached source developed with the camera profile the
photo uses now, else the catalog's.
- profile.import reports a file that is neither .cube, .dcp nor .zip as failed instead of passing over it.
Each with a regression test in tests_dcp.rs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: the Before side decodes with its own camera profile; a failed profile copy fails that file only
- build_job (and region_job_before through it) picks the Before render's source with the Before
settings, so it never reuses or decodes a source developed with the edit's camera profile.
- profile.import: a .dcp whose copy into the library fails is reported in `failed`; the profiles
imported with it stay imported and are saved, and nothing half-written is left.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a cached smart preview stands in while the original is offline
A smart preview carries no camera profile, so with an imported profile the profile check
rejected the cached proxy and every render decoded it again (it gives the same picture). It
now stands in, for its own level and for the thumbnail cut from it, while the original is
known to be offline; otherwise the profile check is as before, so once the original is back
the photo is decoded from it with its profile. Photos without an imported profile keep main's
behaviour. Test `tests_dcp::a_cached_smart_preview_stands_in_while_the_original_is_offline`
(fails without the fix).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: deleting a camera profile removes the library's copy before forgetting it
profile.deleteCamera now removes the library's copy of the profile file
first. A copy that is already gone is fine; any other error (file in use,
no access) fails the command and keeps the profile listed, so the library
never holds a profile file it no longer lists. Test:
a_profile_whose_copy_cannot_be_deleted_stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: deleting a camera profile never follows `..` out of the profiles folder
A listed path with a `..` component can start with the profiles folder and
still lead out of it; such a path is not treated as the library's copy, so
deleting the profile leaves that file alone. Test:
deleting_a_profile_never_follows_dot_dot_out_of_the_profiles_folder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: both tone fits of a DNG see its lens opcodes; no side effect in the profile-tag comparison
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a hover preview's key carries the camera profile file's fingerprint
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: unusable camera profiles not offered; file's WB scale and the profile's tone kept
Review of #1063 (CodeRabbit, outside-diff findings):
- a camera profile whose file is missing or damaged when the library opens
is no longer offered in the profile browser or accepted by develop.profile
(it silently developed with the raw's own colour); the entry stays, so it is
offered again once the file is back.
- a raw on the relative white-balance scale stays relative with a camera
profile (its matrices turned it to Kelvin, so existing edits were read as
absolute temperatures and the catalog and quick previews disagreed).
- with a camera profile its tone curve, then the tone kept for a curve-less
profile, come before the fitted camera look's tone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: one Camera Profiles group; the web loader keeps a raw's own colour
Review of #1063 (CodeRabbit):
- a LUT group named "Camera Profiles" that didn't sort last made the profile
menu list that group twice; it is now one group, last, with both kinds.
- without web workers a render ran inline and the web loader applied the
selected camera profile, unlike the worker (the documented web behaviour
keeps the raw's own colour); the loader now leaves it out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: camera profile files are read at most to the 64 MiB limit
A .dcp larger than the parser accepts was read whole into memory before
being refused. One bounded read (lightcraft_raw::dcp::read_dcp) stops one
byte past the limit and is used for import, reopening a library and the
duplicate check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a test that a hostile hue/saturation map header in a camera profile drops the map (FredApps, #1063)
Dimensions far past the data, past u32 products or zero, an entry count of 4 billion values and a
data offset past the end each drop the map while the profile's matrix still reads.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docs: parity checklist keeps both sides of the merge
* LR-PROF-IMPORT: tests added on main take the file loader's camera-profile argument
* Merge main; a thumbnail test takes the file loader's camera-profile argument
* Docs: one camera colour row, with main's notes and the import note
* Process key tests take the profile salt argument
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
440 lines
21 KiB
Rust
440 lines
21 KiB
Rust
//! End-to-end render benchmark (min of N runs, robust to a loaded machine):
|
||
//! `cargo run --release -p lightcraft-engine --example render_bench -- corpus/raw/arw-sony-a7m3-compressed.arw`
|
||
//! (`N=9` runs per scenario, `RAYON_NUM_THREADS=1` for algorithmic comparisons,
|
||
//! `LIGHTCRAFT_PROFILE=1` for per-stage timings).
|
||
//!
|
||
//! Without a file argument a procedural 6000×4000 source is used. Scenarios: a ~2.5 MP loupe render
|
||
//! of the 2560 px preview (cold, and with a warm stage cache while a slider is dragged), a draft,
|
||
//! and a full-size render + JPEG encode (export); `ONLY=batch` with several files times a full-size
|
||
//! export of each (decode + render + encode). Prints minimum wall-clock and minimum process CPU
|
||
//! time: on a shared machine the CPU time shows the work done, wall-clock also the wait for cores.
|
||
//! Each scenario runs on the CPU pipeline and, when a GPU adapter exists, on `lightcraft-gpu`
|
||
//! (second column; `LIGHTCRAFT_GPU=0` for the CPU only, `GPU_ONLY=1` for the GPU only).
|
||
//!
|
||
//! `ONLY=window`: a 1:1 zoom window cut from the full-size original (the loupe's `Slot::Region`):
|
||
//! the first window of a photo, a pan, and exposure / draft / NR changes with a warm stage cache;
|
||
//! `DUMP=file` writes the GPU window's RGBA bytes, for pixel A/B comparisons between builds.
|
||
//! Opening a photo, per file: `ONLY=source` (decode steps), `ONLY=load` (what the app's loaders
|
||
//! cost: file read, decode, binning, embedded stand-ins, `load_bytes(2560)`, the fs loader),
|
||
//! `ONLY=load1` (decode checksum + `load_bytes(2560)`; `LOADONLY=1`: only that, for a profiler),
|
||
//! `ONLY=jpeg` (a JPEG decoded to fit 256–2560 px boxes).
|
||
use std::sync::Arc;
|
||
use std::time::Instant;
|
||
|
||
use lightcraft_develop::DevelopSettings;
|
||
use lightcraft_engine::export::{ExportOptions, encode_image};
|
||
use lightcraft_engine::media::develop;
|
||
use lightcraft_pipeline::{Quality, RenderRequest, SourceInfo, StageCache};
|
||
use lightcraft_raster::Rgb32f;
|
||
use lightcraft_raster::resample::{Filter, fit};
|
||
|
||
/// Process CPU time in ms (all threads). The only `unsafe` is this libc clock read, in a dev-only example.
|
||
#[allow(unsafe_code)]
|
||
fn cpu_ms() -> f64 {
|
||
#[cfg(unix)]
|
||
{
|
||
let mut ts = libc::timespec { tv_sec: 0, tv_nsec: 0 };
|
||
// SAFETY: `clock_gettime` only writes into the timespec we pass.
|
||
unsafe { libc::clock_gettime(libc::CLOCK_PROCESS_CPUTIME_ID, &mut ts) };
|
||
ts.tv_sec as f64 * 1e3 + ts.tv_nsec as f64 / 1e6
|
||
}
|
||
#[cfg(not(unix))]
|
||
{
|
||
0.0
|
||
}
|
||
}
|
||
|
||
/// Minimum wall-clock and minimum CPU time (ms) over the runs.
|
||
struct T(f64, f64);
|
||
|
||
impl std::fmt::Display for T {
|
||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
write!(f, "{:.1} ms wall, {:.1} ms cpu", self.0, self.1)
|
||
}
|
||
}
|
||
|
||
fn best(n: usize, mut f: impl FnMut()) -> T {
|
||
let mut b = T(f64::MAX, f64::MAX);
|
||
for _ in 0..n {
|
||
let (t, c) = (Instant::now(), cpu_ms());
|
||
f();
|
||
b.1 = b.1.min(cpu_ms() - c);
|
||
b.0 = b.0.min(t.elapsed().as_secs_f64() * 1e3);
|
||
}
|
||
b
|
||
}
|
||
|
||
fn typical() -> DevelopSettings {
|
||
let mut s = DevelopSettings::default();
|
||
s.light.exposure = 0.3;
|
||
s.light.highlights = -40.0;
|
||
s.light.shadows = 30.0;
|
||
s.effects.clarity = 15.0;
|
||
s.effects.texture = 10.0;
|
||
s.effects.dehaze = 10.0;
|
||
s.detail.nr_luminance = 30.0;
|
||
s.detail.nr_color = 25.0;
|
||
s.detail.sharpen_amount = 40.0;
|
||
s
|
||
}
|
||
|
||
/// Max and mean |Δ| (8-bit, RGB) between two renders.
|
||
fn diff(a: &lightcraft_raster::Rgba8, b: &lightcraft_raster::Rgba8) -> (u8, f64) {
|
||
let (mut max, mut sum) = (0u8, 0u64);
|
||
for (p, q) in a.data.iter().zip(&b.data) {
|
||
for c in 0..3 {
|
||
let d = p[c].abs_diff(q[c]);
|
||
max = max.max(d);
|
||
sum += d as u64;
|
||
}
|
||
}
|
||
(max, sum as f64 / (a.data.len() * 3).max(1) as f64)
|
||
}
|
||
|
||
fn benchmark_jpeg(args: &[String], n: usize) {
|
||
// a JPEG (e.g. an embedded preview pulled out with exiftool) decoded to fit a few boxes
|
||
for path in args {
|
||
let bytes = std::fs::read(path).expect("read");
|
||
for edge in [256u32, 512, 1600, 2560] {
|
||
let o = lightcraft_codecs::DecodeOptions::fit(edge, edge);
|
||
let d = lightcraft_codecs::decode(&bytes, o).expect("decode");
|
||
println!(
|
||
" {path} fit {edge}: {}×{} {}",
|
||
d.image.width,
|
||
d.image.height,
|
||
best(n, || drop(lightcraft_codecs::decode(&bytes, o).expect("decode")))
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
fn benchmark_load(args: &[String], n: usize, only: &str) {
|
||
// opening a photo in the loupe, step by step: what the app's loaders cost (per file)
|
||
for path in args {
|
||
let bytes = std::fs::read(path).expect("read");
|
||
println!("{path}");
|
||
if std::env::var("LOADONLY").is_ok() {
|
||
// only the preview load (for a profiler)
|
||
println!(" {:<36} {}", "load_bytes(2560):", best(n, || drop(lightcraft_engine::files::load_bytes(&bytes, 2560).expect("load"))));
|
||
continue;
|
||
}
|
||
println!(" {:<36} {}", "file read:", best(n, || drop(std::fs::read(path).expect("read"))));
|
||
println!(" {:<36} {}", "raw decode:", best(n, || drop(lightcraft_raw::decode(&bytes).expect("decode"))));
|
||
let mut raw = lightcraft_raw::decode(&bytes).expect("decode");
|
||
if let lightcraft_raw::RawData::U16(d) = &raw.data {
|
||
let sum = d.iter().enumerate().fold(0u64, |a, (i, &v)| a.wrapping_mul(31).wrapping_add(v as u64 ^ i as u64));
|
||
println!(" decode checksum: {sum:016x}");
|
||
}
|
||
if only == "load1" {
|
||
println!(" {:<36} {}", "load_bytes(2560):", best(n, || drop(lightcraft_engine::files::load_bytes(&bytes, 2560).expect("load"))));
|
||
continue;
|
||
}
|
||
raw.opcodes.list3.retain(|op| !op.is_lens_correction());
|
||
if let Some(k) = lightcraft_engine::files::bin_factor(&raw, 2560) {
|
||
println!(" {:<36} {}", format!("binned ×{k} masked:"), best(n, || drop(raw.develop_binned_masked(k, 0.99))));
|
||
}
|
||
for edge in [2560usize, 1600] {
|
||
println!(
|
||
" {:<36} {}",
|
||
format!("embedded srgb, whole file ({edge}):"),
|
||
best(n, || drop(lightcraft_engine::files::embedded_preview_srgb(&bytes, edge)))
|
||
);
|
||
let quick = lightcraft_engine::files::fs_preview_loader();
|
||
println!(" {:<36} {}", format!("fs_preview_loader ({edge}):"), best(n, || drop(quick(path, edge))));
|
||
}
|
||
println!(" {:<36} {}", "load_bytes(2560):", best(n, || drop(lightcraft_engine::files::load_bytes(&bytes, 2560).expect("load"))));
|
||
let (loader, _) = lightcraft_engine::files::fs_hooks();
|
||
println!(" {:<36} {}", "fs loader (2560, read+load):", best(n, || drop(loader(path, 2560, None).expect("load"))));
|
||
}
|
||
}
|
||
|
||
fn benchmark_source(args: &[String], n: usize) {
|
||
// opening a photo: where the time goes before the first sharp loupe (per file)
|
||
for path in args {
|
||
let bytes = std::fs::read(path).expect("read");
|
||
println!("{path}");
|
||
let mut raw = lightcraft_raw::decode(&bytes).expect("decode");
|
||
// as the loader does: lens corrections are applied by the pipeline, not in the raw develop
|
||
raw.opcodes.list3.retain(|op| !op.is_lens_correction());
|
||
println!(" {}×{} cpp {} cfa {:?}", raw.width, raw.height, raw.cpp, raw.cfa.as_ref().map(|c| c.name()));
|
||
println!(" {:<36} {}", "raw decode:", best(n, || drop(lightcraft_raw::decode(&bytes).expect("decode"))));
|
||
println!(" {:<36} {}", "normalize:", best(n, || drop(raw.normalized().expect("norm"))));
|
||
let norm = raw.normalized().expect("norm");
|
||
println!(" {:<36} {}", "demosaic AHD:", best(n, || drop(lightcraft_raw::demosaic(&norm, lightcraft_raw::Method::Ahd))));
|
||
if let Some(k) = lightcraft_engine::files::bin_factor(&raw, 2560) {
|
||
println!(" {:<36} {}", format!("binned ×{k} (2560 preview):"), best(n, || drop(raw.develop_binned(k, 0.99))));
|
||
let img = raw.develop_binned(k, 0.99).expect("bin").expect("binnable");
|
||
let t = lightcraft_raw::color::camera_transform(&raw, lightcraft_raw::color::as_shot_white_xy(&raw));
|
||
println!(
|
||
" {:<36} {}",
|
||
"highlight reconstruct (binned):",
|
||
best(n, || {
|
||
let mut i = img.clone();
|
||
lightcraft_raw::highlight::reconstruct(&mut i, t.wb, 0.99);
|
||
})
|
||
);
|
||
println!(" {:<36} {}", "clone (binned):", best(n, || drop(img.clone())));
|
||
println!(" {:<36} {}", "fit 2560 (binned):", best(n, || drop(fit(&img, 2560, 2560, Filter::Box))));
|
||
}
|
||
println!(" {:<36} {}", "embedded preview (2560):", best(n, || drop(lightcraft_engine::files::load_embedded_preview(&bytes, 2560))));
|
||
for edge in [512usize, 2560, usize::MAX] {
|
||
println!(
|
||
" {:<36} {}",
|
||
format!("load_bytes({edge}):"),
|
||
best(n, || drop(lightcraft_engine::files::load_bytes(&bytes, edge).expect("load")))
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
fn main() {
|
||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||
let n: usize = std::env::var("N").ok().and_then(|v| v.parse().ok()).unwrap_or(5);
|
||
let only = std::env::var("ONLY").unwrap_or_default();
|
||
if only == "jpeg" {
|
||
benchmark_jpeg(&args, n);
|
||
return;
|
||
}
|
||
if only == "load" || only == "load1" {
|
||
benchmark_load(&args, n, &only);
|
||
return;
|
||
}
|
||
if only == "source" {
|
||
benchmark_source(&args, n);
|
||
return;
|
||
}
|
||
let run = |name: &str| only.is_empty() || only.split(',').any(|o| name.contains(o));
|
||
let (full, info) = match args.first() {
|
||
Some(path) => {
|
||
let bytes = std::fs::read(path).expect("read");
|
||
let t = Instant::now();
|
||
let r = lightcraft_engine::files::load_bytes(&bytes, usize::MAX).expect("decode");
|
||
println!("decode full: {:.0} ms", t.elapsed().as_secs_f64() * 1e3);
|
||
r
|
||
}
|
||
None => (
|
||
Rgb32f::from_fn(6000, 4000, |x, y| {
|
||
let v = ((x as f32 * 0.011).sin() * (y as f32 * 0.007).cos() * 0.5 + 0.5) * 0.4 + ((x * 31 + y * 17) % 13) as f32 * 0.002;
|
||
[v, v * 0.9, v * 0.7]
|
||
}),
|
||
SourceInfo { raw: true, ..Default::default() },
|
||
),
|
||
};
|
||
let full = Arc::new(full);
|
||
println!("source {}×{} ({:.1} MP), {n} runs each", full.width, full.height, (full.width * full.height) as f64 / 1e6);
|
||
// GPU column: `LIGHTCRAFT_GPU=0` (or no adapter) prints only the CPU column.
|
||
let t = Instant::now();
|
||
let gpu = lightcraft_engine::gpu::available();
|
||
match lightcraft_engine::gpu::adapter_name().filter(|_| gpu) {
|
||
Some(a) => println!("gpu: {a} (device + kernels: {:.0} ms)", t.elapsed().as_secs_f64() * 1e3),
|
||
None => println!("gpu: none"),
|
||
}
|
||
// `GPU_ONLY=1`: skip the CPU column (profiling the GPU path)
|
||
let backends: &[bool] = match (gpu, std::env::var_os("GPU_ONLY").is_some()) {
|
||
(true, true) => &[true],
|
||
(true, false) => &[false, true],
|
||
_ => &[false],
|
||
};
|
||
let row = |name: &str, f: &mut dyn FnMut(bool)| {
|
||
let cols: Vec<String> = backends.iter().map(|&g| format!("{}", best(n, || f(g)))).collect();
|
||
let first = if backends[0] { "gpu" } else { "cpu" };
|
||
println!("{name:<38} {first}: {}{}", cols[0], cols.get(1).map(|g| format!(" | gpu: {g}")).unwrap_or_default());
|
||
};
|
||
let preview = Arc::new(fit(&full, 2560, 2560, Filter::Box));
|
||
let s = typical();
|
||
let view = RenderRequest::fit(1920, 1280);
|
||
let draft = RenderRequest { quality: Quality::Draft, ..RenderRequest::fit(1152, 768) };
|
||
if gpu {
|
||
let c = develop(&preview, &info, &s, &view, None, false).image;
|
||
let g = develop(&preview, &info, &s, &view, None, true).image;
|
||
let (max, mean) = diff(&c, &g);
|
||
println!("gpu vs cpu, loupe 1920×1280 typical: max {max} LSB, mean {mean:.4} LSB");
|
||
}
|
||
|
||
if run("cold") {
|
||
// a new photo: no cached stages (the GPU also uploads the preview)
|
||
row("loupe 1920×1280 cold:", &mut |g| drop(develop(&preview, &info, &s, &view, None, g)));
|
||
row("loupe draft 1152×768 cold:", &mut |g| drop(develop(&preview, &info, &s, &draft, None, g)));
|
||
}
|
||
let caches = [StageCache::default(), StageCache::default()];
|
||
let mut k = 0.0;
|
||
if run("drag") {
|
||
for g in backends {
|
||
drop(develop(&preview, &info, &s, &view, Some(&caches[*g as usize]), *g));
|
||
}
|
||
row("loupe 1920×1280 exposure drag (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.light.contrast = k % 50.0;
|
||
t.light.exposure = 0.3 + k * 0.01;
|
||
drop(develop(&preview, &info, &t, &view, Some(&caches[g as usize]), g));
|
||
});
|
||
for g in backends {
|
||
drop(develop(&preview, &info, &s, &draft, Some(&caches[*g as usize]), *g));
|
||
}
|
||
row("loupe draft highlights drag (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.light.highlights = -40.0 + k % 50.0;
|
||
drop(develop(&preview, &info, &t, &draft, Some(&caches[g as usize]), g));
|
||
});
|
||
row("loupe draft clarity drag (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.effects.clarity = 15.0 + k % 50.0;
|
||
drop(develop(&preview, &info, &t, &draft, Some(&caches[g as usize]), g));
|
||
});
|
||
row("loupe draft NR drag (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.detail.nr_luminance = 30.0 + k % 50.0;
|
||
drop(develop(&preview, &info, &t, &draft, Some(&caches[g as usize]), g));
|
||
});
|
||
row("loupe 1920×1280 NR drag (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.detail.nr_luminance = 30.0 + k % 50.0;
|
||
drop(develop(&preview, &info, &t, &view, Some(&caches[g as usize]), g));
|
||
});
|
||
}
|
||
if run("window") {
|
||
// a 1:1 zoom window (the loupe's `Slot::Region`): visible 1920×1200 + margin, snapped to the
|
||
// 256 px grid, cut from the full-resolution original (`ui-egui` `region::window_for`)
|
||
use lightcraft_pipeline::PixelWindow;
|
||
let (fw, fh) = (full.width, full.height);
|
||
let win = |cx: usize, cy: usize| {
|
||
let snap = |v: usize| v / 256 * 256;
|
||
let (x, y) = (snap(cx.saturating_sub(960 + 512)), snap(cy.saturating_sub(600 + 512)));
|
||
PixelWindow { x, y, w: 3072.min(fw - x), h: 2304.min(fh - y) }
|
||
};
|
||
let at = |w: PixelWindow, q: Quality| RenderRequest { window: Some(w), quality: q, ..RenderRequest::fit(fw, fh) };
|
||
let w0 = win(fw / 2, fh / 2);
|
||
println!("window {}×{} at ({}, {}) of {fw}×{fh}", w0.w, w0.h, w0.x, w0.y);
|
||
// first window of a photo: nothing cached (the GPU uploads the original: `shared_source`)
|
||
row("window first (upload original):", &mut |g| {
|
||
lightcraft_engine::gpu::trim_pool(0);
|
||
drop(develop(&full, &info, &s, &at(w0, Quality::Full), Some(&StageCache::default()), g))
|
||
});
|
||
let wc = [StageCache::default(), StageCache::default()];
|
||
for g in backends {
|
||
drop(develop(&full, &info, &s, &at(w0, Quality::Full), Some(&wc[*g as usize]), *g));
|
||
}
|
||
let mut step = 0usize;
|
||
row("window pan (new window, warm src):", &mut |g| {
|
||
step += 1;
|
||
let w = win(fw / 2 + 512 * (step % 4 + 1), fh / 2);
|
||
drop(develop(&full, &info, &s, &at(w, Quality::Full), Some(&wc[g as usize]), g))
|
||
});
|
||
for g in backends {
|
||
drop(develop(&full, &info, &s, &at(w0, Quality::Full), Some(&wc[*g as usize]), *g));
|
||
}
|
||
row("window exposure change (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.light.exposure = 0.3 + k * 0.01;
|
||
drop(develop(&full, &info, &t, &at(w0, Quality::Full), Some(&wc[g as usize]), g));
|
||
});
|
||
row("window draft exposure drag (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.light.exposure = 0.3 + k * 0.01;
|
||
drop(develop(&full, &info, &t, &at(w0, Quality::Draft), Some(&wc[g as usize]), g));
|
||
});
|
||
row("window NR change (warm):", &mut |g| {
|
||
let mut t = s.clone();
|
||
k += 1.0;
|
||
t.detail.nr_luminance = 30.0 + k % 50.0;
|
||
drop(develop(&full, &info, &t, &at(w0, Quality::Full), Some(&wc[g as usize]), g));
|
||
});
|
||
// `DUMP=file`: the GPU window's raw RGBA bytes (A/B pixel comparisons between builds)
|
||
if let (true, Some(path)) = (gpu, std::env::var_os("DUMP")) {
|
||
let g = develop(&full, &info, &s, &at(w0, Quality::Full), Some(&StageCache::default()), true).image;
|
||
let bytes: Vec<u8> = g.data.iter().flatten().copied().collect();
|
||
std::fs::write(path, bytes).expect("dump");
|
||
}
|
||
if gpu && std::env::var_os("GPU_ONLY").is_none() {
|
||
let c = develop(&full, &info, &s, &at(w0, Quality::Full), None, false).image;
|
||
let g = develop(&full, &info, &s, &at(w0, Quality::Full), None, true).image;
|
||
let (max, mean) = diff(&c, &g);
|
||
println!("gpu vs cpu, window: max {max} LSB, mean {mean:.4} LSB");
|
||
}
|
||
}
|
||
if run("finish") {
|
||
// per-pixel stage cost by feature (warm cache: exposure changes only)
|
||
let variants: [(&str, fn(&mut DevelopSettings)); 6] = [
|
||
("typical", |_| {}),
|
||
("- dehaze", |t| t.effects.dehaze = 0.0),
|
||
("- clarity", |t| t.effects.clarity = 0.0),
|
||
("- texture/sharpen", |t| {
|
||
t.effects.texture = 0.0;
|
||
t.detail.sharpen_amount = 0.0;
|
||
}),
|
||
("- highlights/shadows", |t| {
|
||
t.light.highlights = 0.0;
|
||
t.light.shadows = 0.0;
|
||
}),
|
||
("+ vibrance/saturation", |t| {
|
||
t.color.vibrance = 20.0;
|
||
t.color.saturation = 10.0;
|
||
}),
|
||
];
|
||
for (name, f) in variants {
|
||
let mut t = s.clone();
|
||
f(&mut t);
|
||
for g in backends {
|
||
drop(develop(&preview, &info, &t, &view, Some(&caches[*g as usize]), *g));
|
||
}
|
||
row(&format!("finish 1920×1280 {name}"), &mut |g| {
|
||
k += 1.0;
|
||
t.light.exposure = 0.3 + k * 0.001;
|
||
drop(develop(&preview, &info, &t, &view, Some(&caches[g as usize]), g));
|
||
});
|
||
}
|
||
}
|
||
if run("batch") && args.len() > 1 {
|
||
// full-size JPEG export of all the files given (decode + render + encode), as the Export
|
||
// dialog runs it: several photos side by side (`export_parallelism`), files discarded
|
||
use lightcraft_engine::export::{Destination, export_batch};
|
||
let mut session = lightcraft_engine::Session::new().with_fs();
|
||
let r = session.execute("library.import", &serde_json::json!({"paths": args})).expect("import");
|
||
let ids: Vec<_> = r["imported"].as_array().expect("ids").iter().filter_map(|v| v.as_u64()).map(lightcraft_engine::catalog::PhotoId).collect();
|
||
let o = ExportOptions::default();
|
||
let lanes = lightcraft_engine::export::export_parallelism(ids.len());
|
||
row(&format!("batch export of {} files, {lanes} at a time (decode+render+JPEG):", ids.len()), &mut |g| {
|
||
lightcraft_engine::gpu::set_enabled(g);
|
||
let files = export_batch(&mut session, &ids, &o, &Destination::default(), &mut |_, _| Ok(()), &|_| false).expect("export");
|
||
assert_eq!(files.len(), ids.len());
|
||
for &id in &ids {
|
||
session.media.forget(id); // every original is decoded once per run
|
||
}
|
||
});
|
||
lightcraft_engine::gpu::set_enabled(true);
|
||
return;
|
||
}
|
||
if run("export") {
|
||
let big = RenderRequest::fit(full.width, full.height);
|
||
let ne = n.min(3);
|
||
let mut img = None;
|
||
let cols: Vec<String> = backends
|
||
.iter()
|
||
.map(|&g| {
|
||
let ms = best(ne, || img = Some(develop(&full, &info, &s, &big, None, g).image));
|
||
format!("{ms}")
|
||
})
|
||
.collect();
|
||
println!(
|
||
"{:<38} cpu: {}{}",
|
||
format!("export render {}×{}:", full.width, full.height),
|
||
cols[0],
|
||
cols.get(1).map(|g| format!(" | gpu: {g}")).unwrap_or_default()
|
||
);
|
||
if gpu {
|
||
let c = develop(&full, &info, &s, &big, None, false).image;
|
||
let (max, mean) = diff(&c, img.as_ref().expect("rendered"));
|
||
println!("gpu vs cpu, export {}×{} typical: max {max} LSB, mean {mean:.4} LSB", full.width, full.height);
|
||
}
|
||
let img = img.expect("rendered");
|
||
println!("export JPEG encode: {}", best(ne, || drop(encode_image(&img, &ExportOptions::default()))));
|
||
}
|
||
}
|