mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-19 08:51:49 +01:00
LR-EDIT-DETAIL-DENOISE: built-in BM3D denoising with GPU acceleration (#2982)
* LR-EDIT-DETAIL-DENOISE: AI Denoise works out of the box with a built-in denoiser Turning AI Denoise on no longer needs an ONNX model and a denoise-model.json. Without a model of the user's own, the engine runs a built-in pure-Rust denoiser (noise measured per tile, non-local means on the Bayer planes, edge-directed demosaic) through the same tiling, cache, queue, preview and export path as a model. Installing a model stays optional; Stop using returns to the built-in one, and the id `builtin` is reserved. The set-up prompt and its resume-after-install flow (model_setup.rs, PhotoState::NoModel) are removed. Tests updated for the new behaviour, with new tests for the built-in path; docs, trackers and locale catalogs updated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: built-in denoiser cleans the colour planes together and adapts to the noise The built-in denoiser now measures the photo's noise once from the whole mosaic (the model prepares the photo before its tiles run) instead of per tile, stabilises the variance (generalised Anscombe), rotates the four Bayer planes with a Hadamard transform and runs a non-local-means filter whose patch distance spans all planes, so colour blotches are cleaned with the brightness. It cleans gently at low noise to keep fine detail, and harder, with a second pass that matches on the first pass's cleaner picture, as the noise grows. Cached pictures made by the first version are made again (builtin version 2). Adds an opt-in benchmark (tests/denoise_builtin_quality.rs, public CC0 raw plus noise of known level, scored against the original) and tests for the whole-photo noise estimate, strong noise, bad noise values and the strength ramp. On the Sony A7 III sample the result is 3.6, 7.0, 9.1 and 9.7 dB above the noisy picture at light, medium, heavy and extreme noise, against 2.9, 6.0, 6.5 and 5.8 dB for the first version. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * contributors: add esli1283 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: docs say how to run the built-in denoiser's quality benchmark Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: built-in denoiser cleans colour further, keeps more texture and leaves no isolated specks Colour-difference planes get a wider pass guided by the cleaned brightness plane, the first-pass threshold is lower (more texture kept), and cells with no matching patch lean on a looser average in heavy noise. Skips negligible weights for speed; bumps builtin::VERSION to 3. Benchmark adds a texture figure; on the public A7 III raw the gain over the noisy picture is +3.7 / +7.2 / +9.7 / +10.4 dB (was +3.6 / +7.0 / +9.1 / +9.7). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Windows: tests build paths one component at a time and doc_path has no unused variable On Windows `cargo xtask ci` failed before it reached any of the work under test: - doc_path.rs bound the gvfs path outside the cfg(not(windows)) block that uses it, an unused variable under -D warnings. - tests_import and the MCP headless discovery test joined "trip/day2" onto a temp folder, giving mixed separators, and compared them with the normalised paths the folder walk returns. They now join each component. Test and lint changes only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: built-in denoiser filters with block-matching collaborative filtering, on the GPU The built-in denoiser's filter is now block matching with collaborative filtering (BM3D / CBM3D, written from the paper) instead of non-local means. On the public Sony A7 III benchmark with added noise it scores 0.25 to 0.6 dB higher at every noise level and keeps more texture at medium to extreme noise (light noise keeps slightly less: 0.58 against 0.62), as fast as before on the processor. docs/denoise.md records the comparison with non-local means and weighted nuclear norm minimisation (tried, not kept: about +0.03 texture for ten times the time) and what the tuning showed. - denoise-core: bm3d.rs (matching on the brightness plane, 2-D DCT plus Haar across the group, hard threshold then Wiener, hard threshold rising with the noise). Builtin::run_with takes the filter stage, so every other step is shared between devices. Tuning.bm3d selects it; non-local means stays as the fallback. builtin::VERSION is 4, so cached pictures are made again. - gpu: bm3d.rs and wgsl/bm3d_*.wgsl run the grouping, the filtering and the putting back on the graphics card, in the same order as the reference (the results agree to rounding: at most 0.1 noise deviation at a few tie blocks, 4e-6 on average, identical every run). Noise measurement, stabilising and the demosaic stay on the processor. FXC (DX12) needs the working arrays at module scope and no dynamically indexed vector: documented in docs/gpu-pipeline.md. - engine: the card is set up once per process for the first photo that may use it, checked against the processor on a check tile (in the filter's own domain: the demosaic's direction choice can flip a pixel on a tiny difference), timed, and used where it is faster. A tile it gets wrong runs on the processor and three stop it. Settings' Run on choice, device line and "Try the graphics card again" now work for the built-in denoiser. Its set-up marker lives in the models folder. - The benchmark takes LC_GPU=1, LC_NLM=1 and LC_B_* for sweeps. On an RTX 4080 SUPER a 256-cell tile takes 22 ms on the card against 408 ms on one processor thread, and the 1536 x 1024 benchmark crop 0.13 to 0.24 s against 1.0 to 2.1 s on four threads, with identical scores. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: the built-in denoiser measures the noise per colour plane and sets its strength from it The first noise estimator read a picture's texture as noise: it never reported less than about 0.003 at mid-grey whatever the real noise, so the denoiser always believed a photo was about as noisy as ISO 12800. The threshold curve was tuned on that over-estimate, and its levels (0.024 to 0.14) are far noisier than real Canon bodies produce (about 0.0025 at ISO 400 up to 0.038 above ISO 25600, measured on a private library; only aggregates are recorded in the docs). - estimate_noise: each colour plane is read on its own (they sit at different levels in a raw), a second-difference operator cancels flat and sloping signal, 12 x 12 blocks, the quietest 5 % at each brightness divided by the bias of that quantile of pure noise (0.67, measured), a constrained line fit. The first version stays as estimate_noise_v1 to compare with. On 30 public pictures with known added noise the 10th to 90th percentile of estimated / true deviation at mid-grey is 0.97 to 1.29 at the ISO 6400 level against 0.94 to 1.96. - bm3d::Params::lambda is a curve of the noise (1.2 at 0.0028 up to 3.5 at 0.14, straight against its logarithm) instead of two end values and a strength, and plan / filter take the noise level; the GPU path shares plan, so CPU and GPU agree as before. Fitted on clean low-ISO photos of a Canon EOS R and R6 Mark III with noise of their measured levels added: the lowest threshold within about a quarter of a decibel of the best at each level. - Result (PSNR, EOS R / R6 Mark III, 10 + 5 photos): ISO 25600 level 38.36 / 38.86 from 36.18 / 36.21, ISO 51200 level 33.83 / 34.45 from 28.42 / 28.78, ISO 6400 39.93 / 40.69 from 39.30 / 39.74, quiet photos no longer over-smoothed; the noise left in the result falls from 1.3 to 3.1 down to 0.73 to 0.99. - Tests: threshold curve, flat versus textured pictures, no-flat-area pictures, clipped / NaN mosaics; an opt-in accuracy harness on the public corpus (denoise_noise_estimate) with a calibration of the quantile bias; the benchmark takes LC_REAL, LC_BIN, LC_FULL, LC_EST and LC_B_LOFF. - builtin::VERSION is 5, so cached pictures are made again. docs/denoise.md has "How the noise is measured" and "Fitted on real cameras". Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: GPU workspace pool cannot miss a wake-up; benchmark path and parity date fixed Review findings (CodeRabbit) on the built-in denoiser pull request: - bm3d::Bm3dGpu::forget and nn::NetRunner::forget changed the workspace count without the free-list lock. A take() that had found no free workspace and read made == WORKSPACES, but had not gone to sleep yet, could miss the wake-up and wait for good on a slot that was already free. forget now changes the count under the free lock, in the same order as take(), then notifies. - A test for each runner holds the free lock and checks that forget waits for it; both fail on the old code and pass now. - docs/denoise.md: the benchmark command resolves the raw file from the repository root, since the test runs from the crate's folder. - docs/target-app-parity.md: Last updated matches its newest revision-history entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: doc comments for the functions this branch adds CodeRabbit's pre-merge docstring check counted 49.72 % of the functions this pull request touches as documented (threshold 80 %). Every function the branch adds, the built-in denoiser's block-matching and non-local-means filters, its noise estimator, the GPU runner and their tests, now says what it does or what the test proves. Older functions the branch only touched are left as they were. Comments only: no code line changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: make the GPU set-up marker's folder; fix the benchmark's default path The crash guard was lost when the models folder did not exist yet. The opt-in quality benchmark resolved its default raw file against crates/engine. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: enforce the cache limit without a models folder The built-in denoiser makes products when there is no models folder, but eviction returned early in that case, so the cache could outgrow its limit. It now applies the default limit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * LR-EDIT-DETAIL-DENOISE: the cache-limit test needs no 20 GiB file off Unix The no-models-folder test now checks the limit itself on every platform and keeps the oversized sparse file for Unix only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * S0002: review fixes for the built-in denoiser Tell the runner a photo's noise only when it could be measured, run prepare() after the work gate with a cancel check, reword the Settings hint for builds without a models folder, drop untranslated placeholder locale entries (they fall back to English) and restore the cs.json spacing; rustfmt. Co-Authored-By: Claude Code <noreply@anthropic.com> * S0002: fix review findings: command descriptions, stale gpu test, self-test noise The denoise.models.select and denoise.toggle descriptions now describe the built-in fallback. Drop our workspace-forget test, which read fields that upstream's Workspaces pool (#2631, same fix) replaced and so did not compile; upstream's own tests cover it. The built-in self-test is told a noise instead of measuring a 16-cell tile too small to measure. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: esli1283 <esli.aaron@outlook.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: FredApps <FredApps@users.noreply.github.com>
This commit is contained in:
60 files changed
+3928
-708
No files matched your search
@@ -68,6 +68,10 @@ sync_github_name = true
|
||||
[people.ronibalthazar]
|
||||
sync_github_name = true
|
||||
|
||||
[people.esli1283]
|
||||
real_name = "Aaron Lopez"
|
||||
sync_github_name = false
|
||||
|
||||
[people.dotCooCoo]
|
||||
real_name = "Robert Lee"
|
||||
sync_github_name = true
|
||||
|
||||
@@ -0,0 +1,601 @@
|
||||
//! Block-matching collaborative filtering (after Dabov, Foi, Katkovnik and Egiazarian, "Image denoising by sparse 3-D
|
||||
//! transform-domain collaborative filtering", 2007; the colour variant is their CBM3D), written from the paper.
|
||||
//!
|
||||
//! It works on the same planes as [`crate::nlm`]: four Bayer planes of unit noise (see [`crate::nlm::Stabiliser`]),
|
||||
//! rotated by a Hadamard transform into a brightness plane and three colour-difference planes. Blocks of the
|
||||
//! brightness plane that look alike are stacked into a group; the stack is transformed (2-D DCT of each block, Haar
|
||||
//! across the stack) where the picture is sparse and the noise is not, shrunk, transformed back and put back with
|
||||
//! weights. The first step shrinks by a hard threshold and gives a basic estimate; the second matches blocks on that
|
||||
//! cleaner estimate and shrinks by a Wiener filter built from it. Every plane of a group follows the brightness
|
||||
//! plane's matches, so the colour differences are only averaged across like brightness.
|
||||
|
||||
use crate::nlm::hadamard;
|
||||
use std::f32::consts::FRAC_1_SQRT_2;
|
||||
|
||||
/// What the filter may be tuned by (the defaults are what the built-in denoiser uses).
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Params {
|
||||
/// Side of a block, in cells.
|
||||
pub block: usize,
|
||||
/// Distance, in cells, between the blocks that start a group (1 = every block; larger is faster).
|
||||
pub step: usize,
|
||||
/// How far, in cells, a match is looked for round a block.
|
||||
pub search: usize,
|
||||
/// The most blocks in a group (rounded down to a power of two).
|
||||
pub group: usize,
|
||||
/// How far above the noise two blocks may differ (mean square, in units of the noise variance) and still be
|
||||
/// grouped, in the first step (on the noisy picture) and in the second (on the basic estimate).
|
||||
pub tau1: f32,
|
||||
pub tau2: f32,
|
||||
/// The first step's hard-threshold level, in noise deviations, as a function of how noisy the photo is: points of
|
||||
/// (the noise's deviation at mid-grey, with white = 1; the threshold), rising with the noise and joined in a straight
|
||||
/// line against the logarithm of the noise (flat beyond the first and last). A quieter photo has more fine detail
|
||||
/// per unit of noise to keep, a noisier one less. Fitted on real Canon raws with noise added at their ISO levels
|
||||
/// (docs/denoise.md → Why block matching).
|
||||
pub lambda: [(f32, f32); 6],
|
||||
/// The noise's deviation as the filter takes it (1 = as measured; more cleans harder).
|
||||
pub sigma: f32,
|
||||
/// Whether the second (Wiener) step runs.
|
||||
pub wiener: bool,
|
||||
}
|
||||
|
||||
impl Default for Params {
|
||||
/// What the built-in denoiser runs with: 4 × 4 blocks taken every 3 cells, matched within 8 cells, up to 16 to a
|
||||
/// group, the fitted threshold curve, and the Wiener step on.
|
||||
fn default() -> Self {
|
||||
Params {
|
||||
block: 4,
|
||||
step: 3,
|
||||
search: 8,
|
||||
group: 16,
|
||||
tau1: 4.0,
|
||||
tau2: 1.0,
|
||||
lambda: [(0.0028, 1.2), (0.0062, 1.9), (0.0094, 2.3), (0.0152, 2.65), (0.038, 3.2), (0.14, 3.5)],
|
||||
sigma: 1.0,
|
||||
wiener: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The threshold for a photo whose noise has deviation `noise` at mid-grey: `curve` read in a straight line against the
|
||||
/// logarithm of the noise (the ends hold). A curve that is empty or not rising in its first coordinate gives its first
|
||||
/// point's value for any noise, and a noise that is not a number is the quietest.
|
||||
pub fn threshold_for(curve: &[(f32, f32)], noise: f32) -> f32 {
|
||||
let Some(&(x0, y0)) = curve.first() else { return 3.0 };
|
||||
if !noise.is_finite() || noise <= x0 {
|
||||
return y0;
|
||||
}
|
||||
for pair in curve.windows(2) {
|
||||
let ((xa, ya), (xb, yb)) = (pair[0], pair[1]);
|
||||
if xa.is_finite() && xb.is_finite() && xa > 0.0 && xb > xa && noise <= xb {
|
||||
return ya + (yb - ya) * (noise / xa).ln() / (xb / xa).ln();
|
||||
}
|
||||
}
|
||||
curve.last().map_or(y0, |p| p.1)
|
||||
}
|
||||
|
||||
/// The orthonormal DCT-II of a block and the window the filtered blocks are put back with.
|
||||
struct Transform {
|
||||
n: usize,
|
||||
c: Vec<f32>,
|
||||
window: Vec<f32>,
|
||||
}
|
||||
|
||||
/// The zeroth-order modified Bessel function of the first kind (a series; the Kaiser window needs it).
|
||||
fn bessel_i0(x: f32) -> f32 {
|
||||
let (mut sum, mut term) = (1.0f32, 1.0f32);
|
||||
for k in 1..30 {
|
||||
term *= x * x / (4.0 * (k * k) as f32);
|
||||
sum += term;
|
||||
}
|
||||
sum
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
/// The transform for `n × n` blocks: the DCT-II matrix and the Kaiser window the filtered blocks are put back with.
|
||||
fn new(n: usize) -> Self {
|
||||
let mut c = vec![0f32; n * n];
|
||||
for (k, row) in c.chunks_exact_mut(n).enumerate() {
|
||||
let scale = if k == 0 { (1.0 / n as f32).sqrt() } else { (2.0 / n as f32).sqrt() };
|
||||
for (i, v) in row.iter_mut().enumerate() {
|
||||
*v = scale * (std::f32::consts::PI * (2 * i + 1) as f32 * k as f32 / (2 * n) as f32).cos();
|
||||
}
|
||||
}
|
||||
// a Kaiser window (beta 2) down each side, so a block's edge counts less than its middle
|
||||
let beta = 2.0f32;
|
||||
let side: Vec<f32> = (0..n)
|
||||
.map(|i| {
|
||||
let r = if n > 1 { 2.0 * i as f32 / (n - 1) as f32 - 1.0 } else { 0.0 };
|
||||
bessel_i0(beta * (1.0 - r * r).max(0.0).sqrt()) / bessel_i0(beta)
|
||||
})
|
||||
.collect();
|
||||
let window = side.iter().flat_map(|y| side.iter().map(move |x| x * y)).collect();
|
||||
Transform { n, c, window }
|
||||
}
|
||||
|
||||
/// `blk` (`n × n`) becomes its 2-D DCT.
|
||||
fn forward(&self, blk: &mut [f32], tmp: &mut [f32]) {
|
||||
let n = self.n;
|
||||
for (trow, crow) in tmp.chunks_exact_mut(n).zip(self.c.chunks_exact(n)) {
|
||||
trow.fill(0.0);
|
||||
for (&ck, brow) in crow.iter().zip(blk.chunks_exact(n)) {
|
||||
for (t, &b) in trow.iter_mut().zip(brow) {
|
||||
*t += ck * b;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (orow, trow) in blk.chunks_exact_mut(n).zip(tmp.chunks_exact(n)) {
|
||||
for (o, crow) in orow.iter_mut().zip(self.c.chunks_exact(n)) {
|
||||
*o = trow.iter().zip(crow).map(|(a, b)| a * b).sum();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The inverse of [`Transform::forward`].
|
||||
fn inverse(&self, blk: &mut [f32], tmp: &mut [f32]) {
|
||||
let n = self.n;
|
||||
tmp.fill(0.0);
|
||||
for (crow, xrow) in self.c.chunks_exact(n).zip(blk.chunks_exact(n)) {
|
||||
for (trow, &cki) in tmp.chunks_exact_mut(n).zip(crow) {
|
||||
for (t, &x) in trow.iter_mut().zip(xrow) {
|
||||
*t += cki * x;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (brow, trow) in blk.chunks_exact_mut(n).zip(tmp.chunks_exact(n)) {
|
||||
brow.fill(0.0);
|
||||
for (&t, crow) in trow.iter().zip(self.c.chunks_exact(n)) {
|
||||
for (b, &c) in brow.iter_mut().zip(crow) {
|
||||
*b += t * c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The orthonormal Haar transform of a vector whose length is a power of two.
|
||||
fn haar_forward(v: &mut [f32], tmp: &mut [f32]) {
|
||||
let mut len = v.len();
|
||||
while len > 1 {
|
||||
let half = len / 2;
|
||||
for i in 0..half {
|
||||
let (a, b) = (v.get(2 * i).copied().unwrap_or(0.0), v.get(2 * i + 1).copied().unwrap_or(0.0));
|
||||
if let Some(x) = tmp.get_mut(i) {
|
||||
*x = (a + b) * FRAC_1_SQRT_2;
|
||||
}
|
||||
if let Some(x) = tmp.get_mut(half + i) {
|
||||
*x = (a - b) * FRAC_1_SQRT_2;
|
||||
}
|
||||
}
|
||||
if let (Some(dst), Some(src)) = (v.get_mut(..len), tmp.get(..len)) {
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
len = half;
|
||||
}
|
||||
}
|
||||
|
||||
/// Undoes [`haar_forward`] in place; `tmp` is scratch of the same length.
|
||||
fn haar_inverse(v: &mut [f32], tmp: &mut [f32]) {
|
||||
let mut len = 2;
|
||||
while len <= v.len() {
|
||||
let half = len / 2;
|
||||
for i in 0..half {
|
||||
let (avg, det) = (v.get(i).copied().unwrap_or(0.0), v.get(half + i).copied().unwrap_or(0.0));
|
||||
if let Some(x) = tmp.get_mut(2 * i) {
|
||||
*x = (avg + det) * FRAC_1_SQRT_2;
|
||||
}
|
||||
if let Some(x) = tmp.get_mut(2 * i + 1) {
|
||||
*x = (avg - det) * FRAC_1_SQRT_2;
|
||||
}
|
||||
}
|
||||
if let (Some(dst), Some(src)) = (v.get_mut(..len), tmp.get(..len)) {
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
len *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// Reusable buffers of the group transforms.
|
||||
#[derive(Default)]
|
||||
struct Scratch {
|
||||
tmp: Vec<f32>,
|
||||
col: Vec<f32>,
|
||||
col_tmp: Vec<f32>,
|
||||
}
|
||||
|
||||
/// A group (`m` blocks of `n × n`, one after the other in `buf`) to the transform domain, or back.
|
||||
fn group_transform(tf: &Transform, buf: &mut [f32], m: usize, s: &mut Scratch, forward: bool) {
|
||||
let nn = tf.n * tf.n;
|
||||
s.tmp.resize(nn, 0.0);
|
||||
if !forward {
|
||||
haar_columns(buf, m, nn, s, false);
|
||||
}
|
||||
for blk in buf.chunks_exact_mut(nn) {
|
||||
if forward {
|
||||
tf.forward(blk, &mut s.tmp);
|
||||
} else {
|
||||
tf.inverse(blk, &mut s.tmp);
|
||||
}
|
||||
}
|
||||
if forward {
|
||||
haar_columns(buf, m, nn, s, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// The Haar transform across the blocks of a group, at each of the `nn` positions of a block.
|
||||
fn haar_columns(buf: &mut [f32], m: usize, nn: usize, s: &mut Scratch, forward: bool) {
|
||||
if m < 2 {
|
||||
return;
|
||||
}
|
||||
s.col.resize(m, 0.0);
|
||||
s.col_tmp.resize(m, 0.0);
|
||||
for k in 0..nn {
|
||||
for (i, c) in s.col.iter_mut().enumerate() {
|
||||
*c = buf.get(i * nn + k).copied().unwrap_or(0.0);
|
||||
}
|
||||
if forward {
|
||||
haar_forward(&mut s.col, &mut s.col_tmp);
|
||||
} else {
|
||||
haar_inverse(&mut s.col, &mut s.col_tmp);
|
||||
}
|
||||
for (i, c) in s.col.iter().enumerate() {
|
||||
if let Some(b) = buf.get_mut(i * nn + k) {
|
||||
*b = *c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy the blocks of a group out of a plane (`members` are the blocks' top-left cells).
|
||||
pub(crate) fn gather(plane: &[f32], t: usize, n: usize, members: &[u32], out: &mut Vec<f32>) {
|
||||
out.clear();
|
||||
for &pos in members {
|
||||
for j in 0..n {
|
||||
let at = pos as usize + j * t;
|
||||
match plane.get(at..at + n) {
|
||||
Some(row) => out.extend_from_slice(row),
|
||||
None => out.extend(std::iter::repeat_n(0.0, n)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a plane's blocks start along one side: every `step` cells, and the last one too, so the edge is covered.
|
||||
pub fn starts(blocks: usize, step: usize) -> Vec<usize> {
|
||||
let mut v: Vec<usize> = (0..blocks).step_by(step.max(1)).collect();
|
||||
if let Some(last) = blocks.checked_sub(1)
|
||||
&& v.last() != Some(&last)
|
||||
{
|
||||
v.push(last);
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
/// Insert `(distance, block)` into a list ordered by distance, keeping at most `cap`.
|
||||
fn insert(list: &mut Vec<(f32, u32)>, cap: usize, d: f32, pos: u32) {
|
||||
if list.len() >= cap && list.last().is_some_and(|l| d >= l.0) {
|
||||
return;
|
||||
}
|
||||
let at = list.partition_point(|e| e.0 <= d);
|
||||
list.insert(at, (d, pos));
|
||||
list.truncate(cap);
|
||||
}
|
||||
|
||||
/// For every block that starts a group, the blocks of `plane` within `search` cells (itself first) whose mean squared
|
||||
/// difference from it is at most `tau`, nearest first and at most `cap`. Blocks (of `n × n` cells) are named by their
|
||||
/// top-left cell, and a block starts a group every `step` cells.
|
||||
pub(crate) fn match_groups(plane: &[f32], t: usize, n: usize, step: usize, search: usize, cap: usize, tau: f32) -> Vec<Vec<u32>> {
|
||||
let nb = t + 1 - n;
|
||||
let refs = starts(nb, step);
|
||||
let nr = refs.len();
|
||||
let cap = cap.max(1);
|
||||
let mut lists: Vec<Vec<(f32, u32)>> = Vec::with_capacity(nr * nr);
|
||||
for &ry in &refs {
|
||||
for &rx in &refs {
|
||||
let mut l = Vec::with_capacity(cap + 1);
|
||||
l.push((0.0, (ry * t + rx) as u32));
|
||||
lists.push(l);
|
||||
}
|
||||
}
|
||||
let norm = 1.0 / (n * n) as f32;
|
||||
let r = search as isize;
|
||||
let (mut d, mut hsum) = (vec![0f32; t * t], vec![0f32; t * nr]);
|
||||
let valid = |v: usize, o: isize| (v as isize + o) >= 0 && ((v as isize + o) as usize) < nb;
|
||||
for oy in -r..=r {
|
||||
for ox in -r..=r {
|
||||
if ox == 0 && oy == 0 {
|
||||
continue;
|
||||
}
|
||||
// squared differences between the plane and itself shifted by the offset
|
||||
let (x0, x1) = (0.max(-ox) as usize, (t as isize).min(t as isize - ox) as usize);
|
||||
for y in 0..t {
|
||||
let sy = y as isize + oy;
|
||||
if sy < 0 || sy >= t as isize {
|
||||
continue;
|
||||
}
|
||||
let (Some(a), Some(b), Some(out)) = (
|
||||
plane.get(y * t + x0..y * t + x1),
|
||||
plane.get(sy as usize * t + (x0 as isize + ox) as usize..sy as usize * t + (x1 as isize + ox) as usize),
|
||||
d.get_mut(y * t + x0..y * t + x1),
|
||||
) else {
|
||||
continue;
|
||||
};
|
||||
for ((o, &a), &b) in out.iter_mut().zip(a).zip(b) {
|
||||
*o = (a - b) * (a - b);
|
||||
}
|
||||
}
|
||||
// block sums: along rows at the starting columns, then down at the starting rows
|
||||
for y in 0..t {
|
||||
for (ri, &rx) in refs.iter().enumerate() {
|
||||
if !valid(rx, ox) {
|
||||
continue;
|
||||
}
|
||||
let s: f32 = d.get(y * t + rx..y * t + rx + n).map_or(0.0, |v| v.iter().sum());
|
||||
if let Some(h) = hsum.get_mut(y * nr + ri) {
|
||||
*h = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (rj, &ry) in refs.iter().enumerate() {
|
||||
if !valid(ry, oy) {
|
||||
continue;
|
||||
}
|
||||
for (ri, &rx) in refs.iter().enumerate() {
|
||||
if !valid(rx, ox) {
|
||||
continue;
|
||||
}
|
||||
let s: f32 = (0..n).map(|j| hsum.get((ry + j) * nr + ri).copied().unwrap_or(0.0)).sum::<f32>() * norm;
|
||||
if s <= tau {
|
||||
let other = ((ry as isize + oy) as usize * t) as isize + (rx as isize + ox);
|
||||
if let Some(l) = lists.get_mut(rj * nr + ri) {
|
||||
insert(l, cap, s, other as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lists.into_iter().map(|l| l.into_iter().map(|(_, pos)| pos).collect()).collect()
|
||||
}
|
||||
|
||||
/// [`match_groups`] with each group cut to a power of two, so the Haar transform across it is complete.
|
||||
fn match_blocks(plane: &[f32], t: usize, p: &Params, tau: f32) -> Vec<Vec<u32>> {
|
||||
let mut groups = match_groups(plane, t, p.block, p.step, p.search, p.group, tau);
|
||||
for g in &mut groups {
|
||||
let m = if g.is_empty() { 0 } else { 1usize << g.len().ilog2() };
|
||||
g.truncate(m);
|
||||
}
|
||||
groups
|
||||
}
|
||||
|
||||
/// Filter every plane of `y` over the groups: hard threshold when there is no `pilot`, Wiener shrinkage by it when
|
||||
/// there is.
|
||||
fn collaborate(y: &[Vec<f32>], pilot: Option<&[Vec<f32>]>, groups: &[Vec<u32>], t: usize, p: &Params, lambda: f32, tf: &Transform) -> Vec<Vec<f32>> {
|
||||
let n = tf.n;
|
||||
let sigma = p.sigma.max(1e-3);
|
||||
let lambda = lambda * sigma;
|
||||
let mut s = Scratch::default();
|
||||
let (mut buf, mut pbuf) = (Vec::new(), Vec::new());
|
||||
let mut out = Vec::with_capacity(y.len());
|
||||
for plane in y {
|
||||
let mut num = vec![0f32; t * t];
|
||||
let mut den = vec![0f32; t * t];
|
||||
let c = out.len();
|
||||
let pilot_plane = pilot.and_then(|pl| pl.get(c));
|
||||
for members in groups {
|
||||
let m = members.len();
|
||||
gather(plane, t, n, members, &mut buf);
|
||||
group_transform(tf, &mut buf, m, &mut s, true);
|
||||
let weight = match pilot_plane {
|
||||
None => {
|
||||
let mut kept = 0usize;
|
||||
for v in buf.iter_mut() {
|
||||
if v.abs() < lambda {
|
||||
*v = 0.0;
|
||||
} else {
|
||||
kept += 1;
|
||||
}
|
||||
}
|
||||
1.0 / kept.max(1) as f32
|
||||
}
|
||||
Some(pl) => {
|
||||
gather(pl, t, n, members, &mut pbuf);
|
||||
group_transform(tf, &mut pbuf, m, &mut s, true);
|
||||
let mut energy = 0f32;
|
||||
for (v, &q) in buf.iter_mut().zip(&pbuf) {
|
||||
let w = q * q / (q * q + sigma * sigma);
|
||||
*v *= w;
|
||||
energy += w * w;
|
||||
}
|
||||
1.0 / energy.max(1e-3)
|
||||
}
|
||||
};
|
||||
group_transform(tf, &mut buf, m, &mut s, false);
|
||||
for (&pos, blk) in members.iter().zip(buf.chunks_exact(n * n)) {
|
||||
for (j, row) in blk.chunks_exact(n).enumerate() {
|
||||
let at = pos as usize + j * t;
|
||||
let (Some(nu), Some(de)) = (num.get_mut(at..at + n), den.get_mut(at..at + n)) else { continue };
|
||||
let win = tf.window.get(j * n..(j + 1) * n).unwrap_or_default();
|
||||
for (((nu, de), &v), &w) in nu.iter_mut().zip(de.iter_mut()).zip(row).zip(win) {
|
||||
*nu += weight * w * v;
|
||||
*de += weight * w;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// cells no block reached keep their value
|
||||
out.push(num.iter().zip(&den).zip(plane).map(|((&nu, &de), &own)| if de > 0.0 { nu / de } else { own }).collect());
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// What a run over tiles of `t` cells uses once the parameters are made safe: shared by every device that runs the filter.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Plan {
|
||||
pub params: Params,
|
||||
/// The first step's hard threshold, in noise deviations (before `params.sigma` scales it).
|
||||
pub lambda: f32,
|
||||
}
|
||||
|
||||
/// The parameters as they are used for tiles of `t` cells and a photo whose noise has deviation `noise` at mid-grey
|
||||
/// (white = 1; see [`Params::lambda`]), or `None` when the tiles are smaller than a block (they are then left as they
|
||||
/// are).
|
||||
pub fn plan(p: &Params, t: usize, noise: f32) -> Option<Plan> {
|
||||
let n = p.block.clamp(2, 16);
|
||||
if t < n {
|
||||
return None;
|
||||
}
|
||||
let params = Params { block: n, search: p.search.min(t), group: p.group.clamp(1, 64), ..*p };
|
||||
Some(Plan { params, lambda: threshold_for(&p.lambda, noise) })
|
||||
}
|
||||
|
||||
/// The block-to-block DCT matrix (`n × n`, row `k` is frequency `k`) and the window (`n × n`) the filtered blocks are put
|
||||
/// back with: the constants the graphics-card version is given so that both use the very same numbers.
|
||||
pub fn constants(n: usize) -> (Vec<f32>, Vec<f32>) {
|
||||
let tf = Transform::new(n.clamp(2, 16));
|
||||
(tf.c, tf.window)
|
||||
}
|
||||
|
||||
/// Denoise four unit-noise planes of `t × t` cells (see the module description); `noise` is the photo's noise at
|
||||
/// mid-grey, which sets how hard it cleans (see [`Params::lambda`]).
|
||||
pub fn filter(planes: &[Vec<f32>], t: usize, p: &Params, noise: f32) -> Vec<Vec<f32>> {
|
||||
let y = hadamard(planes);
|
||||
let Some(Plan { params: p, lambda }) = plan(p, t, noise) else { return hadamard(&y) };
|
||||
if y.len() != 4 || y.iter().any(|pl| pl.len() != t * t) {
|
||||
return hadamard(&y);
|
||||
}
|
||||
let tf = Transform::new(p.block);
|
||||
let var = p.sigma.max(1e-3).powi(2);
|
||||
let Some(brightness) = y.first() else { return hadamard(&y) };
|
||||
let first = match_blocks(brightness, t, &p, p.tau1 * var);
|
||||
let basic = collaborate(&y, None, &first, t, &p, lambda, &tf);
|
||||
if !p.wiener {
|
||||
return hadamard(&basic);
|
||||
}
|
||||
let Some(pilot) = basic.first() else { return hadamard(&basic) };
|
||||
let second = match_blocks(pilot, t, &p, p.tau2 * var);
|
||||
hadamard(&collaborate(&y, Some(&basic), &second, t, &p, lambda, &tf))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The DCT keeps a block's energy, and both it and the Haar transform are undone exactly by their inverses.
|
||||
#[test]
|
||||
fn the_dct_and_haar_transforms_invert() {
|
||||
for n in [2, 4, 8] {
|
||||
let tf = Transform::new(n);
|
||||
let block: Vec<f32> = (0..n * n).map(|i| (i as f32 * 0.7).sin() * 3.0).collect();
|
||||
let (mut b, mut tmp) = (block.clone(), vec![0f32; n * n]);
|
||||
tf.forward(&mut b, &mut tmp);
|
||||
let energy = |v: &[f32]| v.iter().map(|x| x * x).sum::<f32>();
|
||||
assert!((energy(&b) - energy(&block)).abs() < 1e-3, "the DCT keeps energy");
|
||||
tf.inverse(&mut b, &mut tmp);
|
||||
assert!(b.iter().zip(&block).all(|(a, c)| (a - c).abs() < 1e-4));
|
||||
}
|
||||
for m in [1usize, 2, 4, 16] {
|
||||
let v: Vec<f32> = (0..m).map(|i| i as f32 * 0.3 - 1.0).collect();
|
||||
let (mut w, mut tmp) = (v.clone(), vec![0f32; m]);
|
||||
haar_forward(&mut w, &mut tmp);
|
||||
assert!((w.iter().map(|x| x * x).sum::<f32>() - v.iter().map(|x| x * x).sum::<f32>()).abs() < 1e-4);
|
||||
haar_inverse(&mut w, &mut tmp);
|
||||
assert!(w.iter().zip(&v).all(|(a, c)| (a - c).abs() < 1e-5));
|
||||
}
|
||||
}
|
||||
|
||||
/// Four planes of unit noise (an LCG and Box-Muller, so the tests need no dependency) round `level`.
|
||||
fn noisy(t: usize, level: f32, seed: u64) -> Vec<Vec<f32>> {
|
||||
let mut state = seed;
|
||||
let mut uniform = move || {
|
||||
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((state >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
};
|
||||
(0..4)
|
||||
.map(|_| {
|
||||
(0..t * t)
|
||||
.map(|_| {
|
||||
let (u, v) = (uniform(), uniform());
|
||||
level + (-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The deviation of the planes' values around `level`.
|
||||
fn spread(planes: &[Vec<f32>], level: f32) -> f32 {
|
||||
let all: Vec<f32> = planes.iter().flatten().copied().collect();
|
||||
(all.iter().map(|v| (v - level) * (v - level)).sum::<f32>() / all.len().max(1) as f32).sqrt()
|
||||
}
|
||||
|
||||
/// The threshold holds at the ends of the curve, passes through its points and never falls as the noise rises; a
|
||||
/// noise that is not a number, an empty curve and curves out of order give a value instead of a panic.
|
||||
#[test]
|
||||
fn the_threshold_follows_the_noise_and_survives_odd_curves() {
|
||||
let c = Params::default().lambda;
|
||||
let at = |n: f32| threshold_for(&c, n);
|
||||
assert_eq!((at(0.0), at(1.0)), (1.2, 3.5), "the ends hold");
|
||||
assert!((at(0.0062) - 1.9).abs() < 1e-4 && (at(0.0152) - 2.65).abs() < 1e-4, "the points are on the curve");
|
||||
let mut last = 0.0;
|
||||
for i in 0..250 {
|
||||
let v = at(0.001 * 1.04f32.powi(i));
|
||||
assert!(v >= last - 1e-6, "the threshold never falls as the noise rises");
|
||||
last = v;
|
||||
}
|
||||
assert_eq!(at(f32::NAN), 1.2, "a noise that is not a number is the quietest");
|
||||
assert_eq!(threshold_for(&[], 0.1), 3.0);
|
||||
// curves that are out of order, or with numbers that are not numbers, give some value and never panic
|
||||
for curve in [vec![(0.0, 1.0), (f32::NAN, 2.0), (0.01, 5.0), (0.005, 4.0)], vec![(0.01, 2.0), (0.01, 3.0)], vec![(-1.0, 2.0), (0.0, 3.0)]] {
|
||||
for n in [0.0, 0.003, 0.02, 1.0, f32::INFINITY] {
|
||||
assert!(threshold_for(&curve, n).is_finite() || !curve.iter().all(|p| p.1.is_finite()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Filtering a flat picture of pure noise leaves well under half of the noise's deviation.
|
||||
#[test]
|
||||
fn a_flat_noisy_picture_comes_out_much_quieter() {
|
||||
let t = 48;
|
||||
let planes = noisy(t, 5.0, 7);
|
||||
let out = filter(&planes, t, &Params::default(), 0.5);
|
||||
// the Hadamard transform keeps the level, so what is left of the spread is the noise that got through
|
||||
assert!(spread(&out, 5.0) < 0.35 * spread(&planes, 5.0), "{} vs {}", spread(&out, 5.0), spread(&planes, 5.0));
|
||||
assert!(out.iter().flatten().all(|v| v.is_finite()));
|
||||
}
|
||||
|
||||
/// A step edge under noise stays a step: a few cells either side of it the values are still near their two levels.
|
||||
#[test]
|
||||
fn a_step_edge_stays_sharp() {
|
||||
let t = 48;
|
||||
let mut planes = noisy(t, 0.0, 9);
|
||||
for pl in &mut planes {
|
||||
for (i, v) in pl.iter_mut().enumerate() {
|
||||
if i % t >= t / 2 {
|
||||
*v += 12.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
let out = filter(&planes, t, &Params::default(), 0.5);
|
||||
let row = t / 2;
|
||||
let at = |x: usize| out.iter().map(|pl| pl.get(row * t + x).copied().unwrap_or(0.0)).sum::<f32>() / 4.0;
|
||||
assert!(at(t / 2 - 3) < 2.0 && at(t / 2 + 2) > 10.0, "{} {}", at(t / 2 - 3), at(t / 2 + 2));
|
||||
}
|
||||
|
||||
/// Tiny and empty tiles, planes of NaN, a tuning with a zero block, step or group, and no planes at all give finite
|
||||
/// values or empty planes and never a panic.
|
||||
#[test]
|
||||
fn odd_inputs_never_panic() {
|
||||
// the sizes and values a tile or a caller could hand over
|
||||
for t in [0usize, 1, 3, 4, 5, 9] {
|
||||
let planes = noisy(t.max(1), 1.0, 3);
|
||||
let out = filter(&planes, t, &Params::default(), 0.5);
|
||||
assert!(out.iter().flatten().all(|v| v.is_finite()));
|
||||
}
|
||||
let planes = vec![vec![f32::NAN; 64]; 4];
|
||||
let _ = filter(&planes, 8, &Params::default(), 0.5);
|
||||
let wild = Params { block: 0, step: 0, search: 1000, group: 0, ..Params::default() };
|
||||
assert!(filter(&noisy(16, 2.0, 1), 16, &wild, 0.5).iter().flatten().all(|v| v.is_finite()));
|
||||
assert!(filter(&[], 8, &Params::default(), 0.5).iter().all(|p| p.is_empty()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,679 @@
|
||||
//! The built-in denoiser: what AI Denoise runs when no model has been installed, so it works out of the box.
|
||||
//!
|
||||
//! It is a [`TileRunner`] with the same contract as a model (four Bayer planes in, camera RGB at twice the plane
|
||||
//! size out), written from scratch and needing no file: the noise level of the photo is measured from the photo itself
|
||||
//! (Poisson-Gaussian: variance = a · signal + b; [`estimate_noise`], with a tile's own measure as the fallback), the
|
||||
//! four planes are cleaned together by block-matching collaborative filtering on variance-stabilised data
|
||||
//! ([`crate::bm3d`]; the non-local-means filter of [`crate::nlm`] is the fallback), which cleans harder as the noise
|
||||
//! grows, and the cleaned mosaic is demosaiced with edge-directed green and colour-difference red and blue.
|
||||
|
||||
use crate::bayer::reflect;
|
||||
use crate::licence::{Commercial, Licence};
|
||||
use crate::manifest::{DenoiserManifest, Domain, Gain};
|
||||
use crate::nlm::{self, Stabiliser, Tuning};
|
||||
use crate::run::{Error, TileRunner};
|
||||
|
||||
/// Id of the built-in denoiser; no installed model may use it (the models folder is never searched for it).
|
||||
pub const ID: &str = "builtin";
|
||||
/// Changes when the algorithm does, so that cached pictures made by an older one are made again.
|
||||
pub const VERSION: u32 = 5;
|
||||
/// Side of its tile, in cells.
|
||||
pub const TILE: u32 = 256;
|
||||
/// Cells neighbouring tiles share.
|
||||
pub const OVERLAP: u32 = 16;
|
||||
|
||||
/// Cells on a side of the blocks the noise level is measured over.
|
||||
const BLOCK: usize = 16;
|
||||
/// The smallest variance used, so that a clean tile is left alone instead of divided by zero.
|
||||
const MIN_VARIANCE: f32 = 1e-10;
|
||||
/// Blocks with a mean above this (white = 1) may be clipped and say nothing about the noise.
|
||||
const CLIPPED: f32 = 0.9;
|
||||
|
||||
/// The manifest of the built-in denoiser, as the engine treats an installed model.
|
||||
pub fn manifest() -> DenoiserManifest {
|
||||
DenoiserManifest {
|
||||
id: ID.into(),
|
||||
name: "Built-in".into(),
|
||||
version: VERSION.to_string(),
|
||||
licence: Licence {
|
||||
name: "MIT OR Apache-2.0".into(),
|
||||
commercial: Commercial::Yes,
|
||||
url: None,
|
||||
notice: "Part of LightCraft: no download, no weights.".into(),
|
||||
},
|
||||
source: None,
|
||||
sha256: None,
|
||||
size_bytes: None,
|
||||
provenance: "Block-matching collaborative filtering with a noise level measured from each photo, written for LightCraft.".into(),
|
||||
domain: Domain::BayerToRgb,
|
||||
tile: TILE,
|
||||
overlap: OVERLAP,
|
||||
gain: Gain::None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The built-in denoiser as a tile runner.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Builtin {
|
||||
/// The noise of the whole photo as `(a, b)`, variance = `a · signal + b` (see [`estimate_noise`]). Without it each
|
||||
/// tile measures its own, which is rougher and can show as a change of strength between tiles.
|
||||
pub noise: Option<(f32, f32)>,
|
||||
pub tuning: Tuning,
|
||||
}
|
||||
|
||||
impl Builtin {
|
||||
/// The runner told the photo's noise as `(a, b)`, variance = `a · signal + b` (see [`estimate_noise`]), with the default tuning.
|
||||
pub fn with_noise(noise: (f32, f32)) -> Self {
|
||||
Builtin { noise: Some(noise), tuning: Tuning::default() }
|
||||
}
|
||||
|
||||
/// The block-matching filter's parameters when this one uses it (the only filter with a graphics-card version, see
|
||||
/// `lightcraft_gpu::bm3d`), else `None`.
|
||||
pub fn bm3d_params(&self) -> Option<crate::bm3d::Params> {
|
||||
self.tuning.bm3d
|
||||
}
|
||||
|
||||
/// [`TileRunner::run`] with the filter stage given: it gets the four variance-stabilised planes (unit noise), their
|
||||
/// side, and the photo's noise at mid-grey (which sets how strongly to clean, see [`Tuning::strength`]), and returns
|
||||
/// the cleaned planes. Everything else (measuring the noise, stabilising and its inverse, demosaicing) is shared, so
|
||||
/// a filter that is the same computation on another device gives the same picture.
|
||||
pub fn run_with(&self, input: &[f32], filter: &dyn Fn(&[Vec<f32>], usize, f32) -> Result<Vec<Vec<f32>>, Error>) -> Result<Vec<f32>, Error> {
|
||||
let t = side_of(input.len()).ok_or_else(|| Error::Input("the tile is not four square planes".into()))?;
|
||||
let clean: Vec<f32> = input.iter().map(|v| if v.is_finite() { *v } else { 0.0 }).collect();
|
||||
let n = t * t;
|
||||
let (a, b) = match self.noise {
|
||||
Some((a, b)) if a.is_finite() && b.is_finite() => (a, b),
|
||||
_ => noise_model(&clean.chunks_exact(n).collect::<Vec<_>>(), t),
|
||||
};
|
||||
let st = Stabiliser::new(a, b);
|
||||
let stabilised: Vec<Vec<f32>> = clean.chunks_exact(n).map(|p| p.iter().map(|&v| st.forward(v)).collect()).collect();
|
||||
let cleaned = filter(&stabilised, t, (a * 0.18 + b).max(0.0).sqrt())?;
|
||||
if cleaned.len() != 4 || cleaned.iter().any(|p| p.len() != n) {
|
||||
return Err(Error::Runtime("the filter returned planes of the wrong size".into()));
|
||||
}
|
||||
let planes: Vec<Vec<f32>> = cleaned.iter().map(|p| p.iter().map(|&v| st.inverse(v)).collect()).collect();
|
||||
Ok(demosaic(&planes, t))
|
||||
}
|
||||
|
||||
/// The filter stage on the processor.
|
||||
pub fn filter_on_cpu(&self, stabilised: &[Vec<f32>], t: usize, noise: f32) -> Vec<Vec<f32>> {
|
||||
match &self.tuning.bm3d {
|
||||
Some(p) => crate::bm3d::filter(stabilised, t, p, noise),
|
||||
None => nlm::filter(stabilised, t, &self.tuning, noise),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TileRunner for Builtin {
|
||||
/// Clean one tile, all on the processor.
|
||||
fn run(&self, input: &[f32]) -> Result<Vec<f32>, Error> {
|
||||
self.run_with(input, &|planes, t, noise| Ok(self.filter_on_cpu(planes, t, noise)))
|
||||
}
|
||||
}
|
||||
|
||||
/// The side of the planes of a tile of `len` values, if it is four squares.
|
||||
fn side_of(len: usize) -> Option<usize> {
|
||||
let per = len / 4;
|
||||
let t = (per as f64).sqrt().round() as usize;
|
||||
(len.is_multiple_of(4) && (8..=2048).contains(&t) && t * t == per).then_some(t)
|
||||
}
|
||||
|
||||
/// Measure the noise of a tile: `(a, b)` with variance = `a · signal + b`. Each block of a plane gives the signal
|
||||
/// (its mean) and the variance of its cells' difference from their four neighbours (which texture and edges only
|
||||
/// raise), the lower part of the variances at each brightness is the noise, and a line is fitted through them.
|
||||
fn noise_model(planes: &[&[f32]], t: usize) -> (f32, f32) {
|
||||
let mut blocks: Vec<(f32, f32)> = Vec::new();
|
||||
for p in planes {
|
||||
let at = |x: usize, y: usize| p.get(y * t + x).copied().unwrap_or(0.0);
|
||||
let mut by = 1;
|
||||
while by + BLOCK < t {
|
||||
let mut bx = 1;
|
||||
while bx + BLOCK < t {
|
||||
let (mut sum, mut sq) = (0f64, 0f64);
|
||||
for y in by..by + BLOCK {
|
||||
for x in bx..bx + BLOCK {
|
||||
let c = at(x, y);
|
||||
let r = c - 0.25 * (at(x - 1, y) + at(x + 1, y) + at(x, y - 1) + at(x, y + 1));
|
||||
sum += f64::from(c);
|
||||
sq += f64::from(r * r);
|
||||
}
|
||||
}
|
||||
let cells = (BLOCK * BLOCK) as f64;
|
||||
let mean = (sum / cells) as f32;
|
||||
// a cell minus the mean of four neighbours has 1.25 times the variance of one
|
||||
let variance = (sq / cells / 1.25) as f32;
|
||||
if mean < CLIPPED && mean.is_finite() && variance.is_finite() {
|
||||
blocks.push((mean, variance));
|
||||
}
|
||||
bx += BLOCK;
|
||||
}
|
||||
by += BLOCK;
|
||||
}
|
||||
}
|
||||
fit_noise(blocks)
|
||||
}
|
||||
|
||||
/// The noise of a whole mosaic as `(a, b)` (variance = `a · signal + b`), measured from the picture itself.
|
||||
///
|
||||
/// Each of the four colour planes (they sit at different levels in a raw, so they are never mixed) is cut into blocks.
|
||||
/// A block's noise variance is read from a second-difference operator (`[1 -2 1; -2 4 -2; 1 -2 1]`, which cancels flat
|
||||
/// and smoothly sloping signal and has `36 σ²` of white noise's variance); texture and edges only add to it. At each
|
||||
/// brightness the quietest few blocks are the noise (a low quantile, divided by the bias of that quantile of pure
|
||||
/// noise), and a line is fitted through them. A picture with no flat area still reads somewhat high, never low.
|
||||
pub fn estimate_noise(mosaic: &[f32], width: usize, height: usize) -> (f32, f32) {
|
||||
estimate_noise_with(mosaic, width, height, &NoiseProbe::default())
|
||||
}
|
||||
|
||||
/// [`estimate_noise`], or `None` when the mosaic could not be measured (too small, the wrong size, or no unclipped
|
||||
/// block): the runner then measures each tile's own noise instead of being told a made-up one.
|
||||
pub fn measure_noise(mosaic: &[f32], width: usize, height: usize) -> Option<(f32, f32)> {
|
||||
let noise = estimate_noise(mosaic, width, height);
|
||||
(noise != (0.0, MIN_VARIANCE)).then_some(noise)
|
||||
}
|
||||
|
||||
/// What [`estimate_noise_with`] may be tuned by.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct NoiseProbe {
|
||||
/// Cells on a side of the blocks, in a colour plane.
|
||||
pub block: usize,
|
||||
/// Which of a brightness's blocks (by how noisy they look, 0 = the quietest) is taken as the noise.
|
||||
pub quantile: f32,
|
||||
/// What that quantile of the variances of noise-only blocks is, as a fraction of their true variance.
|
||||
pub correction: f32,
|
||||
}
|
||||
|
||||
impl Default for NoiseProbe {
|
||||
/// The settings the estimator was calibrated with: 12-cell blocks, the quietest 5 %, and the 0.67 bias of that quantile.
|
||||
fn default() -> Self {
|
||||
NoiseProbe { block: 12, quantile: 0.05, correction: 0.67 }
|
||||
}
|
||||
}
|
||||
|
||||
/// [`estimate_noise`] with its settings given.
|
||||
pub fn estimate_noise_with(mosaic: &[f32], width: usize, height: usize, probe: &NoiseProbe) -> (f32, f32) {
|
||||
let (pw, ph) = (width / 2, height / 2);
|
||||
let b = probe.block.clamp(6, 64);
|
||||
if pw < b + 2 || ph < b + 2 || width.checked_mul(height) != Some(mosaic.len()) {
|
||||
return (0.0, MIN_VARIANCE);
|
||||
}
|
||||
let mut blocks: Vec<(f32, f32)> = Vec::new();
|
||||
let mut plane = vec![0f32; pw * ph];
|
||||
for c in 0..4 {
|
||||
let (dx, dy) = (c % 2, c / 2);
|
||||
for (y, row) in plane.chunks_exact_mut(pw).enumerate() {
|
||||
for (x, v) in row.iter_mut().enumerate() {
|
||||
*v = mosaic.get((2 * y + dy) * width + 2 * x + dx).copied().unwrap_or(0.0);
|
||||
}
|
||||
}
|
||||
let at = |x: usize, y: usize| plane.get(y * pw + x).copied().unwrap_or(0.0);
|
||||
let mut by = 1;
|
||||
while by + b < ph {
|
||||
let mut bx = 1;
|
||||
while bx + b < pw {
|
||||
let (mut sum, mut sq, mut top) = (0f64, 0f64, f32::MIN);
|
||||
for y in by..by + b {
|
||||
for x in bx..bx + b {
|
||||
let m = at(x, y);
|
||||
let r = 4.0 * m - 2.0 * (at(x - 1, y) + at(x + 1, y) + at(x, y - 1) + at(x, y + 1))
|
||||
+ (at(x - 1, y - 1) + at(x + 1, y - 1) + at(x - 1, y + 1) + at(x + 1, y + 1));
|
||||
sum += f64::from(m);
|
||||
sq += f64::from(r * r);
|
||||
top = top.max(m);
|
||||
}
|
||||
}
|
||||
let cells = (b * b) as f64;
|
||||
let (mean, variance) = ((sum / cells) as f32, (sq / cells / 36.0) as f32);
|
||||
if top < CLIPPED && mean.is_finite() && variance.is_finite() {
|
||||
blocks.push((mean, variance));
|
||||
}
|
||||
bx += b;
|
||||
}
|
||||
by += b;
|
||||
}
|
||||
}
|
||||
fit_quiet_blocks(blocks, probe.quantile, probe.correction)
|
||||
}
|
||||
|
||||
/// Fit `variance = a · signal + b` through the `(mean, variance)` of blocks: at each brightness (about 300 blocks of
|
||||
/// each) the `quantile` of the variances, divided by `correction`, is the noise.
|
||||
fn fit_quiet_blocks(mut blocks: Vec<(f32, f32)>, quantile: f32, correction: f32) -> (f32, f32) {
|
||||
if blocks.is_empty() {
|
||||
return (0.0, MIN_VARIANCE);
|
||||
}
|
||||
blocks.sort_by(|x, y| x.0.total_cmp(&y.0));
|
||||
let groups = (blocks.len() / 300).clamp(1, 10);
|
||||
let q = if quantile.is_finite() { quantile.clamp(0.0, 0.5) } else { 0.1 };
|
||||
let correction = if correction.is_finite() && correction > 0.05 { correction } else { 1.0 };
|
||||
let mut points: Vec<(f64, f64)> = Vec::new();
|
||||
for g in 0..groups {
|
||||
let slice = blocks.get(g * blocks.len() / groups..(g + 1) * blocks.len() / groups).unwrap_or(&[]);
|
||||
if slice.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mean = slice.iter().map(|b| f64::from(b.0)).sum::<f64>() / slice.len() as f64;
|
||||
let mut variances: Vec<f32> = slice.iter().map(|b| b.1).collect();
|
||||
variances.sort_by(f32::total_cmp);
|
||||
let quiet = variances.get(((variances.len() as f32 * q) as usize).min(variances.len().saturating_sub(1))).copied().unwrap_or(0.0);
|
||||
points.push((mean, f64::from(quiet / correction)));
|
||||
}
|
||||
fit_line(&points)
|
||||
}
|
||||
|
||||
/// The noise of a whole mosaic as `(a, b)` (variance = `a · signal + b`), from blocks spread over the picture. This is
|
||||
/// the first version (blocks mix the colour planes, a plain neighbour difference, the lower quarter of the blocks):
|
||||
/// it reads texture as noise and reports at least about 0.003 at mid-grey whatever the noise. Kept to compare with.
|
||||
pub fn estimate_noise_v1(mosaic: &[f32], width: usize, height: usize) -> (f32, f32) {
|
||||
const SIDE: usize = 32;
|
||||
const MOST_BLOCKS: usize = 6000;
|
||||
let mut blocks: Vec<(f32, f32)> = Vec::new();
|
||||
if width < SIDE + 4 || height < SIDE + 4 || width.checked_mul(height) != Some(mosaic.len()) {
|
||||
return (0.0, MIN_VARIANCE);
|
||||
}
|
||||
let total = (width / SIDE).saturating_mul(height / SIDE);
|
||||
let skip = (total / MOST_BLOCKS + 1).isqrt().max(1);
|
||||
let at = |x: usize, y: usize| mosaic.get(y * width + x).copied().unwrap_or(0.0);
|
||||
let mut by = 2;
|
||||
while by + SIDE + 2 <= height {
|
||||
let mut bx = 2;
|
||||
while bx + SIDE + 2 <= width {
|
||||
let (mut sum, mut sq) = (0f64, 0f64);
|
||||
for y in by..by + SIDE {
|
||||
for x in bx..bx + SIDE {
|
||||
let c = at(x, y);
|
||||
// the neighbours of the same colour, two samples away
|
||||
let r = c - 0.25 * (at(x - 2, y) + at(x + 2, y) + at(x, y - 2) + at(x, y + 2));
|
||||
sum += f64::from(c);
|
||||
sq += f64::from(r * r);
|
||||
}
|
||||
}
|
||||
let cells = (SIDE * SIDE) as f64;
|
||||
let (mean, variance) = ((sum / cells) as f32, (sq / cells / 1.25) as f32);
|
||||
if mean < CLIPPED && mean.is_finite() && variance.is_finite() {
|
||||
blocks.push((mean, variance));
|
||||
}
|
||||
bx += SIDE * skip;
|
||||
}
|
||||
by += SIDE * skip;
|
||||
}
|
||||
fit_noise(blocks)
|
||||
}
|
||||
|
||||
/// Fit `variance = a · signal + b` through the `(mean, variance)` of blocks: the quieter part of the variances at
|
||||
/// each brightness is the noise (texture and edges only raise a block's variance), and a line is fitted through them.
|
||||
fn fit_noise(mut blocks: Vec<(f32, f32)>) -> (f32, f32) {
|
||||
if blocks.is_empty() {
|
||||
return (0.0, MIN_VARIANCE);
|
||||
}
|
||||
blocks.sort_by(|x, y| x.0.total_cmp(&y.0));
|
||||
let groups = (blocks.len() / 8).clamp(1, 6);
|
||||
let points: Vec<(f64, f64)> = {
|
||||
let mut points: Vec<(f64, f64)> = Vec::new();
|
||||
for g in 0..groups {
|
||||
let slice = blocks.get(g * blocks.len() / groups..(g + 1) * blocks.len() / groups).unwrap_or(&[]);
|
||||
if slice.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mean = slice.iter().map(|b| f64::from(b.0)).sum::<f64>() / slice.len() as f64;
|
||||
let mut variances: Vec<f32> = slice.iter().map(|b| b.1).collect();
|
||||
variances.sort_by(f32::total_cmp);
|
||||
let quiet = variances.get(variances.len() / 4).copied().unwrap_or(0.0);
|
||||
points.push((mean, f64::from(quiet)));
|
||||
}
|
||||
points
|
||||
};
|
||||
fit_line(&points)
|
||||
}
|
||||
|
||||
/// The line `variance = a · signal + b` through `(signal, variance)` points, with neither `a` nor `b` negative.
|
||||
fn fit_line(points: &[(f64, f64)]) -> (f32, f32) {
|
||||
if points.is_empty() {
|
||||
return (0.0, MIN_VARIANCE);
|
||||
}
|
||||
let n = points.len() as f64;
|
||||
let (sx, sy) = points.iter().fold((0.0, 0.0), |s, p| (s.0 + p.0, s.1 + p.1));
|
||||
let (sxx, sxy) = points.iter().fold((0.0, 0.0), |s, p| (s.0 + p.0 * p.0, s.1 + p.0 * p.1));
|
||||
let det = n * sxx - sx * sx;
|
||||
let (mut a, mut b) =
|
||||
if points.len() >= 2 && det.abs() > 1e-12 { ((n * sxy - sx * sy) / det, (sy - (n * sxy - sx * sy) / det * sx) / n) } else { (0.0, sy / n) };
|
||||
if a < 0.0 {
|
||||
(a, b) = (0.0, sy / n);
|
||||
} else if b < 0.0 {
|
||||
(a, b) = (if sxx > 0.0 { sxy / sxx } else { 0.0 }, 0.0);
|
||||
}
|
||||
(a.max(0.0) as f32, (b.max(0.0) as f32).max(MIN_VARIANCE))
|
||||
}
|
||||
|
||||
/// Demosaic four planes `[R, G1, G2, B]` of an RGGB tile into camera RGB planes `[R, G, B]` of `2t × 2t`.
|
||||
pub fn demosaic(planes: &[Vec<f32>], t: usize) -> Vec<f32> {
|
||||
let s = 2 * t;
|
||||
let si = s as isize;
|
||||
// the mosaic: R at (even, even), G1 at (odd, even), G2 at (even, odd), B at (odd, odd)
|
||||
let mut m = vec![0f32; s * s];
|
||||
for (p, plane) in planes.iter().enumerate() {
|
||||
let (dx, dy) = (p % 2, p / 2);
|
||||
for cy in 0..t {
|
||||
for cx in 0..t {
|
||||
if let (Some(dst), Some(v)) = (m.get_mut((2 * cy + dy) * s + 2 * cx + dx), plane.get(cy * t + cx)) {
|
||||
*dst = *v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let at = |x: isize, y: isize| m.get(reflect(y, s) * s + reflect(x, s)).copied().unwrap_or(0.0);
|
||||
// green everywhere: measured where there is a green sample, else interpolated along the smoother direction
|
||||
let mut g = vec![0f32; s * s];
|
||||
for y in 0..si {
|
||||
for x in 0..si {
|
||||
let v = if (x + y) % 2 == 1 {
|
||||
at(x, y)
|
||||
} else {
|
||||
let c = at(x, y);
|
||||
let (l, r, u, d) = (at(x - 1, y), at(x + 1, y), at(x, y - 1), at(x, y + 1));
|
||||
let (gh, gv) =
|
||||
((l + r) / 2.0 + (2.0 * c - at(x - 2, y) - at(x + 2, y)) / 4.0, (u + d) / 2.0 + (2.0 * c - at(x, y - 2) - at(x, y + 2)) / 4.0);
|
||||
let (dh, dv) =
|
||||
((l - r).abs() + (2.0 * c - at(x - 2, y) - at(x + 2, y)).abs(), (u - d).abs() + (2.0 * c - at(x, y - 2) - at(x, y + 2)).abs());
|
||||
let est = if dh < dv {
|
||||
gh
|
||||
} else if dv < dh {
|
||||
gv
|
||||
} else {
|
||||
(gh + gv) / 2.0
|
||||
};
|
||||
est.clamp(l.min(r).min(u).min(d), l.max(r).max(u).max(d))
|
||||
};
|
||||
if let Some(dst) = g.get_mut(y as usize * s + x as usize) {
|
||||
*dst = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
let gat = |x: isize, y: isize| g.get(reflect(y, s) * s + reflect(x, s)).copied().unwrap_or(0.0);
|
||||
// red and blue: the difference from green is smooth, so interpolate it from the nearest samples of the colour
|
||||
let chroma = |px: isize, py: isize| -> Vec<f32> {
|
||||
let diff = |x: isize, y: isize| at(x, y) - gat(x, y);
|
||||
let mut out = vec![0f32; s * s];
|
||||
for y in 0..si {
|
||||
for x in 0..si {
|
||||
let (col, row) = (x % 2 == px, y % 2 == py);
|
||||
let d = match (col, row) {
|
||||
(true, true) => diff(x, y),
|
||||
(false, true) => (diff(x - 1, y) + diff(x + 1, y)) / 2.0,
|
||||
(true, false) => (diff(x, y - 1) + diff(x, y + 1)) / 2.0,
|
||||
(false, false) => (diff(x - 1, y - 1) + diff(x + 1, y - 1) + diff(x - 1, y + 1) + diff(x + 1, y + 1)) / 4.0,
|
||||
};
|
||||
if let Some(dst) = out.get_mut(y as usize * s + x as usize) {
|
||||
*dst = d + gat(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
};
|
||||
let mut out = chroma(0, 0);
|
||||
out.extend_from_slice(&g);
|
||||
out.extend(chroma(1, 1));
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Deterministic standard normal numbers.
|
||||
struct Noise(u64);
|
||||
|
||||
impl Noise {
|
||||
/// The next uniform number, strictly between 0 and 1.
|
||||
fn uniform(&mut self) -> f32 {
|
||||
self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((self.0 >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
}
|
||||
|
||||
/// The next standard normal number (Box-Muller).
|
||||
fn normal(&mut self) -> f32 {
|
||||
let (u, v) = (self.uniform(), self.uniform());
|
||||
(-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos()
|
||||
}
|
||||
}
|
||||
|
||||
/// A scene of camera RGB with an edge and a gradient, `s × s`.
|
||||
fn scene(s: usize) -> [Vec<f32>; 3] {
|
||||
let mut out = [vec![0f32; s * s], vec![0f32; s * s], vec![0f32; s * s]];
|
||||
for y in 0..s {
|
||||
for x in 0..s {
|
||||
let base = 0.15 + 0.5 * x as f32 / s as f32;
|
||||
let step = if y > s / 2 { 0.2 } else { 0.0 };
|
||||
for (c, plane) in out.iter_mut().enumerate() {
|
||||
plane[y * s + x] = base + step * (1.0 + c as f32 * 0.3) / 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The scene's RGGB mosaic with noise of variance `a · signal + b`, as the four planes a tile has.
|
||||
fn mosaic_planes(truth: &[Vec<f32>; 3], t: usize, a: f32, b: f32, seed: u64) -> Vec<f32> {
|
||||
let s = 2 * t;
|
||||
let mut rng = Noise(seed);
|
||||
let mut planes = vec![0f32; 4 * t * t];
|
||||
for (p, &(dx, dy)) in [(0, 0), (1, 0), (0, 1), (1, 1)].iter().enumerate() {
|
||||
let c = [0, 1, 1, 2][p];
|
||||
for cy in 0..t {
|
||||
for cx in 0..t {
|
||||
let v = truth[c][(2 * cy + dy) * s + 2 * cx + dx];
|
||||
planes[p * t * t + cy * t + cx] = v + rng.normal() * (a * v + b).sqrt();
|
||||
}
|
||||
}
|
||||
}
|
||||
planes
|
||||
}
|
||||
|
||||
/// Mean squared error of an RGB result against the scene, away from the tile's edges.
|
||||
fn error(out: &[f32], truth: &[Vec<f32>; 3], s: usize) -> f64 {
|
||||
let (mut sum, mut n) = (0f64, 0f64);
|
||||
for (c, plane) in truth.iter().enumerate() {
|
||||
for y in 12..s - 12 {
|
||||
for x in 12..s - 12 {
|
||||
let d = f64::from(out[c * s * s + y * s + x] - plane[y * s + x]);
|
||||
sum += d * d;
|
||||
n += 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
sum / n
|
||||
}
|
||||
|
||||
/// A noisy tile comes out at least five times closer to the scene (squared error) than a plain demosaic of it.
|
||||
#[test]
|
||||
fn a_noisy_tile_comes_out_much_closer_to_the_scene_than_a_plain_demosaic() {
|
||||
let (t, a, b) = (64, 0.004, 0.0004);
|
||||
let truth = scene(2 * t);
|
||||
let input = mosaic_planes(&truth, t, a, b, 7);
|
||||
let planes: Vec<Vec<f32>> = input.chunks_exact(t * t).map(<[f32]>::to_vec).collect();
|
||||
let plain = error(&demosaic(&planes, t), &truth, 2 * t);
|
||||
let cleaned = error(&Builtin::default().run(&input).unwrap(), &truth, 2 * t);
|
||||
assert!(cleaned < plain / 5.0, "plain {plain}, cleaned {cleaned}");
|
||||
}
|
||||
|
||||
/// A tile with no noise is demosaiced almost exactly, and the step between two rows of its scene survives.
|
||||
#[test]
|
||||
fn a_noise_free_tile_is_demosaiced_without_blurring_its_edge() {
|
||||
let t = 64;
|
||||
let truth = scene(2 * t);
|
||||
let input = mosaic_planes(&truth, t, 0.0, 0.0, 1);
|
||||
let out = Builtin::default().run(&input).unwrap();
|
||||
assert!(error(&out, &truth, 2 * t) < 2e-5);
|
||||
// the step between rows 63 and 65 survives
|
||||
let s = 2 * t;
|
||||
let (above, below) = (out[s * (s / 2 - 2) + s / 2], out[s * (s / 2 + 2) + s / 2]);
|
||||
assert!(below - above > 0.9 * 0.2 / 1.6, "{above} {below}");
|
||||
}
|
||||
|
||||
/// The tile's own noise model finds the added noise within 30 % at two brightness levels.
|
||||
#[test]
|
||||
fn the_noise_level_is_found_from_the_tile() {
|
||||
let (t, a, b) = (128, 0.004, 0.0004);
|
||||
let truth = scene(2 * t);
|
||||
let input = mosaic_planes(&truth, t, a, b, 3);
|
||||
let planes: Vec<&[f32]> = input.chunks_exact(t * t).collect();
|
||||
let (ea, eb) = noise_model(&planes, t);
|
||||
for signal in [0.2f32, 0.5] {
|
||||
let (want, got) = (a * signal + b, ea * signal + eb);
|
||||
assert!((got / want - 1.0).abs() < 0.3, "at {signal}: {got} against {want}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Black, mid-grey and fully clipped tiles give finite results that stay at their level.
|
||||
#[test]
|
||||
fn flat_dark_and_clipped_tiles_do_not_break_it() {
|
||||
let t = 32;
|
||||
for v in [0.0f32, 0.5, 1.0] {
|
||||
let out = Builtin::default().run(&vec![v; 4 * t * t]).unwrap();
|
||||
assert_eq!(out.len(), 3 * 4 * t * t);
|
||||
assert!(out.iter().all(|x| x.is_finite() && (x - v).abs() < 1e-4), "{v}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Empty tiles and tiles that are not four squares are errors; NaN and infinite values in a tile are cleaned up.
|
||||
#[test]
|
||||
fn bad_tiles_are_errors_and_bad_numbers_are_cleaned_up() {
|
||||
assert!(Builtin::default().run(&[]).is_err());
|
||||
assert!(Builtin::default().run(&[0.0; 30]).is_err());
|
||||
assert!(Builtin::default().run(&vec![0.0; 4 * 9 * 10]).is_err());
|
||||
let mut input = vec![0.3f32; 4 * 16 * 16];
|
||||
input[5] = f32::NAN;
|
||||
input[77] = f32::INFINITY;
|
||||
assert!(Builtin::default().run(&input).unwrap().iter().all(|v| v.is_finite()));
|
||||
}
|
||||
|
||||
/// The whole-mosaic estimate finds the added noise within 25 %; a mosaic that is too small or not the size it says
|
||||
/// gets the minimum variance instead of a panic.
|
||||
#[test]
|
||||
fn the_noise_of_a_whole_mosaic_is_found_and_hostile_mosaics_are_refused() {
|
||||
let (s, a, b) = (384, 0.01f32, 0.0005f32);
|
||||
let truth = scene(s);
|
||||
let mut rng = Noise(5);
|
||||
let mosaic: Vec<f32> = (0..s * s)
|
||||
.map(|i| {
|
||||
let (x, y) = (i % s, i / s);
|
||||
let v = truth[[0, 1, 1, 2][(y % 2) * 2 + x % 2]][i];
|
||||
v + rng.normal() * (a * v + b).sqrt()
|
||||
})
|
||||
.collect();
|
||||
let (ea, eb) = estimate_noise(&mosaic, s, s);
|
||||
for signal in [0.2f32, 0.5] {
|
||||
let (want, got) = (a * signal + b, ea * signal + eb);
|
||||
assert!((got / want - 1.0).abs() < 0.25, "at {signal}: {got} against {want}");
|
||||
}
|
||||
// too small, or not the size it says: no estimate, and no panic
|
||||
assert_eq!(estimate_noise(&mosaic, 10, 10).1, MIN_VARIANCE);
|
||||
assert_eq!(estimate_noise(&mosaic, s, s - 1).1, MIN_VARIANCE);
|
||||
assert_eq!(estimate_noise(&[], 0, 0).1, MIN_VARIANCE);
|
||||
assert_eq!(measure_noise(&[], 0, 0), None, "a mosaic that cannot be measured has no noise to tell the runner");
|
||||
assert_eq!(measure_noise(&mosaic, 10, 10), None);
|
||||
assert!(measure_noise(&mosaic, s, s).is_some());
|
||||
assert_eq!(estimate_noise(&mosaic, usize::MAX, usize::MAX).1, MIN_VARIANCE);
|
||||
}
|
||||
|
||||
/// A 640 x 640 mosaic: a smooth slope (dark at the top, bright at the bottom), texture (fine lines, edges) over its
|
||||
/// left part and flat over the rest, with noise of variance `a · signal + b` added.
|
||||
fn textured_and_flat(a: f32, b: f32, flat_from: usize, seed: u64) -> Vec<f32> {
|
||||
let s = 640;
|
||||
let mut rng = Noise(seed);
|
||||
(0..s * s)
|
||||
.map(|i| {
|
||||
let (x, y) = (i % s, i / s);
|
||||
let slope = 0.02 + 0.6 * y as f32 / s as f32 + 0.1 * x as f32 / s as f32;
|
||||
let texture = if x < flat_from {
|
||||
0.04 * ((x as f32 * 1.3).sin() + (y as f32 * 0.9).sin()) + if (x / 9 + y / 7) % 2 == 0 { 0.05 } else { 0.0 }
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let v = (slope + texture).max(0.0);
|
||||
v + rng.normal() * (a * v + b).sqrt()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// With texture over most of the picture and a flat strip beside it, the estimate follows the strip's noise within
|
||||
/// 25 % (in deviation), where the first version read the texture as several times too much.
|
||||
#[test]
|
||||
fn the_noise_is_read_from_the_flat_areas_and_not_from_the_texture_beside_them() {
|
||||
let (a, b) = (5e-4f32, 1e-6f32);
|
||||
// texture over the left 70 % and flat over the rest: the flat part is what shows the noise
|
||||
let mosaic = textured_and_flat(a, b, 450, 7);
|
||||
let (ea, eb) = estimate_noise(&mosaic, 640, 640);
|
||||
for signal in [0.1f32, 0.2, 0.4] {
|
||||
let (want, got) = ((a * signal + b).sqrt(), (ea * signal + eb).sqrt());
|
||||
assert!((got / want - 1.0).abs() < 0.25, "the deviation at {signal}: {got} against {want}");
|
||||
}
|
||||
// the first version read the texture as noise (several times too much); this one is far closer
|
||||
let old = estimate_noise_v1(&mosaic, 640, 640);
|
||||
assert!(((old.0 * 0.2 + old.1) / (a * 0.2 + b)).sqrt() > 1.4, "the first version is the thing this one improves on");
|
||||
}
|
||||
|
||||
/// A picture that is all texture is read as noisier than it is, never as meaningfully quieter.
|
||||
#[test]
|
||||
fn a_picture_with_no_flat_area_reads_noisier_than_it_is_never_quieter() {
|
||||
let (a, b) = (5e-4f32, 1e-6f32);
|
||||
let mosaic = textured_and_flat(a, b, 640, 9);
|
||||
let (ea, eb) = estimate_noise(&mosaic, 640, 640);
|
||||
for signal in [0.1f32, 0.3] {
|
||||
assert!(ea * signal + eb >= 0.9 * (a * signal + b), "at {signal}: {} against {}", ea * signal + eb, a * signal + b);
|
||||
}
|
||||
}
|
||||
|
||||
/// Black, fully clipped and NaN mosaics, and a nonsensical probe setting, give finite numbers and no panic.
|
||||
#[test]
|
||||
fn a_clipped_or_all_dark_mosaic_is_measured_without_a_panic() {
|
||||
for level in [0.0f32, 1.0, f32::NAN] {
|
||||
let mosaic = vec![level; 200 * 200];
|
||||
let (a, b) = estimate_noise(&mosaic, 200, 200);
|
||||
assert!(a.is_finite() && b.is_finite() && a >= 0.0 && b > 0.0, "{level}: {a} {b}");
|
||||
}
|
||||
let probe = NoiseProbe { block: 0, quantile: f32::NAN, correction: -1.0 };
|
||||
let (a, b) = estimate_noise_with(&vec![0.3; 200 * 200], 200, 200, &probe);
|
||||
assert!(a.is_finite() && b.is_finite());
|
||||
}
|
||||
|
||||
/// A heavily noisy tile is cleaned to under an eighth of a plain demosaic's error, whether the runner measures the
|
||||
/// noise itself or is told it.
|
||||
#[test]
|
||||
fn a_heavily_noisy_tile_is_cleaned_far_more_than_a_plain_demosaic_and_by_the_photos_noise() {
|
||||
let (t, a, b) = (64, 0.03, 0.004);
|
||||
let truth = scene(2 * t);
|
||||
let input = mosaic_planes(&truth, t, a, b, 9);
|
||||
let planes: Vec<Vec<f32>> = input.chunks_exact(t * t).map(<[f32]>::to_vec).collect();
|
||||
let plain = error(&demosaic(&planes, t), &truth, 2 * t);
|
||||
let own = error(&Builtin::default().run(&input).unwrap(), &truth, 2 * t);
|
||||
let told = error(&Builtin::with_noise((a, b)).run(&input).unwrap(), &truth, 2 * t);
|
||||
assert!(own < plain / 8.0 && told < plain / 8.0, "plain {plain}, own {own}, told {told}");
|
||||
}
|
||||
|
||||
/// Noise values that are not numbers fall back to the tile's own measurement; a tuning with no search, and the
|
||||
/// non-local-means fallback, still give finite pictures; and the strength rises with the noise from 0 to 1.
|
||||
#[test]
|
||||
fn noise_values_that_are_not_numbers_fall_back_to_the_tiles_own_and_the_strength_follows_the_noise() {
|
||||
let t = 32;
|
||||
let input = vec![0.3f32; 4 * t * t];
|
||||
for bad in [(f32::NAN, 1e-3), (0.01, f32::INFINITY), (-1.0, -1.0)] {
|
||||
let out = Builtin { noise: Some(bad), tuning: Tuning::default() }.run(&input).unwrap();
|
||||
assert!(out.iter().all(|v| v.is_finite()), "{bad:?}");
|
||||
}
|
||||
// no search at all is a plain demosaic, not a crash
|
||||
let none = Builtin { noise: Some((0.01, 1e-3)), tuning: Tuning { search: 0, search2: 0, bm3d: None, ..Tuning::default() } };
|
||||
assert!(none.run(&input).unwrap().iter().all(|v| v.is_finite()));
|
||||
let nlm = Builtin { noise: Some((0.01, 1e-3)), tuning: Tuning { bm3d: None, ..Tuning::default() } };
|
||||
assert!(nlm.run(&input).unwrap().iter().all(|v| v.is_finite()));
|
||||
let tune = Tuning::default();
|
||||
let ramp: Vec<f32> = [0.0, 0.02, 0.05, 0.1, 0.2].iter().map(|&n| tune.strength(n)).collect();
|
||||
assert!(ramp.windows(2).all(|w| w[0] <= w[1]) && ramp[0] == 0.0 && ramp[4] == 1.0, "{ramp:?}");
|
||||
}
|
||||
|
||||
/// The built-in denoiser's manifest passes the manifest check and carries the tile and overlap the runner uses.
|
||||
#[test]
|
||||
fn its_manifest_is_valid() {
|
||||
let m = manifest();
|
||||
crate::manifest::validate(&m).unwrap();
|
||||
assert_eq!((m.tile, m.overlap), (TILE, OVERLAP));
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,13 @@
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
pub mod archive;
|
||||
pub mod bayer;
|
||||
pub mod bm3d;
|
||||
pub mod builtin;
|
||||
pub mod hash;
|
||||
pub mod known;
|
||||
pub mod licence;
|
||||
pub mod manifest;
|
||||
pub mod nlm;
|
||||
pub mod product;
|
||||
pub mod run;
|
||||
pub mod tiles;
|
||||
|
||||
@@ -0,0 +1,416 @@
|
||||
//! The built-in denoiser's filter: variance stabilisation and a non-local-means average whose weights come from all
|
||||
//! four colour planes of a tile at once, so the planes are cleaned together instead of each on its own.
|
||||
//!
|
||||
//! Noise in a raw file has variance `a · signal + b`. The generalised Anscombe transform ([`Stabiliser`]) turns that
|
||||
//! into noise of variance 1 everywhere, so one threshold fits every brightness. The four planes are then rotated
|
||||
//! (a Hadamard transform, which keeps unit noise) into a brightness plane and three colour-difference planes.
|
||||
//! Each cell becomes the average of the cells around it whose patch, over all four planes, looks like its own
|
||||
//! within the noise, in two passes: the second finds matches on the first pass's much cleaner picture, so it can
|
||||
//! look further and keep finer detail.
|
||||
|
||||
use crate::bayer::reflect;
|
||||
|
||||
/// What the filter may be tuned by (the defaults are what the built-in denoiser uses).
|
||||
///
|
||||
/// How strongly a photo is cleaned follows its noise, measured as the standard deviation at mid-grey (0.18, white = 1):
|
||||
/// below `light` it is cleaned gently and in one pass, above `heavy` as hard as the filter goes, and in between smoothly.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Tuning {
|
||||
/// Search window radius, in cells, of the first pass.
|
||||
pub search: usize,
|
||||
/// Search window radius of the second pass, which finds matches on the first pass's cleaner picture; 0 skips it.
|
||||
pub search2: usize,
|
||||
/// How far above the noise two patches may differ and still be averaged in the first pass (larger blurs more),
|
||||
/// for a light and for a heavily noisy photo.
|
||||
pub h_light: f32,
|
||||
pub h_heavy: f32,
|
||||
/// The same for the second pass, which is blended in as the noise grows.
|
||||
pub h2: f32,
|
||||
/// Noise at mid-grey where the stronger settings start and where they are in full.
|
||||
pub light: f32,
|
||||
pub heavy: f32,
|
||||
/// Search radius and threshold of the colour-difference planes' own pass, guided by the cleaned brightness
|
||||
/// plane (colour noise is the cheapest to remove without losing texture); radius 0 skips it.
|
||||
pub search_c: usize,
|
||||
pub h_c: f32,
|
||||
/// Patch radius (a patch is `2 · half + 1` cells on a side) of the first and of the later passes.
|
||||
pub half: usize,
|
||||
pub half2: usize,
|
||||
/// How much looser (a multiple of the threshold) the average is that cells with few matching patches lean on in
|
||||
/// the first pass; 0 turns it off.
|
||||
pub loose: f32,
|
||||
/// The matched weight below which they lean on it, in a heavily noisy photo (scaled down with the noise).
|
||||
pub few: f32,
|
||||
/// Block-matching collaborative filtering ([`crate::bm3d`]) is what cleans the planes; with `None` the non-local-means
|
||||
/// averages above do (their settings apply only then).
|
||||
pub bm3d: Option<crate::bm3d::Params>,
|
||||
}
|
||||
|
||||
impl Default for Tuning {
|
||||
/// The built-in denoiser's tuning: block matching on, and the non-local-means settings it falls back to when that is off.
|
||||
fn default() -> Self {
|
||||
Tuning {
|
||||
search: 3,
|
||||
search2: 5,
|
||||
h_light: 0.3,
|
||||
h_heavy: 0.45,
|
||||
h2: 0.1,
|
||||
light: 0.03,
|
||||
heavy: 0.14,
|
||||
search_c: 7,
|
||||
h_c: 1.0,
|
||||
half: 1,
|
||||
half2: 1,
|
||||
loose: 4.0,
|
||||
few: 0.6,
|
||||
bm3d: Some(crate::bm3d::Params::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tuning {
|
||||
/// 0 for a lightly noisy photo up to 1 for a heavily noisy one.
|
||||
pub fn strength(&self, noise: f32) -> f32 {
|
||||
let span = (self.heavy - self.light).max(1e-6);
|
||||
let x = ((noise - self.light) / span).clamp(0.0, 1.0);
|
||||
x * x * (3.0 - 2.0 * x)
|
||||
}
|
||||
}
|
||||
|
||||
/// The generalised Anscombe transform for noise of variance `a · v + b`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Stabiliser {
|
||||
a: f32,
|
||||
b: f32,
|
||||
}
|
||||
|
||||
/// Below this the noise has no signal-dependent part worth modelling.
|
||||
const MIN_GAIN: f32 = 1e-6;
|
||||
|
||||
impl Stabiliser {
|
||||
/// The transform for noise of variance `a · signal + b`; a gain or offset that is not a number counts as none.
|
||||
pub fn new(a: f32, b: f32) -> Self {
|
||||
Stabiliser { a: if a.is_finite() { a.max(0.0) } else { 0.0 }, b: if b.is_finite() { b.max(1e-12) } else { 1e-12 } }
|
||||
}
|
||||
|
||||
/// A value as a signal with unit noise deviation (a plain scaling when the noise has no signal-dependent part).
|
||||
pub fn forward(self, v: f32) -> f32 {
|
||||
if self.a < MIN_GAIN {
|
||||
return v / self.b.sqrt();
|
||||
}
|
||||
let x = (v + self.b / self.a) / self.a;
|
||||
2.0 * (x + 0.375).max(0.0).sqrt()
|
||||
}
|
||||
|
||||
/// The inverse, with the correction for the bias a plain inverse has on averaged data.
|
||||
pub fn inverse(self, y: f32) -> f32 {
|
||||
if self.a < MIN_GAIN {
|
||||
return y * self.b.sqrt();
|
||||
}
|
||||
let x = if y >= 1.5 {
|
||||
let (i1, i2) = (1.0 / y, 1.0 / (y * y));
|
||||
y * y / 4.0 + 0.25 * 1.5f32.sqrt() * i1 - 11.0 / 8.0 * i2 + 5.0 / 8.0 * 1.5f32.sqrt() * i2 * i1 - 0.125
|
||||
} else {
|
||||
y * y / 4.0 - 0.375
|
||||
};
|
||||
self.a * x - self.b / self.a
|
||||
}
|
||||
}
|
||||
|
||||
/// The orthonormal 4 × 4 Hadamard transform across four planes (its own inverse).
|
||||
pub fn hadamard(p: &[Vec<f32>]) -> Vec<Vec<f32>> {
|
||||
let n = p.first().map_or(0, Vec::len);
|
||||
let mut out = vec![vec![0f32; n]; 4];
|
||||
for i in 0..n {
|
||||
let g = |c: usize| p.get(c).and_then(|v| v.get(i)).copied().unwrap_or(0.0);
|
||||
let (r, g1, g2, b) = (g(0), g(1), g(2), g(3));
|
||||
let vals = [(r + g1 + g2 + b) / 2.0, (r - g1 + g2 - b) / 2.0, (r + g1 - g2 - b) / 2.0, (r - g1 - g2 + b) / 2.0];
|
||||
for (c, v) in vals.into_iter().enumerate() {
|
||||
if let Some(o) = out.get_mut(c).and_then(|o| o.get_mut(i)) {
|
||||
*o = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// A plane with `pad` cells mirrored round every edge (`t + 2 · pad` on a side).
|
||||
fn padded(src: &[f32], t: usize, pad: usize) -> Vec<f32> {
|
||||
let wd = t + 2 * pad;
|
||||
let mut out = vec![0f32; wd * wd];
|
||||
for y in 0..wd {
|
||||
let sy = reflect(y as isize - pad as isize, t);
|
||||
for x in 0..wd {
|
||||
let sx = reflect(x as isize - pad as isize, t);
|
||||
if let (Some(o), Some(v)) = (out.get_mut(y * wd + x), src.get(sy * t + sx)) {
|
||||
*o = *v;
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// What one [`pass`] is run with.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Pass {
|
||||
/// Search window radius and patch radius, in cells.
|
||||
radius: usize,
|
||||
half: usize,
|
||||
/// The threshold and the floor of the weights (see [`pass`]).
|
||||
h: f32,
|
||||
floor: f32,
|
||||
/// A second, looser average (threshold `h · loose`) that cells with few matches lean on, so a cell no patch
|
||||
/// resembles is not left as it was; 0 turns it off.
|
||||
loose: f32,
|
||||
/// Matched weight below which a cell starts to lean on that looser average.
|
||||
few: f32,
|
||||
}
|
||||
|
||||
/// One pass: every cell becomes the weighted average of the cells within `radius` whose patch (`2 · half + 1` cells
|
||||
/// on a side), over all planes, is like its own. `guide` holds the planes the patches are compared on, `data` the
|
||||
/// planes that are averaged (the same ones in the first pass). Weights are `exp(-(excess) / h)`, `excess` being how
|
||||
/// far the mean squared difference of the patches is above `floor` (what two noisy views of one signal give).
|
||||
fn pass(guide: &[Vec<f32>], data: &[Vec<f32>], t: usize, p: &Pass) -> Vec<Vec<f32>> {
|
||||
let Pass { radius, half, h, floor, loose, few } = *p;
|
||||
let pad = radius + half;
|
||||
let wd = t + 2 * pad;
|
||||
let guide: Vec<Vec<f32>> = guide.iter().map(|p| padded(p, t, pad)).collect();
|
||||
let data: Vec<Vec<f32>> = data.iter().map(|p| padded(p, t, pad)).collect();
|
||||
let (n, region, span) = (t * t, t + 2 * half, 2 * half + 1);
|
||||
let planes = data.len().max(1);
|
||||
let mut num = vec![vec![0f32; n]; planes];
|
||||
let mut den = vec![0f32; n];
|
||||
let mut num_l = vec![vec![0f32; n]; if loose > 0.0 { planes } else { 0 }];
|
||||
let mut den_l = vec![0f32; if loose > 0.0 { n } else { 0 }];
|
||||
let (mut d, mut rows) = (vec![0f32; region * region], vec![0f32; region * t]);
|
||||
let norm = 1.0 / ((span * span) as f32 * guide.len().max(1) as f32);
|
||||
let r = radius as isize;
|
||||
for oy in -r..=r {
|
||||
for ox in -r..=r {
|
||||
if ox == 0 && oy == 0 {
|
||||
continue;
|
||||
}
|
||||
let shift = oy * wd as isize + ox;
|
||||
// squared differences over the planes, for the cells and the ring round them the patch reaches
|
||||
for j in 0..region {
|
||||
let base = (j + pad - half) * wd + pad - half;
|
||||
for i in 0..region {
|
||||
let pos = base + i;
|
||||
let other = (pos as isize + shift) as usize;
|
||||
let mut s = 0f32;
|
||||
for p in &guide {
|
||||
let (a, b) = (p.get(pos).copied().unwrap_or(0.0), p.get(other).copied().unwrap_or(0.0));
|
||||
s += (a - b) * (a - b);
|
||||
}
|
||||
if let Some(v) = d.get_mut(j * region + i) {
|
||||
*v = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// the sum over each cell's patch: along rows, then down columns
|
||||
for j in 0..region {
|
||||
for x in 0..t {
|
||||
let k = j * region + x;
|
||||
let s: f32 = (0..span).map(|i| d.get(k + i).copied().unwrap_or(0.0)).sum();
|
||||
if let Some(v) = rows.get_mut(j * t + x) {
|
||||
*v = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
for y in 0..t {
|
||||
for x in 0..t {
|
||||
let k = y * t + x;
|
||||
let patch = (0..span).map(|j| rows.get(k + j * t).copied().unwrap_or(0.0)).sum::<f32>() * norm;
|
||||
let excess = (patch - floor).max(0.0);
|
||||
let wide = if loose > 0.0 { loose } else { 1.0 };
|
||||
// beyond this the weight is below 5e-5: not worth the exponential and the sums
|
||||
if excess > 10.0 * h * wide {
|
||||
continue;
|
||||
}
|
||||
let pos = (y + pad) * wd + x + pad;
|
||||
let other = (pos as isize + shift) as usize;
|
||||
if excess <= 10.0 * h {
|
||||
let w = (-excess / h).exp();
|
||||
if let Some(dn) = den.get_mut(k) {
|
||||
*dn += w;
|
||||
}
|
||||
for (nu, p) in num.iter_mut().zip(&data) {
|
||||
if let (Some(nu), Some(v)) = (nu.get_mut(k), p.get(other)) {
|
||||
*nu += w * v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if loose > 0.0 {
|
||||
let w = (-excess / (h * loose)).exp();
|
||||
if let Some(dn) = den_l.get_mut(k) {
|
||||
*dn += w;
|
||||
}
|
||||
for (nu, p) in num_l.iter_mut().zip(&data) {
|
||||
if let (Some(nu), Some(v)) = (nu.get_mut(k), p.get(other)) {
|
||||
*nu += w * v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// the cell itself counts as much as a perfect match
|
||||
let mut out = vec![vec![0f32; n]; planes];
|
||||
for (c, (o, (nu, p))) in out.iter_mut().zip(num.iter().zip(&data)).enumerate() {
|
||||
for k in 0..n {
|
||||
let own = p.get((k / t + pad) * wd + k % t + pad).copied().unwrap_or(0.0);
|
||||
if let (Some(o), Some(nu), Some(dn)) = (o.get_mut(k), nu.get(k), den.get(k)) {
|
||||
let tight = (nu + own) / (dn + 1.0);
|
||||
*o = match (num_l.get(c).and_then(|v| v.get(k)), den_l.get(k)) {
|
||||
(Some(nl), Some(dl)) => {
|
||||
let loose = (nl + own) / (dl + 1.0);
|
||||
let lean = if few > 0.0 { few / (dn + few) } else { 0.0 };
|
||||
tight + (loose - tight) * lean
|
||||
}
|
||||
_ => tight,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Denoise four unit-noise planes of `t × t` cells (see the module description); `noise` is the photo's noise at
|
||||
/// mid-grey, which sets how strongly (see [`Tuning`]).
|
||||
pub fn filter(planes: &[Vec<f32>], t: usize, tune: &Tuning, noise: f32) -> Vec<Vec<f32>> {
|
||||
let y = hadamard(planes);
|
||||
let k = tune.strength(if noise.is_finite() { noise } else { 0.0 });
|
||||
// two noisy views of one signal differ by 2 in mean square: the floor the excess is counted from
|
||||
let h1 = tune.h_light + (tune.h_heavy - tune.h_light) * k;
|
||||
let first = pass(&y, &y, t, &Pass { radius: tune.search, half: tune.half, h: h1, floor: 2.0, loose: tune.loose, few: tune.few * k });
|
||||
if tune.search2 == 0 || k <= 0.0 {
|
||||
return hadamard(&first);
|
||||
}
|
||||
// the first pass's picture still carries a little noise (of unknown size), so the floor is 0 and the threshold
|
||||
// alone decides
|
||||
let second = pass(&first, &y, t, &Pass { radius: tune.search2, half: tune.half2, h: tune.h2, floor: 0.0, loose: 0.0, few: 0.0 });
|
||||
let mut blended: Vec<Vec<f32>> = first.iter().zip(&second).map(|(f, s)| f.iter().zip(s).map(|(f, s)| f + (s - f) * k).collect()).collect();
|
||||
if tune.search_c > 0 {
|
||||
// matches found on the cleaned brightness plane alone, so colour is only averaged across like brightness
|
||||
let guide = blended.get(..1).unwrap_or_default();
|
||||
let colour = pass(
|
||||
guide,
|
||||
y.get(1..).unwrap_or_default(),
|
||||
t,
|
||||
&Pass { radius: tune.search_c, half: tune.half2, h: tune.h_c, floor: 0.0, loose: 0.0, few: 0.0 },
|
||||
);
|
||||
for (b, c) in blended.iter_mut().skip(1).zip(&colour) {
|
||||
for (b, c) in b.iter_mut().zip(c) {
|
||||
*b += (c - *b) * k;
|
||||
}
|
||||
}
|
||||
}
|
||||
hadamard(&blended)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The transform is undone by its inverse within a little, a step of one noise deviation is a step of about 1
|
||||
/// whatever the brightness, and with no signal-dependent noise it is a plain scaling.
|
||||
#[test]
|
||||
fn the_stabiliser_round_trips_and_gives_unit_noise() {
|
||||
let s = Stabiliser::new(0.01, 0.0005);
|
||||
for v in [0.0f32, 0.01, 0.1, 0.5, 0.9] {
|
||||
let back = s.inverse(s.forward(v));
|
||||
assert!((back - v).abs() < 0.005 + 0.03 * v, "{v} -> {back}");
|
||||
}
|
||||
// a step of one standard deviation is a step of about 1 whatever the brightness
|
||||
for v in [0.05f32, 0.2, 0.6] {
|
||||
let sigma = (0.01 * v + 0.0005).sqrt();
|
||||
let step = s.forward(v + sigma) - s.forward(v);
|
||||
assert!((step - 1.0).abs() < 0.15, "at {v}: {step}");
|
||||
}
|
||||
let flat = Stabiliser::new(0.0, 4e-4);
|
||||
assert!((flat.forward(0.1) - 5.0).abs() < 1e-4 && (flat.inverse(5.0) - 0.1).abs() < 1e-6);
|
||||
}
|
||||
|
||||
/// The Hadamard transform applied twice gives the planes back, and it keeps their energy.
|
||||
#[test]
|
||||
fn the_hadamard_transform_is_its_own_inverse_and_keeps_energy() {
|
||||
let planes: Vec<Vec<f32>> = (0..4).map(|c| (0..9).map(|i| (c * 9 + i) as f32 * 0.37 - 3.0).collect()).collect();
|
||||
let back = hadamard(&hadamard(&planes));
|
||||
for (a, b) in planes.iter().flatten().zip(back.iter().flatten()) {
|
||||
assert!((a - b).abs() < 1e-4);
|
||||
}
|
||||
let energy = |p: &[Vec<f32>]| p.iter().flatten().map(|v| v * v).sum::<f32>();
|
||||
assert!((energy(&planes) - energy(&hadamard(&planes))).abs() < 1e-2);
|
||||
}
|
||||
|
||||
/// Four planes of unit noise (an LCG and Box-Muller, so the tests need no dependency) round `level`.
|
||||
fn noisy(t: usize, level: f32, seed: u64) -> Vec<Vec<f32>> {
|
||||
let mut state = seed;
|
||||
let mut uniform = move || {
|
||||
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((state >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
};
|
||||
(0..4)
|
||||
.map(|_| {
|
||||
(0..t * t)
|
||||
.map(|_| {
|
||||
let (u, v) = (uniform(), uniform());
|
||||
level + (-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The deviation of the planes' values around `level`.
|
||||
fn spread(planes: &[Vec<f32>], level: f32) -> f32 {
|
||||
let all: Vec<f32> = planes.iter().flatten().copied().collect();
|
||||
(all.iter().map(|v| (v - level) * (v - level)).sum::<f32>() / all.len().max(1) as f32).sqrt()
|
||||
}
|
||||
|
||||
/// The colour planes' own pass leaves less noise than brightness alone would, and takes unit noise well below 0.5.
|
||||
#[test]
|
||||
fn the_colour_pass_cleans_colour_planes_further_than_brightness_alone_would() {
|
||||
let (t, noise) = (40, 0.2);
|
||||
let planes = noisy(t, 5.0, 3);
|
||||
let with = filter(&planes, t, &Tuning::default(), noise);
|
||||
let without = filter(&planes, t, &Tuning { search_c: 0, ..Tuning::default() }, noise);
|
||||
// after the Hadamard rotation the colour differences are planes 1..4 of the mixed result, so compare it all
|
||||
assert!(spread(&with, 5.0) < spread(&without, 5.0), "{} vs {}", spread(&with, 5.0), spread(&without, 5.0));
|
||||
assert!(spread(&with, 5.0) < 0.5, "unit noise should drop well below 0.5: {}", spread(&with, 5.0));
|
||||
}
|
||||
|
||||
/// A cell far from its surroundings, which no patch resembles, ends up nearer to them with the looser average than without it.
|
||||
#[test]
|
||||
fn a_cell_no_patch_resembles_is_not_left_as_a_speck_in_heavy_noise() {
|
||||
let (t, noise) = (40, 0.2);
|
||||
let mut planes = noisy(t, 5.0, 9);
|
||||
// one cell far from its surroundings in every plane: nothing matches it
|
||||
let at = (t / 2) * t + t / 2;
|
||||
for p in &mut planes {
|
||||
if let Some(v) = p.get_mut(at) {
|
||||
*v += 6.0;
|
||||
}
|
||||
}
|
||||
let with = filter(&planes, t, &Tuning::default(), noise);
|
||||
let without = filter(&planes, t, &Tuning { loose: 0.0, ..Tuning::default() }, noise);
|
||||
let peak = |planes: &[Vec<f32>]| planes.iter().filter_map(|p| p.get(at)).map(|v| (v - 5.0).abs()).fold(0f32, f32::max);
|
||||
assert!(peak(&with) < peak(&without), "{} vs {}", peak(&with), peak(&without));
|
||||
}
|
||||
|
||||
/// Noise of 0, NaN or next to nothing, with one cell far from the rest, still gives finite values.
|
||||
#[test]
|
||||
fn a_photo_with_no_measured_noise_stays_finite_even_with_an_odd_cell() {
|
||||
let t = 24;
|
||||
let mut planes = noisy(t, 5.0, 5);
|
||||
for p in &mut planes {
|
||||
if let Some(v) = p.get_mut(t * t / 2) {
|
||||
*v += 50.0;
|
||||
}
|
||||
}
|
||||
for noise in [0.0, f32::NAN, 1e-9] {
|
||||
assert!(filter(&planes, t, &Tuning::default(), noise).iter().flatten().all(|v| v.is_finite()), "noise {noise}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# lightcraft-denoise
|
||||
|
||||
L1 pure-Rust AI RAW denoise primitives and CPU inference. No weights are bundled.
|
||||
L1 pure-Rust AI RAW denoise primitives and CPU inference. No weights are bundled; `lightcraft_denoise_core::builtin` is the model-free denoiser used by default.
|
||||
See [user workflow and limitations](../../docs/denoise.md).
|
||||
|
||||
`lightcraft-denoise-core` provides metadata, Bayer helpers and cache formats,
|
||||
|
||||
@@ -118,6 +118,9 @@ fn identify(path: &Path, c: &str, sha_known: Option<&str>) -> Result<Source> {
|
||||
&& let Some(bytes) = read_capped(&sibling, MAX_MANIFEST_BYTES)
|
||||
{
|
||||
let m = manifest::parse(&bytes).map_err(|e| bad(c, format!("{}: {e}", sibling.display())))?;
|
||||
if m.id == lightcraft_denoise::builtin::ID {
|
||||
return Err(bad(c, "the id `builtin` is LightCraft's own denoiser: give the model another id in its denoise-model.json"));
|
||||
}
|
||||
return Ok(Source { manifest: m, entry: None, file_name });
|
||||
}
|
||||
Err(bad(
|
||||
@@ -660,20 +663,20 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
cmd!(query "denoise.models.downloadCancel", "Cancel Denoise Model Download", [], None, "{id} → {discarded} — stop a download, or delete a finished one that was not installed", always, download_cancel),
|
||||
cmd!(query "denoise.models.test", "Test Denoise Model", [], None, "{id} → {ok, result} — load an installed model and check it gives sensible pictures; needs the denoise runtime", always, test),
|
||||
cmd!(query "denoise.models.remove", "Remove Denoise Model", [], None, "{id} → {removed, model} — delete an installed model (its cached pictures stay until they are evicted)", always, remove),
|
||||
cmd!(query "denoise.models.select", "Choose Denoise Model", [], None, "{id: installed model | null} → {model} — null switches denoise off", always, select),
|
||||
cmd!(query "denoise.models.select", "Choose Denoise Model", [], None, "{id: installed model | null} → {model} — null uses the built-in denoiser", always, select),
|
||||
cmd!(query "denoise.settings", "Denoise Settings", [], None, "{auto?: bool, cacheGb?: 1..10000, threads?: 1..64 | null, runOn?: auto | gpu | cpu} → the settings — `auto`: make the picture of the photos being looked at that have a Denoise amount; `cacheGb`: how much the cached pictures may take; `threads`: most tiles run at once; `runOn`: where the model runs — `auto` (the default) the graphics card where it is faster than the processor (both timed on this computer when the card is set up), `gpu` the card whenever it can run the model, `cpu` the processor. Setting `runOn` also lets the card be tried again after a set-up that failed or closed LightCraft", always, settings),
|
||||
cmd!(
|
||||
"denoise.toggle",
|
||||
"AI Denoise",
|
||||
[],
|
||||
None,
|
||||
"{id?: photoId, enabled?: bool} → {id, enabled, amount} — turn AI Denoise on (50% initially) or off for one raw photo, independent of selection and Auto Sync; needs an installed model to turn on",
|
||||
"{id?: photoId, enabled?: bool} → {id, enabled, amount} — turn AI Denoise on (50% initially) or off for one raw photo, independent of selection and Auto Sync; uses the built-in denoiser when no model is chosen",
|
||||
always,
|
||||
toggle
|
||||
),
|
||||
cmd!(query "denoise.queue", "Denoise Photos", [], None, "{ids?: [photoId], scope?: selected | visible | withAmount, retry?: false} → {added, …status} — make the denoised pictures of raw photos that have none, in the background. `retry` tries photos that failed before", always, queue),
|
||||
cmd!(query "denoise.cancel", "Cancel Denoise", [], None, "{id?, all?} → {cancelled} — stop the photo being made and/or forget the ones waiting (all of them when `id` is omitted)", always, cancel),
|
||||
cmd!(query "denoise.status", "Denoise Status", [], None, "{id?} → {enabled, model, runtime, productsDir, queued, running: {photo, done, total, seconds} | null, ready, made, auto, runOn, device: {kind: gpu | cpu | pending | none, adapter?, reason?, cardMs?, cpuMs?, fellBack?, remote?: {address, state: pending | unavailable | used | idle | slower | given up, device?, remoteMs?, localMs?, reason?, failures?, lastError?}}, cache: {files, bytes, limitBytes}, generation, photo?: {state: notApplicable | noModel | ready | queued | running | failed | idle, …}}", always, status),
|
||||
cmd!(query "denoise.status", "Denoise Status", [], None, "{id?} → {enabled, model, runtime, productsDir, queued, running: {photo, done, total, seconds} | null, ready, made, auto, runOn, device: {kind: gpu | cpu | pending | none, adapter?, reason?, cardMs?, cpuMs?, fellBack?, remote?: {address, state: pending | unavailable | used | idle | slower | given up, device?, remoteMs?, localMs?, reason?, failures?, lastError?}}, cache: {files, bytes, limitBytes}, generation, photo?: {state: notApplicable | ready | queued | running | failed | idle, …}}", always, status),
|
||||
cmd!(query "denoise.pump", "Denoise Pump", [], None, "{pace?: pause | light | normal | full} → {active, running, queued, ready, generation, downloading} — called every frame by the app: takes in finished work and keeps one photo going", always, pump),
|
||||
cmd!(query "denoise.clear", "Clear Denoise Cache", [], None, "{} → {deleted, bytes} — delete every cached denoised picture of this library (they are made again when wanted)", always, clear),
|
||||
]
|
||||
|
||||
@@ -36,6 +36,7 @@ use crate::merge::ByteReader;
|
||||
use crate::model_download::Downloads;
|
||||
use crate::{Selection, Session};
|
||||
|
||||
mod builtin;
|
||||
mod gpu;
|
||||
mod model;
|
||||
mod products;
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
use super::gpu::GPU_SETUP_MARKER;
|
||||
#[cfg(feature = "denoise")]
|
||||
use super::gpu::{GPU_MAX_FALLBACKS, GPU_PARALLEL, GPU_SETUP_LIMIT, card_is_faster, card_tile_ms, set_up_card};
|
||||
#[cfg(feature = "denoise")]
|
||||
use super::model::worth_retrying;
|
||||
use super::model::{Model, RunOn};
|
||||
#[cfg(feature = "denoise")]
|
||||
use super::state::Pace;
|
||||
#[cfg(feature = "denoise")]
|
||||
use super::{Arc, AtomicUsize, Mutex, Ordering, PoisonError, RunError};
|
||||
use super::{OnceLock, Path, PathBuf, TileRunner, Value, json};
|
||||
|
||||
/// The built-in denoiser (`lightcraft_denoise::builtin`): nothing to load, so it is what runs until a model is chosen. Its
|
||||
/// filter runs on the graphics card when there is one that agrees with the CPU on a check tile and is faster, else on
|
||||
/// the CPU (see [`BuiltinCard`]); the rest of it always runs on the CPU.
|
||||
pub(super) struct BuiltinModel {
|
||||
runner: OnceLock<lightcraft_denoise::builtin::Builtin>,
|
||||
#[cfg(feature = "denoise")]
|
||||
card: Arc<BuiltinCard>,
|
||||
/// The runner of a photo that runs on the card.
|
||||
#[cfg(feature = "denoise")]
|
||||
hybrid: OnceLock<CardRunner>,
|
||||
}
|
||||
|
||||
impl BuiltinModel {
|
||||
/// For a photo, with the card's state for the set-up marker `marker` (where its set-up is recorded).
|
||||
pub(super) fn new(#[cfg_attr(not(feature = "denoise"), allow(unused_variables))] marker: &Path) -> Self {
|
||||
BuiltinModel {
|
||||
runner: OnceLock::new(),
|
||||
#[cfg(feature = "denoise")]
|
||||
card: builtin_card(marker),
|
||||
#[cfg(feature = "denoise")]
|
||||
hybrid: OnceLock::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Model for BuiltinModel {
|
||||
fn runner(&self, run_on: RunOn, threads: usize) -> (&dyn TileRunner, usize) {
|
||||
let cpu = self.runner.get_or_init(Default::default);
|
||||
#[cfg(feature = "denoise")]
|
||||
{
|
||||
let threads = threads.max(1);
|
||||
self.card.last_threads.store(threads, Ordering::Relaxed);
|
||||
if let Ok(side) = self.card.choose(run_on, threads, true)
|
||||
&& let Ok(gpu) = lightcraft_gpu::bm3d::BuiltinRunner::new(side.gpu.clone(), *cpu)
|
||||
{
|
||||
let hybrid = self.hybrid.get_or_init(|| CardRunner { gpu, cpu: *cpu, card: self.card.clone() });
|
||||
return (hybrid, threads.min(GPU_PARALLEL));
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "denoise"))]
|
||||
let _ = run_on;
|
||||
(cpu, threads)
|
||||
}
|
||||
|
||||
/// Measure the whole photo's noise once, so every tile is cleaned by the photo's noise instead of its own. A photo
|
||||
/// that cannot be measured is told nothing: each tile then measures its own.
|
||||
fn prepare(&self, mosaic: &[f32], width: usize, height: usize) {
|
||||
if let Some(noise) = lightcraft_denoise::builtin::measure_noise(mosaic, width, height) {
|
||||
let _ = self.runner.set(lightcraft_denoise::builtin::Builtin::with_noise(noise));
|
||||
}
|
||||
}
|
||||
|
||||
fn self_test(&self, _run_on: RunOn) -> Result<Value, String> {
|
||||
let side = 16;
|
||||
let out = lightcraft_denoise::builtin::Builtin::with_noise((0.01, 0.001)).run(&vec![0.25; 4 * side * side]).map_err(|e| e.to_string())?;
|
||||
if out.len() != 12 * side * side || out.iter().any(|v| !v.is_finite()) {
|
||||
return Err("the built-in denoiser gave an unexpected result".into());
|
||||
}
|
||||
Ok(json!({"ok": true, "builtin": true}))
|
||||
}
|
||||
|
||||
/// Planes, the two mosaics and the working copies of a 256-cell tile.
|
||||
fn bytes_per_tile(&self) -> usize {
|
||||
64 * 1024 * 1024
|
||||
}
|
||||
|
||||
fn device(&self, run_on: RunOn) -> Value {
|
||||
#[cfg(feature = "denoise")]
|
||||
{
|
||||
self.card.device(run_on)
|
||||
}
|
||||
#[cfg(not(feature = "denoise"))]
|
||||
{
|
||||
let _ = run_on;
|
||||
json!({"kind": "cpu", "reason": "built-in"})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// the built-in denoiser on the graphics card
|
||||
|
||||
/// The noise the check tile is made with and the built-in denoiser is told for it (variance = a · signal + b).
|
||||
#[cfg(feature = "denoise")]
|
||||
const CHECK_NOISE: (f32, f32) = (0.01, 0.001);
|
||||
/// How far the card's filter may be from the CPU's on the check tile, in the noise's deviations: at most this at one place
|
||||
/// (a few blocks whose match or threshold falls either side of a tie in the two devices' roundings change by up to about a
|
||||
/// tenth; a broken kernel by far more), and this on average.
|
||||
#[cfg(feature = "denoise")]
|
||||
const BUILTIN_AGREE_WORST: f32 = 0.3;
|
||||
#[cfg(feature = "denoise")]
|
||||
const BUILTIN_AGREE_MEAN: f32 = 1e-3;
|
||||
|
||||
/// A mosaic tile (four planes of `side` cells): a ramp, edges and some texture with noise of [`CHECK_NOISE`], the same
|
||||
/// every time.
|
||||
#[cfg(feature = "denoise")]
|
||||
fn builtin_check_tile(side: usize) -> Vec<f32> {
|
||||
let mut state = 0x2545_f491_4f6c_dd1du64;
|
||||
let mut uniform = move || {
|
||||
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((state >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
};
|
||||
let mut out = Vec::with_capacity(4 * side * side);
|
||||
for plane in 0..4 {
|
||||
for i in 0..side * side {
|
||||
let (x, y) = (i % side, i / side);
|
||||
let step = if (x / 37 + y / 29) % 2 == 0 { 0.25 } else { 0.0 };
|
||||
let signal =
|
||||
(0.1 + 0.4 * x as f32 / side as f32 + 0.1 * y as f32 / side as f32 + step + 0.05 * ((x as f32 + 4.0 * plane as f32) * 0.7).sin())
|
||||
.clamp(0.02, 0.95);
|
||||
let (u, v) = (uniform(), uniform());
|
||||
let noise = (-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos();
|
||||
out.push((signal + noise * (CHECK_NOISE.0 * signal + CHECK_NOISE.1).sqrt()).max(0.0));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The card set up for the built-in denoiser: its kernels, and the check tile's time on it and on the CPU.
|
||||
#[cfg(feature = "denoise")]
|
||||
struct BuiltinGpu {
|
||||
gpu: Arc<lightcraft_gpu::bm3d::Bm3dGpu>,
|
||||
adapter: String,
|
||||
/// The check tile on the card, the fastest of a few runs (ms).
|
||||
card_ms: f64,
|
||||
/// The check tile on the CPU, on one thread (ms).
|
||||
cpu_ms: f64,
|
||||
}
|
||||
|
||||
/// Set the card up for the built-in denoiser: kernels built, the check tile run on both and compared, both timed.
|
||||
#[cfg(feature = "denoise")]
|
||||
fn make_builtin_gpu(marker: &Path) -> Result<BuiltinGpu, String> {
|
||||
use lightcraft_denoise::builtin::{Builtin, TILE};
|
||||
let tile = TILE as usize;
|
||||
let builtin = Builtin::with_noise(CHECK_NOISE);
|
||||
let params = builtin.bm3d_params().ok_or("the built-in denoiser does not use the block-matching filter")?;
|
||||
let input = Arc::new(builtin_check_tile(tile));
|
||||
let on_card = input.clone();
|
||||
let card = move || -> Result<_, String> {
|
||||
let gpu = Arc::new(lightcraft_gpu::bm3d::Bm3dGpu::new(¶ms, tile)?);
|
||||
let runner = lightcraft_gpu::bm3d::BuiltinRunner::new(gpu.clone(), builtin)?;
|
||||
let agreement = runner.agreement(&on_card).map_err(|e| format!("the GPU could not run the check tile: {e}"))?;
|
||||
let whole = runner.run(&on_card).map_err(|e| format!("the GPU could not run the check tile: {e}"))?;
|
||||
let card_ms = card_tile_ms(&runner, &on_card);
|
||||
Ok((gpu, agreement, whole, card_ms))
|
||||
};
|
||||
let on_cpu = || {
|
||||
let started = web_time::Instant::now();
|
||||
(builtin.run(&input), started.elapsed().as_secs_f64() * 1000.0)
|
||||
};
|
||||
let ((gpu, agreement, whole, card_ms), (want, cpu_ms)) = set_up_card(marker, GPU_SETUP_LIMIT, card, on_cpu)?;
|
||||
let want = want.map_err(|e| format!("the CPU could not check the GPU: {e}"))?;
|
||||
if whole.len() != want.len() || !whole.iter().all(|v| v.is_finite()) {
|
||||
return Err("its picture of the check tile is not the CPU's size or has numbers that are not finite: not used".into());
|
||||
}
|
||||
if !(agreement.worst <= BUILTIN_AGREE_WORST && agreement.mean <= BUILTIN_AGREE_MEAN) {
|
||||
return Err(format!(
|
||||
"its filter's answer on the check tile is not the CPU's (off by {:.2} at most and {:.1e} on average, in noise deviations): not used",
|
||||
agreement.worst, agreement.mean
|
||||
));
|
||||
}
|
||||
let adapter = gpu.adapter();
|
||||
Ok(BuiltinGpu { gpu, adapter, card_ms, cpu_ms })
|
||||
}
|
||||
|
||||
/// What the built-in denoiser knows about the graphics card in this process: set up for the first photo that may use it,
|
||||
/// and used while it keeps working. Kept by the marker of its set-up (see [`builtin_card`]) so that every photo shares it.
|
||||
#[cfg(feature = "denoise")]
|
||||
pub(super) struct BuiltinCard {
|
||||
marker: PathBuf,
|
||||
gpu: OnceLock<Result<BuiltinGpu, String>>,
|
||||
/// Tiles the card got wrong (an error, numbers that are not finite) and the CPU ran.
|
||||
fallbacks: AtomicUsize,
|
||||
/// Tiles at once of the photo started last (0: none yet), to say where the work runs.
|
||||
last_threads: AtomicUsize,
|
||||
}
|
||||
|
||||
#[cfg(feature = "denoise")]
|
||||
static BUILTIN_CARDS: Mutex<Vec<(PathBuf, Arc<BuiltinCard>)>> = Mutex::new(Vec::new());
|
||||
|
||||
/// The card's state for the set-up marker `marker`, made the first time it is asked for.
|
||||
#[cfg(feature = "denoise")]
|
||||
pub(super) fn builtin_card(marker: &Path) -> Arc<BuiltinCard> {
|
||||
let mut all = BUILTIN_CARDS.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
if let Some((_, c)) = all.iter().find(|(m, _)| m == marker) {
|
||||
return c.clone();
|
||||
}
|
||||
let c = Arc::new(BuiltinCard {
|
||||
marker: marker.to_path_buf(),
|
||||
gpu: OnceLock::new(),
|
||||
fallbacks: AtomicUsize::new(0),
|
||||
last_threads: AtomicUsize::new(0),
|
||||
});
|
||||
all.push((marker.to_path_buf(), c.clone()));
|
||||
c
|
||||
}
|
||||
|
||||
/// Forget the card's state for the marker (and the marker): the card is tried afresh for the next photo.
|
||||
#[cfg(feature = "denoise")]
|
||||
pub(super) fn forget_builtin_card(marker: &Path) {
|
||||
BUILTIN_CARDS.lock().unwrap_or_else(PoisonError::into_inner).retain(|(m, _)| m != marker);
|
||||
let _ = std::fs::remove_file(marker);
|
||||
}
|
||||
|
||||
/// Where the card's set-up is recorded for the built-in denoiser whose `onnx` is its model's (made-up) path in the models
|
||||
/// folder: beside it, and in the temporary folder when there is no models folder.
|
||||
pub(super) fn builtin_marker(onnx: &Path) -> PathBuf {
|
||||
match onnx.parent() {
|
||||
Some(p) if !p.as_os_str().is_empty() => onnx.with_file_name(GPU_SETUP_MARKER),
|
||||
_ => std::env::temp_dir().join(format!("lightcraft-builtin-{GPU_SETUP_MARKER}")),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "denoise")]
|
||||
impl BuiltinCard {
|
||||
/// The card when it can be used now, else why not. `start` sets it up when that has not been tried yet; without it
|
||||
/// nothing is started.
|
||||
fn card(&self, start: bool) -> Result<&BuiltinGpu, String> {
|
||||
let side = if start {
|
||||
Some(self.gpu.get_or_init(|| {
|
||||
let made = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| make_builtin_gpu(&self.marker)))
|
||||
.unwrap_or_else(|_| Err("the GPU runner gave up".into()));
|
||||
if let Err(why) = &made {
|
||||
log::info!("denoise: the built-in denoiser runs on the CPU ({why})");
|
||||
}
|
||||
made
|
||||
}))
|
||||
} else {
|
||||
self.gpu.get()
|
||||
};
|
||||
let g = match side {
|
||||
None => return Err("the graphics card is not set up yet".into()),
|
||||
Some(Err(why)) => return Err(why.clone()),
|
||||
Some(Ok(g)) => g,
|
||||
};
|
||||
if let Some(why) = lightcraft_gpu::nn::broken_reason() {
|
||||
return Err(format!("the graphics card stopped working ({why})"));
|
||||
}
|
||||
if self.fallbacks.load(Ordering::Relaxed) >= GPU_MAX_FALLBACKS {
|
||||
return Err(format!("{} got {GPU_MAX_FALLBACKS} tiles wrong", g.adapter));
|
||||
}
|
||||
Ok(g)
|
||||
}
|
||||
|
||||
/// The card, when a photo made `threads` tiles at a time under `run_on` runs on it; else why the CPU does.
|
||||
fn choose(&self, run_on: RunOn, threads: usize, start: bool) -> Result<&BuiltinGpu, String> {
|
||||
if run_on == RunOn::Cpu {
|
||||
return Err("the processor is chosen in Settings".into());
|
||||
}
|
||||
let g = self.card(start)?;
|
||||
if run_on == RunOn::Auto && !card_is_faster(g.card_ms, g.cpu_ms, threads) {
|
||||
return Err(format!("it is faster than {} on this computer", g.adapter));
|
||||
}
|
||||
Ok(g)
|
||||
}
|
||||
|
||||
fn fell_back(&self, why: &str) {
|
||||
let n = self.fallbacks.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
if n == 1 {
|
||||
log::warn!("denoise: a tile came back wrong from the GPU ({why}); the CPU runs it");
|
||||
} else if n == GPU_MAX_FALLBACKS {
|
||||
log::warn!("denoise: the GPU got {n} tiles wrong; the CPU does the rest");
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the tiles run (see [`Model::device`]).
|
||||
pub(super) fn device(&self, run_on: RunOn) -> Value {
|
||||
if run_on != RunOn::Cpu && self.gpu.get().is_none() {
|
||||
return json!({"kind": "pending"});
|
||||
}
|
||||
let threads = match self.last_threads.load(Ordering::Relaxed) {
|
||||
0 => Pace::Full.parallel(std::thread::available_parallelism().map_or(1, |n| n.get()), None),
|
||||
n => n,
|
||||
};
|
||||
let mut v = match self.choose(run_on, threads, false) {
|
||||
Ok(g) => json!({"kind": "gpu", "adapter": g.adapter}),
|
||||
// a set-up that crashed or ran out of time can be tried again (`denoise.settings {runOn}`)
|
||||
Err(why) => json!({"kind": "cpu", "retry": worth_retrying(&why), "reason": why}),
|
||||
};
|
||||
if let (Some(Ok(g)), Some(o)) = (self.gpu.get(), v.as_object_mut()) {
|
||||
o.insert("cardMs".into(), json!(g.card_ms));
|
||||
o.insert("cpuMs".into(), json!(g.cpu_ms));
|
||||
o.insert("fellBack".into(), json!(self.fallbacks.load(Ordering::Relaxed)));
|
||||
}
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
/// The built-in denoiser for a photo that runs on the card: the filter there, and the CPU running any tile the card gets
|
||||
/// wrong, so a photo is always finished.
|
||||
#[cfg(feature = "denoise")]
|
||||
struct CardRunner {
|
||||
gpu: lightcraft_gpu::bm3d::BuiltinRunner,
|
||||
cpu: lightcraft_denoise::builtin::Builtin,
|
||||
card: Arc<BuiltinCard>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "denoise")]
|
||||
impl TileRunner for CardRunner {
|
||||
fn run(&self, input: &[f32]) -> Result<Vec<f32>, RunError> {
|
||||
if self.card.card(false).is_ok() {
|
||||
match self.gpu.run(input) {
|
||||
Ok(out) if out.iter().all(|v| v.is_finite()) => return Ok(out),
|
||||
Ok(_) => self.card.fell_back("numbers that are not finite"),
|
||||
Err(e) => self.card.fell_back(&e.to_string()),
|
||||
}
|
||||
}
|
||||
self.cpu.run(input)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "denoise"))]
|
||||
mod tests;
|
||||
@@ -0,0 +1,155 @@
|
||||
use super::*;
|
||||
use crate::denoise::forget_gpu_set_ups;
|
||||
|
||||
/// A folder of the test's own: the card's set-up leaves its marker in it.
|
||||
fn folder(name: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("lc-engine-builtin-{}-{name}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
/// The built-in denoiser for one photo of `noise` `(a, b)`, its card state kept by a marker in a folder of its own.
|
||||
fn builtin(name: &str) -> (BuiltinModel, PathBuf) {
|
||||
let dir = folder(name);
|
||||
let m = BuiltinModel::new(&dir.join(GPU_SETUP_MARKER));
|
||||
let _ = m.runner.set(lightcraft_denoise::builtin::Builtin::with_noise(CHECK_NOISE));
|
||||
(m, dir)
|
||||
}
|
||||
|
||||
/// Compare a tile from the card with the CPU's picture: equal on average, and with few values far off. (The demosaic
|
||||
/// chooses a direction at each pixel, so a tiny difference of the filter can change a pixel by a good deal.)
|
||||
fn agree(want: &[f32], got: &[f32]) {
|
||||
assert_eq!(want.len(), got.len());
|
||||
let scale = want.iter().fold(1e-9f32, |m, v| m.max(v.abs()));
|
||||
let mean = want.iter().zip(got).map(|(a, b)| (a - b).abs()).sum::<f32>() / want.len() as f32 / scale;
|
||||
let far = want.iter().zip(got).filter(|(a, b)| (*a - *b).abs() > 0.05 * scale).count() as f32 / want.len() as f32;
|
||||
assert!(mean < 1e-3 && far < 5e-3, "off by {mean:e} on average of the largest value, {far:e} of the values far off");
|
||||
}
|
||||
|
||||
/// With the card chosen, the built-in denoiser's tile agrees with the processor's, a few tiles feed the card at once,
|
||||
/// and a set-up that ended leaves no marker; where there is no card it stays on the processor.
|
||||
#[test]
|
||||
fn the_built_in_denoiser_on_the_card_gives_the_cpus_tile() {
|
||||
use lightcraft_denoise::builtin::{Builtin, TILE};
|
||||
let (m, dir) = builtin("builtin-card");
|
||||
let tile = builtin_check_tile(TILE as usize);
|
||||
let want = Builtin::with_noise(CHECK_NOISE).run(&tile).unwrap();
|
||||
let (runner, at_once) = m.runner(RunOn::Gpu, 16);
|
||||
let device = m.device(RunOn::Gpu);
|
||||
eprintln!("device: {device}");
|
||||
match device["kind"].as_str() {
|
||||
Some("gpu") => {
|
||||
assert!(at_once <= GPU_PARALLEL, "a card is fed by a few tiles at once");
|
||||
agree(&want, &runner.run(&tile).unwrap());
|
||||
assert!(device["cardMs"].as_f64().is_some_and(|ms| ms > 0.0) && device["cpuMs"].as_f64().is_some_and(|ms| ms > 0.0), "{device}");
|
||||
}
|
||||
Some("cpu") => {
|
||||
lightcraft_testkit::skip!(Gpu, "the built-in denoiser stays on the CPU here: {}", device["reason"]);
|
||||
assert_eq!(at_once, 16);
|
||||
}
|
||||
other => panic!("the first photo decides where the work runs, not {other:?}"),
|
||||
}
|
||||
assert!(!dir.join(GPU_SETUP_MARKER).exists(), "a set-up that ended leaves no marker");
|
||||
forget_builtin_card(&dir.join(GPU_SETUP_MARKER));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// With the processor chosen, the built-in denoiser gives the processor's tile bit for bit, uses all the threads
|
||||
/// asked for and never sets the card up.
|
||||
#[test]
|
||||
fn with_the_processor_chosen_the_built_in_denoiser_runs_on_the_cpu_and_never_starts_the_card() {
|
||||
use lightcraft_denoise::builtin::{Builtin, TILE};
|
||||
let (m, dir) = builtin("builtin-cpu");
|
||||
let tile = builtin_check_tile(TILE as usize);
|
||||
let (runner, at_once) = m.runner(RunOn::Cpu, 16);
|
||||
assert_eq!(runner.run(&tile).unwrap(), Builtin::with_noise(CHECK_NOISE).run(&tile).unwrap(), "the CPU path is the CPU runner, bit for bit");
|
||||
assert_eq!(at_once, 16, "the threads asked for are the threads used");
|
||||
assert_eq!(m.device(RunOn::Cpu)["kind"], "cpu");
|
||||
assert_eq!(m.device(RunOn::Auto)["kind"], "pending", "the card was not even set up");
|
||||
forget_builtin_card(&dir.join(GPU_SETUP_MARKER));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A set-up marker left behind (the app closed while it ran) keeps the card off the built-in denoiser, with a reason
|
||||
/// and a retry, until choosing where denoise runs forgets it.
|
||||
#[test]
|
||||
fn a_set_up_marker_left_behind_keeps_the_card_off_the_built_in_denoiser_until_a_choice_is_made() {
|
||||
let (m, dir) = builtin("builtin-marker");
|
||||
let marker = dir.join(GPU_SETUP_MARKER);
|
||||
std::fs::write(&marker, "setting up the graphics card for AI Denoise (unix time 1)\n").unwrap();
|
||||
let (_, at_once) = m.runner(RunOn::Gpu, 6);
|
||||
assert_eq!(at_once, 6, "no card: the threads asked for");
|
||||
let device = m.device(RunOn::Gpu);
|
||||
assert_eq!(device["kind"], "cpu", "{device}");
|
||||
assert_eq!(device["retry"], true, "{device}");
|
||||
assert!(device["reason"].as_str().unwrap().contains("closed"), "{device}");
|
||||
// choosing where denoise runs forgets it (and the marker): the card is set up afresh for the next photo
|
||||
forget_gpu_set_ups(&dir);
|
||||
assert!(!marker.exists());
|
||||
let (again, _) = builtin("builtin-marker-again");
|
||||
assert_eq!(again.device(RunOn::Auto)["kind"], "pending");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// The card's filter stays within the agreement limits of the processor's on the check tile, well inside them, and
|
||||
/// gives the same answer every time.
|
||||
#[test]
|
||||
fn the_cards_filter_agrees_with_the_cpus_on_the_check_tile_and_gives_the_same_answer_every_time() {
|
||||
use lightcraft_denoise::builtin::{Builtin, TILE};
|
||||
let tile = builtin_check_tile(TILE as usize);
|
||||
let b = Builtin::with_noise(CHECK_NOISE);
|
||||
let params = b.bm3d_params().unwrap();
|
||||
let gpu = match lightcraft_gpu::bm3d::Bm3dGpu::new(¶ms, TILE as usize) {
|
||||
Ok(g) => Arc::new(g),
|
||||
Err(why) => return lightcraft_testkit::skip!(Gpu, "no card for the built-in denoiser here: {why}"),
|
||||
};
|
||||
let runner = lightcraft_gpu::bm3d::BuiltinRunner::new(gpu, b).unwrap();
|
||||
let a = runner.agreement(&tile).unwrap();
|
||||
eprintln!("the card's filter is off by {:.3} at most and {:.1e} on average (noise deviations)", a.worst, a.mean);
|
||||
assert!(a.worst <= BUILTIN_AGREE_WORST && a.mean <= BUILTIN_AGREE_MEAN, "{a:?}");
|
||||
assert!(a.worst < 0.15 && a.mean < 1e-4, "a card within the limits but far from what it manages: {a:?}");
|
||||
let (first, again) = (runner.run(&tile).unwrap(), runner.run(&tile).unwrap());
|
||||
assert_eq!(first, again, "the card gives the same answer every time");
|
||||
agree(&Builtin::with_noise(CHECK_NOISE).run(&tile).unwrap(), &first);
|
||||
}
|
||||
|
||||
/// A tile the card cannot do (another size than it was made for) is run on the processor, and after three of them
|
||||
/// the card is stopped for the built-in denoiser.
|
||||
#[test]
|
||||
fn a_tile_the_card_gets_wrong_is_run_on_the_processor_and_three_stop_the_card_for_the_built_in_denoiser() {
|
||||
use lightcraft_denoise::builtin::Builtin;
|
||||
let (m, dir) = builtin("builtin-wrong");
|
||||
let (_, _) = m.runner(RunOn::Gpu, 8);
|
||||
if m.device(RunOn::Gpu)["kind"] != "gpu" {
|
||||
lightcraft_testkit::skip!(Gpu, "no card for the built-in denoiser here: {}", m.device(RunOn::Gpu)["reason"]);
|
||||
forget_builtin_card(&dir.join(GPU_SETUP_MARKER));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
return;
|
||||
}
|
||||
// a tile of another size than the card was made for is one it cannot do: the CPU runs it, and three stop the card
|
||||
let small = 64;
|
||||
let input = builtin_check_tile(small);
|
||||
let want = Builtin::with_noise(CHECK_NOISE).run(&input).unwrap();
|
||||
let (runner, _) = m.runner(RunOn::Gpu, 8);
|
||||
for _ in 0..GPU_MAX_FALLBACKS {
|
||||
assert_eq!(runner.run(&input).unwrap(), want, "a tile the card cannot do is the CPU's tile");
|
||||
}
|
||||
let device = m.device(RunOn::Gpu);
|
||||
assert_eq!(device["kind"], "cpu", "{device}");
|
||||
assert!(device["reason"].as_str().unwrap().contains("tiles wrong"), "{device}");
|
||||
assert_eq!(device["fellBack"], GPU_MAX_FALLBACKS);
|
||||
let (_, at_once) = m.runner(RunOn::Gpu, 8);
|
||||
assert_eq!(at_once, 8, "the next photo runs on the CPU, even with the card chosen");
|
||||
forget_builtin_card(&dir.join(GPU_SETUP_MARKER));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A photo whose noise cannot be measured is not told a made-up noise (which would leave it undenoised): the runner
|
||||
/// keeps measuring each tile's own.
|
||||
#[test]
|
||||
fn a_photo_whose_noise_cannot_be_measured_leaves_the_runner_to_measure_each_tile() {
|
||||
let m = BuiltinModel::new(&std::env::temp_dir().join("lc-engine-builtin-unmeasured"));
|
||||
m.prepare(&[0.5; 100], 10, 10);
|
||||
assert!(m.runner.get().is_none(), "nothing was measured, so nothing is set");
|
||||
}
|
||||
@@ -14,7 +14,7 @@ const GPU_AGREE: f32 = 1e-3;
|
||||
/// Longest the card may take to set up (build its kernels, run the check tile, time it) before the processor does the
|
||||
/// work instead.
|
||||
#[cfg(feature = "denoise")]
|
||||
const GPU_SETUP_LIMIT: Duration = Duration::from_secs(30);
|
||||
pub(super) const GPU_SETUP_LIMIT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// Tiles the card may get wrong (an error, numbers that are not finite) before it stops being used for the model.
|
||||
#[cfg(feature = "denoise")]
|
||||
@@ -80,7 +80,10 @@ pub(super) fn set_up_card<T: Send + 'static, R>(
|
||||
return Err(GPU_CRASHED.into());
|
||||
}
|
||||
let secs = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map_or(0, |d| d.as_secs());
|
||||
// a marker that cannot be written only loses the crash guard
|
||||
// the models folder may not exist yet; a marker that cannot be written only loses the crash guard
|
||||
if let Some(parent) = marker.parent() {
|
||||
let _ = std::fs::create_dir_all(parent);
|
||||
}
|
||||
let _ = std::fs::write(marker, format!("setting up the graphics card for AI Denoise (unix time {secs})\n"));
|
||||
running.push(marker.to_path_buf());
|
||||
SetUpEnded(marker.to_path_buf())
|
||||
@@ -107,7 +110,7 @@ pub(super) fn set_up_card<T: Send + 'static, R>(
|
||||
/// The card's time for one tile once it is warm: the fastest of up to three runs, stopping after about two seconds (a
|
||||
/// slow card is slow enough to tell at once).
|
||||
#[cfg(feature = "denoise")]
|
||||
fn card_tile_ms(runner: &dyn TileRunner, input: &[f32]) -> f64 {
|
||||
pub(super) fn card_tile_ms(runner: &dyn TileRunner, input: &[f32]) -> f64 {
|
||||
if runner.run(input).is_err() {
|
||||
return f64::INFINITY;
|
||||
}
|
||||
|
||||
@@ -279,6 +279,26 @@ fn a_set_up_runs_beside_the_cpu_and_removes_its_marker() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_set_up_makes_the_folder_of_its_marker() {
|
||||
let dir = folder("setup-folder").join("not").join("yet");
|
||||
let marker = dir.join(GPU_SETUP_MARKER);
|
||||
let (m, seen) = (marker.clone(), Arc::new(AtomicBool::new(false)));
|
||||
let s = seen.clone();
|
||||
let r = set_up_card(
|
||||
&marker,
|
||||
Duration::from_secs(10),
|
||||
move || {
|
||||
s.store(m.exists(), Ordering::Relaxed);
|
||||
Ok(())
|
||||
},
|
||||
|| (),
|
||||
);
|
||||
assert_eq!(r, Ok(((), ())));
|
||||
assert!(seen.load(Ordering::Relaxed), "the crash guard is written even when the models folder was missing");
|
||||
let _ = std::fs::remove_dir_all(dir.ancestors().nth(2).unwrap_or(&dir));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_set_up_that_takes_too_long_is_given_up_on() {
|
||||
let dir = folder("slowsetup");
|
||||
|
||||
@@ -51,6 +51,8 @@ pub(crate) trait Model: Send + Sync {
|
||||
/// What runs a photo's tiles, and how many to run at once, when `threads` may be used and the setting is `run_on`
|
||||
/// (a graphics card is kept busy by a few). The first time the card may be used it is set up and checked here.
|
||||
fn runner(&self, run_on: RunOn, threads: usize) -> (&dyn TileRunner, usize);
|
||||
/// Called once per photo with its whole mosaic before the tiles run, for a model that adapts to the photo.
|
||||
fn prepare(&self, _mosaic: &[f32], _width: usize, _height: usize) {}
|
||||
/// Check it does something sensible: the test's result, or why not. Unless `run_on` is the processor the graphics
|
||||
/// card is set up and checked too, and the result says where the work will run.
|
||||
fn self_test(&self, run_on: RunOn) -> Result<Value, String>;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::builtin::{BuiltinModel, builtin_marker};
|
||||
use super::model::{Loader, Model, ModelSlot, RunOn, STACK};
|
||||
use super::settings::EXT;
|
||||
use super::{
|
||||
@@ -133,6 +134,9 @@ impl Progress {
|
||||
|
||||
/// The loaded model, loading it first when it is not (kept for the next photo).
|
||||
pub(super) fn loaded(spec: &JobSpec) -> Result<Arc<dyn Model>, MakeError> {
|
||||
if spec.manifest.id == lightcraft_denoise::builtin::ID {
|
||||
return Ok(Arc::new(BuiltinModel::new(&builtin_marker(&spec.onnx))));
|
||||
}
|
||||
if let Some(m) = spec.model.lock().unwrap_or_else(PoisonError::into_inner).clone() {
|
||||
return Ok(m);
|
||||
}
|
||||
@@ -196,6 +200,10 @@ pub(crate) fn make_product(spec: &JobSpec, progress: Option<&Progress>) -> Resul
|
||||
let (_, budget) = crate::memory::work_gate().usage();
|
||||
let parallel = spec.parallel.clamp(1, 4).min((budget / scratch.max(1)).max(1));
|
||||
let _held = crate::memory::work_gate().acquire(mosaic.data.len().saturating_mul(20).saturating_add(scratch.saturating_mul(parallel)));
|
||||
model.prepare(&mosaic.data, mosaic.width, mosaic.height);
|
||||
if cancelled() {
|
||||
return Err(MakeError::Cancelled);
|
||||
}
|
||||
let (runner, parallel) = model.runner(spec.run_on, parallel);
|
||||
let params = Params {
|
||||
tile: spec.manifest.tile as usize,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "denoise")]
|
||||
use super::builtin::{builtin_card, builtin_marker};
|
||||
#[cfg(doc)]
|
||||
use super::model::Model;
|
||||
use super::model::STACK;
|
||||
@@ -15,6 +17,11 @@ impl Session {
|
||||
let loaded = self.denoise.active.as_ref().and_then(|a| a.model.lock().unwrap_or_else(PoisonError::into_inner).clone());
|
||||
match loaded {
|
||||
Some(m) => m.device(self.denoise.settings.run_on()),
|
||||
#[cfg(feature = "denoise")]
|
||||
None if self.denoise.active.as_ref().is_some_and(|a| a.id == lightcraft_denoise::builtin::ID) => {
|
||||
let onnx = self.denoise.active.as_ref().map(|a| a.onnx.clone()).unwrap_or_default();
|
||||
builtin_card(&builtin_marker(&onnx)).device(self.denoise.settings.run_on())
|
||||
}
|
||||
None => json!({"kind": "none"}),
|
||||
}
|
||||
}
|
||||
@@ -37,23 +44,20 @@ impl Session {
|
||||
let id = self.denoise.settings.model.clone()?;
|
||||
installed_models(dir).into_iter().find(|i| i.manifest.id == id)
|
||||
});
|
||||
let found = chosen.map(|i| (i.fingerprint(), i));
|
||||
let same = match (&self.denoise.active, &found) {
|
||||
(None, None) => true,
|
||||
(Some(a), Some((fp, _))) => a.fingerprint == *fp,
|
||||
_ => false,
|
||||
// no model chosen (or the one chosen is gone): the built-in denoiser
|
||||
let (fingerprint, manifest, onnx) = match chosen {
|
||||
Some(i) => (i.fingerprint(), i.manifest, i.onnx),
|
||||
None => {
|
||||
let manifest = lightcraft_denoise::builtin::manifest();
|
||||
let onnx = self.denoise.models_dir.as_deref().map(|d| d.join(lightcraft_denoise::builtin::ID)).unwrap_or_default();
|
||||
(format!("{}@{}", manifest.id, manifest.version), manifest, onnx)
|
||||
}
|
||||
};
|
||||
if same {
|
||||
if self.denoise.active.as_ref().is_some_and(|a| a.fingerprint == fingerprint) {
|
||||
return;
|
||||
}
|
||||
// another model: what was made with the old one is not this one's, and what failed may work now
|
||||
self.denoise.active = found.map(|(fingerprint, i)| Active {
|
||||
id: i.manifest.id.clone(),
|
||||
manifest: i.manifest,
|
||||
onnx: i.onnx,
|
||||
fingerprint,
|
||||
model: Arc::new(Mutex::new(None)),
|
||||
});
|
||||
self.denoise.active = Some(Active { id: manifest.id.clone(), manifest, onnx, fingerprint, model: Arc::new(Mutex::new(None)) });
|
||||
if let Some(r) = self.denoise.running.take() {
|
||||
r.progress.cancel_now();
|
||||
}
|
||||
@@ -142,8 +146,8 @@ impl Session {
|
||||
return PhotoState::NotApplicable;
|
||||
}
|
||||
if self.denoise.active.is_none() {
|
||||
// the model folder has not been looked at yet (just started): not "no model" until it has been
|
||||
return if self.denoise.active_seen.is_none() { PhotoState::Idle } else { PhotoState::NoModel };
|
||||
// the model in use has not been looked at yet (just started)
|
||||
return PhotoState::Idle;
|
||||
}
|
||||
if self.denoise_products_dir().is_none() {
|
||||
return PhotoState::Failed {
|
||||
@@ -310,8 +314,12 @@ impl Session {
|
||||
/// Keep the cache within its limit: the pictures nobody asks for go first, the oldest first; `keep` (the one just
|
||||
/// made) never goes. The index forgets what was deleted.
|
||||
pub(crate) fn denoise_evict(&mut self, keep: Option<&Path>) {
|
||||
let Some(models) = self.denoise.models_dir.clone() else { return };
|
||||
self.denoise_evict_to(read_settings(&models).cache_bytes(), keep);
|
||||
self.denoise_evict_to(self.denoise_cache_limit(), keep);
|
||||
}
|
||||
|
||||
/// The cache's size limit in bytes (the default without a models folder).
|
||||
pub(crate) fn denoise_cache_limit(&self) -> u64 {
|
||||
self.denoise.models_dir.as_deref().map(read_settings).unwrap_or_default().cache_bytes()
|
||||
}
|
||||
|
||||
/// [`Self::denoise_evict`] for a limit of `limit` bytes.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "denoise")]
|
||||
use super::builtin::{builtin_marker, forget_builtin_card};
|
||||
use super::gpu::GPU_SETUP_MARKER;
|
||||
use super::model::RunOn;
|
||||
use super::{DenoiserManifest, Deserialize, Duration, Path, PathBuf, Serialize, Value};
|
||||
@@ -108,7 +110,7 @@ pub(crate) fn installed_models(dir: &Path) -> Vec<Installed> {
|
||||
let p = e.path();
|
||||
let Some(name) = p.file_name().and_then(|n| n.to_str()).map(str::to_string) else { continue };
|
||||
let onnx = p.join("model.onnx");
|
||||
if !lightcraft_denoise::licence::valid_id(&name) || !p.is_dir() || !onnx.is_file() {
|
||||
if name == lightcraft_denoise::builtin::ID || !lightcraft_denoise::licence::valid_id(&name) || !p.is_dir() || !onnx.is_file() {
|
||||
continue;
|
||||
}
|
||||
let Some(m) = read_capped(&p.join("denoise-model.json"), lightcraft_denoise::manifest::MAX_MANIFEST_BYTES)
|
||||
@@ -132,4 +134,6 @@ pub(crate) fn forget_gpu_set_ups(dir: &Path) {
|
||||
for i in installed_models(dir) {
|
||||
let _ = std::fs::remove_file(i.onnx.with_file_name(GPU_SETUP_MARKER));
|
||||
}
|
||||
#[cfg(feature = "denoise")]
|
||||
forget_builtin_card(&builtin_marker(&dir.join(lightcraft_denoise::builtin::ID)));
|
||||
}
|
||||
@@ -54,8 +54,6 @@ impl Pace {
|
||||
pub enum PhotoState {
|
||||
/// Not a photo denoise applies to (not a raw, offline, a demo).
|
||||
NotApplicable,
|
||||
/// No model is chosen: nothing can be made.
|
||||
NoModel,
|
||||
/// Its picture is made: the Amount slider works.
|
||||
Ready,
|
||||
Queued {
|
||||
|
||||
@@ -108,7 +108,8 @@ fn model_installation_keeps_the_frame_pump_responsive_and_reuses_the_loaded_mode
|
||||
// The loader is blocked: the frame pump must still return, reporting installation in progress.
|
||||
let state = x.s.execute("denoise.models.downloads", &json!({})).unwrap();
|
||||
assert_eq!(state["downloads"][0]["state"], "installing");
|
||||
assert_eq!(x.s.execute("denoise.pump", &json!({"pace": "pause"})).unwrap()["active"], false);
|
||||
// the built-in denoiser is in use meanwhile
|
||||
assert_eq!(x.s.execute("denoise.status", &json!({})).unwrap()["model"]["id"], "builtin");
|
||||
assert!(x.s.execute("denoise.models.install", &json!({"path": path, "acknowledged": true, "background": true})).is_err());
|
||||
release_tx.send(()).unwrap();
|
||||
for _ in 0..600 {
|
||||
@@ -226,13 +227,13 @@ fn a_model_is_installed_chosen_and_removed_with_the_terms_accepted() {
|
||||
// it can be checked again, switched off and on, and removed
|
||||
assert_eq!(x.s.execute("denoise.models.test", &json!({"id": "stand-in"})).unwrap()["ok"], true);
|
||||
assert_eq!(x.s.execute("denoise.models.select", &json!({"id": null})).unwrap()["model"], Value::Null);
|
||||
assert!(x.s.denoise.active.is_none());
|
||||
assert_eq!(x.s.denoise.active.as_ref().map(|a| a.id.as_str()), Some("builtin"), "without a model the built-in denoiser runs");
|
||||
assert!(x.s.execute("denoise.models.select", &json!({"id": "nothing"})).is_err());
|
||||
x.s.execute("denoise.models.select", &json!({"id": "stand-in"})).unwrap();
|
||||
assert!(x.s.denoise.active.is_some());
|
||||
let r = x.s.execute("denoise.models.remove", &json!({"id": "stand-in"})).unwrap();
|
||||
assert_eq!(r["model"], Value::Null);
|
||||
assert!(x.s.denoise.active.is_none());
|
||||
assert_eq!(x.s.denoise.active.as_ref().map(|a| a.id.as_str()), Some("builtin"));
|
||||
assert!(!x.dir.join("denoise-models").join("stand-in").exists());
|
||||
// ids that are not folder names, and folders that are not models, are never touched
|
||||
for bad in ["../library", "", "a/b", "settings.json"] {
|
||||
@@ -407,10 +408,13 @@ fn an_export_makes_its_picture_when_the_queue_has_not_and_never_comes_out_withou
|
||||
x.s.denoise_pump(crate::denoise::Pace::Pause);
|
||||
assert_eq!(x.s.denoise_photo_state(id), PhotoState::Ready);
|
||||
|
||||
// no model: the export says so instead of leaving the denoise out
|
||||
// no model: the built-in denoiser makes the picture instead (the stand-in is not asked)
|
||||
x.s.execute("denoise.models.select", &json!({"id": null})).unwrap();
|
||||
let e = export_photo(&mut x.s, id, &o, 1).err().unwrap();
|
||||
assert!(e.contains("no denoise model is chosen") && e.contains("ramp.dng"), "{e}");
|
||||
let runs = x.runs.load(Ordering::Relaxed);
|
||||
let builtin = decode(&export_photo(&mut x.s, id, &o, 1).unwrap().bytes);
|
||||
assert_eq!(x.runs.load(Ordering::Relaxed), runs);
|
||||
assert!(builtin.is_finite());
|
||||
assert_eq!(std::fs::read_dir(x.dir.join("library").join("denoise")).unwrap().flatten().count(), 2, "its picture is its own");
|
||||
set_amount(&mut x.s, 0.0);
|
||||
assert!(export_photo(&mut x.s, id, &o, 1).is_ok(), "without an amount nothing is asked of the model");
|
||||
let _ = std::fs::remove_dir_all(&x.dir);
|
||||
@@ -478,14 +482,13 @@ fn only_raw_photos_on_disk_are_denoised_and_nothing_is_queued_without_a_model()
|
||||
let id = demo.active().unwrap();
|
||||
assert_eq!(demo.denoise_photo_state(id), PhotoState::NotApplicable, "a generated photo has no sensor data");
|
||||
let e = demo.execute("denoise.queue", &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("no denoise model is chosen"), "{e}");
|
||||
assert!(e.contains("open a library on disk first"), "no model is needed, a place for the pictures is: {e}");
|
||||
// no models folder at all (the web build): the commands say so, nothing panics
|
||||
let mut web = Session::with_demo();
|
||||
for cmd in ["denoise.models.install", "denoise.models.select", "denoise.models.remove", "denoise.settings"] {
|
||||
assert!(web.execute(cmd, &json!({"path": "x", "acknowledged": true, "id": "x"})).is_err(), "{cmd}");
|
||||
}
|
||||
assert_eq!(web.execute("denoise.pump", &json!({})).unwrap()["active"], false);
|
||||
assert_eq!(web.execute("denoise.status", &json!({})).unwrap()["enabled"], false);
|
||||
assert_eq!(web.execute("denoise.status", &json!({})).unwrap()["model"]["id"], "builtin");
|
||||
// no library open: nowhere to keep pictures, and the queue says so
|
||||
let x = setup("eligible2", true);
|
||||
let mut bare = Session::new().with_fs();
|
||||
@@ -797,8 +800,6 @@ fn the_denoise_switch_validates_arguments_and_accepts_explicit_targets_without_s
|
||||
for params in [json!({"id": "bad"}), json!({"id": u64::MAX}), json!({"id": id.0, "enabled": "yes"})] {
|
||||
assert!(x.s.execute("denoise.toggle", ¶ms).is_err());
|
||||
}
|
||||
assert!(x.s.execute("denoise.toggle", &json!({"id": id.0, "enabled": true})).is_err());
|
||||
assert_eq!(x.s.develop_of(id).unwrap().enhance.denoise, 0.0);
|
||||
let model = model_files(&x.dir, "toggle-model");
|
||||
x.s.execute("denoise.models.install", &json!({"path": model.to_string_lossy(), "acknowledged": true})).unwrap();
|
||||
x.s.selection = Default::default();
|
||||
@@ -859,3 +860,50 @@ fn denoise_row_while_queue_is_busy() {
|
||||
assert!(rows(&x.s).is_empty(), "the row goes once the photo is made");
|
||||
let _ = std::fs::remove_dir_all(&x.dir);
|
||||
}
|
||||
|
||||
/// With no model installed, turning denoise on makes the picture with the built-in denoiser alone; it is not an
|
||||
/// installed model, and no model can take its id.
|
||||
#[test]
|
||||
fn without_a_model_the_built_in_denoiser_makes_the_picture_by_itself() {
|
||||
let mut x = setup("builtin", false);
|
||||
let id = photo(&x.s);
|
||||
assert!(x.s.denoise.active.is_none(), "nothing is looked at before it is needed");
|
||||
let r = x.s.execute("denoise.toggle", &json!({"id": id.0, "enabled": true})).unwrap();
|
||||
assert_eq!(r["amount"], 50.0);
|
||||
assert_eq!(x.s.denoise.active.as_ref().map(|a| a.id.as_str()), Some("builtin"));
|
||||
let r = pump_until_ready(&mut x.s, 1);
|
||||
assert_eq!(r["queued"], 0, "{r}");
|
||||
assert_eq!(x.s.denoise_photo_state(id), PhotoState::Ready);
|
||||
assert_eq!(x.runs.load(Ordering::Relaxed), 0, "no model was involved");
|
||||
assert_eq!(x.s.execute("denoise.status", &json!({})).unwrap()["model"]["name"], "Built-in");
|
||||
assert!(x.s.execute("denoise.models.test", &json!({"id": "builtin"})).is_err(), "it is not an installed model");
|
||||
// a model cannot take its id
|
||||
let onnx = model_files(&x.dir, "builtin");
|
||||
let e = x.s.execute("denoise.models.install", &json!({"path": onnx.to_string_lossy(), "acknowledged": true})).unwrap_err().to_string();
|
||||
assert!(e.contains("builtin"), "{e}");
|
||||
let _ = std::fs::remove_dir_all(&x.dir);
|
||||
}
|
||||
|
||||
/// A build with no models folder still makes products with the built-in denoiser, so its cache obeys the default limit.
|
||||
#[test]
|
||||
fn without_a_models_folder_the_cache_still_obeys_the_default_limit() {
|
||||
let mut x = setup("builtin-evict", false);
|
||||
x.s.execute("denoise.toggle", &json!({"id": photo(&x.s).0, "enabled": true})).unwrap();
|
||||
pump_until_ready(&mut x.s, 1);
|
||||
x.s.set_denoise_models_dir(None);
|
||||
let limit = u64::from(crate::denoise::DEFAULT_CACHE_GB) << 30;
|
||||
assert_eq!(x.s.denoise_cache_limit(), limit);
|
||||
// sparse files are cheap on Unix only: elsewhere a file that size may reserve its space
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let stray = x.dir.join("library").join("denoise").join("aaaa.lcdn");
|
||||
let f = std::fs::File::create(&stray).unwrap();
|
||||
f.set_len(limit + 1).unwrap();
|
||||
f.set_modified(std::time::SystemTime::now() - std::time::Duration::from_secs(1000)).unwrap();
|
||||
drop(f);
|
||||
x.s.denoise_evict(None);
|
||||
assert!(!stray.exists(), "the stray picture goes");
|
||||
assert_eq!(x.s.denoise_photo_state(photo(&x.s)), PhotoState::Ready, "the photo's own picture stays");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&x.dir);
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
//! Opt-in quality check of the built-in denoiser on one public Bayer raw (CC0, from `cargo xtask corpus --download`).
|
||||
//!
|
||||
//! Noise of a known level is added to the raw's own mosaic, the built-in denoiser runs over it, and the result is
|
||||
//! scored against the untouched mosaic demosaiced the same way. PSNR is measured on gamma-encoded camera RGB; the
|
||||
//! detail figure is the gradient energy of the result over that of the truth (1 = as sharp, below 1 = smoother).
|
||||
//!
|
||||
//! LC_DENOISE_RAW=../../corpus/raw/arw-sony-a7m3-compressed.arw LC_DENOISE_OUT=/tmp/dn \
|
||||
//! cargo test --release -p lightcraft-engine --test denoise_builtin_quality -- --ignored --nocapture
|
||||
//! LC_DENOISE_OUT, when set, receives side-by-side PNGs (truth | noisy | denoised) of a 100 % crop per level.
|
||||
|
||||
use lightcraft_codecs::encode::{EncodeImage, EncodeMeta, Samples, encode_png};
|
||||
use lightcraft_denoise_core::bayer::Layout;
|
||||
use lightcraft_denoise_core::builtin::{Builtin, OVERLAP, TILE, demosaic, estimate_noise};
|
||||
use lightcraft_denoise_core::manifest::Gain;
|
||||
use lightcraft_denoise_core::nlm::Tuning;
|
||||
use lightcraft_denoise_core::run::{Control, Params, denoise_bayer};
|
||||
use std::time::Instant;
|
||||
|
||||
struct Rng(u64);
|
||||
|
||||
impl Rng {
|
||||
/// The next uniform number, strictly between 0 and 1.
|
||||
fn uniform(&mut self) -> f32 {
|
||||
self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((self.0 >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
}
|
||||
|
||||
/// The next standard normal number (Box-Muller).
|
||||
fn normal(&mut self) -> f32 {
|
||||
let (u, v) = (self.uniform(), self.uniform());
|
||||
(-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos()
|
||||
}
|
||||
}
|
||||
|
||||
/// The plain demosaic of a mosaic (RGGB, even size) as camera RGB planes, through the tile packer the runner uses.
|
||||
fn plain(mosaic: &[f32], w: usize, h: usize) -> Vec<[f32; 3]> {
|
||||
let (cw, ch) = (w / 2, h / 2);
|
||||
let mut planes = vec![vec![0f32; cw * ch]; 4];
|
||||
for cy in 0..ch {
|
||||
for cx in 0..cw {
|
||||
for (p, (dx, dy)) in [(0, 0), (1, 0), (0, 1), (1, 1)].into_iter().enumerate() {
|
||||
planes[p][cy * cw + cx] = mosaic[(2 * cy + dy) * w + 2 * cx + dx];
|
||||
}
|
||||
}
|
||||
}
|
||||
// `demosaic` takes square planes: run it on square blocks and stitch
|
||||
let side = cw.min(ch);
|
||||
let mut out = vec![[0f32; 3]; w * h];
|
||||
for by in (0..ch).step_by(side) {
|
||||
for bx in (0..cw).step_by(side) {
|
||||
let (x0, y0) = (bx.min(cw - side), by.min(ch - side));
|
||||
let block: Vec<Vec<f32>> = planes.iter().map(|pl| (0..side * side).map(|i| pl[(y0 + i / side) * cw + x0 + i % side]).collect()).collect();
|
||||
let rgb = demosaic(&block, side);
|
||||
let s2 = 2 * side;
|
||||
for y in 0..s2 {
|
||||
for x in 0..s2 {
|
||||
let o = (2 * y0 + y) * w + 2 * x0 + x;
|
||||
out[o] = [rgb[y * s2 + x], rgb[s2 * s2 + y * s2 + x], rgb[2 * s2 * s2 + y * s2 + x]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// A linear value encoded for viewing: clamped to 0..1, then gamma 2.2.
|
||||
fn gamma(v: f32) -> f32 {
|
||||
v.clamp(0.0, 1.0).powf(1.0 / 2.2)
|
||||
}
|
||||
|
||||
/// PSNR in dB between two camera-RGB pictures after exposure `scale` and gamma, leaving out a 16-pixel border.
|
||||
fn psnr(a: &[[f32; 3]], b: &[[f32; 3]], w: usize, h: usize, scale: f32) -> f64 {
|
||||
let (mut sum, mut n) = (0f64, 0f64);
|
||||
for y in 16..h - 16 {
|
||||
for x in 16..w - 16 {
|
||||
for c in 0..3 {
|
||||
let d = f64::from(gamma(a[y * w + x][c] * scale) - gamma(b[y * w + x][c] * scale));
|
||||
sum += d * d;
|
||||
n += 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
-10.0 * (sum / n).log10()
|
||||
}
|
||||
|
||||
/// The summed gradient of the picture's green channel after exposure `scale` and gamma, leaving out a 16-pixel border.
|
||||
fn gradient(a: &[[f32; 3]], w: usize, h: usize, scale: f32) -> f64 {
|
||||
let mut sum = 0f64;
|
||||
for y in 16..h - 16 {
|
||||
for x in 16..w - 16 {
|
||||
let g = |x: usize, y: usize| f64::from(gamma(a[y * w + x][1] * scale));
|
||||
sum += (g(x + 1, y) - g(x, y)).abs() + (g(x, y + 1) - g(x, y)).abs();
|
||||
}
|
||||
}
|
||||
sum
|
||||
}
|
||||
|
||||
/// How much of the true picture's fine structure the result keeps: the slope of the result's high-pass (green minus
|
||||
/// its 5 x 5 mean) against the truth's. Noise is independent of the truth, so unlike gradient energy it can't inflate it.
|
||||
fn texture(a: &[[f32; 3]], truth: &[[f32; 3]], w: usize, h: usize, scale: f32) -> f64 {
|
||||
let hp = |p: &[[f32; 3]], x: usize, y: usize| {
|
||||
let mut m = 0f64;
|
||||
for j in 0..5 {
|
||||
for i in 0..5 {
|
||||
m += f64::from(gamma(p[(y + j - 2) * w + x + i - 2][1] * scale));
|
||||
}
|
||||
}
|
||||
f64::from(gamma(p[y * w + x][1] * scale)) - m / 25.0
|
||||
};
|
||||
let (mut xy, mut xx) = (0f64, 0f64);
|
||||
for y in 16..h - 16 {
|
||||
for x in 16..w - 16 {
|
||||
let t = hp(truth, x, y);
|
||||
xy += t * hp(a, x, y);
|
||||
xx += t * t;
|
||||
}
|
||||
}
|
||||
xy / xx
|
||||
}
|
||||
|
||||
/// A `side × side` crop of the picture from `(x0, y0)` as 8-bit RGB with a daylight white balance, for the PNGs.
|
||||
fn crop_rgb8(a: &[[f32; 3]], w: usize, (x0, y0): (usize, usize), side: usize, scale: f32) -> Vec<u8> {
|
||||
let wb = [2.0f32, 1.0, 1.6];
|
||||
let mut out = Vec::with_capacity(side * side * 3);
|
||||
for y in 0..side {
|
||||
for x in 0..side {
|
||||
for c in 0..3 {
|
||||
out.push((gamma(a[(y0 + y) * w + x0 + x][c] * wb[c] * scale) * 255.0 + 0.5) as u8);
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Adds noise of known levels to a public raw's mosaic, denoises it with the built-in denoiser and prints how close the
|
||||
/// result is to the untouched mosaic. Opt-in: it needs the raw named by `LC_DENOISE_RAW`.
|
||||
#[test]
|
||||
#[ignore = "needs a public raw: LC_DENOISE_RAW=<file>"]
|
||||
fn the_built_in_denoiser_scored_on_a_real_raw_with_added_noise() {
|
||||
let path = std::env::var("LC_DENOISE_RAW").unwrap_or_else(|_| "../../corpus/raw/arw-sony-a7m3-compressed.arw".into());
|
||||
let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{path}: {e}"));
|
||||
let n = lightcraft_raw::decode(&bytes).unwrap().normalized().unwrap();
|
||||
let cfa = n.cfa.as_ref().unwrap();
|
||||
let layout = Layout::from_cell([cfa.color_at(0, 0), cfa.color_at(1, 0), cfa.color_at(0, 1), cfa.color_at(1, 1)]).unwrap();
|
||||
assert_eq!(layout, Layout { dx: 0, dy: 0 }, "the benchmark assumes RGGB");
|
||||
// an even-aligned window from the middle of the frame keeps the colour pattern
|
||||
let (w, h) = (1536usize, 1024usize);
|
||||
let (ox, oy) = (((n.width - w) / 2) & !1, ((n.height - h) / 2) & !1);
|
||||
let truth: Vec<f32> = (0..w * h).map(|i| n.data[(oy + i / w) * n.width + ox + i % w]).collect();
|
||||
// LC_BIN=1: average each cell with the three nearest of its own colour (a 2 x 2 binning of the colour pattern's
|
||||
// cells), which halves the reference's own noise so that noise added at a camera's low levels dominates it
|
||||
let (w, h, truth) = if std::env::var("LC_BIN").is_ok_and(|v| v != "0") {
|
||||
let (bw, bh) = (w / 2, h / 2);
|
||||
let binned: Vec<f32> = (0..bw * bh)
|
||||
.map(|i| {
|
||||
let (x, y) = (i % bw, i / bw);
|
||||
let (sx, sy, cx, cy) = (x / 2, y / 2, x % 2, y % 2);
|
||||
let at = |di: usize, dj: usize| truth[(2 * (2 * sy + dj) + cy) * w + 2 * (2 * sx + di) + cx];
|
||||
(at(0, 0) + at(1, 0) + at(0, 1) + at(1, 1)) / 4.0
|
||||
})
|
||||
.collect();
|
||||
(bw, bh, binned)
|
||||
} else {
|
||||
(w, h, truth)
|
||||
};
|
||||
let mean = truth.iter().map(|v| f64::from(*v)).sum::<f64>() / truth.len() as f64;
|
||||
let scale = (0.18 / mean) as f32;
|
||||
let truth_rgb = plain(&truth, w, h);
|
||||
let own = estimate_noise(&truth, w, h);
|
||||
println!(
|
||||
"the reference's own noise by the estimator: a {:.5} b {:.6} (sd at 0.18 {:.4}); a clean reference would read about 0",
|
||||
own.0,
|
||||
own.1,
|
||||
(own.0 * 0.18 + own.1).sqrt()
|
||||
);
|
||||
println!("{path}: {}x{}, window {w}x{h}, mean {mean:.4}", n.width, n.height);
|
||||
println!("{:<14}{:>10}{:>10}{:>9}{:>9}{:>9}{:>9}", "noise (a, b)", "noisy dB", "denoised", "gain", "detail", "texture", "seconds");
|
||||
let out_dir = std::env::var("LC_DENOISE_OUT").ok();
|
||||
#[cfg(feature = "denoise")]
|
||||
let gpu = std::env::var("LC_GPU").is_ok_and(|v| v != "0").then(|| {
|
||||
let p = Tuning::default().bm3d.unwrap();
|
||||
let g = lightcraft_gpu::bm3d::Bm3dGpu::new(&p, TILE as usize).unwrap();
|
||||
println!("on the graphics card: {} ({})", g.adapter(), g.build_report());
|
||||
std::sync::Arc::new(g)
|
||||
});
|
||||
// LC_REAL=1 runs the noise levels measured on real Canon EOS R / R6 Mark III raws instead (their standard deviation at
|
||||
// mid-grey is 0.003, 0.006, 0.0095, 0.015 and 0.038: ISO <= 400, 1600, 6400, 25600 and above)
|
||||
let levels: &[(&str, f32, f32)] = if std::env::var("LC_REAL").is_ok_and(|v| v != "0") {
|
||||
&[("iso400", 4e-5, 1e-7), ("iso1600", 2.1e-4, 3e-7), ("iso6400", 4.9e-4, 1e-6), ("iso25600", 1.19e-3, 1.7e-5), ("iso51200", 6.9e-3, 2.08e-4)]
|
||||
} else {
|
||||
&[("light", 0.002, 0.0002), ("medium", 0.008, 0.001), ("heavy", 0.025, 0.004), ("extreme", 0.06, 0.012)]
|
||||
};
|
||||
for &(name, a, b) in levels {
|
||||
let mut rng = Rng(11);
|
||||
let noisy: Vec<f32> = truth.iter().map(|&v| v + rng.normal() * (a * v.max(0.0) + b).sqrt()).collect();
|
||||
let started = Instant::now();
|
||||
let params = Params { tile: TILE as usize, overlap: OVERLAP as usize, gain: Gain::None, clip: Some(0.99), parallel: 4 };
|
||||
// LC_EST=v1 (the first estimator) | true (the noise that was added) | anything else: the current estimator
|
||||
// LC_FULL=1: measure the noise on the whole frame with the same noise added, as the app does (it measures the whole
|
||||
// photo), instead of on the crop
|
||||
let measure = |mosaic: &[f32], mw: usize, mh: usize| match std::env::var("LC_EST").as_deref() {
|
||||
Ok("v1") => lightcraft_denoise_core::builtin::estimate_noise_v1(mosaic, mw, mh),
|
||||
_ => estimate_noise(mosaic, mw, mh),
|
||||
};
|
||||
let est = match std::env::var("LC_EST").as_deref() {
|
||||
Ok("true") => (a, b),
|
||||
_ if std::env::var("LC_TRUE").is_ok_and(|v| v != "0") => (a, b),
|
||||
_ if std::env::var("LC_FULL").is_ok_and(|v| v != "0") => {
|
||||
let mut rng = Rng(23);
|
||||
let frame: Vec<f32> = n.data.iter().map(|&v| v + rng.normal() * (a * v.max(0.0) + b).sqrt()).collect();
|
||||
measure(&frame, n.width, n.height)
|
||||
}
|
||||
_ => measure(&noisy, w, h),
|
||||
};
|
||||
let mut tuning = Tuning::default();
|
||||
let env = |k: &str| std::env::var(k).ok().and_then(|v| v.parse::<f32>().ok());
|
||||
(tuning.search, tuning.search2) = (env("LC_S1").map_or(tuning.search, |v| v as usize), env("LC_S2").map_or(tuning.search2, |v| v as usize));
|
||||
(tuning.h_light, tuning.h_heavy, tuning.h2) =
|
||||
(env("LC_HL").unwrap_or(tuning.h_light), env("LC_HH").unwrap_or(tuning.h_heavy), env("LC_H2").unwrap_or(tuning.h2));
|
||||
(tuning.light, tuning.heavy) = (env("LC_LIGHT").unwrap_or(tuning.light), env("LC_HEAVY").unwrap_or(tuning.heavy));
|
||||
(tuning.half, tuning.half2) = (env("LC_P1").map_or(tuning.half, |v| v as usize), env("LC_P2").map_or(tuning.half2, |v| v as usize));
|
||||
(tuning.loose, tuning.few) = (env("LC_LOOSE").unwrap_or(tuning.loose), env("LC_FEW").unwrap_or(tuning.few));
|
||||
(tuning.search_c, tuning.h_c) = (env("LC_SC").map_or(tuning.search_c, |v| v as usize), env("LC_HC").unwrap_or(tuning.h_c));
|
||||
// LC_NLM=1 runs the old non-local-means filter instead; LC_B_* override the block-matching filter's parameters
|
||||
if env("LC_NLM").is_some_and(|v| v > 0.0) {
|
||||
tuning.bm3d = None;
|
||||
}
|
||||
if let Some(b) = tuning.bm3d.as_mut() {
|
||||
(b.block, b.step, b.search, b.group) = (
|
||||
env("LC_B_N").map_or(b.block, |v| v as usize),
|
||||
env("LC_B_STEP").map_or(b.step, |v| v as usize),
|
||||
env("LC_B_S").map_or(b.search, |v| v as usize),
|
||||
env("LC_B_K").map_or(b.group, |v| v as usize),
|
||||
);
|
||||
(b.tau1, b.tau2) = (env("LC_B_T1").unwrap_or(b.tau1), env("LC_B_T2").unwrap_or(b.tau2));
|
||||
// LC_B_LOFF adds to every point of the threshold curve (a sweep of how hard it cleans)
|
||||
let off = env("LC_B_LOFF").unwrap_or(0.0);
|
||||
for point in &mut b.lambda {
|
||||
point.1 += off;
|
||||
}
|
||||
b.sigma = env("LC_B_SIG").unwrap_or(b.sigma);
|
||||
b.wiener = env("LC_B_WIENER").is_none_or(|v| v > 0.0);
|
||||
}
|
||||
let runner = Builtin { noise: Some(est), tuning };
|
||||
// LC_GPU=1 (with `--features denoise`) runs the block-matching filter on the graphics card
|
||||
#[cfg(feature = "denoise")]
|
||||
let out = match &gpu {
|
||||
Some(g) => {
|
||||
let on_card = lightcraft_gpu::bm3d::BuiltinRunner::new(g.clone(), runner).unwrap();
|
||||
denoise_bayer(&noisy, w, h, layout, &on_card, ¶ms, &Control::default()).unwrap()
|
||||
}
|
||||
None => denoise_bayer(&noisy, w, h, layout, &runner, ¶ms, &Control::default()).unwrap(),
|
||||
};
|
||||
#[cfg(not(feature = "denoise"))]
|
||||
let out = denoise_bayer(&noisy, w, h, layout, &runner, ¶ms, &Control::default()).unwrap();
|
||||
let secs = started.elapsed().as_secs_f64();
|
||||
let noisy_rgb = plain(&noisy, w, h);
|
||||
let (p_noisy, p_out) = (psnr(&noisy_rgb, &truth_rgb, w, h, scale), psnr(&out.data, &truth_rgb, w, h, scale));
|
||||
let detail = gradient(&out.data, w, h, scale) / gradient(&truth_rgb, w, h, scale);
|
||||
let tex = texture(&out.data, &truth_rgb, w, h, scale);
|
||||
println!(
|
||||
"{:<14}{:>10.2}{:>10.2}{:>+9.2}{:>9.3}{:>9.3}{:>9.2} noise a {:.4} (true {a}), b {:.5} (true {b})",
|
||||
name,
|
||||
p_noisy,
|
||||
p_out,
|
||||
p_out - p_noisy,
|
||||
detail,
|
||||
tex,
|
||||
secs,
|
||||
est.0,
|
||||
est.1
|
||||
);
|
||||
if let Some(dir) = &out_dir {
|
||||
let side = 400;
|
||||
let at = (w / 2 - side / 2, h / 2 - side / 2);
|
||||
let tiles =
|
||||
[crop_rgb8(&truth_rgb, w, at, side, scale), crop_rgb8(&noisy_rgb, w, at, side, scale), crop_rgb8(&out.data, w, at, side, scale)];
|
||||
let mut sheet = Vec::with_capacity(side * side * 9);
|
||||
for y in 0..side {
|
||||
for t in &tiles {
|
||||
sheet.extend_from_slice(&t[y * side * 3..(y + 1) * side * 3]);
|
||||
}
|
||||
}
|
||||
let img = EncodeImage::new((3 * side) as u32, side as u32, 3, Samples::U8(&sheet));
|
||||
std::fs::create_dir_all(dir).unwrap();
|
||||
std::fs::write(format!("{dir}/{name}.png"), encode_png(&img, &EncodeMeta::default()).unwrap()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
//! Opt-in accuracy check of the built-in denoiser's noise estimator (public CC0 raws from `cargo xtask corpus --download`).
|
||||
//!
|
||||
//! 1. `a_quantile_of_pure_noise_blocks_...`: white noise of a known level: what fraction of the true variance a quantile of
|
||||
//! the blocks' variances is (the correction `NoiseProbe::correction` divides by).
|
||||
//! 2. `the_noise_estimate_...`: noise of known levels added to 2 x 2-binned crops of many raws (which halves the pictures'
|
||||
//! own noise), then the estimates against the truth, for the first version and the current one, at 0.03 (the dark
|
||||
//! cells of a typical photo) and 0.18 (mid-grey).
|
||||
//!
|
||||
//! LC_CORPUS=C:/.../corpus/raw LC_STRIDE=6 cargo test --release -p lightcraft-engine --test denoise_noise_estimate -- --ignored --nocapture
|
||||
use lightcraft_denoise_core::builtin::{NoiseProbe, estimate_noise_v1, estimate_noise_with};
|
||||
|
||||
struct Rng(u64);
|
||||
|
||||
impl Rng {
|
||||
/// The next uniform number, strictly between 0 and 1.
|
||||
fn uniform(&mut self) -> f32 {
|
||||
self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((self.0 >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
}
|
||||
|
||||
/// The next standard normal number (Box-Muller).
|
||||
fn normal(&mut self) -> f32 {
|
||||
let (u, v) = (self.uniform(), self.uniform());
|
||||
(-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos()
|
||||
}
|
||||
}
|
||||
|
||||
/// The environment variable `k` as a number, if it is set and parses.
|
||||
fn env(k: &str) -> Option<f32> {
|
||||
std::env::var(k).ok().and_then(|v| v.parse().ok())
|
||||
}
|
||||
|
||||
/// Prints what fraction of the true variance a quantile of pure-noise blocks' variances is, for each block size and
|
||||
/// quantile: the calibration behind `NoiseProbe::correction`.
|
||||
#[test]
|
||||
#[ignore = "calibration printout"]
|
||||
fn a_quantile_of_pure_noise_blocks_is_a_known_fraction_of_the_true_variance() {
|
||||
let (w, h) = (2048usize, 2048usize);
|
||||
let sigma = 0.01f32;
|
||||
let mut rng = Rng(3);
|
||||
let mosaic: Vec<f32> = (0..w * h).map(|i| 0.1 + 0.7 * (i % w) as f32 / w as f32 + rng.normal() * sigma).collect();
|
||||
println!("{:>6}{:>9}{:>14} (estimated variance / true variance, correction 1; a brightness ramp, pure noise)", "block", "quantile", "fraction");
|
||||
for block in [8usize, 12, 16, 24, 32] {
|
||||
for quantile in [0.02f32, 0.05, 0.1, 0.2, 0.5] {
|
||||
let (_, b) = estimate_noise_with(&mosaic, w, h, &NoiseProbe { block, quantile, correction: 1.0 });
|
||||
println!("{block:>6}{quantile:>9}{:>14.3}", b / (sigma * sigma));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The 2 x 2 colour-cell binning of a window of a normalised mosaic (halves its own noise), as the quality benchmark does.
|
||||
fn binned_crop(n: &lightcraft_raw::Normalized, side: usize) -> Option<(Vec<f32>, usize)> {
|
||||
let side = side.min(n.width).min(n.height) & !3;
|
||||
if side < 512 {
|
||||
return None;
|
||||
}
|
||||
let (ox, oy) = (((n.width - side) / 2) & !1, ((n.height - side) / 2) & !1);
|
||||
let half = side / 2;
|
||||
let out = (0..half * half)
|
||||
.map(|i| {
|
||||
let (x, y) = (i % half, i / half);
|
||||
let (sx, sy, cx, cy) = (x / 2, y / 2, x % 2, y % 2);
|
||||
let at = |di: usize, dj: usize| n.data[(oy + 2 * (2 * sy + dj) + cy) * n.width + ox + 2 * (2 * sx + di) + cx];
|
||||
(at(0, 0) + at(1, 0) + at(0, 1) + at(1, 1)) / 4.0
|
||||
})
|
||||
.collect();
|
||||
Some((out, half))
|
||||
}
|
||||
|
||||
/// Prints how the estimated noise compares with the noise added to crops of many raws, for the first version and for
|
||||
/// several settings of the current one. Opt-in: it needs the raw corpus folder named by `LC_CORPUS`.
|
||||
#[test]
|
||||
#[ignore = "needs the public raw corpus: LC_CORPUS=<folder>"]
|
||||
fn the_noise_estimate_follows_the_noise_added_to_many_different_pictures() {
|
||||
let dir = std::env::var("LC_CORPUS").unwrap_or_else(|_| "../../corpus/raw".into());
|
||||
let stride = env("LC_STRIDE").map_or(6, |v| v as usize).max(1);
|
||||
let mut files: Vec<_> = std::fs::read_dir(&dir).unwrap_or_else(|e| panic!("{dir}: {e}")).flatten().map(|e| e.path()).collect();
|
||||
files.sort();
|
||||
let probes = [
|
||||
("v1 (old)", None),
|
||||
("block 16, q 0.10", Some(NoiseProbe { block: 16, quantile: 0.10, correction: env("LC_C").unwrap_or(0.8) })),
|
||||
("block 12, q 0.05", Some(NoiseProbe { block: 12, quantile: 0.05, correction: env("LC_C2").unwrap_or(0.65) })),
|
||||
("block 24, q 0.10", Some(NoiseProbe { block: 24, quantile: 0.10, correction: env("LC_C3").unwrap_or(0.85) })),
|
||||
];
|
||||
// sd at mid-grey 0.0062, 0.0094, 0.015, 0.038 (Canon EOS R / R6 Mark III at ISO 1600, 6400, 25600 and above)
|
||||
let levels = [("sd .0062", 2.1e-4f32, 3e-7f32), ("sd .0094", 4.9e-4, 1e-6), ("sd .0152", 1.19e-3, 1.7e-5), ("sd .0381", 6.9e-3, 2.08e-4)];
|
||||
// ratios[level][probe][where] -> estimated sd / true sd
|
||||
let mut ratios: Vec<Vec<[Vec<f32>; 2]>> = levels.iter().map(|_| probes.iter().map(|_| [Vec::new(), Vec::new()]).collect()).collect();
|
||||
let mut used = 0;
|
||||
for path in files.iter().step_by(stride) {
|
||||
let Ok(bytes) = std::fs::read(path) else { continue };
|
||||
let Ok(raw) = lightcraft_raw::decode(&bytes) else { continue };
|
||||
if raw.cpp != 1 || !raw.cfa.as_ref().is_some_and(lightcraft_raw::Cfa::is_bayer) {
|
||||
continue;
|
||||
}
|
||||
let Ok(n) = raw.normalized() else { continue };
|
||||
let Some((mosaic, side)) = binned_crop(&n, 2048) else { continue };
|
||||
used += 1;
|
||||
for (li, &(_, a, b)) in levels.iter().enumerate() {
|
||||
let mut rng = Rng(11 + li as u64);
|
||||
let noisy: Vec<f32> = mosaic.iter().map(|&v| v + rng.normal() * (a * v.max(0.0) + b).sqrt()).collect();
|
||||
for (pi, (_, probe)) in probes.iter().enumerate() {
|
||||
let (ea, eb) = match probe {
|
||||
None => estimate_noise_v1(&noisy, side, side),
|
||||
Some(p) => estimate_noise_with(&noisy, side, side, p),
|
||||
};
|
||||
for (wi, at) in [0.03f32, 0.18].into_iter().enumerate() {
|
||||
ratios[li][pi][wi].push(((ea * at + eb) / (a * at + b)).sqrt());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("{used} pictures (every {stride}th raw of {dir}), each binned to {} cells, noise added at 4 levels", 1024);
|
||||
println!("estimated sd / true sd: median [10th .. 90th percentile], share within -20 % .. +25 %");
|
||||
for (li, (name, _, _)) in levels.iter().enumerate() {
|
||||
for (wi, at) in ["at 0.03", "at 0.18"].into_iter().enumerate() {
|
||||
println!("{name} {at}:");
|
||||
for (pi, (pname, _)) in probes.iter().enumerate() {
|
||||
let mut r = ratios[li][pi][wi].clone();
|
||||
r.sort_by(f32::total_cmp);
|
||||
if r.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let q = |f: f32| r[((r.len() - 1) as f32 * f) as usize];
|
||||
let within = r.iter().filter(|&&v| (0.8..=1.25).contains(&v)).count() as f32 / r.len() as f32;
|
||||
println!(" {pname:<18} {:.2} [{:.2} .. {:.2}] {:>3.0} % within", q(0.5), q(0.1), q(0.9), within * 100.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
//! The built-in denoiser's block-matching filter ([`lightcraft_denoise::bm3d`], which is the reference) on the GPU:
|
||||
//! three WGSL kernels (`wgsl/bm3d_*.wgsl`) that group alike blocks, filter each group's blocks together and put them
|
||||
//! back, run twice (a hard threshold, then a Wiener filter built from its result) in one command buffer per tile.
|
||||
//!
|
||||
//! Only the filter stage runs here. Measuring the noise, the variance-stabilising transform and its inverse and the
|
||||
//! demosaic stay on the processor ([`Builtin::run_with`]), so a tile differs from the processor's only by the rounding
|
||||
//! of the filter itself. Like [`crate::nn`], the runner has a device of its own, respects the same switches and the same
|
||||
//! crash sentinel, never panics, and a failure is an `Err` that makes the caller run that tile on the CPU.
|
||||
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use lightcraft_denoise::bm3d::{self, Params};
|
||||
use lightcraft_denoise::builtin::Builtin;
|
||||
use lightcraft_denoise::nlm::hadamard;
|
||||
use lightcraft_denoise::run::{Error, TileRunner};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::nn::{CLOSING, Dev, TIMEOUT, dev, entry, mark_broken, pipeline, storage};
|
||||
|
||||
/// Tiles that can be on the GPU at once (each has buffers of its own).
|
||||
const WORKSPACES: usize = 2;
|
||||
/// The largest tile side (in cells) the buffers and dispatch sizes are made for.
|
||||
const MAX_TILE: usize = 512;
|
||||
/// The block side and the group size the kernels are written for.
|
||||
const BLOCK: usize = 4;
|
||||
const GROUP: usize = 16;
|
||||
/// Invocations in a workgroup (the kernels' `@workgroup_size`).
|
||||
const WORKGROUP: u32 = 64;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||
struct Uniforms {
|
||||
t: u32,
|
||||
nr: u32,
|
||||
nb: u32,
|
||||
search: u32,
|
||||
cap: u32,
|
||||
wiener: u32,
|
||||
pad0: u32,
|
||||
pad1: u32,
|
||||
tau: f32,
|
||||
lambda: f32,
|
||||
sigma: f32,
|
||||
pad2: f32,
|
||||
}
|
||||
|
||||
struct Pipes {
|
||||
matching: wgpu::ComputePipeline,
|
||||
matching_layout: wgpu::BindGroupLayout,
|
||||
collab: wgpu::ComputePipeline,
|
||||
collab_layout: wgpu::BindGroupLayout,
|
||||
agg: wgpu::ComputePipeline,
|
||||
agg_layout: wgpu::BindGroupLayout,
|
||||
/// How long each kernel took to build (the driver compiles them), for the log and the tests.
|
||||
built: Vec<(String, f64)>,
|
||||
}
|
||||
|
||||
/// Compile the three kernels (match, filter, put back) and make their bind-group layouts, timing each build.
|
||||
fn build_pipes(d: &Dev) -> Pipes {
|
||||
use wgpu::BufferBindingType::{Storage, Uniform};
|
||||
let (ro, rw) = (Storage { read_only: true }, Storage { read_only: false });
|
||||
let layout =
|
||||
|entries: &[wgpu::BindGroupLayoutEntry]| d.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: None, entries });
|
||||
let matching_layout = layout(&[entry(0, Uniform), entry(1, ro), entry(2, ro), entry(3, rw)]);
|
||||
let collab_layout = layout(&[entry(0, Uniform), entry(1, ro), entry(2, ro), entry(3, ro), entry(4, ro), entry(5, rw), entry(6, rw)]);
|
||||
let agg_layout = layout(&[entry(0, Uniform), entry(1, ro), entry(2, ro), entry(3, ro), entry(4, ro), entry(5, ro), entry(6, rw)]);
|
||||
let common = include_str!("wgsl/bm3d_common.wgsl");
|
||||
let transform = include_str!("wgsl/bm3d_transform.wgsl");
|
||||
// the group's transforms, for the noisy blocks (`buf`) and for the pilot's (`pb`)
|
||||
let collab_source = format!(
|
||||
"{}\n{}\n{}",
|
||||
transform.replace("{{A}}", "buf").replace("{{S}}", ""),
|
||||
transform.replace("{{A}}", "pb").replace("{{S}}", "_p"),
|
||||
include_str!("wgsl/bm3d_collab.wgsl")
|
||||
);
|
||||
let mut built = Vec::new();
|
||||
let mut make = |name: &str, kernel: &str, layout: &wgpu::BindGroupLayout| {
|
||||
let started = std::time::Instant::now();
|
||||
let p = pipeline(d, name, &format!("{common}\n{kernel}"), layout);
|
||||
built.push((name.to_string(), started.elapsed().as_secs_f64() * 1000.0));
|
||||
p
|
||||
};
|
||||
let matching = make("bm3d match", include_str!("wgsl/bm3d_match.wgsl"), &matching_layout);
|
||||
let collab = make("bm3d filter", &collab_source, &collab_layout);
|
||||
let agg = make("bm3d put back", include_str!("wgsl/bm3d_agg.wgsl"), &agg_layout);
|
||||
Pipes { matching, matching_layout, collab, collab_layout, agg, agg_layout, built }
|
||||
}
|
||||
|
||||
/// One tile's buffers and bind groups.
|
||||
struct Workspace {
|
||||
y: wgpu::Buffer,
|
||||
basic: wgpu::Buffer,
|
||||
out: wgpu::Buffer,
|
||||
/// The two steps' uniforms (their match tolerance and the filter they use differ).
|
||||
first: wgpu::Buffer,
|
||||
second: wgpu::Buffer,
|
||||
staging: wgpu::Buffer,
|
||||
/// Match, filter and put back, for the first step then the second.
|
||||
bound: [wgpu::BindGroup; 6],
|
||||
_slots: [wgpu::Buffer; 3],
|
||||
}
|
||||
|
||||
/// The filter on the GPU for one tile size and one set of parameters. Cheap to share between threads: each call takes a
|
||||
/// free workspace.
|
||||
pub struct Bm3dGpu {
|
||||
dev: &'static Dev,
|
||||
pipes: Pipes,
|
||||
/// The parameters it was made for, as they were given.
|
||||
requested: Params,
|
||||
t: usize,
|
||||
/// Blocks that start a group, along a side, and how many blocks fit along a side.
|
||||
nr: usize,
|
||||
nb: usize,
|
||||
consts: wgpu::Buffer,
|
||||
free: Mutex<Vec<Workspace>>,
|
||||
/// Workspaces made so far (they are made when a call finds none free, up to [`WORKSPACES`]).
|
||||
made: Mutex<usize>,
|
||||
wake: Condvar,
|
||||
}
|
||||
|
||||
/// An error for something the kernels do not do, with `why` as its text.
|
||||
fn unsupported<T>(why: impl Into<String>) -> Result<T, String> {
|
||||
Err(why.into())
|
||||
}
|
||||
|
||||
impl Bm3dGpu {
|
||||
/// The filter with `params` for tiles of `t × t` cells on the GPU, or why it cannot be (no GPU, parameters or a size
|
||||
/// the kernels do not do, the device refusing the buffers). Creates the device on first use and compiles the kernels.
|
||||
pub fn new(params: &Params, t: usize) -> Result<Bm3dGpu, String> {
|
||||
let _work = crate::exit::enter().ok_or(CLOSING)?;
|
||||
let Some(plan) = bm3d::plan(params, t, 0.0) else { return unsupported("the tile is smaller than a block") };
|
||||
let p = plan.params;
|
||||
if p.block != BLOCK || p.group > GROUP || p.step == 0 {
|
||||
return unsupported(format!("the kernels do {BLOCK} x {BLOCK} blocks in groups of at most {GROUP}"));
|
||||
}
|
||||
if t > MAX_TILE {
|
||||
return unsupported(format!("tiles of more than {MAX_TILE} cells on a side are not done on the GPU"));
|
||||
}
|
||||
let d = dev()?;
|
||||
let nb = t + 1 - BLOCK;
|
||||
let axis = bm3d::starts(nb, p.step);
|
||||
let nr = axis.len();
|
||||
let blocks_bytes = (nr * nr * 4 * GROUP * BLOCK * BLOCK * 4) as u64;
|
||||
if blocks_bytes > d.limits.max_storage_buffer_binding_size.min(d.limits.max_buffer_size) {
|
||||
return unsupported(format!("{} cannot hold a tile's filtered blocks ({} MB)", d.info.name, blocks_bytes >> 20));
|
||||
}
|
||||
let (dct, window) = bm3d::constants(BLOCK);
|
||||
let consts: Vec<u32> = dct.iter().chain(&window).map(|v| v.to_bits()).chain(axis.iter().map(|&a| a as u32)).collect();
|
||||
let scope = [
|
||||
d.device.push_error_scope(wgpu::ErrorFilter::OutOfMemory),
|
||||
d.device.push_error_scope(wgpu::ErrorFilter::Validation),
|
||||
d.device.push_error_scope(wgpu::ErrorFilter::Internal),
|
||||
];
|
||||
// the driver compiles the kernels here: a crash in it is reported at the next launch (issue #250)
|
||||
let pipes = crate::backend::with_marker("denoise kernel compilation", || build_pipes(d));
|
||||
let consts = d.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("bm3d consts"),
|
||||
contents: bytemuck::cast_slice(&consts),
|
||||
usage: wgpu::BufferUsages::STORAGE,
|
||||
});
|
||||
let mut me =
|
||||
Bm3dGpu { dev: d, pipes, requested: *params, t, nr, nb, consts, free: Mutex::new(Vec::new()), made: Mutex::new(1), wake: Condvar::new() };
|
||||
let first = me.workspace();
|
||||
me.free = Mutex::new(vec![first]);
|
||||
let [oom, validation, internal] = scope;
|
||||
let errors = [pollster::block_on(internal.pop()), pollster::block_on(validation.pop()), pollster::block_on(oom.pop())];
|
||||
if let Some(e) = errors.into_iter().flatten().next() {
|
||||
return Err(format!("{}: the denoise kernels could not be set up ({e})", d.info.name));
|
||||
}
|
||||
Ok(me)
|
||||
}
|
||||
|
||||
/// The adapter this runs on.
|
||||
pub fn adapter(&self) -> String {
|
||||
format!("{} ({:?})", self.dev.info.name, self.dev.info.backend)
|
||||
}
|
||||
|
||||
/// The parameters it was made for.
|
||||
pub fn params(&self) -> Params {
|
||||
self.requested
|
||||
}
|
||||
|
||||
/// How long each kernel took to build, e.g. `bm3d match: 812 ms`.
|
||||
pub fn build_report(&self) -> String {
|
||||
self.pipes.built.iter().map(|(k, ms)| format!("{k}: {ms:.0} ms")).collect::<Vec<_>>().join(", ")
|
||||
}
|
||||
|
||||
/// A new workspace for this runner's tile size: the plane, scratch and staging buffers and the six bind groups.
|
||||
fn workspace(&self) -> Workspace {
|
||||
let d = self.dev;
|
||||
let (t, groups) = (self.t, self.nr * self.nr);
|
||||
let planes = (4 * t * t * 4) as u64;
|
||||
let (y, basic, out) = (
|
||||
storage(d, "bm3d y", planes, wgpu::BufferUsages::COPY_DST),
|
||||
storage(d, "bm3d basic", planes, wgpu::BufferUsages::COPY_SRC),
|
||||
storage(d, "bm3d out", planes, wgpu::BufferUsages::COPY_SRC),
|
||||
);
|
||||
let members = storage(d, "bm3d members", (groups * (GROUP + 1) * 4) as u64, wgpu::BufferUsages::empty());
|
||||
let blocks = storage(d, "bm3d blocks", (groups * 4 * GROUP * BLOCK * BLOCK * 4) as u64, wgpu::BufferUsages::empty());
|
||||
let weights = storage(d, "bm3d weights", (groups * 4 * 4) as u64, wgpu::BufferUsages::empty());
|
||||
let uniform = |label| {
|
||||
d.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some(label),
|
||||
size: std::mem::size_of::<Uniforms>() as u64,
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
})
|
||||
};
|
||||
let (first, second) = (uniform("bm3d first step"), uniform("bm3d second step"));
|
||||
let staging = d.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("bm3d readback"),
|
||||
size: planes,
|
||||
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
let bind = |layout: &wgpu::BindGroupLayout, buffers: &[&wgpu::Buffer]| {
|
||||
let entries: Vec<wgpu::BindGroupEntry> =
|
||||
buffers.iter().enumerate().map(|(i, b)| wgpu::BindGroupEntry { binding: i as u32, resource: b.as_entire_binding() }).collect();
|
||||
d.device.create_bind_group(&wgpu::BindGroupDescriptor { label: None, layout, entries: &entries })
|
||||
};
|
||||
let (m, c, a) = (&self.pipes.matching_layout, &self.pipes.collab_layout, &self.pipes.agg_layout);
|
||||
let k = &self.consts;
|
||||
let bound = [
|
||||
bind(m, &[&first, k, &y, &members]),
|
||||
// the first step's filter has no pilot: it is given a buffer it does not read
|
||||
bind(c, &[&first, k, &y, &basic, &members, &blocks, &weights]),
|
||||
bind(a, &[&first, k, &y, &members, &blocks, &weights, &basic]),
|
||||
bind(m, &[&second, k, &basic, &members]),
|
||||
bind(c, &[&second, k, &y, &basic, &members, &blocks, &weights]),
|
||||
bind(a, &[&second, k, &y, &members, &blocks, &weights, &out]),
|
||||
];
|
||||
Workspace { y, basic, out, first, second, staging, bound, _slots: [members, blocks, weights] }
|
||||
}
|
||||
|
||||
/// A free workspace, a new one when fewer than [`WORKSPACES`] exist, else wait for one to come back.
|
||||
fn take(&self) -> Result<Workspace, Error> {
|
||||
let mut free = self.free.lock().unwrap_or_else(|e| e.into_inner());
|
||||
loop {
|
||||
if let Some(w) = free.pop() {
|
||||
return Ok(w);
|
||||
}
|
||||
{
|
||||
let mut made = self.made.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if *made < WORKSPACES {
|
||||
*made += 1;
|
||||
drop(made);
|
||||
drop(free);
|
||||
let d = self.dev;
|
||||
let scopes =
|
||||
[d.device.push_error_scope(wgpu::ErrorFilter::OutOfMemory), d.device.push_error_scope(wgpu::ErrorFilter::Validation)];
|
||||
let w = self.workspace();
|
||||
let [oom, validation] = scopes;
|
||||
let (validation, oom) = (pollster::block_on(validation.pop()), pollster::block_on(oom.pop()));
|
||||
if let Some(e) = oom.or(validation) {
|
||||
self.forget();
|
||||
return Err(Error::Runtime(format!("the GPU could not make room for another tile: {e}")));
|
||||
}
|
||||
return Ok(w);
|
||||
}
|
||||
}
|
||||
free = self.wake.wait(free).unwrap_or_else(|e| e.into_inner());
|
||||
}
|
||||
}
|
||||
|
||||
/// A workspace comes back after a good run: it goes on the free list and one waiting caller is woken.
|
||||
fn give(&self, w: Workspace) {
|
||||
self.free.lock().unwrap_or_else(|e| e.into_inner()).push(w);
|
||||
self.wake.notify_one();
|
||||
}
|
||||
|
||||
/// A workspace is gone (dropped after a failure): room for a new one, and a waiting caller may make it.
|
||||
fn forget(&self) {
|
||||
// under `free`, as `take` is when it reads `made` and goes to wait: a wake-up sent between the two would be lost
|
||||
let free = self.free.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut made = self.made.lock().unwrap_or_else(|e| e.into_inner());
|
||||
*made = made.saturating_sub(1);
|
||||
drop(made);
|
||||
drop(free);
|
||||
self.wake.notify_one();
|
||||
}
|
||||
|
||||
/// Denoise four unit-noise planes of `t × t` cells as [`bm3d::filter`] does; `noise` as there.
|
||||
pub fn filter(&self, planes: &[Vec<f32>], t: usize, noise: f32) -> Result<Vec<Vec<f32>>, Error> {
|
||||
if let Some(why) = crate::nn::broken_reason() {
|
||||
return Err(Error::Runtime(format!("the GPU is not used any more: {why}")));
|
||||
}
|
||||
let Some(plan) = bm3d::plan(&self.requested, t, noise).filter(|_| t == self.t) else {
|
||||
return Err(Error::Input("the tile is not the size the filter was made for".into()));
|
||||
};
|
||||
if planes.len() != 4 || planes.iter().any(|p| p.len() != t * t) {
|
||||
return Err(Error::Input("the tile is not four square planes".into()));
|
||||
}
|
||||
let y = hadamard(planes);
|
||||
// one tile is one piece of GPU work: a photo's worth would outlast any wait at exit
|
||||
let Some(_work) = crate::exit::enter() else { return Err(Error::Runtime(CLOSING.into())) };
|
||||
let w = self.take()?;
|
||||
let flat: Vec<f32> = y.concat();
|
||||
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| self.execute(&w, &flat, &plan))) {
|
||||
Ok(Ok(out)) => {
|
||||
self.give(w);
|
||||
Ok(hadamard(&out.chunks_exact(t * t).map(<[f32]>::to_vec).collect::<Vec<_>>()))
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
// its readback buffer may be left half-mapped: a fresh workspace is made when one is next needed
|
||||
drop(w);
|
||||
self.forget();
|
||||
Err(e)
|
||||
}
|
||||
Err(_) => {
|
||||
// a panic inside wgpu: this workspace is not given back, and the GPU is not used again
|
||||
mark_broken("a denoise tile panicked");
|
||||
drop(w);
|
||||
self.forget();
|
||||
Err(Error::Runtime("the GPU runner gave up".into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the filter's steps in `w` on the rotated planes `y` (one plane after another) and read the result back; a
|
||||
/// device that runs out of memory or fails validation gives an error.
|
||||
fn execute(&self, w: &Workspace, y: &[f32], plan: &bm3d::Plan) -> Result<Vec<f32>, Error> {
|
||||
let d = self.dev;
|
||||
let p = &plan.params;
|
||||
let sigma = p.sigma.max(1e-3);
|
||||
let var = sigma * sigma;
|
||||
let uniforms = |tau: f32, wiener: u32| Uniforms {
|
||||
t: self.t as u32,
|
||||
nr: self.nr as u32,
|
||||
nb: self.nb as u32,
|
||||
search: p.search as u32,
|
||||
cap: p.group as u32,
|
||||
wiener,
|
||||
pad0: 0,
|
||||
pad1: 0,
|
||||
tau,
|
||||
lambda: plan.lambda * sigma,
|
||||
sigma,
|
||||
pad2: 0.0,
|
||||
};
|
||||
let groups = (self.nr * self.nr) as u32;
|
||||
let cells = (self.t * self.t) as u32;
|
||||
let scopes = [
|
||||
d.device.push_error_scope(wgpu::ErrorFilter::OutOfMemory),
|
||||
d.device.push_error_scope(wgpu::ErrorFilter::Validation),
|
||||
d.device.push_error_scope(wgpu::ErrorFilter::Internal),
|
||||
];
|
||||
d.queue.write_buffer(&w.y, 0, bytemuck::cast_slice(y));
|
||||
d.queue.write_buffer(&w.first, 0, bytemuck::bytes_of(&uniforms(p.tau1 * var, 0)));
|
||||
d.queue.write_buffer(&w.second, 0, bytemuck::bytes_of(&uniforms(p.tau2 * var, 1)));
|
||||
let mut enc = d.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
{
|
||||
let mut pass = enc.begin_compute_pass(&wgpu::ComputePassDescriptor { label: Some("bm3d tile"), timestamp_writes: None });
|
||||
let steps = if p.wiener { 2 } else { 1 };
|
||||
for step in 0..steps {
|
||||
for (i, (pipe, count)) in
|
||||
[(&self.pipes.matching, groups), (&self.pipes.collab, groups * 4), (&self.pipes.agg, cells)].into_iter().enumerate()
|
||||
{
|
||||
pass.set_pipeline(pipe);
|
||||
pass.set_bind_group(0, w.bound.get(step * 3 + i), &[]);
|
||||
pass.dispatch_workgroups(count.div_ceil(WORKGROUP), 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = if p.wiener { &w.out } else { &w.basic };
|
||||
let bytes = (y.len() * 4) as u64;
|
||||
enc.copy_buffer_to_buffer(result, 0, &w.staging, 0, bytes);
|
||||
d.queue.submit([enc.finish()]);
|
||||
let slice = w.staging.slice(..bytes);
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
slice.map_async(wgpu::MapMode::Read, move |r| {
|
||||
let _ = tx.send(r);
|
||||
});
|
||||
let waited = d.device.poll(wgpu::PollType::Wait { submission_index: None, timeout: Some(TIMEOUT) });
|
||||
let [oom, validation, internal] = scopes;
|
||||
let errors = [pollster::block_on(internal.pop()), pollster::block_on(validation.pop()), pollster::block_on(oom.pop())];
|
||||
let [internal, validation, oom] = errors;
|
||||
if let Some(e) = oom {
|
||||
// not a broken device: this tile runs on the CPU, and the next may fit
|
||||
return Err(Error::Runtime(format!("the GPU ran out of memory: {e}")));
|
||||
}
|
||||
if let Some(e) = internal.or(validation) {
|
||||
mark_broken(&format!("device error: {e}"));
|
||||
return Err(Error::Runtime(format!("the GPU reported an error: {e}")));
|
||||
}
|
||||
if let Err(e) = waited {
|
||||
mark_broken(&format!("the GPU did not finish a tile: {e}"));
|
||||
return Err(Error::Runtime(format!("the GPU did not finish: {e}")));
|
||||
}
|
||||
match rx.recv_timeout(Duration::from_secs(10)) {
|
||||
Ok(Ok(())) => {}
|
||||
Ok(Err(e)) => return Err(Error::Runtime(format!("reading the result back failed: {e}"))),
|
||||
Err(e) => return Err(Error::Runtime(format!("reading the result back failed: {e}"))),
|
||||
}
|
||||
let out = {
|
||||
let data = slice.get_mapped_range().map_err(|e| Error::Runtime(format!("reading the result back failed: {e:?}")))?;
|
||||
data.as_chunks::<4>().0.iter().map(|b| f32::from_le_bytes(*b)).collect::<Vec<f32>>()
|
||||
};
|
||||
w.staging.unmap();
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
||||
/// The built-in denoiser with its filter on the GPU: a [`TileRunner`] for one photo (its noise level is in `builtin`).
|
||||
pub struct BuiltinRunner {
|
||||
gpu: Arc<Bm3dGpu>,
|
||||
builtin: Builtin,
|
||||
}
|
||||
|
||||
/// How close the card's filter is to the processor's on a tile, in the noise's deviations (the filter's own domain, where
|
||||
/// the noise has deviation 1): the largest difference at one place and the mean one.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Agreement {
|
||||
pub worst: f32,
|
||||
pub mean: f32,
|
||||
}
|
||||
|
||||
impl BuiltinRunner {
|
||||
/// `builtin` must use the block-matching filter with the parameters `gpu` was made for.
|
||||
pub fn new(gpu: Arc<Bm3dGpu>, builtin: Builtin) -> Result<Self, String> {
|
||||
match builtin.bm3d_params() {
|
||||
Some(p) if p == gpu.params() => Ok(BuiltinRunner { gpu, builtin }),
|
||||
_ => Err("the settings of the built-in denoiser are not the ones the graphics card was set up for".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The adapter it runs on.
|
||||
pub fn adapter(&self) -> String {
|
||||
self.gpu.adapter()
|
||||
}
|
||||
|
||||
/// Run the filter of the tile `input` on the card and on the processor and say how far apart they are. The two
|
||||
/// differ by the rounding of the card's arithmetic: a few blocks whose match or threshold falls either side of a
|
||||
/// tie change a little (well under half a deviation), and a broken kernel by far more. (The final picture is not
|
||||
/// compared: the demosaic's choice of direction at a pixel can flip on a tiny difference.)
|
||||
pub fn agreement(&self, input: &[f32]) -> Result<Agreement, Error> {
|
||||
let seen = std::cell::Cell::new(None);
|
||||
self.builtin.run_with(input, &|planes, t, noise| {
|
||||
let want = bm3d::filter(planes, t, &self.gpu.params(), noise);
|
||||
let got = self.gpu.filter(planes, t, noise)?;
|
||||
let (mut worst, mut sum, mut n) = (0f32, 0f64, 0usize);
|
||||
for (a, b) in want.iter().flatten().zip(got.iter().flatten()) {
|
||||
let d = (a - b).abs();
|
||||
worst = if d.is_nan() { f32::INFINITY } else { worst.max(d) };
|
||||
sum += f64::from(d);
|
||||
n += 1;
|
||||
}
|
||||
seen.set(Some(Agreement { worst, mean: (sum / n.max(1) as f64) as f32 }));
|
||||
Ok(got)
|
||||
})?;
|
||||
seen.get().ok_or_else(|| Error::Runtime("the filter was not run".into()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TileRunner for BuiltinRunner {
|
||||
/// Clean one tile with the built-in pipeline, its block-matching filter running on the card.
|
||||
fn run(&self, input: &[f32]) -> Result<Vec<f32>, Error> {
|
||||
self.builtin.run_with(input, &|planes, t, noise| self.gpu.filter(planes, t, noise))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Four planes of `t × t` cells: edges, a ramp and some texture, plus unit noise (an LCG and Box-Muller).
|
||||
fn scene(t: usize, seed: u64) -> Vec<Vec<f32>> {
|
||||
let mut state = seed;
|
||||
let mut uniform = move || {
|
||||
state = state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
||||
((state >> 40) as f32 + 0.5) / (1u64 << 24) as f32
|
||||
};
|
||||
(0..4)
|
||||
.map(|c| {
|
||||
(0..t * t)
|
||||
.map(|i| {
|
||||
let (x, y) = ((i % t) as f32, (i / t) as f32);
|
||||
let signal = 20.0
|
||||
+ 0.1 * x
|
||||
+ if (x as usize / 17 + y as usize / 23).is_multiple_of(2) { 6.0 } else { 0.0 }
|
||||
+ 2.0 * ((x + 3.0 * c as f32) * 0.9).sin();
|
||||
let (u, v) = (uniform(), uniform());
|
||||
signal + (-2.0 * u.ln()).sqrt() * (std::f32::consts::TAU * v).cos()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The filter on the GPU, or `None` (with a note) on a machine with no usable GPU.
|
||||
fn gpu(p: &Params, t: usize) -> Option<Bm3dGpu> {
|
||||
match Bm3dGpu::new(p, t) {
|
||||
Ok(g) => Some(g),
|
||||
Err(e) => {
|
||||
lightcraft_testkit::skip!(Gpu, "no GPU runner here ({e})");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The largest and the mean difference between two sets of planes.
|
||||
fn differ(a: &[Vec<f32>], b: &[Vec<f32>]) -> (f32, f32) {
|
||||
let (mut worst, mut sum, mut n) = (0f32, 0f64, 0usize);
|
||||
for (x, y) in a.iter().flatten().zip(b.iter().flatten()) {
|
||||
worst = worst.max((x - y).abs());
|
||||
sum += f64::from((x - y).abs());
|
||||
n += 1;
|
||||
}
|
||||
(worst, (sum / n.max(1) as f64) as f32)
|
||||
}
|
||||
|
||||
/// At four tile sizes the card's result is finite and within 0.1 noise deviations of the processor's at worst, and
|
||||
/// 1e-3 on average.
|
||||
#[test]
|
||||
fn the_gpu_gives_what_the_cpu_gives() {
|
||||
let p = Params::default();
|
||||
for (t, seed, noise) in [(32usize, 1u64, 0.003f32), (64, 2, 0.01), (100, 3, 0.04), (256, 4, 0.02)] {
|
||||
let Some(g) = gpu(&p, t) else { return };
|
||||
let planes = scene(t, seed);
|
||||
let want = bm3d::filter(&planes, t, &p, noise);
|
||||
let got = g.filter(&planes, t, noise).unwrap();
|
||||
let (worst, mean) = differ(&got, &want);
|
||||
eprintln!("{}: tile {t}, noise {noise}: worst {worst:e}, mean {mean:e} (noise deviation 1); {}", g.adapter(), g.build_report());
|
||||
assert!(got.iter().flatten().all(|v| v.is_finite()));
|
||||
assert!(mean < 1e-3 && worst < 0.1, "tile {t}: the GPU is off by {worst:e} at most and {mean:e} on average");
|
||||
}
|
||||
}
|
||||
|
||||
/// `forget` must change `made` under the `free` lock: a waiting `take` holds it from reading `made` until it sleeps, so
|
||||
/// a slot given up in between cannot be announced to nobody (the waiter would sleep on a free slot for good).
|
||||
#[test]
|
||||
fn forgetting_a_workspace_waits_for_a_taker_that_is_about_to_sleep() {
|
||||
let Some(g) = gpu(&Params::default(), 32) else { return };
|
||||
let g = Arc::new(g);
|
||||
let before = *g.made.lock().unwrap();
|
||||
let held = g.free.lock().unwrap();
|
||||
let other = g.clone();
|
||||
let forgetter = std::thread::spawn(move || other.forget());
|
||||
std::thread::sleep(std::time::Duration::from_millis(200));
|
||||
assert_eq!(*g.made.lock().unwrap(), before, "forget changed the count while a taker held the free list");
|
||||
drop(held);
|
||||
forgetter.join().unwrap();
|
||||
assert_eq!(*g.made.lock().unwrap(), before.saturating_sub(1));
|
||||
}
|
||||
|
||||
/// One runner shared by four threads, each filtering several tiles, agrees with the processor on every one.
|
||||
#[test]
|
||||
fn a_runner_is_reusable_and_shared_between_threads() {
|
||||
let p = Params::default();
|
||||
let t = 48;
|
||||
let Some(g) = gpu(&p, t) else { return };
|
||||
let g = Arc::new(g);
|
||||
let handles: Vec<_> = (0..4u64)
|
||||
.map(|k| {
|
||||
let g = g.clone();
|
||||
std::thread::spawn(move || {
|
||||
for round in 0..3 {
|
||||
let planes = scene(t, 10 + k * 7 + round);
|
||||
let want = bm3d::filter(&planes, t, &Params::default(), 0.01);
|
||||
let got = g.filter(&planes, t, 0.01).unwrap();
|
||||
let (worst, mean) = differ(&got, &want);
|
||||
assert!(mean < 1e-3 && worst < 0.1, "thread {k}, round {round}: off by {worst:e} / {mean:e}");
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
for h in handles {
|
||||
h.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Block or group sizes the kernels are not written for, and tiles too small or too big, are errors; so are a tile
|
||||
/// or planes of the wrong size. NaN input does not panic, and a flat tile stays flat.
|
||||
#[test]
|
||||
fn what_the_kernels_do_not_do_is_an_error_and_odd_inputs_never_panic() {
|
||||
// not the block or group size the kernels are written for, or too big a tile
|
||||
assert!(Bm3dGpu::new(&Params { block: 6, ..Params::default() }, 64).is_err());
|
||||
assert!(Bm3dGpu::new(&Params { group: 32, ..Params::default() }, 64).is_err());
|
||||
assert!(Bm3dGpu::new(&Params::default(), 2).is_err());
|
||||
assert!(Bm3dGpu::new(&Params::default(), 4096).is_err());
|
||||
let Some(g) = gpu(&Params::default(), 32) else { return };
|
||||
// a tile of another size, planes of the wrong size, numbers that are not finite
|
||||
assert!(g.filter(&scene(40, 1), 40, 0.5).is_err());
|
||||
assert!(g.filter(&scene(32, 1).into_iter().take(3).collect::<Vec<_>>(), 32, 0.5).is_err());
|
||||
let nan = vec![vec![f32::NAN; 32 * 32]; 4];
|
||||
let _ = g.filter(&nan, 32, f32::NAN);
|
||||
let flat = vec![vec![5.0f32; 32 * 32]; 4];
|
||||
let out = g.filter(&flat, 32, 0.5).unwrap();
|
||||
assert!(out.iter().flatten().all(|v| (v - 5.0).abs() < 1e-3));
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ use lightcraft_raster::Rgb32f;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod backend;
|
||||
#[cfg(all(feature = "denoise", not(target_arch = "wasm32")))]
|
||||
pub mod bm3d;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod ctx;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
||||
+12
-12
@@ -22,7 +22,7 @@ use lightcraft_denoise::run::{Error, TileRunner};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
/// Longest wait for one tile's GPU work before the device is given up on.
|
||||
const TIMEOUT: Duration = Duration::from_secs(60);
|
||||
pub(crate) const TIMEOUT: Duration = Duration::from_secs(60);
|
||||
/// The largest tile side (in input cells) the dispatch sizes and 32-bit indexing are checked for.
|
||||
const MAX_TILE: usize = 1024;
|
||||
/// The largest single buffer used: indices in the kernels are 32-bit element offsets.
|
||||
@@ -33,18 +33,18 @@ const WORKSPACES: usize = 2;
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// the device
|
||||
|
||||
struct Dev {
|
||||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
info: wgpu::AdapterInfo,
|
||||
limits: wgpu::Limits,
|
||||
pub(crate) struct Dev {
|
||||
pub(crate) device: wgpu::Device,
|
||||
pub(crate) queue: wgpu::Queue,
|
||||
pub(crate) info: wgpu::AdapterInfo,
|
||||
pub(crate) limits: wgpu::Limits,
|
||||
}
|
||||
|
||||
static DEV: OnceLock<Result<Dev, String>> = OnceLock::new();
|
||||
static BROKEN: AtomicBool = AtomicBool::new(false);
|
||||
static BROKEN_WHY: Mutex<Option<String>> = Mutex::new(None);
|
||||
|
||||
fn mark_broken(why: &str) {
|
||||
pub(crate) fn mark_broken(why: &str) {
|
||||
let mut w = BROKEN_WHY.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if w.is_none() {
|
||||
*w = Some(why.to_string());
|
||||
@@ -57,7 +57,7 @@ pub fn broken_reason() -> Option<String> {
|
||||
BROKEN.load(Ordering::Relaxed).then(|| BROKEN_WHY.lock().unwrap_or_else(|e| e.into_inner()).clone().unwrap_or_else(|| "device error".into()))
|
||||
}
|
||||
|
||||
fn dev() -> Result<&'static Dev, String> {
|
||||
pub(crate) fn dev() -> Result<&'static Dev, String> {
|
||||
if let Some(why) = broken_reason() {
|
||||
return Err(format!("stopped after a GPU failure: {why}"));
|
||||
}
|
||||
@@ -73,7 +73,7 @@ fn dev() -> Result<&'static Dev, String> {
|
||||
}
|
||||
|
||||
/// Why nothing runs on the GPU once [`crate::begin_shutdown`] was called.
|
||||
const CLOSING: &str = "LightCraft is closing";
|
||||
pub(crate) const CLOSING: &str = "LightCraft is closing";
|
||||
|
||||
fn create_device() -> Result<Dev, String> {
|
||||
let Some(backends) = crate::backend::compute_backends() else { return Err("disabled by LIGHTCRAFT_GPU_BACKEND=off".into()) };
|
||||
@@ -480,7 +480,7 @@ struct Pipelines {
|
||||
built: Vec<(String, f64)>,
|
||||
}
|
||||
|
||||
fn entry(binding: u32, ty: wgpu::BufferBindingType) -> wgpu::BindGroupLayoutEntry {
|
||||
pub(crate) fn entry(binding: u32, ty: wgpu::BufferBindingType) -> wgpu::BindGroupLayoutEntry {
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding,
|
||||
visibility: wgpu::ShaderStages::COMPUTE,
|
||||
@@ -489,7 +489,7 @@ fn entry(binding: u32, ty: wgpu::BufferBindingType) -> wgpu::BindGroupLayoutEntr
|
||||
}
|
||||
}
|
||||
|
||||
fn pipeline(d: &Dev, label: &str, src: &str, layout: &wgpu::BindGroupLayout) -> wgpu::ComputePipeline {
|
||||
pub(crate) fn pipeline(d: &Dev, label: &str, src: &str, layout: &wgpu::BindGroupLayout) -> wgpu::ComputePipeline {
|
||||
let module = d.device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some(label), source: wgpu::ShaderSource::Wgsl(src.into()) });
|
||||
let pl = d.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: None, bind_group_layouts: &[Some(layout)], immediate_size: 0 });
|
||||
d.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
@@ -574,7 +574,7 @@ struct Shared {
|
||||
dummy: wgpu::Buffer,
|
||||
}
|
||||
|
||||
fn storage(d: &Dev, label: &str, bytes: u64, extra: wgpu::BufferUsages) -> wgpu::Buffer {
|
||||
pub(crate) fn storage(d: &Dev, label: &str, bytes: u64, extra: wgpu::BufferUsages) -> wgpu::Buffer {
|
||||
d.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some(label),
|
||||
size: bytes.max(16),
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// Putting the filtered blocks back: every cell becomes the weighted average of the filtered blocks that cover it, added
|
||||
// in the order the reference adds them (groups in raster order, a group's blocks in order), so no two invocations
|
||||
// write the same cell. One invocation per cell, all four planes.
|
||||
|
||||
@group(0) @binding(2) var<storage, read> y: array<f32>;
|
||||
@group(0) @binding(3) var<storage, read> members: array<u32>;
|
||||
@group(0) @binding(4) var<storage, read> blocks: array<f32>;
|
||||
@group(0) @binding(5) var<storage, read> weights: array<f32>;
|
||||
@group(0) @binding(6) var<storage, read_write> dst: array<f32>;
|
||||
|
||||
// The first group start that is at least `v`.
|
||||
fn lower_bound(v: u32) -> u32 {
|
||||
var lo = 0u;
|
||||
var hi = p.nr;
|
||||
while (lo < hi) {
|
||||
let mid = (lo + hi) / 2u;
|
||||
if (axis(mid) < v) {
|
||||
lo = mid + 1u;
|
||||
} else {
|
||||
hi = mid;
|
||||
}
|
||||
}
|
||||
return lo;
|
||||
}
|
||||
|
||||
@compute @workgroup_size(64)
|
||||
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
let g = gid.x;
|
||||
let t = p.t;
|
||||
if (g >= t * t) {
|
||||
return;
|
||||
}
|
||||
let cx = g % t;
|
||||
let cy = g / t;
|
||||
// a group's blocks lie within `search` of its start and are N wide: only these starts can reach this cell
|
||||
let reach = p.search + N - 1u;
|
||||
var xlo = 0u;
|
||||
if (cx >= reach) {
|
||||
xlo = cx - reach;
|
||||
}
|
||||
var ylo = 0u;
|
||||
if (cy >= reach) {
|
||||
ylo = cy - reach;
|
||||
}
|
||||
var num: array<f32, 4>;
|
||||
var den: array<f32, 4>;
|
||||
for (var ch = 0u; ch < 4u; ch = ch + 1u) {
|
||||
num[ch] = 0.0;
|
||||
den[ch] = 0.0;
|
||||
}
|
||||
for (var rj = lower_bound(ylo); rj < p.nr; rj = rj + 1u) {
|
||||
if (axis(rj) > cy + p.search) {
|
||||
break;
|
||||
}
|
||||
for (var ri = lower_bound(xlo); ri < p.nr; ri = ri + 1u) {
|
||||
if (axis(ri) > cx + p.search) {
|
||||
break;
|
||||
}
|
||||
let rf = rj * p.nr + ri;
|
||||
let m = members[rf * STRIDE];
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
let pos = members[rf * STRIDE + 1u + i];
|
||||
let px = pos % t;
|
||||
let py = pos / t;
|
||||
if (px <= cx && cx < px + N && py <= cy && cy < py + N) {
|
||||
let cell = (cy - py) * N + (cx - px);
|
||||
let w = win(cell);
|
||||
for (var ch = 0u; ch < 4u; ch = ch + 1u) {
|
||||
let ww = weights[rf * 4u + ch] * w;
|
||||
num[ch] = num[ch] + ww * blocks[((rf * 4u + ch) * K + i) * NN + cell];
|
||||
den[ch] = den[ch] + ww;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// cells no block reached keep their value
|
||||
for (var ch = 0u; ch < 4u; ch = ch + 1u) {
|
||||
let own = y[ch * t * t + g];
|
||||
if (den[ch] > 0.0) {
|
||||
dst[ch * t * t + g] = num[ch] / den[ch];
|
||||
} else {
|
||||
dst[ch * t * t + g] = own;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Collaborative filtering of one group of one plane: the blocks are stacked, transformed (a 2-D DCT of each block, a
|
||||
// Haar transform across the stack), shrunk (a hard threshold, or a Wiener filter built from the pilot) and transformed
|
||||
// back. One invocation per group and plane; the filtered blocks and the group's weight are stored for the aggregation.
|
||||
// (The transforms come from bm3d_transform.wgsl: `buf` is the noisy group, `pb` the pilot's.)
|
||||
|
||||
@group(0) @binding(2) var<storage, read> y: array<f32>;
|
||||
@group(0) @binding(3) var<storage, read> pilot: array<f32>;
|
||||
@group(0) @binding(4) var<storage, read> members: array<u32>;
|
||||
@group(0) @binding(5) var<storage, read_write> blocks: array<f32>;
|
||||
@group(0) @binding(6) var<storage, read_write> weights: array<f32>;
|
||||
|
||||
@compute @workgroup_size(64)
|
||||
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
let g = gid.x;
|
||||
if (g >= p.nr * p.nr * 4u) {
|
||||
return;
|
||||
}
|
||||
let rf = g / 4u;
|
||||
let ch = g % 4u;
|
||||
let t = p.t;
|
||||
let m = members[rf * STRIDE];
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
let pos = members[rf * STRIDE + 1u + i];
|
||||
for (var j = 0u; j < N; j = j + 1u) {
|
||||
for (var c = 0u; c < N; c = c + 1u) {
|
||||
buf[i * NN + j * N + c] = y[ch * t * t + pos + j * t + c];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
dct_fwd(i * NN);
|
||||
}
|
||||
haar(m, true);
|
||||
var weight = 1.0;
|
||||
if (p.wiener == 0u) {
|
||||
var kept = 0u;
|
||||
for (var k = 0u; k < m * NN; k = k + 1u) {
|
||||
if (abs(buf[k]) < p.lambda) {
|
||||
buf[k] = 0.0;
|
||||
} else {
|
||||
kept = kept + 1u;
|
||||
}
|
||||
}
|
||||
weight = 1.0 / f32(max(kept, 1u));
|
||||
} else {
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
let pos = members[rf * STRIDE + 1u + i];
|
||||
for (var j = 0u; j < N; j = j + 1u) {
|
||||
for (var c = 0u; c < N; c = c + 1u) {
|
||||
pb[i * NN + j * N + c] = pilot[ch * t * t + pos + j * t + c];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
dct_fwd_p(i * NN);
|
||||
}
|
||||
haar_p(m, true);
|
||||
var energy = 0.0;
|
||||
for (var k = 0u; k < m * NN; k = k + 1u) {
|
||||
let q = pb[k];
|
||||
let w = q * q / (q * q + p.sigma * p.sigma);
|
||||
buf[k] = buf[k] * w;
|
||||
energy = energy + w * w;
|
||||
}
|
||||
weight = 1.0 / max(energy, 1e-3);
|
||||
}
|
||||
haar(m, false);
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
dct_inv(i * NN);
|
||||
}
|
||||
let base = (rf * 4u + ch) * K * NN;
|
||||
for (var k = 0u; k < m * NN; k = k + 1u) {
|
||||
blocks[base + k] = buf[k];
|
||||
}
|
||||
weights[rf * 4u + ch] = weight;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Block-matching collaborative filtering of one tile: the shared part of the three kernels. The reference is
|
||||
// crates/denoise-core/src/bm3d.rs (the same steps in the same order, so the two agree to rounding): 4 x 4-cell blocks,
|
||||
// groups of at most 16, planes of `t x t` cells with 4 planes one after the other.
|
||||
|
||||
struct P {
|
||||
t: u32, // cells on a side of a plane
|
||||
nr: u32, // blocks that start a group, along a side
|
||||
nb: u32, // blocks along a side (t - 3)
|
||||
search: u32, // how far a match is looked for, in cells
|
||||
cap: u32, // most blocks in a group (at most 16)
|
||||
wiener: u32, // 0: hard threshold, 1: Wiener shrinkage by the pilot
|
||||
pad0: u32,
|
||||
pad1: u32,
|
||||
tau: f32, // how far above the noise two blocks may differ (mean square) and be grouped
|
||||
lambda: f32, // hard threshold (already scaled by the noise's deviation)
|
||||
sigma: f32, // the noise's deviation
|
||||
pad2: f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> p: P;
|
||||
// [0, 16): the DCT matrix, [16, 32): the window (both f32 bits), [32, ..): where the blocks that start a group are
|
||||
@group(0) @binding(1) var<storage, read> consts: array<u32>;
|
||||
|
||||
const N: u32 = 4u;
|
||||
const NN: u32 = 16u;
|
||||
const K: u32 = 16u;
|
||||
// a group's entry in `members`: its size, then its blocks' top-left cells
|
||||
const STRIDE: u32 = 17u;
|
||||
const INV_SQRT2: f32 = 0.70710677;
|
||||
|
||||
fn axis(i: u32) -> u32 {
|
||||
return consts[32u + i];
|
||||
}
|
||||
|
||||
fn dct(i: u32) -> f32 {
|
||||
return bitcast<f32>(consts[i]);
|
||||
}
|
||||
|
||||
fn win(i: u32) -> f32 {
|
||||
return bitcast<f32>(consts[16u + i]);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Grouping: for every block that starts a group, its nearest blocks (itself first) within the search window, nearest
|
||||
// first, at most `cap` and at most `tau` away, cut to a power of two. One invocation per group.
|
||||
|
||||
@group(0) @binding(2) var<storage, read> src: array<f32>;
|
||||
@group(0) @binding(3) var<storage, read_write> members: array<u32>;
|
||||
|
||||
@compute @workgroup_size(64)
|
||||
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
let g = gid.x;
|
||||
if (g >= p.nr * p.nr) {
|
||||
return;
|
||||
}
|
||||
let t = p.t;
|
||||
let rx = axis(g % p.nr);
|
||||
let ry = axis(g / p.nr);
|
||||
var dist: array<f32, 17>;
|
||||
var pos: array<u32, 17>;
|
||||
var len = 1u;
|
||||
dist[0] = 0.0;
|
||||
pos[0] = ry * t + rx;
|
||||
let r = i32(p.search);
|
||||
let nb = i32(p.nb);
|
||||
for (var oy = -r; oy <= r; oy = oy + 1) {
|
||||
let by = i32(ry) + oy;
|
||||
if (by < 0 || by >= nb) {
|
||||
continue;
|
||||
}
|
||||
for (var ox = -r; ox <= r; ox = ox + 1) {
|
||||
if (ox == 0 && oy == 0) {
|
||||
continue;
|
||||
}
|
||||
let bx = i32(rx) + ox;
|
||||
if (bx < 0 || bx >= nb) {
|
||||
continue;
|
||||
}
|
||||
// the sum of squared differences, along each row and then down the rows, as the reference adds them
|
||||
var s = 0.0;
|
||||
for (var j = 0u; j < N; j = j + 1u) {
|
||||
var h = 0.0;
|
||||
let a0 = (ry + j) * t + rx;
|
||||
let b0 = (u32(by) + j) * t + u32(bx);
|
||||
for (var i = 0u; i < N; i = i + 1u) {
|
||||
let d = src[a0 + i] - src[b0 + i];
|
||||
h = h + d * d;
|
||||
}
|
||||
s = s + h;
|
||||
}
|
||||
s = s * 0.0625;
|
||||
if (!(s <= p.tau)) {
|
||||
continue;
|
||||
}
|
||||
if (len >= p.cap && s >= dist[len - 1u]) {
|
||||
continue;
|
||||
}
|
||||
// after every block at most as far away, as the reference's ordered insert does
|
||||
var at = 0u;
|
||||
while (at < len && dist[at] <= s) {
|
||||
at = at + 1u;
|
||||
}
|
||||
var k = len;
|
||||
while (k > at) {
|
||||
dist[k] = dist[k - 1u];
|
||||
pos[k] = pos[k - 1u];
|
||||
k = k - 1u;
|
||||
}
|
||||
dist[at] = s;
|
||||
pos[at] = u32(by) * t + u32(bx);
|
||||
len = min(len + 1u, p.cap);
|
||||
}
|
||||
}
|
||||
var m = 1u;
|
||||
while (m * 2u <= len) {
|
||||
m = m * 2u;
|
||||
}
|
||||
members[g * STRIDE] = m;
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
members[g * STRIDE + 1u + i] = pos[i];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// The transforms of one group, on the module-scope array `{{A}}` (the shader is built once for the noisy blocks and once
|
||||
// for the pilot's). The arrays are not passed to functions: FXC (DX12) cannot index an array it is handed by reference
|
||||
// without unrolling every loop.
|
||||
|
||||
var<private> {{A}}: array<f32, 256>;
|
||||
|
||||
fn dct_fwd{{S}}(base: u32) {
|
||||
var tmp: array<f32, 16>;
|
||||
for (var k = 0u; k < N; k = k + 1u) {
|
||||
for (var j = 0u; j < N; j = j + 1u) {
|
||||
var s = 0.0;
|
||||
for (var i = 0u; i < N; i = i + 1u) {
|
||||
s = s + dct(k * N + i) * {{A}}[base + i * N + j];
|
||||
}
|
||||
tmp[k * N + j] = s;
|
||||
}
|
||||
}
|
||||
for (var k = 0u; k < N; k = k + 1u) {
|
||||
for (var l = 0u; l < N; l = l + 1u) {
|
||||
var s = 0.0;
|
||||
for (var j = 0u; j < N; j = j + 1u) {
|
||||
s = s + tmp[k * N + j] * dct(l * N + j);
|
||||
}
|
||||
{{A}}[base + k * N + l] = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn dct_inv{{S}}(base: u32) {
|
||||
var tmp: array<f32, 16>;
|
||||
for (var i = 0u; i < N; i = i + 1u) {
|
||||
for (var l = 0u; l < N; l = l + 1u) {
|
||||
var s = 0.0;
|
||||
for (var k = 0u; k < N; k = k + 1u) {
|
||||
s = s + dct(k * N + i) * {{A}}[base + k * N + l];
|
||||
}
|
||||
tmp[i * N + l] = s;
|
||||
}
|
||||
}
|
||||
for (var i = 0u; i < N; i = i + 1u) {
|
||||
for (var j = 0u; j < N; j = j + 1u) {
|
||||
var s = 0.0;
|
||||
for (var l = 0u; l < N; l = l + 1u) {
|
||||
s = s + tmp[i * N + l] * dct(l * N + j);
|
||||
}
|
||||
{{A}}[base + i * N + j] = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The Haar transform across the `m` blocks (m is a power of two), at each of the 16 positions of a block.
|
||||
fn haar{{S}}(m: u32, forward: bool) {
|
||||
if (m < 2u) {
|
||||
return;
|
||||
}
|
||||
var col: array<f32, 16>;
|
||||
var tmp: array<f32, 16>;
|
||||
for (var k = 0u; k < NN; k = k + 1u) {
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
col[i] = {{A}}[i * NN + k];
|
||||
}
|
||||
if (forward) {
|
||||
var len = m;
|
||||
while (len > 1u) {
|
||||
let half = len / 2u;
|
||||
for (var i = 0u; i < half; i = i + 1u) {
|
||||
let a = col[2u * i];
|
||||
let c = col[2u * i + 1u];
|
||||
tmp[i] = (a + c) * INV_SQRT2;
|
||||
tmp[half + i] = (a - c) * INV_SQRT2;
|
||||
}
|
||||
for (var i = 0u; i < len; i = i + 1u) {
|
||||
col[i] = tmp[i];
|
||||
}
|
||||
len = half;
|
||||
}
|
||||
} else {
|
||||
var len = 2u;
|
||||
while (len <= m) {
|
||||
let half = len / 2u;
|
||||
for (var i = 0u; i < half; i = i + 1u) {
|
||||
let avg = col[i];
|
||||
let det = col[half + i];
|
||||
tmp[2u * i] = (avg + det) * INV_SQRT2;
|
||||
tmp[2u * i + 1u] = (avg - det) * INV_SQRT2;
|
||||
}
|
||||
for (var i = 0u; i < len; i = i + 1u) {
|
||||
col[i] = tmp[i];
|
||||
}
|
||||
len = len * 2u;
|
||||
}
|
||||
}
|
||||
for (var i = 0u; i < m; i = i + 1u) {
|
||||
{{A}}[i * NN + k] = col[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,6 @@
|
||||
"A pen's pressure sets the size and flow of the brush": "Přítlak pera určuje velikost a tok štětce",
|
||||
"AI Denoise": "Redukce šumu pomocí AI",
|
||||
"AI Denoise Model": "Model pro redukci šumu pomocí AI",
|
||||
"AI Denoise is enabled on the requesting photo": "Redukce šumu pomocí AI je u požadované fotografie zapnutá",
|
||||
"AI Denoise is off: press Use on a model.": "Redukce šumu pomocí AI je vypnutá: u modelu klikněte na Použít.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Redukce šumu pomocí AI vyžaduje model. Nainstalujte jej v Nastavení.",
|
||||
"AI Mask Model Status": "Stav modelu pro maskování pomocí AI",
|
||||
"About": "O aplikaci",
|
||||
"About LightCraft": "O aplikaci LightCraft",
|
||||
@@ -183,7 +180,6 @@
|
||||
"After 7 days": "Po 7 dnech",
|
||||
"After 90 days": "Po 90 dnech",
|
||||
"After a year": "Po roce",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Po instalaci se u požadované fotografie zapne redukce šumu pomocí AI.",
|
||||
"Album": "Album",
|
||||
"Albums": "Alba",
|
||||
"Albums hold library photos: Add to My Photos first": "Alba obsahují fotografie z knihovny: nejprve je přidejte do mých fotografií",
|
||||
@@ -333,9 +329,7 @@
|
||||
"Cancel Download": "Zrušit stahování",
|
||||
"Cancel Face Model Download": "Zrušit stahování modelu rozpoznávání obličejů",
|
||||
"Cancel Interaction": "Zrušit interakci",
|
||||
"Cancel Pending Photo Action": "Zrušit čekající akci s fotografií",
|
||||
"Cancel Preview Build": "Zrušit vytváření náhledů",
|
||||
"Cancel pending action": "Zrušit čekající akci",
|
||||
"Candidate": "Kandidát",
|
||||
"Caption": "Popisek",
|
||||
"Capture Date": "Datum pořízení",
|
||||
@@ -945,10 +939,8 @@
|
||||
"Inspecting Lightroom Catalog": "Prohlížení katalogu Lightroom",
|
||||
"Install Denoise Model": "Nainstalovat model pro redukci šumu",
|
||||
"Install Face Model": "Nainstalovat model rozpoznávání obličejů",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Chcete-li u této fotografie zapnout redukci šumu pomocí AI, nainstalujte model",
|
||||
"Install from file…": "Nainstalovat ze souboru…",
|
||||
"Install the SAM 3 Model": "Nainstalovat model SAM 3",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Nainstalujte vlastní model ONNX se souborem denoise-model.json vedle něj. Toto sestavení nenabízí stahování modelů.",
|
||||
"Instant ’70s": "Instantní sedmdesátky",
|
||||
"Intent:": "Záměr:",
|
||||
"Interface": "Rozhraní",
|
||||
@@ -1353,8 +1345,6 @@
|
||||
"Paste pages": "Vložit stránky",
|
||||
"Pastel Haze": "Pastelový opar",
|
||||
"Pen Pressure": "Přítlak pera",
|
||||
"Pending photo action cancelled": "Čekající akce s fotografií byla zrušena",
|
||||
"Pending photo action cancelled because its library or photo changed": "Čekající akce byla zrušena, protože se změnila knihovna nebo fotografie",
|
||||
"People": "Lidé",
|
||||
"People Count": "Počet osob",
|
||||
"Percent": "Procenta",
|
||||
@@ -1748,7 +1738,6 @@
|
||||
"Set date & time": "Nastavit datum a čas",
|
||||
"Set name": "Název sady",
|
||||
"Set the mix from the photo's colours": "Nastavit směs podle barev fotografie",
|
||||
"Set up AI Denoise…": "Nastavit redukci šumu pomocí AI…",
|
||||
"Settings": "Nastavení",
|
||||
"Settings file problem": "Problém souboru nastavení",
|
||||
"Settings new raw photos start from. Changing them doesn't touch photos already in the library.": "Výchozí nastavení nových fotografií RAW. Jejich změna neovlivní fotografie, které již jsou v knihovně.",
|
||||
@@ -1944,9 +1933,7 @@
|
||||
"Thirds": "Třetiny",
|
||||
"This Computer": "Tento počítač",
|
||||
"This build can't download the model yet. To install it by hand, put model.safetensors, vocab.json and merges.txt from Meta's facebook/sam3 in the folder above: Object and Describe work as soon as they are there.": "Toto sestavení zatím neumí model stáhnout. Pro ruční instalaci vložte model.safetensors, vocab.json a merges.txt z facebook/sam3 společnosti Meta do složky výše: Objekt a Popsat budou fungovat, jakmile tam soubory budou.",
|
||||
"This build cannot run denoise models.": "Toto sestavení neumí spouštět modely pro redukci šumu.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "Toto sestavení neumí spouštět modely rozpoznávání: lze je přidat a vybrat, ale nelze je použít.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Toto sestavení nemá kam ukládat modely pro redukci šumu, takže redukce šumu pomocí AI není dostupná. (Desktopová aplikace tuto možnost má.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "Toto sestavení nemá kam ukládat modely obličejů, takže seznam modelů není dostupný. (Desktopová aplikace tuto možnost má.)",
|
||||
"This file cannot be used yet": "Tento soubor zatím nelze použít",
|
||||
"This folder is not available (drive disconnected?). Smart previews are not built or used until it is back or you choose another folder.": "Tato složka není dostupná (odpojený disk?). Inteligentní náhledy se nevytvářejí ani nepoužívají, dokud nebude znovu dostupná nebo nezvolíte jinou složku.",
|
||||
|
||||
@@ -1868,8 +1868,6 @@
|
||||
"Back to this person": "Zurück zu dieser Person",
|
||||
"AI Denoise": "KI-Entrauschen",
|
||||
"AI Denoise Model": "KI-Entrauschungsmodell",
|
||||
"AI Denoise is off: press Use on a model.": "KI-Entrauschen ist aus: Klicke bei einem Modell auf „Verwenden“.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "KI-Entrauschen benötigt ein Modell. Installiere eines in den Einstellungen.",
|
||||
"Accept & Download": "Akzeptieren und herunterladen",
|
||||
"Already installed. Remove it before installing a replacement.": "Bereits installiert. Entferne es, bevor du einen Ersatz installierst.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Automatisch verwendet die Grafikkarte, wo sie schneller als der Prozessor ist: Beide werden beim ersten berechneten Foto auf diesem Computer gemessen.",
|
||||
@@ -1888,7 +1886,6 @@
|
||||
"Inspect Denoise Model": "Entrauschungsmodell prüfen",
|
||||
"Install Denoise Model": "Entrauschungsmodell installieren",
|
||||
"Install from file…": "Aus Datei installieren…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Installiere ein eigenes ONNX-Modell mit einer denoise-model.json daneben. Diese Version bietet keine Modelldownloads an.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Sein entrauschtes Bild ist noch nicht berechnet, und Bilder werden nicht automatisch berechnet (Einstellungen, KI-Entrauschen).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft kennt dieses Modell nicht und hat daher angenommen:",
|
||||
"Limit": "Grenze",
|
||||
@@ -1901,7 +1898,6 @@
|
||||
"Open the model's page": "Seite des Modells öffnen",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Öffnet die Seite des Modells im Browser, um mehr darüber zu lesen oder die Datei selbst herunterzuladen.",
|
||||
"Processor": "Prozessor",
|
||||
"Set up AI Denoise…": "KI-Entrauschen einrichten…",
|
||||
"Speed": "Geschwindigkeit",
|
||||
"Starting…": "Wird gestartet…",
|
||||
"Tested and works on this computer": "Getestet, funktioniert auf diesem Computer",
|
||||
@@ -1910,8 +1906,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "Das Modell bleibt nur auf diesem Computer. LightCraft lädt es nie hoch und gibt es nie weiter.",
|
||||
"The processor does the work.": "Der Prozessor erledigt die Arbeit.",
|
||||
"There is no model file to install": "Es gibt keine Modelldatei zum Installieren",
|
||||
"This build cannot run denoise models.": "Diese Version kann keine Entrauschungsmodelle ausführen.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Diese Version hat keinen Speicherort für Entrauschungsmodelle, daher ist KI-Entrauschen nicht verfügbar. (Die Desktop-App schon.)",
|
||||
"This file cannot be used yet": "Diese Datei kann noch nicht verwendet werden",
|
||||
"Tick the box to accept the model's terms first": "Setze zuerst das Häkchen, um die Bedingungen des Modells zu akzeptieren",
|
||||
"Try again": "Erneut versuchen",
|
||||
@@ -1948,12 +1942,6 @@
|
||||
"Download Denoise Model": "Entrauschungsmodell herunterladen",
|
||||
"Remove Denoise Model": "Entrauschungsmodell entfernen",
|
||||
"Test Denoise Model": "Entrauschungsmodell testen",
|
||||
"AI Denoise is enabled on the requesting photo": "KI-Entrauschen ist für das anfragende Foto aktiviert",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Nach der Installation wird KI-Entrauschen für das anfragende Foto eingeschaltet.",
|
||||
"Cancel pending action": "Ausstehende Aktion abbrechen",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Installiere ein Entrauschungsmodell, um KI-Entrauschen für dieses Foto zu aktivieren",
|
||||
"Pending photo action cancelled": "Ausstehende Fotoaktion abgebrochen",
|
||||
"Pending photo action cancelled because its library or photo changed": "Ausstehende Fotoaktion abgebrochen, weil sich die Bibliothek oder das Foto geändert hat",
|
||||
"ONNX model": "ONNX-Modell",
|
||||
"commercial use subject to GPL conditions": "kommerzielle Nutzung unter GPL-Bedingungen",
|
||||
"Decrease Rating": "Bewertung verringern",
|
||||
@@ -2181,7 +2169,6 @@
|
||||
"Adding to Apple Photos": "Wird zu Apple Fotos hinzugefügt",
|
||||
"Add Face Model…": "Gesichtsmodell hinzufügen…",
|
||||
"Cancel Face Model Download": "Download des Gesichtsmodells abbrechen",
|
||||
"Cancel Pending Photo Action": "Ausstehende Fotoaktion abbrechen",
|
||||
"Choose Face Recognition Model": "Gesichtserkennungsmodell wählen",
|
||||
"Choose a model below (Use) to start.": "Wähle unten ein Modell („Verwenden“), um zu beginnen.",
|
||||
"Detect Faces": "Gesichter erkennen",
|
||||
|
||||
@@ -187,7 +187,6 @@
|
||||
"Cancel Download": "Cancelar descarga",
|
||||
"Cancel Face Model Download": "Cancelar la descarga del modelo de caras",
|
||||
"Cancel Interaction": "Cancelar interacción",
|
||||
"Cancel Pending Photo Action": "Cancelar la acción pendiente sobre la foto",
|
||||
"Canon CR2 photos from the EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II and 1D Mark IV (and other": "Fotos CR2 de Canon de las EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II y 1D Mark IV (y otros",
|
||||
"Canon CR3 files show their full-size embedded JPEG (e.g. 6960 × 4640 on an EOS R6 Mark III) instead of the": "Los archivos CR3 de Canon muestran su JPEG incrustado a tamaño completo (p. ej., 6960 × 4640 en una EOS R6 Mark III) en lugar de la",
|
||||
"Canon EOS R5 Mark II C-RAW files that opened as \"preview only\" (more than half of them, depending on the": "Los archivos C-RAW de la Canon EOS R5 Mark II que se abrían como «solo vista previa» (más de la mitad, según la",
|
||||
@@ -1882,8 +1881,6 @@
|
||||
"Back to this person": "Volver a esta persona",
|
||||
"AI Denoise": "Reducción de ruido con IA",
|
||||
"AI Denoise Model": "Modelo de reducción de ruido con IA",
|
||||
"AI Denoise is off: press Use on a model.": "La reducción de ruido con IA está desactivada: pulsar Usar en un modelo.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "La reducción de ruido con IA necesita un modelo. Instalar uno en Ajustes.",
|
||||
"Accept & Download": "Aceptar y descargar",
|
||||
"Already installed. Remove it before installing a replacement.": "Ya está instalado. Quitarlo antes de instalar uno nuevo.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Automático usa la tarjeta gráfica cuando es más rápida que el procesador: ambos se cronometran en este equipo la primera vez que se genera una foto.",
|
||||
@@ -1905,7 +1902,6 @@
|
||||
"Install Face Model": "Instalar modelo de caras",
|
||||
"JPEG with the same name (`IMG_0001.CR3` + `IMG_0001.JPG`) no longer share one sidecar: the raw keeps `IMG_0001.xmp`,": "JPEG con el mismo nombre (`IMG_0001.CR3` + `IMG_0001.JPG`) ya no comparten un archivo complementario: el raw conserva `IMG_0001.xmp`,",
|
||||
"Install from file…": "Instalar desde archivo…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Instalar un modelo ONNX propio con denoise-model.json junto a él. Esta versión no ofrece descargas de modelos.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Su imagen sin ruido aún no se ha generado, y las imágenes no se generan por sí solas (Ajustes, Reducción de ruido con IA).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft no conoce este modelo, así que supuso:",
|
||||
"Limit": "Límite",
|
||||
@@ -1918,7 +1914,6 @@
|
||||
"Open the model's page": "Abrir la página del modelo",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Abre la página del modelo en el navegador, para leer sobre él u obtener el archivo a mano.",
|
||||
"Processor": "Procesador",
|
||||
"Set up AI Denoise…": "Configurar la reducción de ruido con IA…",
|
||||
"Speed": "Velocidad",
|
||||
"Starting…": "Iniciando…",
|
||||
"Tested and works on this computer": "Probado y funciona en este equipo",
|
||||
@@ -1927,9 +1922,7 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "El modelo se guarda solo en este equipo. LightCraft nunca lo sube ni lo comparte.",
|
||||
"The processor does the work.": "El procesador hace el trabajo.",
|
||||
"There is no model file to install": "No hay ningún archivo de modelo que instalar",
|
||||
"This build cannot run denoise models.": "Esta versión no puede ejecutar modelos de reducción de ruido.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "Esta versión no puede ejecutar modelos de reconocimiento: se pueden añadir y elegir, pero no usar.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Esta versión no tiene dónde guardar modelos de reducción de ruido, así que la reducción de ruido con IA no está disponible. (La aplicación de escritorio sí.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "Esta versión no tiene dónde guardar modelos de caras, así que la lista de modelos no está disponible. (La aplicación de escritorio sí.)",
|
||||
"This file cannot be used yet": "Este archivo aún no se puede usar",
|
||||
"Tick the box to accept the model's terms first": "Marcar antes la casilla para aceptar las condiciones del modelo",
|
||||
@@ -1974,12 +1967,6 @@
|
||||
"The catalog has a format version (issue #102). Opening a library from an older LightCraft upgrades it; a library": "El catálogo tiene una versión de formato (issue #102). Abrir una biblioteca de un LightCraft anterior la actualiza; una biblioteca",
|
||||
"The control port (`--control`) closes a connection as soon as it receives anything that isn't a JSON request": "El puerto de control (`--control`) cierra una conexión en cuanto recibe algo que no es una solicitud JSON",
|
||||
"The thumbnail cache only ever counts and deletes its own files (issue #98): a library opened on a folder that": "La caché de miniaturas solo cuenta y elimina sus propios archivos (issue #98): una biblioteca abierta en una carpeta que",
|
||||
"AI Denoise is enabled on the requesting photo": "La reducción de ruido con IA está activada en la foto que la pidió",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Tras la instalación, la reducción de ruido con IA se activará en la foto que la pidió.",
|
||||
"Cancel pending action": "Cancelar acción pendiente",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Instalar un modelo de reducción de ruido para activar la reducción de ruido con IA en esta foto",
|
||||
"Pending photo action cancelled": "Acción pendiente sobre la foto cancelada",
|
||||
"Pending photo action cancelled because its library or photo changed": "Acción pendiente sobre la foto cancelada porque cambió su biblioteca o su foto",
|
||||
"ONNX model": "Modelo ONNX",
|
||||
"commercial use subject to GPL conditions": "uso comercial sujeto a las condiciones de la GPL",
|
||||
"Decrease Rating": "Reducir valoración",
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
"A slide stays up for its duration, its fade in included. A fade of 0 cuts.": "Dia pysyy näkyvillä kestonsa ajan, häivytys mukaan lukien. Häivytys 0 vaihtaa suoraan.",
|
||||
"AI Denoise": "Tekoälykohinanpoisto",
|
||||
"AI Denoise Model": "Tekoälykohinanpoiston malli",
|
||||
"AI Denoise is enabled on the requesting photo": "Tekoälykohinanpoisto on käytössä sitä pyytävällä kuvalla",
|
||||
"AI Denoise is off: press Use on a model.": "Tekoälykohinanpoisto on pois päältä: paina mallin kohdalla Käytä.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Tekoälykohinanpoisto tarvitsee mallin. Asenna sellainen asetuksissa.",
|
||||
"AI Mask Model Status": "Tekoälymaskin mallin tila",
|
||||
"AV1 video, each slide held for its duration with its fades. No sound: music is not exported yet.": "AV1-video, jossa kutakin diaa näytetään sen keston ajan häivytyksineen. Ei ääntä: musiikkia ei vielä viedä.",
|
||||
"About": "Tietoja",
|
||||
@@ -86,7 +83,6 @@
|
||||
"After 7 days": "7 päivän kuluttua",
|
||||
"After 90 days": "90 päivän kuluttua",
|
||||
"After a year": "Vuoden kuluttua",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Asennuksen jälkeen tekoälykohinanpoisto otetaan käyttöön sitä pyytävälle kuvalle.",
|
||||
"Album": "Albumi",
|
||||
"Albums": "Albumit",
|
||||
"Albums hold library photos: Add to My Photos first": "Albumit sisältävät kirjaston kuvia: lisää ensin Omiin kuviin",
|
||||
@@ -253,9 +249,7 @@
|
||||
"Cancel Download": "Peruuta lataus",
|
||||
"Cancel Face Model Download": "Peruuta kasvomallin lataus",
|
||||
"Cancel Interaction": "Peruuta vuorovaikutus",
|
||||
"Cancel Pending Photo Action": "Peruuta odottava kuvatoiminto",
|
||||
"Cancel Preview Build": "Peruuta esikatselun luonti",
|
||||
"Cancel pending action": "Peruuta odottava toiminto",
|
||||
"Candidate": "Ehdokas",
|
||||
"Caption": "Kuvateksti",
|
||||
"Capture Date": "Kuvauspäivä",
|
||||
@@ -956,10 +950,8 @@
|
||||
"Inspecting Lightroom Catalog": "Tarkastellaan Lightroom-katalogia",
|
||||
"Install Denoise Model": "Asenna kohinanpoistomalli",
|
||||
"Install Face Model": "Asenna kasvomalli",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Asenna kohinanpoistomalli ottaaksesi tekoälykohinanpoiston käyttöön tällä kuvalla",
|
||||
"Install from file…": "Asenna tiedostosta…",
|
||||
"Install the SAM 3 Model": "Asenna SAM 3 -malli",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Asenna oma ONNX-mallisi, jonka vieressä on denoise-model.json. Tämä versio ei tarjoa mallilatauksia.",
|
||||
"Instant ’70s": "Välitön 70-luku",
|
||||
"Intent:": "Tarkoitus:",
|
||||
"Interface": "Käyttöliittymä",
|
||||
@@ -1406,8 +1398,6 @@
|
||||
"Pastel Haze": "Pastellihuntu",
|
||||
"Pause / Resume Slideshow": "Keskeytä / jatka diaesitystä",
|
||||
"Pen Pressure": "Kynän paine",
|
||||
"Pending photo action cancelled": "Odottava kuvatoiminto peruttu",
|
||||
"Pending photo action cancelled because its library or photo changed": "Odottava kuvatoiminto peruttu, koska sen kirjasto tai kuva muuttui",
|
||||
"People": "Henkilöt",
|
||||
"People Count": "Henkilöiden määrä",
|
||||
"Percent": "Prosentti",
|
||||
@@ -1813,7 +1803,6 @@
|
||||
"Set date & time": "Aseta päivämäärä ja aika",
|
||||
"Set name": "Aseta nimi",
|
||||
"Set the mix from the photo's colours": "Aseta sekoitus kuvan väreistä",
|
||||
"Set up AI Denoise…": "Ota tekoälykohinanpoisto käyttöön…",
|
||||
"Settings": "Asetukset",
|
||||
"Settings file problem": "Asetustiedoston ongelma",
|
||||
"Settings new raw photos start from. Changing them doesn't touch photos already in the library.": "Asetukset, joista uudet raw-kuvat lähtevät liikkeelle. Niiden muuttaminen ei koske kirjastossa jo olevia kuvia.",
|
||||
@@ -2043,9 +2032,7 @@
|
||||
"Thirds": "Kolmasosat",
|
||||
"This Computer": "Tämä tietokone",
|
||||
"This build can't download the model yet. To install it by hand, put model.safetensors, vocab.json and merges.txt from Meta's facebook/sam3 in the folder above: Object and Describe work as soon as they are there.": "Tämä versio ei vielä voi ladata mallia. Asentaaksesi sen käsin laita Metan facebook/sam3-mallin tiedostot model.safetensors, vocab.json ja merges.txt yllä olevaan kansioon: Kohde ja Kuvaile toimivat heti, kun ne ovat siellä.",
|
||||
"This build cannot run denoise models.": "Tämä versio ei voi ajaa kohinanpoistomalleja.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "Tämä versio ei voi ajaa tunnistusmalleja: ne voi lisätä ja valita, mutta ei käyttää.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Tällä versiolla ei ole paikkaa kohinanpoistomalleille, joten tekoälykohinanpoisto ei ole käytettävissä. (Työpöytäsovelluksessa on.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "Tällä versiolla ei ole paikkaa kasvomalleille, joten malliluettelo ei ole käytettävissä. (Työpöytäsovelluksessa on.)",
|
||||
"This file cannot be used yet": "Tätä tiedostoa ei voi vielä käyttää",
|
||||
"This folder is not available (drive disconnected?). Smart previews are not built or used until it is back or you choose another folder.": "Tämä kansio ei ole käytettävissä (asema irrotettu?). Älyesikatseluita ei luoda eikä käytetä, ennen kuin se on takaisin tai valitset toisen kansion.",
|
||||
|
||||
@@ -1701,8 +1701,6 @@
|
||||
"Back to this person": "Retour à cette personne",
|
||||
"AI Denoise": "Débruitage IA",
|
||||
"AI Denoise Model": "Modèle de débruitage IA",
|
||||
"AI Denoise is off: press Use on a model.": "Le débruitage IA est désactivé : appuyez sur Utiliser sur un modèle.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Le débruitage IA nécessite un modèle. Installez-en un dans les Réglages.",
|
||||
"Accept & Download": "Accepter et télécharger",
|
||||
"Already installed. Remove it before installing a replacement.": "Déjà installé. Supprimez-le avant d'installer un remplaçant.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Automatique utilise la carte graphique lorsqu'elle est plus rapide que le processeur : les deux sont chronométrés sur cet ordinateur la première fois qu'une photo est générée.",
|
||||
@@ -1721,7 +1719,6 @@
|
||||
"Inspect Denoise Model": "Inspecter le modèle de débruitage",
|
||||
"Install Denoise Model": "Installer le modèle de débruitage",
|
||||
"Install from file…": "Installer à partir d'un fichier…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Installez votre propre modèle ONNX avec denoise-model.json à côté. Cette version ne propose aucun téléchargement de modèle.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Son image débruitée n'est pas encore générée, et les images ne sont pas générées automatiquement (Réglages, Débruitage IA).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft ne connaît pas ce modèle ; il a donc supposé :",
|
||||
"Limit": "Limite",
|
||||
@@ -1734,7 +1731,6 @@
|
||||
"Open the model's page": "Ouvrir la page du modèle",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Ouvre la page du modèle dans votre navigateur, pour vous renseigner ou récupérer le fichier vous-même.",
|
||||
"Processor": "Processeur",
|
||||
"Set up AI Denoise…": "Configurer le débruitage IA…",
|
||||
"Speed": "Vitesse",
|
||||
"Starting…": "Démarrage…",
|
||||
"Tested and works on this computer": "Testé et fonctionnel sur cet ordinateur",
|
||||
@@ -1743,8 +1739,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "Le modèle est conservé uniquement sur cet ordinateur. LightCraft ne le téléverse ni ne le partage jamais.",
|
||||
"The processor does the work.": "Le processeur effectue le travail.",
|
||||
"There is no model file to install": "Il n'y a aucun fichier de modèle à installer",
|
||||
"This build cannot run denoise models.": "Cette version ne peut pas exécuter de modèles de débruitage.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Cette version n'a aucun endroit où conserver les modèles de débruitage ; le débruitage IA n'est donc pas disponible. (L'application de bureau en a un.)",
|
||||
"This file cannot be used yet": "Ce fichier ne peut pas encore être utilisé",
|
||||
"Tick the box to accept the model's terms first": "Cochez d'abord la case pour accepter les conditions du modèle",
|
||||
"Try again": "Réessayer",
|
||||
@@ -1781,12 +1775,6 @@
|
||||
"Download Denoise Model": "Télécharger le modèle de débruitage",
|
||||
"Remove Denoise Model": "Supprimer le modèle de débruitage",
|
||||
"Test Denoise Model": "Tester le modèle de débruitage",
|
||||
"AI Denoise is enabled on the requesting photo": "Le débruitage IA est activé sur la photo à l'origine de la demande",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Après l'installation, le débruitage IA sera activé pour la photo à l'origine de la demande.",
|
||||
"Cancel pending action": "Annuler l'action en attente",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Installez un modèle de débruitage pour activer le débruitage IA sur cette photo",
|
||||
"Pending photo action cancelled": "Action de photo en attente annulée",
|
||||
"Pending photo action cancelled because its library or photo changed": "Action de photo en attente annulée car sa bibliothèque ou sa photo a changé",
|
||||
"ONNX model": "Modèle ONNX",
|
||||
"commercial use subject to GPL conditions": "usage commercial soumis aux conditions de la GPL",
|
||||
"Camera local tone mapping": "Mappage local des tons de l’appareil",
|
||||
@@ -2039,7 +2027,6 @@
|
||||
"Auto-Tag from Tracklog: GPS locations for your photos from a GPX track log, matched by capture time.": "Géolocalisation depuis un tracé : positions GPS de vos photos tirées d'un tracé GPX, associées par date de prise de vue.",
|
||||
"Browser version (experimental), keeping a library safe (issue #107): File ▸ Back Up Library… downloads the catalog": "Version navigateur (expérimentale), protection de la bibliothèque (ticket #107) : Fichier → Sauvegarder la bibliothèque… télécharge le catalogue",
|
||||
"Cancel Face Model Download": "Annuler le téléchargement du modèle de visages",
|
||||
"Cancel Pending Photo Action": "Annuler l'action en attente sur la photo",
|
||||
"Canon CR2 photos from the EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II and 1D Mark IV (and other": "Les photos CR2 Canon des EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II et 1D Mark IV (et d'autres",
|
||||
"Canon CR3 files show their full-size embedded JPEG (e.g. 6960 × 4640 on an EOS R6 Mark III) instead of the": "Les fichiers CR3 Canon affichent leur JPEG intégré en pleine taille (p. ex. 6960 × 4640 sur un EOS R6 Mark III) au lieu de l'",
|
||||
"Canon EOS R5 Mark II C-RAW files that opened as \"preview only\" (more than half of them, depending on the": "Les fichiers C-RAW du Canon EOS R5 Mark II qui s'ouvraient en « aperçu uniquement » (plus de la moitié, selon la",
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
"A pen's pressure sets the size and flow of the brush": "Tekanan pena mengatur ukuran dan aliran kuas",
|
||||
"AI Denoise": "Pengurangan noise AI",
|
||||
"AI Denoise Model": "Model pengurangan noise AI",
|
||||
"AI Denoise is enabled on the requesting photo": "Pengurangan noise AI diaktifkan pada foto yang bersangkutan",
|
||||
"AI Denoise is off: press Use on a model.": "Pengurangan noise AI nonaktif: tekan Gunakan pada salah satu model.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Pengurangan noise AI memerlukan model. Instal model di Pengaturan.",
|
||||
"AI Mask Model Status": "Status model masker AI",
|
||||
"AV1 video, each slide held for its duration with its fades. No sound: music is not exported yet.": "Video AV1; setiap slide ditampilkan sesuai durasinya, lengkap dengan transisi pudar. Tanpa suara: musik belum ikut diekspor.",
|
||||
"About": "Tentang",
|
||||
@@ -87,7 +84,6 @@
|
||||
"After 7 days": "Setelah 7 hari",
|
||||
"After 90 days": "Setelah 90 hari",
|
||||
"After a year": "Setelah satu tahun",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Setelah terinstal, pengurangan noise AI akan aktif untuk foto tersebut.",
|
||||
"Album": "Album",
|
||||
"Albums": "Album",
|
||||
"Albums hold library photos: Add to My Photos first": "Album hanya berisi foto pustaka: tambahkan ke Foto saya terlebih dahulu",
|
||||
@@ -257,9 +253,7 @@
|
||||
"Cancel Download": "Batalkan unduhan",
|
||||
"Cancel Face Model Download": "Batalkan unduhan model wajah",
|
||||
"Cancel Interaction": "Batalkan interaksi",
|
||||
"Cancel Pending Photo Action": "Batalkan tindakan foto yang tertunda",
|
||||
"Cancel Preview Build": "Batalkan pembuatan pratinjau",
|
||||
"Cancel pending action": "Batalkan tindakan yang tertunda",
|
||||
"Candidate": "Kandidat",
|
||||
"Caption": "Keterangan",
|
||||
"Capture Date": "Tanggal pengambilan",
|
||||
@@ -961,10 +955,8 @@
|
||||
"Inspecting Lightroom Catalog": "Memeriksa katalog Lightroom",
|
||||
"Install Denoise Model": "Instal model pengurangan noise",
|
||||
"Install Face Model": "Instal model wajah",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Instal model untuk mengaktifkan pengurangan noise AI pada foto ini",
|
||||
"Install from file…": "Instal dari file…",
|
||||
"Install the SAM 3 Model": "Instal model SAM 3",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Instal model ONNX Anda sendiri beserta file denoise-model.json di sebelahnya. Build ini tidak menyediakan unduhan model.",
|
||||
"Instant ’70s": "Instant ’70s",
|
||||
"Intent:": "Metode rendering:",
|
||||
"Interface": "Antarmuka",
|
||||
@@ -1390,8 +1382,6 @@
|
||||
"Pastel Haze": "Kabut Pastel",
|
||||
"Pause / Resume Slideshow": "Jeda / lanjutkan tayangan slide",
|
||||
"Pen Pressure": "Tekanan pena",
|
||||
"Pending photo action cancelled": "Tindakan foto yang tertunda dibatalkan",
|
||||
"Pending photo action cancelled because its library or photo changed": "Tindakan foto yang tertunda dibatalkan karena pustaka atau fotonya berubah",
|
||||
"People": "Orang",
|
||||
"People Count": "Jumlah orang",
|
||||
"Percent": "Persen",
|
||||
@@ -1810,7 +1800,6 @@
|
||||
"Set date & time": "Atur tanggal & waktu",
|
||||
"Set name": "Nama set",
|
||||
"Set the mix from the photo's colours": "Atur campuran berdasarkan warna foto",
|
||||
"Set up AI Denoise…": "Siapkan pengurangan noise AI…",
|
||||
"Settings": "Pengaturan",
|
||||
"Settings file problem": "Masalah file pengaturan",
|
||||
"Settings new raw photos start from. Changing them doesn't touch photos already in the library.": "Pengaturan awal untuk foto raw baru. Mengubahnya tidak memengaruhi foto yang sudah ada di pustaka.",
|
||||
@@ -2042,9 +2031,7 @@
|
||||
"Thirds": "Aturan sepertiga",
|
||||
"This Computer": "Komputer ini",
|
||||
"This build can't download the model yet. To install it by hand, put model.safetensors, vocab.json and merges.txt from Meta's facebook/sam3 in the folder above: Object and Describe work as soon as they are there.": "Build ini belum bisa mengunduh model. Untuk menginstalnya secara manual, letakkan model.safetensors, vocab.json, dan merges.txt dari facebook/sam3 milik Meta ke folder di atas: masker Objek dan Deskripsi langsung berfungsi setelah file tersebut tersedia.",
|
||||
"This build cannot run denoise models.": "Build ini tidak dapat menjalankan model pengurangan noise.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "Build ini tidak dapat menjalankan model pengenalan: model bisa ditambahkan dan dipilih, tetapi tidak bisa digunakan.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Build ini tidak memiliki tempat untuk menyimpan model pengurangan noise, sehingga pengurangan noise AI tidak tersedia. (Tersedia di aplikasi desktop.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "Build ini tidak memiliki tempat untuk menyimpan model wajah, sehingga daftar model tidak tersedia. (Tersedia di aplikasi desktop.)",
|
||||
"This file cannot be used yet": "File ini belum dapat digunakan",
|
||||
"This folder is not available (drive disconnected?). Smart previews are not built or used until it is back or you choose another folder.": "Folder ini tidak tersedia (drive terputus?). Pratinjau pintar tidak akan dibuat atau dipakai sampai folder ini tersedia lagi atau Anda memilih folder lain.",
|
||||
|
||||
@@ -1732,8 +1732,6 @@
|
||||
"Back to this person": "Torna a questa persona",
|
||||
"AI Denoise": "Riduzione disturbo IA",
|
||||
"AI Denoise Model": "Modello di riduzione disturbo IA",
|
||||
"AI Denoise is off: press Use on a model.": "La riduzione disturbo IA è disattivata: premi Usa su un modello.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "La riduzione disturbo IA ha bisogno di un modello. Installane uno nelle Impostazioni.",
|
||||
"Accept & Download": "Accetta e scarica",
|
||||
"Already installed. Remove it before installing a replacement.": "Già installato. Rimuovilo prima di installarne un altro.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Automatico usa la scheda grafica quando è più veloce del processore: la prima volta che si elabora una foto, su questo computer vengono cronometrati entrambi.",
|
||||
@@ -1752,7 +1750,6 @@
|
||||
"Inspect Denoise Model": "Esamina il modello di riduzione disturbo",
|
||||
"Install Denoise Model": "Installa un modello di riduzione disturbo",
|
||||
"Install from file…": "Installa da file…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Installa un tuo modello ONNX con accanto denoise-model.json. Questa versione non offre download di modelli.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "La sua immagine con il disturbo ridotto non è ancora pronta, e le immagini non vengono generate da sole (Impostazioni, Riduzione disturbo IA).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft non conosce questo modello, quindi ha ipotizzato:",
|
||||
"Limit": "Limite",
|
||||
@@ -1765,7 +1762,6 @@
|
||||
"Open the model's page": "Apri la pagina del modello",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Apre nel browser la pagina del modello, per leggerne i dettagli o scaricare il file da te.",
|
||||
"Processor": "Processore",
|
||||
"Set up AI Denoise…": "Configura la riduzione disturbo IA…",
|
||||
"Speed": "Velocità",
|
||||
"Starting…": "Avvio in corso…",
|
||||
"Tested and works on this computer": "Testato e funzionante su questo computer",
|
||||
@@ -1774,8 +1770,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "Il modello resta solo su questo computer. LightCraft non lo carica né lo condivide mai.",
|
||||
"The processor does the work.": "Il lavoro lo fa il processore.",
|
||||
"There is no model file to install": "Non c'è nessun file di modello da installare",
|
||||
"This build cannot run denoise models.": "Questa versione non può eseguire modelli di riduzione disturbo.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Questa versione non ha dove tenere i modelli di riduzione disturbo, quindi la riduzione disturbo IA non è disponibile. (L'app desktop ce l'ha.)",
|
||||
"This file cannot be used yet": "Questo file non si può ancora usare",
|
||||
"Tick the box to accept the model's terms first": "Prima spunta la casella per accettare le condizioni del modello",
|
||||
"Try again": "Riprova",
|
||||
@@ -1814,12 +1808,6 @@
|
||||
"Download Denoise Model": "Scarica il modello di riduzione disturbo",
|
||||
"Remove Denoise Model": "Rimuovi il modello di riduzione disturbo",
|
||||
"Test Denoise Model": "Testa il modello di riduzione disturbo",
|
||||
"AI Denoise is enabled on the requesting photo": "La riduzione disturbo IA è attiva sulla foto che l'ha richiesta",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Dopo l'installazione, la riduzione disturbo IA si attiverà sulla foto che l'ha richiesta.",
|
||||
"Cancel pending action": "Annulla l'azione in sospeso",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Installa un modello di riduzione disturbo per attivare la riduzione disturbo IA su questa foto",
|
||||
"Pending photo action cancelled": "Azione sulla foto in sospeso annullata",
|
||||
"Pending photo action cancelled because its library or photo changed": "Azione sulla foto in sospeso annullata perché la libreria o la foto sono cambiate",
|
||||
"ONNX model": "Modello ONNX",
|
||||
"commercial use subject to GPL conditions": "uso commerciale soggetto alle condizioni della GPL",
|
||||
"Decrease Rating": "Diminuisci valutazione",
|
||||
@@ -2280,7 +2268,6 @@
|
||||
"This raw is now developed from its raw data": "Questo raw ora viene sviluppato dai suoi dati raw",
|
||||
"This raw variant still can't be decoded": "Questa variante raw non si può ancora decodificare",
|
||||
"Cancel Face Model Download": "Annulla il download del modello dei volti",
|
||||
"Cancel Pending Photo Action": "Annulla l'azione in sospeso sulla foto",
|
||||
"Choose Face Recognition Model": "Scegli il modello di riconoscimento dei volti",
|
||||
"Choose a model below (Use) to start.": "Per cominciare, scegli un modello qui sotto (Usa).",
|
||||
"Detect Faces": "Rileva i volti",
|
||||
|
||||
@@ -1714,8 +1714,6 @@
|
||||
"Back to this person": "この人物に戻る",
|
||||
"AI Denoise": "AIノイズ除去",
|
||||
"AI Denoise Model": "AIノイズ除去モデル",
|
||||
"AI Denoise is off: press Use on a model.": "AIノイズ除去はオフです:モデルの「使用」を押してください。",
|
||||
"AI Denoise needs a model. Install one in Settings.": "AIノイズ除去にはモデルが必要です。設定でインストールしてください。",
|
||||
"Accept & Download": "同意してダウンロード",
|
||||
"Already installed. Remove it before installing a replacement.": "インストール済みです。置き換える前に削除してください。",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "「自動」は処理装置より速い場合にグラフィックカードを使います。最初に写真を作成するとき、このコンピューターで両方の速度を計ります。",
|
||||
@@ -1734,7 +1732,6 @@
|
||||
"Inspect Denoise Model": "ノイズ除去モデルを調べる",
|
||||
"Install Denoise Model": "ノイズ除去モデルをインストール",
|
||||
"Install from file…": "ファイルからインストール…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "denoise-model.json を横に置いた独自の ONNX モデルをインストールしてください。このビルドにはモデルのダウンロードがありません。",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "ノイズ除去した画像はまだ作成されておらず、自動では作成されません(設定、AIノイズ除去)。",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft はこのモデルを知らないため、次のように仮定しました:",
|
||||
"Limit": "上限",
|
||||
@@ -1747,7 +1744,6 @@
|
||||
"Open the model's page": "モデルのページを開く",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "モデルのページをブラウザーで開き、詳細を読んだりファイルを自分で入手したりできます。",
|
||||
"Processor": "処理装置",
|
||||
"Set up AI Denoise…": "AIノイズ除去を設定…",
|
||||
"Speed": "速度",
|
||||
"Starting…": "開始中…",
|
||||
"Tested and works on this computer": "このコンピューターでテスト済み、動作します",
|
||||
@@ -1756,8 +1752,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "モデルはこのコンピューターにのみ保存されます。LightCraft がアップロードや共有をすることはありません。",
|
||||
"The processor does the work.": "処理装置が処理します。",
|
||||
"There is no model file to install": "インストールするモデルファイルがありません",
|
||||
"This build cannot run denoise models.": "このビルドではノイズ除去モデルを実行できません。",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "このビルドにはノイズ除去モデルの保存場所がないため、AIノイズ除去は使えません。(デスクトップ版にはあります。)",
|
||||
"This file cannot be used yet": "このファイルはまだ使えません",
|
||||
"Tick the box to accept the model's terms first": "まずチェックボックスをオンにしてモデルの条件に同意してください",
|
||||
"Try again": "再試行",
|
||||
@@ -1794,12 +1788,6 @@
|
||||
"Download Denoise Model": "ノイズ除去モデルをダウンロード",
|
||||
"Remove Denoise Model": "ノイズ除去モデルを削除",
|
||||
"Test Denoise Model": "ノイズ除去モデルをテスト",
|
||||
"AI Denoise is enabled on the requesting photo": "要求した写真でAIノイズ除去が有効になりました",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "インストール後、要求した写真でAIノイズ除去がオンになります。",
|
||||
"Cancel pending action": "保留中の操作をキャンセル",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "この写真でAIノイズ除去を使うには、ノイズ除去モデルをインストールしてください",
|
||||
"Pending photo action cancelled": "保留中の写真操作をキャンセルしました",
|
||||
"Pending photo action cancelled because its library or photo changed": "ライブラリまたは写真が変更されたため、保留中の写真操作をキャンセルしました",
|
||||
"ONNX model": "ONNX モデル",
|
||||
"commercial use subject to GPL conditions": "商用利用は GPL の条件に従う",
|
||||
"Decrease Rating": "評価を下げる",
|
||||
@@ -2044,7 +2032,6 @@
|
||||
"Auto-Tag from Tracklog: GPS locations for your photos from a GPX track log, matched by capture time.": "トラックログから自動タグ付け:GPX トラックログから撮影日時で照合した GPS 位置を写真に付けます。",
|
||||
"Browser version (experimental), keeping a library safe (issue #107): File ▸ Back Up Library… downloads the catalog": "ブラウザー版(試験的)、ライブラリを安全に保つ(issue #107):ファイル → ライブラリをバックアップ… でカタログと",
|
||||
"Cancel Face Model Download": "顔モデルのダウンロードをキャンセル",
|
||||
"Cancel Pending Photo Action": "保留中の写真操作をキャンセル",
|
||||
"Canon CR2 photos from the EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II and 1D Mark IV (and other": "EOS 7D、50D、60D、550D、600D、1200D、1300D、5D Mark II、1D Mark IV の Canon CR2 写真(およびその他",
|
||||
"Canon CR3 files show their full-size embedded JPEG (e.g. 6960 × 4640 on an EOS R6 Mark III) instead of the": "Canon CR3 ファイルは、フルサイズの埋め込み JPEG(例:EOS R6 Mark III で 6960 × 4640)を表示し、",
|
||||
"Canon EOS R5 Mark II C-RAW files that opened as \"preview only\" (more than half of them, depending on the": "「プレビューのみ」で開いていた Canon EOS R5 Mark II の C-RAW ファイル(撮影シーンによっては半数以上",
|
||||
|
||||
@@ -81,9 +81,6 @@
|
||||
"AI Denoise": "AI ხმაურის მოცილება",
|
||||
"AI Denoise Model": "AI ხმაურის მოცილების მოდელი",
|
||||
"AI Denoise and Find Missing Photos. Each row has the task's name, a progress bar, the count and what it is working": "AI ხმაურის მოცილება და დაკარგული ფოტოების მოძებნა. თითოეულ სტრიქონს აქვს ამოცანის სახელი, პროგრესის ზოლი, რაოდენობა და ის, რაზეც",
|
||||
"AI Denoise is enabled on the requesting photo": "AI ხმაურის მოცილება ჩართულია მომთხოვნ ფოტოზე",
|
||||
"AI Denoise is off: press Use on a model.": "AI ხმაურის მოცილება გამორთულია: მოდელზე დააჭირეთ „გამოყენებას“.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "AI ხმაურის მოცილებას მოდელი სჭირდება. დააინსტალირეთ პარამეტრებში.",
|
||||
"AI Mask Model Status": "AI ნიღბების მოდელის მდგომარეობა",
|
||||
"AI RAW denoise": "RAW-ის AI ხმაურის მოცილება",
|
||||
"AI masks with SAM 3 (Object and Describe in the Masking panel): click an object to select it (⌥-click leaves a": "AI ნიღბები SAM 3-ით (ობიექტი და აღწერა ნიღბვის პანელში): დაწკაპეთ ობიექტზე მის მოსანიშნად (⌥-დაწკაპუნება ტოვებს",
|
||||
@@ -138,7 +135,6 @@
|
||||
"After 7 days": "7 დღის შემდეგ",
|
||||
"After 90 days": "90 დღის შემდეგ",
|
||||
"After a year": "ერთი წლის შემდეგ",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "დაინსტალირების შემდეგ AI ხმაურის მოცილება მომთხოვნ ფოტოზე ჩაირთვება.",
|
||||
"Agents list and stop tasks with `activity.list` and `activity.cancel`; `ui.inspect` reports them as `activity`.": "აგენტები ამოცანებს ჩამოთვლიან და აჩერებენ `activity.list`-ით და `activity.cancel`-ით; `ui.inspect` მათ `activity`-ად აბრუნებს.",
|
||||
"Agents use `app.newLibrary {path, name}`, `app.recentLibraries` and `app.clearRecentLibraries`.": "აგენტები იყენებენ `app.newLibrary {path, name}`, `app.recentLibraries` და `app.clearRecentLibraries`.",
|
||||
"Agents: `app.export {addToPhotos, photosAlbum}`, `export.addToPhotos {paths}` for files already on disk, and": "აგენტები: `app.export {addToPhotos, photosAlbum}`, `export.addToPhotos {paths}` დისკზე უკვე არსებული ფაილებისთვის, და",
|
||||
@@ -315,9 +311,7 @@
|
||||
"Cancel Download": "ჩამოტვირთვის გაუქმება",
|
||||
"Cancel Face Model Download": "სახეების მოდელის ჩამოტვირთვის გაუქმება",
|
||||
"Cancel Interaction": "ურთიერთქმედების გაუქმება",
|
||||
"Cancel Pending Photo Action": "ფოტოს მოლოდინში მყოფი მოქმედების გაუქმება",
|
||||
"Cancel Preview Build": "წინასწარი ხედების შექმნის გაუქმება",
|
||||
"Cancel pending action": "მოლოდინში მყოფი მოქმედების გაუქმება",
|
||||
"Candidate": "კანდიდატი",
|
||||
"Canon CR2 and Pentax PEF raws get the same starting look fitted to the camera's own JPEG as ARW, NEF, RW2, RAF": "Canon CR2 და Pentax PEF RAW-ები კამერის საკუთარ JPEG-ზე მორგებულ იმავე საწყის იერს იღებს, როგორც ARW, NEF, RW2, RAF",
|
||||
"Canon CR2 highlights": "Canon CR2-ის ღია ტონები",
|
||||
@@ -1026,10 +1020,8 @@
|
||||
"Inspecting Lightroom Catalog": "Lightroom-ის კატალოგი მოწმდება",
|
||||
"Install Denoise Model": "ხმაურის მოცილების მოდელის ინსტალაცია",
|
||||
"Install Face Model": "სახეების მოდელის ინსტალაცია",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "ამ ფოტოზე AI ხმაურის მოცილების ჩასართავად დააინსტალირეთ ხმაურის მოცილების მოდელი",
|
||||
"Install from file…": "ინსტალაცია ფაილიდან…",
|
||||
"Install the SAM 3 Model": "SAM 3 მოდელის ინსტალაცია",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "დააინსტალირეთ საკუთარი ONNX მოდელი, გვერდით denoise-model.json ფაილით. ეს ვერსია მოდელების ჩამოტვირთვას არ გთავაზობთ.",
|
||||
"Instant ’70s": "მყისიერი ’70-იანები",
|
||||
"Intent:": "განზრახვა:",
|
||||
"Interface": "ინტერფეისი",
|
||||
@@ -1473,8 +1465,6 @@
|
||||
"Paste from Previous": "წინადან ჩასმა",
|
||||
"Paste pages": "გვერდების ჩასმა",
|
||||
"Pastel Haze": "პასტელის ნისლი",
|
||||
"Pending photo action cancelled": "ფოტოს მოლოდინში მყოფი მოქმედება გაუქმდა",
|
||||
"Pending photo action cancelled because its library or photo changed": "ფოტოს მოლოდინში მყოფი მოქმედება გაუქმდა, რადგან მისი ბიბლიოთეკა ან ფოტო შეიცვალა",
|
||||
"Pentax raws without black borders": "Pentax-ის RAW ფაილები შავი კიდეების გარეშე",
|
||||
"People": "ადამიანები",
|
||||
"People Count": "ადამიანების რაოდენობა",
|
||||
@@ -1889,7 +1879,6 @@
|
||||
"Set date & time": "თარიღისა და დროის დაყენება",
|
||||
"Set name": "ნაკრების სახელი",
|
||||
"Set the mix from the photo's colours": "მიქსის დაყენება ფოტოს ფერების მიხედვით",
|
||||
"Set up AI Denoise…": "AI ხმაურის მოცილების გამართვა…",
|
||||
"Setting or clearing a colour label shows a brief bottom confirmation, like rating a photo; custom label names appear in the message too.": "ფერადი იარლიყის დაყენება ან მოხსნა ქვემოთ მოკლე დადასტურებას აჩვენებს, როგორც ფოტოს შეფასება; შეტყობინებაში იარლიყების მორგებული სახელებიც ჩანს.",
|
||||
"Settings": "პარამეტრები",
|
||||
"Settings file problem": "პარამეტრების ფაილის პრობლემა",
|
||||
@@ -2149,9 +2138,7 @@
|
||||
"Thirds": "მესამედები",
|
||||
"This Computer": "ეს კომპიუტერი",
|
||||
"This build can't download the model yet. To install it by hand, put model.safetensors, vocab.json and merges.txt from Meta's facebook/sam3 in the folder above: Object and Describe work as soon as they are there.": "ამ ვერსიას მოდელის ჩამოტვირთვა ჯერ არ შეუძლია. ხელით დასაინსტალირებლად ზემოთ მითითებულ საქაღალდეში მოათავსეთ model.safetensors, vocab.json და merges.txt Meta-ს facebook/sam3-დან: „ობიექტი“ და „აღწერა“ იქ მათი გაჩენისთანავე იმუშავებს.",
|
||||
"This build cannot run denoise models.": "ამ ვერსიას ხმაურის მოცილების მოდელების გაშვება არ შეუძლია.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "ამ ვერსიას ამოცნობის მოდელების გაშვება არ შეუძლია: მათი დამატება და არჩევა შეიძლება, გამოყენება — არა.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "ამ ვერსიას ხმაურის მოცილების მოდელების შესანახი ადგილი არ აქვს, ამიტომ AI ხმაურის მოცილება მიუწვდომელია. (სამაგიდო აპლიკაციას აქვს.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "ამ ვერსიას სახეების მოდელების შესანახი ადგილი არ აქვს, ამიტომ მოდელების სია მიუწვდომელია. (სამაგიდო აპლიკაციას აქვს.)",
|
||||
"This file cannot be used yet": "ამ ფაილის გამოყენება ჯერ შეუძლებელია",
|
||||
"This folder is not available (drive disconnected?). Smart previews are not built or used until it is back or you choose another folder.": "ეს საქაღალდე მიუწვდომელია (დისკი გამოერთებულია?). ჭკვიანი წინასწარი ხედები არ იქმნება და არ გამოიყენება, სანამ ის არ დაბრუნდება ან სხვა საქაღალდეს არ აირჩევთ.",
|
||||
|
||||
@@ -1665,8 +1665,6 @@
|
||||
"Back to this person": "Wróć do tej osoby",
|
||||
"AI Denoise": "Odszumianie AI",
|
||||
"AI Denoise Model": "Model odszumiania AI",
|
||||
"AI Denoise is off: press Use on a model.": "Odszumianie AI jest wyłączone: kliknij „Użyj” przy modelu.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Odszumianie AI wymaga modelu. Zainstaluj go w Ustawieniach.",
|
||||
"Accept & Download": "Akceptuj i pobierz",
|
||||
"Already installed. Remove it before installing a replacement.": "Już zainstalowano. Usuń obecny model przed zainstalowaniem nowego.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Tryb automatyczny używa karty graficznej, jeśli jest szybsza od procesora. Przy pierwszym przetwarzaniu zdjęcia LightCraft mierzy wydajność obu urządzeń.",
|
||||
@@ -1685,7 +1683,6 @@
|
||||
"Inspect Denoise Model": "Sprawdź model odszumiania",
|
||||
"Install Denoise Model": "Zainstaluj model odszumiania",
|
||||
"Install from file…": "Zainstaluj z pliku…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Zainstaluj własny model ONNX z plikiem denoise-model.json w tym samym katalogu. W tej kompilacji nie można pobierać modeli.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Nie utworzono jeszcze odszumionego obrazu, a obrazy nie są przetwarzane automatycznie (Ustawienia, Odszumianie AI).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft nie rozpoznaje tego modelu, dlatego przyjęto następujące założenia:",
|
||||
"Limit": "Limit",
|
||||
@@ -1698,7 +1695,6 @@
|
||||
"Open the model's page": "Otwórz stronę modelu",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Otwiera stronę modelu w przeglądarce, gdzie można przeczytać o nim lub samodzielnie pobrać plik.",
|
||||
"Processor": "Procesor",
|
||||
"Set up AI Denoise…": "Skonfiguruj odszumianie AI…",
|
||||
"Speed": "Szybkość",
|
||||
"Starting…": "Uruchamianie…",
|
||||
"Tested and works on this computer": "Przetestowano — działa na tym komputerze",
|
||||
@@ -1707,8 +1703,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "Model jest przechowywany wyłącznie na tym komputerze. LightCraft nigdy go nie przesyła ani nie udostępnia.",
|
||||
"The processor does the work.": "Przetwarzanie wykonuje procesor.",
|
||||
"There is no model file to install": "Brak pliku modelu do zainstalowania",
|
||||
"This build cannot run denoise models.": "Ta kompilacja nie obsługuje modeli odszumiania.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Ta kompilacja nie ma miejsca na przechowywanie modeli odszumiania, więc odszumianie AI jest niedostępne (dostępne w aplikacji komputerowej).",
|
||||
"This file cannot be used yet": "Nie można jeszcze użyć tego pliku",
|
||||
"Tick the box to accept the model's terms first": "Najpierw zaznacz pole akceptacji warunków modelu",
|
||||
"Try again": "Spróbuj ponownie",
|
||||
@@ -1744,12 +1738,6 @@
|
||||
"Download Denoise Model": "Pobierz model odszumiania",
|
||||
"Remove Denoise Model": "Usuń model odszumiania",
|
||||
"Test Denoise Model": "Przetestuj model odszumiania",
|
||||
"AI Denoise is enabled on the requesting photo": "Odszumianie AI włączono dla wybranego zdjęcia",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Po instalacji odszumianie AI zostanie włączone dla wybranego zdjęcia.",
|
||||
"Cancel pending action": "Anuluj oczekującą operację",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Zainstaluj model odszumiania, aby włączyć odszumianie AI dla tego zdjęcia",
|
||||
"Pending photo action cancelled": "Anulowano oczekującą operację",
|
||||
"Pending photo action cancelled because its library or photo changed": "Anulowano oczekującą operację, ponieważ zmieniła się biblioteka lub zdjęcie",
|
||||
"ONNX model": "Model ONNX",
|
||||
"commercial use subject to GPL conditions": "użytek komercyjny na warunkach licencji GPL",
|
||||
"Decrease Rating": "Zmniejsz ocenę",
|
||||
@@ -2069,7 +2057,6 @@
|
||||
"Appearance Mode": "Tryb wyglądu",
|
||||
"Appearance Settings…": "Ustawienia wyglądu…",
|
||||
"Cancel Face Model Download": "Anuluj pobieranie modelu twarzy",
|
||||
"Cancel Pending Photo Action": "Anuluj oczekującą operację na zdjęciu",
|
||||
"Canon EOS R5 Mark II C-RAW files that opened as \"preview only\" (more than half of them, depending on the": "Pliki C-RAW z aparatu Canon EOS R5 Mark II, które otwierały się jako „tylko podgląd” (w zależności od",
|
||||
"scene) now develop from their sensor data with every editing tool, like the camera's other raws. Photos": "sceny ponad połowa z nich), są teraz wywoływane z danych matrycy wszystkimi narzędziami, jak inne pliki RAW. Zdjęcia",
|
||||
"imported earlier switch over with Photo ▸ Reload from Disk.": "zaimportowane wcześniej przełączysz poleceniem Zdjęcie → Wczytaj ponownie z dysku.",
|
||||
|
||||
@@ -1714,8 +1714,6 @@
|
||||
"Back to this person": "Voltar para esta pessoa",
|
||||
"AI Denoise": "Redução de ruído com IA",
|
||||
"AI Denoise Model": "Modelo de redução de ruído com IA",
|
||||
"AI Denoise is off: press Use on a model.": "A redução de ruído com IA está desativada: clique em Usar em um modelo.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "A redução de ruído com IA precisa de um modelo. Instale um em Configurações.",
|
||||
"Accept & Download": "Aceitar e baixar",
|
||||
"Already installed. Remove it before installing a replacement.": "Já instalado. Remova-o antes de instalar um substituto.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Automático usa a placa de vídeo quando ela é mais rápida que o processador: ambos são cronometrados neste computador na primeira vez que uma foto é gerada.",
|
||||
@@ -1734,7 +1732,6 @@
|
||||
"Inspect Denoise Model": "Inspecionar modelo de redução de ruído",
|
||||
"Install Denoise Model": "Instalar modelo de redução de ruído",
|
||||
"Install from file…": "Instalar de arquivo…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Instale seu próprio modelo ONNX com o denoise-model.json ao lado dele. Esta versão não oferece downloads de modelos.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "A imagem com ruído reduzido ainda não foi gerada, e as imagens não são geradas automaticamente (Configurações, Redução de ruído com IA).",
|
||||
"LightCraft does not know this model, so it assumed:": "O LightCraft não conhece este modelo, então presumiu:",
|
||||
"Limit": "Limite",
|
||||
@@ -1747,7 +1744,6 @@
|
||||
"Open the model's page": "Abrir a página do modelo",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Abre a página do próprio modelo no seu navegador, para ler sobre ele ou baixar o arquivo você mesmo.",
|
||||
"Processor": "Processador",
|
||||
"Set up AI Denoise…": "Configurar redução de ruído com IA…",
|
||||
"Speed": "Velocidade",
|
||||
"Starting…": "Iniciando…",
|
||||
"Tested and works on this computer": "Testado e funcionando neste computador",
|
||||
@@ -1756,8 +1752,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "O modelo fica somente neste computador. O LightCraft nunca o envia nem o compartilha.",
|
||||
"The processor does the work.": "O processador faz o trabalho.",
|
||||
"There is no model file to install": "Não há arquivo de modelo para instalar",
|
||||
"This build cannot run denoise models.": "Esta versão não consegue executar modelos de redução de ruído.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Esta versão não tem onde guardar modelos de redução de ruído, então a redução de ruído com IA não está disponível. (O aplicativo para desktop tem.)",
|
||||
"This file cannot be used yet": "Este arquivo ainda não pode ser usado",
|
||||
"Tick the box to accept the model's terms first": "Marque a caixa para aceitar primeiro os termos do modelo",
|
||||
"Try again": "Tentar novamente",
|
||||
@@ -1794,12 +1788,6 @@
|
||||
"Download Denoise Model": "Baixar modelo de redução de ruído",
|
||||
"Remove Denoise Model": "Remover modelo de redução de ruído",
|
||||
"Test Denoise Model": "Testar modelo de redução de ruído",
|
||||
"AI Denoise is enabled on the requesting photo": "A redução de ruído com IA está ativada na foto que a solicitou",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Após a instalação, a redução de ruído com IA será ativada na foto que a solicitou.",
|
||||
"Cancel pending action": "Cancelar ação pendente",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Instale um modelo de redução de ruído para ativar a redução de ruído com IA nesta foto",
|
||||
"Pending photo action cancelled": "Ação pendente da foto cancelada",
|
||||
"Pending photo action cancelled because its library or photo changed": "Ação pendente da foto cancelada porque a biblioteca ou a foto foi alterada",
|
||||
"ONNX model": "Modelo ONNX",
|
||||
"commercial use subject to GPL conditions": "uso comercial sujeito às condições da GPL",
|
||||
"Decrease Rating": "Diminuir avaliação",
|
||||
@@ -2025,7 +2013,6 @@
|
||||
"Sort Albums A–Z": "Ordenar álbuns de A a Z",
|
||||
"Go back to listing them by name": "Voltar a listá-los por nome",
|
||||
"Sort Contents A–Z": "Ordenar conteúdo de A a Z",
|
||||
"Cancel Pending Photo Action": "Cancelar ação pendente da foto",
|
||||
"Show Person": "Mostrar pessoa",
|
||||
"Add Face Model…": "Adicionar modelo de rostos…",
|
||||
"Cancel Face Model Download": "Cancelar download do modelo de rostos",
|
||||
|
||||
@@ -1602,8 +1602,6 @@
|
||||
"Back to this person": "Вернуться к этому человеку",
|
||||
"AI Denoise": "ИИ-шумоподавление",
|
||||
"AI Denoise Model": "Модель ИИ-шумоподавления",
|
||||
"AI Denoise is off: press Use on a model.": "ИИ-шумоподавление выключено: нажмите «Использовать» у модели.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Для ИИ-шумоподавления нужна модель. Установите её в настройках.",
|
||||
"Accept & Download": "Принять и загрузить",
|
||||
"Already installed. Remove it before installing a replacement.": "Уже установлено. Удалите перед установкой замены.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Автоматический режим использует видеокарту, когда она быстрее процессора: время обоих измеряется на этом компьютере при первой обработке фото.",
|
||||
@@ -1622,7 +1620,6 @@
|
||||
"Inspect Denoise Model": "Проверить модель шумоподавления",
|
||||
"Install Denoise Model": "Установить модель шумоподавления",
|
||||
"Install from file…": "Установить из файла…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Установите собственную модель ONNX, положив рядом denoise-model.json. В этой сборке загрузка моделей недоступна.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Его изображение с подавленным шумом ещё не создано, а изображения сами не создаются (Настройки, ИИ-шумоподавление).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft не знает эту модель и предполагает:",
|
||||
"Limit": "Ограничение",
|
||||
@@ -1636,7 +1633,6 @@
|
||||
"Open the model's page": "Открыть страницу модели",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Открывает страницу модели в браузере, чтобы прочитать о ней или получить файл самостоятельно.",
|
||||
"Processor": "Процессор",
|
||||
"Set up AI Denoise…": "Настроить ИИ-шумоподавление…",
|
||||
"Speed": "Скорость",
|
||||
"Starting…": "Запуск…",
|
||||
"Tested and works on this computer": "Проверено и работает на этом компьютере",
|
||||
@@ -1645,8 +1641,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "Модель хранится только на этом компьютере. LightCraft никогда не выгружает и не распространяет её.",
|
||||
"The processor does the work.": "Работу выполняет процессор.",
|
||||
"There is no model file to install": "Нет файла модели для установки",
|
||||
"This build cannot run denoise models.": "Эта сборка не может запускать модели шумоподавления.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "В этой сборке негде хранить модели шумоподавления, поэтому ИИ-шумоподавление недоступно. (В настольном приложении есть.)",
|
||||
"This file cannot be used yet": "Этот файл пока нельзя использовать",
|
||||
"Tick the box to accept the model's terms first": "Сначала отметьте согласие с условиями модели",
|
||||
"Try again": "Повторить попытку",
|
||||
@@ -1683,12 +1677,6 @@
|
||||
"Download Denoise Model": "Загрузить модель шумоподавления",
|
||||
"Remove Denoise Model": "Удалить модель шумоподавления",
|
||||
"Test Denoise Model": "Проверить модель шумоподавления",
|
||||
"AI Denoise is enabled on the requesting photo": "ИИ-шумоподавление включено для запросившего фото",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "После установки ИИ-шумоподавление включится для запросившего фото.",
|
||||
"Cancel pending action": "Отменить отложенное действие",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Установите модель шумоподавления, чтобы включить ИИ-шумоподавление для этого фото",
|
||||
"Pending photo action cancelled": "Отложенное действие с фото отменено",
|
||||
"Pending photo action cancelled because its library or photo changed": "Отложенное действие с фото отменено, так как изменилась библиотека или фото",
|
||||
"ONNX model": "Модель ONNX",
|
||||
"commercial use subject to GPL conditions": "коммерческое использование на условиях GPL",
|
||||
"Decrease Rating": "Уменьшить оценку",
|
||||
@@ -1999,7 +1987,6 @@
|
||||
"Camera make and model": "Производитель и модель камеры",
|
||||
"Cancel AI Mask Model Download": "Отменить загрузку модели ИИ-масок",
|
||||
"Cancel Face Model Download": "Отменить загрузку модели лиц",
|
||||
"Cancel Pending Photo Action": "Отменить отложенное действие с фото",
|
||||
"Canon CR2 photos from the EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II and 1D Mark IV (and other": "Фото Canon CR2 с EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II и 1D Mark IV (и других",
|
||||
"Canon CR3 files show their full-size embedded JPEG (e.g. 6960 × 4640 on an EOS R6 Mark III) instead of the": "Файлы Canon CR3 показывают полноразмерный встроенный JPEG (например, 6960 × 4640 на EOS R6 Mark III) вместо",
|
||||
"Capture date and time in your own format (directives below)": "Дата и время съёмки в вашем формате (директивы ниже)",
|
||||
|
||||
@@ -95,15 +95,11 @@
|
||||
"After 7 days": "Efter 7 dagar",
|
||||
"After 90 days": "Efter 90 dagar",
|
||||
"After a year": "Efter ett år",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Efter installationen aktiveras AI-brusreducering för fotot som begärde den.",
|
||||
"afterwards (issue #101): the partial write is cut off before LightCraft retries, so the next launch replays every": "efteråt (ärende #101): den ofullständiga skrivningen kapas innan LightCraft försöker igen, så nästa start spelar upp varje",
|
||||
"again. Change the period (or turn it off) in Settings → Performance.": "igen. Ändra intervallet (eller stäng av det) i Inställningar → Prestanda.",
|
||||
"against the library's originals no longer scans the whole library when nothing is at that path.": "mot bibliotekets original söker inte längre igenom hela biblioteket när det inte finns något på den sökvägen.",
|
||||
"AI Denoise": "AI-brusreducering",
|
||||
"AI Denoise is enabled on the requesting photo": "AI-brusreducering är aktiverad på fotot som begärde den",
|
||||
"AI Denoise is off: press Use on a model.": "AI-brusreducering är av: tryck på Använd på en modell.",
|
||||
"AI Denoise Model": "Modell för AI-brusreducering",
|
||||
"AI Denoise needs a model. Install one in Settings.": "AI-brusreducering behöver en modell. Installera en i Inställningar.",
|
||||
"AI Mask Model Status": "Status för AI-maskmodell",
|
||||
"AI masks with SAM 3 (Object and Describe in the Masking panel): click an object to select it (⌥-click leaves a": "AI-masker med SAM 3 (Objekt och Beskriv i panelen Maskering): klicka på ett objekt för att markera det (⌥-klick lämnar ett",
|
||||
"Album": "Album",
|
||||
@@ -291,8 +287,6 @@
|
||||
"Cancel Download": "Avbryt hämtning",
|
||||
"Cancel Face Model Download": "Avbryt hämtning av ansiktsmodell",
|
||||
"Cancel Interaction": "Avbryt interaktion",
|
||||
"Cancel pending action": "Avbryt väntande åtgärd",
|
||||
"Cancel Pending Photo Action": "Avbryt väntande fotoåtgärd",
|
||||
"Cancel Preview Build": "Avbryt bygge av förhandsgranskningar",
|
||||
"Candidate": "Kandidat",
|
||||
"Canon CR2 photos from the EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II and 1D Mark IV (and other": "Canon CR2-foton från EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II och 1D Mark IV (och andra",
|
||||
@@ -1022,12 +1016,10 @@
|
||||
"Inspect Lightroom Catalog": "Inspektera Lightroom-katalog",
|
||||
"Inspect Photo": "Inspektera foto",
|
||||
"Inspecting Lightroom Catalog": "Inspekterar Lightroom-katalog",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Installera en brusreduceringsmodell för att aktivera AI-brusreducering för det här fotot",
|
||||
"Install Denoise Model": "Installera brusreduceringsmodell",
|
||||
"Install Face Model": "Installera ansiktsmodell",
|
||||
"Install from file…": "Installera från fil…",
|
||||
"Install the SAM 3 Model": "Installera SAM 3-modellen",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Installera din egen ONNX-modell med denoise-model.json bredvid. Den här versionen erbjuder inga modellnedladdningar.",
|
||||
"installed": "installerad",
|
||||
"Instant ’70s": "Instant 70-tal",
|
||||
"Intent:": "Återgivningsmetod:",
|
||||
@@ -1532,8 +1524,6 @@
|
||||
"Paste Settings from Previous": "Klistra in inställningar från föregående",
|
||||
"Pastel Haze": "Pastelldis",
|
||||
"Pen Pressure": "Penntryck",
|
||||
"Pending photo action cancelled": "Väntande fotoåtgärd avbröts",
|
||||
"Pending photo action cancelled because its library or photo changed": "Väntande fotoåtgärd avbröts eftersom dess bibliotek eller foto ändrades",
|
||||
"People": "Människor",
|
||||
"People Count": "Antal personer",
|
||||
"Percent": "Procent",
|
||||
@@ -1962,7 +1952,6 @@
|
||||
"Set Rating": "Ange betyg",
|
||||
"Set the mix from the photo's colours": "Ange mixen utifrån fotots färger",
|
||||
"Set Top of Stack": "Ange överst i stapeln",
|
||||
"Set up AI Denoise…": "Konfigurera AI-brusreducering…",
|
||||
"Settings": "Inställningar",
|
||||
"Settings file problem": "Problem med inställningsfil",
|
||||
"Settings files are never quietly reset (issue #103): a damaged `prefs.json`, `presets.json` or `view.json` is kept": "Inställningsfiler återställs aldrig i tysthet (ärende #103): en skadad `prefs.json`, `presets.json` eller `view.json` behålls",
|
||||
@@ -2219,9 +2208,7 @@
|
||||
"They move to Recently Deleted and can be restored; no file on disk is touched.": "De flyttas till Nyligen raderade och kan återställas; inga filer på disken påverkas.",
|
||||
"Thirds": "Tredjedelar",
|
||||
"This build can't download the model yet. To install it by hand, put model.safetensors, vocab.json and merges.txt from Meta's facebook/sam3 in the folder above: Object and Describe work as soon as they are there.": "Den här versionen kan inte hämta modellen än. Om du vill installera den manuellt lägger du model.safetensors, vocab.json och merges.txt från Metas facebook/sam3 i mappen ovan: Objekt och Beskriv fungerar så snart de finns där.",
|
||||
"This build cannot run denoise models.": "Den här versionen kan inte köra brusreduceringsmodeller.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "Den här versionen kan inte köra igenkänningsmodeller: de kan läggas till och väljas, men inte användas.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Den här versionen har ingenstans att spara brusreduceringsmodeller, så AI-brusreducering är inte tillgänglig. (Skrivbordsappen har det.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "Den här versionen har ingenstans att spara ansiktsmodeller, så modellistan är inte tillgänglig. (Skrivbordsappen har det.)",
|
||||
"This Computer": "Den här datorn",
|
||||
"This file cannot be used yet": "Den här filen kan inte användas än",
|
||||
|
||||
@@ -1705,8 +1705,6 @@
|
||||
"Back to this person": "Повернутися до цієї особи",
|
||||
"AI Denoise": "ШІ: усунення шуму",
|
||||
"AI Denoise Model": "Модель усунення шуму ШІ",
|
||||
"AI Denoise is off: press Use on a model.": "Усунення шуму ШІ вимкнено: натисніть «Використовувати» на моделі.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Для усунення шуму ШІ потрібна модель. Установіть її в налаштуваннях.",
|
||||
"Accept & Download": "Прийняти й завантажити",
|
||||
"Already installed. Remove it before installing a replacement.": "Уже встановлено. Видаліть перед установленням заміни.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Автоматичний режим використовує відеокарту, коли вона швидша за процесор: час обох вимірюється на цьому комп’ютері під час першої обробки фото.",
|
||||
@@ -1725,7 +1723,6 @@
|
||||
"Inspect Denoise Model": "Перевірити модель усунення шуму",
|
||||
"Install Denoise Model": "Установити модель усунення шуму",
|
||||
"Install from file…": "Установити з файлу…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Установіть власну модель ONNX із denoise-model.json поруч. Ця збірка не пропонує завантаження моделей.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Зображення з усуненим шумом ще не створено, а автоматичне створення вимкнено (Налаштування, ШІ: усунення шуму).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft не знає цю модель, тому припускає:",
|
||||
"Limit": "Обмеження",
|
||||
@@ -1738,7 +1735,6 @@
|
||||
"Open the model's page": "Відкрити сторінку моделі",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Відкриває сторінку моделі в браузері, щоб прочитати про неї або отримати файл самостійно.",
|
||||
"Processor": "Процесор",
|
||||
"Set up AI Denoise…": "Налаштувати усунення шуму ШІ…",
|
||||
"Starting…": "Запуск…",
|
||||
"Tested and works on this computer": "Перевірено й працює на цьому комп’ютері",
|
||||
"The denoise model is installed and in use: the AI Denoise Amount slider under Detail now works": "Модель усунення шуму встановлено й використовується: повзунок інтенсивності усунення шуму ШІ в деталях тепер працює",
|
||||
@@ -1746,8 +1742,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "Модель зберігається лише на цьому комп’ютері. LightCraft ніколи не вивантажує й не поширює її.",
|
||||
"The processor does the work.": "Роботу виконує процесор.",
|
||||
"There is no model file to install": "Немає файлу моделі для встановлення",
|
||||
"This build cannot run denoise models.": "Ця збірка не може запускати моделі усунення шуму.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Ця збірка не має місця для моделей усунення шуму, тому ця функція ШІ недоступна. (Настільний застосунок має.)",
|
||||
"This file cannot be used yet": "Цей файл поки не можна використовувати",
|
||||
"Tick the box to accept the model's terms first": "Спочатку позначте прийняття умов моделі",
|
||||
"Try again": "Спробувати знову",
|
||||
@@ -1784,12 +1778,6 @@
|
||||
"Download Denoise Model": "Завантажити модель усунення шуму",
|
||||
"Remove Denoise Model": "Видалити модель усунення шуму",
|
||||
"Test Denoise Model": "Перевірити модель усунення шуму",
|
||||
"AI Denoise is enabled on the requesting photo": "Усунення шуму ШІ ввімкнено для фото, що запросило дію",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Після встановлення усунення шуму ШІ ввімкнеться для фото, що запросило дію.",
|
||||
"Cancel pending action": "Скасувати відкладену дію",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Установіть модель усунення шуму, щоб увімкнути його для цього фото",
|
||||
"Pending photo action cancelled": "Відкладену дію фото скасовано",
|
||||
"Pending photo action cancelled because its library or photo changed": "Відкладену дію фото скасовано, оскільки змінилася бібліотека або фото",
|
||||
"ONNX model": "Модель ONNX",
|
||||
"commercial use subject to GPL conditions": "комерційне використання за умов GPL",
|
||||
"\"saved in memory but not written to disk\", the top bar shows a warning, and LightCraft keeps retrying until the": "«збережено в пам’яті, але не записано на диск», верхня панель показує попередження, а LightCraft повторює спроби, доки",
|
||||
@@ -1950,7 +1938,6 @@
|
||||
"Sort Albums A–Z": "Сортувати альбоми А–Я",
|
||||
"Go back to listing them by name": "Повернутися до списку за назвою",
|
||||
"Sort Contents A–Z": "Сортувати вміст А–Я",
|
||||
"Cancel Pending Photo Action": "Скасувати відкладену дію фото",
|
||||
"Show Person": "Показати особу",
|
||||
"Add Face Model…": "Додати модель облич…",
|
||||
"Cancel Face Model Download": "Скасувати завантаження моделі облич",
|
||||
|
||||
@@ -35,9 +35,6 @@
|
||||
"A sleeping NAS, a dropped network share or a USB drive spinning up no longer freezes the window (issue #104):": "NAS đang ngủ, ổ mạng bị ngắt hoặc ổ USB đang quay lên không còn làm đóng băng cửa sổ (issue #104):",
|
||||
"AI Denoise": "Khử nhiễu AI",
|
||||
"AI Denoise Model": "Mô hình khử nhiễu AI",
|
||||
"AI Denoise is enabled on the requesting photo": "Khử nhiễu AI đã bật trên ảnh yêu cầu",
|
||||
"AI Denoise is off: press Use on a model.": "Khử nhiễu AI đang tắt: nhấn Dùng trên một mô hình.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "Khử nhiễu AI cần một mô hình. Hãy cài trong Cài đặt.",
|
||||
"AI Mask Model Status": "Trạng thái mô hình mặt nạ AI",
|
||||
"AI masks with SAM 3 (Object and Describe in the Masking panel): click an object to select it (⌥-click leaves a": "Mặt nạ AI với SAM 3 (Object và Describe trong bảng Mặt nạ): bấm vào đối tượng để chọn (⌥-click để lại",
|
||||
"About": "Giới thiệu",
|
||||
@@ -88,7 +85,6 @@
|
||||
"After 7 days": "Sau 7 ngày",
|
||||
"After 90 days": "Sau 90 ngày",
|
||||
"After a year": "Sau một năm",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "Sau khi cài, Khử nhiễu AI sẽ bật cho ảnh yêu cầu.",
|
||||
"Album": "Album",
|
||||
"Albums": "Album",
|
||||
"Albums hold library photos: Add to My Photos first": "Album chứa ảnh thư viện: hãy Thêm vào Ảnh của tôi trước",
|
||||
@@ -243,9 +239,7 @@
|
||||
"Cancel Download": "Hủy tải",
|
||||
"Cancel Face Model Download": "Hủy tải mô hình khuôn mặt",
|
||||
"Cancel Interaction": "Hủy tương tác",
|
||||
"Cancel Pending Photo Action": "Hủy thao tác ảnh đang chờ",
|
||||
"Cancel Preview Build": "Hủy tạo bản xem trước",
|
||||
"Cancel pending action": "Hủy thao tác đang chờ",
|
||||
"Candidate": "Ảnh ứng viên",
|
||||
"Canon CR2 photos from the EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II and 1D Mark IV (and other": "Ảnh Canon CR2 từ EOS 7D, 50D, 60D, 550D, 600D, 1200D, 1300D, 5D Mark II và 1D Mark IV (và các",
|
||||
"Canon CR3 files show their full-size embedded JPEG (e.g. 6960 × 4640 on an EOS R6 Mark III) instead of the": "Tệp Canon CR3 hiển thị JPEG nhúng full-size (ví dụ 6960 × 4640 trên EOS R6 Mark III) thay vì",
|
||||
@@ -880,10 +874,8 @@
|
||||
"Inspecting Lightroom Catalog": "Đang kiểm tra catalog Lightroom",
|
||||
"Install Denoise Model": "Cài mô hình khử nhiễu",
|
||||
"Install Face Model": "Cài mô hình khuôn mặt",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Cài mô hình khử nhiễu để bật AI Khử nhiễu cho ảnh này",
|
||||
"Install from file…": "Cài từ tệp…",
|
||||
"Install the SAM 3 Model": "Cài mô hình SAM 3",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Cài mô hình ONNX của bạn kèm denoise-model.json bên cạnh. Bản build này không tải mô hình.",
|
||||
"Instant ’70s": "Thập niên 70 tức thì",
|
||||
"Intent:": "Ý định:",
|
||||
"Interface": "Giao diện",
|
||||
@@ -1281,8 +1273,6 @@
|
||||
"Paste from Previous": "Dán từ ảnh trước",
|
||||
"Paste pages": "Dán trang",
|
||||
"Pastel Haze": "Sương pastel",
|
||||
"Pending photo action cancelled": "Đã hủy thao tác ảnh đang chờ",
|
||||
"Pending photo action cancelled because its library or photo changed": "Đã hủy thao tác ảnh đang chờ vì thư viện hoặc ảnh đã thay đổi",
|
||||
"People": "Người",
|
||||
"People Count": "Số người",
|
||||
"Percent": "Phần trăm",
|
||||
@@ -1668,7 +1658,6 @@
|
||||
"Set date & time": "Đặt ngày & giờ",
|
||||
"Set name": "Đặt tên",
|
||||
"Set the mix from the photo's colours": "Đặt hỗn hợp từ màu của ảnh",
|
||||
"Set up AI Denoise…": "Thiết lập AI Khử nhiễu…",
|
||||
"Settings": "Cài đặt",
|
||||
"Settings file problem": "Lỗi tệp thiết lập",
|
||||
"Settings files are never quietly reset (issue #103): a damaged `prefs.json`, `presets.json` or `view.json` is kept": "Tệp cài đặt không bao giờ im lặng đặt lại (issue #103): `prefs.json`, `presets.json` hoặc `view.json` hỏng được giữ",
|
||||
@@ -1873,9 +1862,7 @@
|
||||
"Thirds": "Một phần ba",
|
||||
"This Computer": "Máy này",
|
||||
"This build can't download the model yet. To install it by hand, put model.safetensors, vocab.json and merges.txt from Meta's facebook/sam3 in the folder above: Object and Describe work as soon as they are there.": "Bản build này chưa tải mô hình được. Cài tay: đặt model.safetensors, vocab.json và merges.txt từ facebook/sam3 của Meta vào thư mục trên: Object và Describe hoạt động ngay khi có đủ.",
|
||||
"This build cannot run denoise models.": "Bản build này không chạy được mô hình khử nhiễu.",
|
||||
"This build cannot run recognition models: they can be added and chosen, not used.": "Bản build này không chạy mô hình nhận dạng: có thể thêm và chọn, không dùng được.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "Bản build này không có chỗ lưu mô hình khử nhiễu, nên AI Denoise không khả dụng. (App desktop có.)",
|
||||
"This build has nowhere to keep face models, so the model list is not available. (The desktop app has.)": "Bản build này không có chỗ lưu mô hình khuôn mặt, nên danh sách mô hình không khả dụng. (App desktop có.)",
|
||||
"This file cannot be used yet": "Tệp này chưa dùng được",
|
||||
"This folder is not available (drive disconnected?). Smart previews are not built or used until it is back or you choose another folder.": "Thư mục không khả dụng (ổ đã rút?). Xem trước thông minh không được tạo hay dùng cho đến khi ổ trở lại hoặc bạn chọn thư mục khác.",
|
||||
|
||||
@@ -1708,8 +1708,6 @@
|
||||
"Back to this person": "返回此人",
|
||||
"AI Denoise": "AI 降噪",
|
||||
"AI Denoise Model": "AI 降噪模型",
|
||||
"AI Denoise is off: press Use on a model.": "AI 降噪已关闭:请在某个模型上点击“使用”。",
|
||||
"AI Denoise needs a model. Install one in Settings.": "AI 降噪需要模型。请在设置中安装一个。",
|
||||
"Accept & Download": "接受并下载",
|
||||
"Already installed. Remove it before installing a replacement.": "已安装。安装替代模型前请先将其移除。",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "自动模式会在显卡快于处理器时使用显卡:两者都会在首次生成照片时于本机计时比较。",
|
||||
@@ -1728,7 +1726,6 @@
|
||||
"Inspect Denoise Model": "查看降噪模型",
|
||||
"Install Denoise Model": "安装降噪模型",
|
||||
"Install from file…": "从文件安装…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "请自行安装 ONNX 模型,并在其旁边放置 denoise-model.json。此版本不提供模型下载。",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "该照片的降噪结果尚未生成,而且不会自动生成(设置、AI 降噪)。",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft 不认识此模型,因此按以下假设处理:",
|
||||
"Limit": "上限",
|
||||
@@ -1741,7 +1738,6 @@
|
||||
"Open the model's page": "打开该模型的页面",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "在浏览器中打开该模型的主页,以便查阅说明或自行获取文件。",
|
||||
"Processor": "处理器",
|
||||
"Set up AI Denoise…": "设置 AI 降噪…",
|
||||
"Speed": "速度",
|
||||
"Starting…": "正在启动…",
|
||||
"Tested and works on this computer": "已在本机测试通过并可正常使用",
|
||||
@@ -1750,8 +1746,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "模型仅保存在本机。LightCraft 绝不会上传或分享它。",
|
||||
"The processor does the work.": "由处理器完成运算。",
|
||||
"There is no model file to install": "没有可安装的模型文件",
|
||||
"This build cannot run denoise models.": "此版本无法运行降噪模型。",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "此版本没有存放降噪模型的位置,因此无法使用 AI 降噪。(桌面版可以。)",
|
||||
"This file cannot be used yet": "此文件暂时无法使用",
|
||||
"Tick the box to accept the model's terms first": "请先勾选以接受该模型的条款",
|
||||
"Try again": "重试",
|
||||
@@ -1788,12 +1782,6 @@
|
||||
"Download Denoise Model": "下载降噪模型",
|
||||
"Remove Denoise Model": "移除降噪模型",
|
||||
"Test Denoise Model": "测试降噪模型",
|
||||
"AI Denoise is enabled on the requesting photo": "已在发起请求的照片上启用 AI 降噪",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "安装完成后,将为发起请求的照片开启 AI 降噪。",
|
||||
"Cancel pending action": "取消待处理操作",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "安装降噪模型后即可在此照片上启用 AI 降噪",
|
||||
"Pending photo action cancelled": "已取消待处理的照片操作",
|
||||
"Pending photo action cancelled because its library or photo changed": "待处理的照片操作已取消,因为其所属图库或照片发生了变化",
|
||||
"ONNX model": "ONNX 模型",
|
||||
"commercial use subject to GPL conditions": "商用须遵循 GPL 条款",
|
||||
"Decrease Rating": "降低星级",
|
||||
@@ -2013,7 +2001,6 @@
|
||||
"Remove from favorites": "从收藏中移除",
|
||||
"Add Face Model…": "添加人脸模型…",
|
||||
"Cancel Face Model Download": "取消人脸模型下载",
|
||||
"Cancel Pending Photo Action": "取消待处理的照片操作",
|
||||
"Choose Face Recognition Model": "选择人脸识别模型",
|
||||
"Choose a model below (Use) to start.": "请在下方选择模型(点击“使用”)以开始。",
|
||||
"Detect Faces": "检测人脸",
|
||||
|
||||
@@ -1714,8 +1714,6 @@
|
||||
"Back to this person": "Back to this person",
|
||||
"AI Denoise": "AI Denoise",
|
||||
"AI Denoise Model": "AI Denoise Model",
|
||||
"AI Denoise is off: press Use on a model.": "AI Denoise is off: press Use on a model.",
|
||||
"AI Denoise needs a model. Install one in Settings.": "AI Denoise needs a model. Install one in Settings.",
|
||||
"Accept & Download": "Accept & Download",
|
||||
"Already installed. Remove it before installing a replacement.": "Already installed. Remove it before installing a replacement.",
|
||||
"Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.": "Automatic uses the graphics card where it is faster than the processor: both are timed on this computer the first time a photo is made.",
|
||||
@@ -1734,7 +1732,6 @@
|
||||
"Inspect Denoise Model": "Inspect Denoise Model",
|
||||
"Install Denoise Model": "Install Denoise Model",
|
||||
"Install from file…": "Install from file…",
|
||||
"Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.": "Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.",
|
||||
"Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).": "Its denoised picture is not made yet, and pictures are not made on their own (Settings, AI Denoise).",
|
||||
"LightCraft does not know this model, so it assumed:": "LightCraft does not know this model, so it assumed:",
|
||||
"Limit": "Limit",
|
||||
@@ -1747,7 +1744,6 @@
|
||||
"Open the model's page": "Open the model's page",
|
||||
"Opens the model's own page in your browser, to read about it or get the file yourself.": "Opens the model's own page in your browser, to read about it or get the file yourself.",
|
||||
"Processor": "Processor",
|
||||
"Set up AI Denoise…": "Set up AI Denoise…",
|
||||
"Speed": "Speed",
|
||||
"Starting…": "Starting…",
|
||||
"Tested and works on this computer": "Tested and works on this computer",
|
||||
@@ -1756,8 +1752,6 @@
|
||||
"The model is kept on this computer only. LightCraft never uploads or shares it.": "The model is kept on this computer only. LightCraft never uploads or shares it.",
|
||||
"The processor does the work.": "The processor does the work.",
|
||||
"There is no model file to install": "There is no model file to install",
|
||||
"This build cannot run denoise models.": "This build cannot run denoise models.",
|
||||
"This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)": "This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)",
|
||||
"This file cannot be used yet": "This file cannot be used yet",
|
||||
"Tick the box to accept the model's terms first": "Tick the box to accept the model's terms first",
|
||||
"Try again": "Try again",
|
||||
@@ -1794,12 +1788,6 @@
|
||||
"Download Denoise Model": "Download Denoise Model",
|
||||
"Remove Denoise Model": "Remove Denoise Model",
|
||||
"Test Denoise Model": "Test Denoise Model",
|
||||
"AI Denoise is enabled on the requesting photo": "AI Denoise is enabled on the requesting photo",
|
||||
"After installation, AI Denoise will turn on for the requesting photo.": "After installation, AI Denoise will turn on for the requesting photo.",
|
||||
"Cancel pending action": "Cancel pending action",
|
||||
"Install a denoise model to enable AI Denoise on this photo": "Install a denoise model to enable AI Denoise on this photo",
|
||||
"Pending photo action cancelled": "Pending photo action cancelled",
|
||||
"Pending photo action cancelled because its library or photo changed": "Pending photo action cancelled because its library or photo changed",
|
||||
"ONNX model": "ONNX model",
|
||||
"commercial use subject to GPL conditions": "commercial use subject to GPL conditions",
|
||||
"Decrease Rating": "降低評分",
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{
|
||||
MAX_PENDING_SHOTS, MAX_SHOT_BYTES, MAX_SHOT_TOTAL_BYTES, MAX_TEXTURE_SIDE, PendingGesture, PendingShot, Perf, Receiver, SCREEN_PROFILE,
|
||||
SCREENSHOT_FALLBACK_MS, SCREENSHOT_SETTLE_MS, SHOT_FORCE_BUSY_MS, SHOT_SETTLE_FRAMES, SHOT_SETTLE_MS, Sender, Session, ShotGeometry,
|
||||
TOAST_SECONDS, UiState, Value, docking, drop_overlay, export_task, focus_scan, frame_rate, headless, i18n, import, lightroom_import, menus,
|
||||
merge, model_setup, panels, pick, recheck, render, shortcuts, slideshow_export, state, sync, tasks, theme, updates_ui, widgets,
|
||||
merge, panels, pick, recheck, render, shortcuts, slideshow_export, state, sync, tasks, theme, updates_ui, widgets,
|
||||
};
|
||||
|
||||
mod control;
|
||||
@@ -142,7 +142,6 @@ impl LightcraftApp {
|
||||
alt_asks_for_library: false,
|
||||
recent_checks: Default::default(),
|
||||
activity_expanded: false,
|
||||
model_setup: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,9 +202,6 @@ impl LightcraftApp {
|
||||
/// [`LightcraftApp::run`], keeping what kind of error a refusal is: for code that decides on it
|
||||
/// (offer a model's download, treat a cancel as one) instead of reading the message.
|
||||
pub fn run_typed(&mut self, id: &str, params: Value) -> Result<Value, CommandError> {
|
||||
if let Some(result) = model_setup::intercept(self, id, ¶ms) {
|
||||
return result.map_err(CommandError::from);
|
||||
}
|
||||
if let Some(r) = menus::run_ui_command(self, id, ¶ms) {
|
||||
if r.is_ok() {
|
||||
docking::reveal_command(self, id)?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
LightcraftApp, docking, drop_overlay, export_task, focus_scan, import, lightroom_import, merge, model_setup, monotonic_ms, panels, pick, recheck,
|
||||
shortcuts, slideshow_export, state, sync, tasks, theme, updates_ui, widgets,
|
||||
LightcraftApp, docking, drop_overlay, export_task, focus_scan, import, lightroom_import, merge, monotonic_ms, panels, pick, recheck, shortcuts,
|
||||
slideshow_export, state, sync, tasks, theme, updates_ui, widgets,
|
||||
};
|
||||
|
||||
impl LightcraftApp {
|
||||
@@ -81,7 +81,6 @@ impl LightcraftApp {
|
||||
self.slideshow_tick(ctx, now);
|
||||
panels::denoise::pump_background(self, ctx, now);
|
||||
panels::faces::pump_background(self, ctx, now);
|
||||
model_setup::pump(self, ctx, now);
|
||||
focus_scan::pump(self, ctx, now);
|
||||
// auto import: list the watched folder every few seconds (on a worker thread: it may be on
|
||||
// a network share), then import what's new like any import (also on a worker thread)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/// A raw photo is offered the AI Denoise switch with no set-up and one click turns it on with the built-in
|
||||
/// denoiser; Settings still offers installing a model, and a photo that is not raw is not offered it.
|
||||
#[test]
|
||||
fn detail_offers_ai_denoise_for_raw_photos_and_leads_to_its_settings() {
|
||||
fn detail_offers_ai_denoise_for_raw_photos_without_any_set_up() {
|
||||
use crate::state::Dialog;
|
||||
use lightcraft_catalog::{MediaKind, Op, Photo, PhotoId, Source};
|
||||
let mut h = demo([1400.0, 900.0]);
|
||||
@@ -29,13 +31,17 @@ fn detail_offers_ai_denoise_for_raw_photos_and_leads_to_its_settings() {
|
||||
h.step();
|
||||
h.step();
|
||||
let w = widgets(&mut h);
|
||||
assert!(w.contains("\"denoise:setup\""), "a raw photo with no model is offered the setup: {w}");
|
||||
// One click lands in Settings, with local installation available even without a download offer.
|
||||
let r = h.request("ui.clickWidget", json!({"id": "denoise:setup"}), t);
|
||||
assert!(w.contains("\"denoise:enabled\"") && !w.contains("\"denoise:setup\""), "a raw photo is offered the switch, with no set-up: {w}");
|
||||
// One click turns it on with the built-in denoiser: nothing to install first.
|
||||
let r = h.request("ui.clickWidget", json!({"id": "denoise:enabled"}), t);
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
h.step();
|
||||
h.step();
|
||||
assert_eq!(h.app.ui.dialog, Some(Dialog::Settings { tab: "denoise".into() }));
|
||||
assert_eq!(h.app.ui.dialog, None);
|
||||
assert!(h.app.session.develop_of(id).is_some_and(|d| d.enhance.denoise_enabled()));
|
||||
assert_eq!(h.app.session.execute("denoise.status", &json!({})).unwrap()["model"]["id"], "builtin");
|
||||
// Settings still offers installing a model of one's own.
|
||||
h.app.ui.dialog = Some(Dialog::Settings { tab: "denoise".into() });
|
||||
h.settle(SETTLE);
|
||||
let listed = h.app.session.execute("denoise.models.list", &json!({})).unwrap();
|
||||
assert_eq!(listed["models"].as_array().unwrap().len(), lightcraft_denoise::known::all().len(), "{listed}");
|
||||
@@ -50,7 +56,7 @@ fn detail_offers_ai_denoise_for_raw_photos_and_leads_to_its_settings() {
|
||||
h.settle(SETTLE);
|
||||
h.step();
|
||||
h.step();
|
||||
assert!(!widgets(&mut h).contains("\"denoise:setup\""), "nothing is offered for a photo denoise does not apply to");
|
||||
assert_eq!(h.app.session.denoise_photo_state(h.app.session.active().unwrap()), lightcraft_engine::denoise::PhotoState::NotApplicable);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ pub mod links;
|
||||
pub mod loupe_timing;
|
||||
pub mod menus;
|
||||
mod missing_sweep;
|
||||
mod model_setup;
|
||||
pub mod panels;
|
||||
pub mod pick;
|
||||
pub mod recheck;
|
||||
@@ -146,7 +145,6 @@ impl QuitPrompt {
|
||||
}
|
||||
|
||||
pub struct LightcraftApp {
|
||||
pub(crate) model_setup: model_setup::Pending,
|
||||
/// Per-catalog-revision caches of library-wide results the panels show every frame
|
||||
/// (expensive on big libraries).
|
||||
pub caches: Caches,
|
||||
|
||||
@@ -60,7 +60,6 @@ pub fn language_from_command(id: &str) -> Option<crate::i18n::Locale> {
|
||||
pub const UI_COMMANDS: &[UiCommand] = &[
|
||||
("ui.dock", "Arrange Panel", None, ""),
|
||||
("ui.dock.reset", "Reset Panel Layout", None, "Window"),
|
||||
("modelSetup.cancel", "Cancel Pending Photo Action", None, ""),
|
||||
("view.photoGrid", "Photo Grid", None, "View"),
|
||||
("view.squareGrid", "Square Grid", None, "View"),
|
||||
// G: Photo Grid ↔ Square Grid (from other views: the photo grid)
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
//! Resume a denoise request after model setup, bound to its original photo and library.
|
||||
|
||||
use crate::i18n::tr;
|
||||
use crate::{LightcraftApp, state::Dialog};
|
||||
use lightcraft_catalog::{PhotoId, Source};
|
||||
use lightcraft_engine::denoise::PhotoState;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
struct Request {
|
||||
library: u64,
|
||||
photo: PhotoId,
|
||||
source: Source,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
fn capture(app: &LightcraftApp, id: PhotoId) -> Result<Self, String> {
|
||||
let photo = app.session.catalog.photo(id).filter(|p| !p.deleted).ok_or("the requested photo is no longer available")?;
|
||||
Ok(Self { library: app.session.library_generation(), photo: id, source: photo.source.clone() })
|
||||
}
|
||||
|
||||
fn valid(&self, app: &LightcraftApp) -> bool {
|
||||
self.library == app.session.library_generation()
|
||||
&& app.session.catalog.photo(self.photo).is_some_and(|p| !p.deleted && p.source == self.source)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Pending {
|
||||
denoise: Option<Request>,
|
||||
next_check: f64,
|
||||
}
|
||||
|
||||
pub(crate) fn denoise_requested(app: &LightcraftApp, id: PhotoId) -> bool {
|
||||
app.model_setup.denoise.as_ref().is_some_and(|r| r.photo == id && r.valid(app))
|
||||
}
|
||||
|
||||
pub(crate) fn intercept(app: &mut LightcraftApp, command: &str, params: &Value) -> Option<Result<Value, String>> {
|
||||
if matches!(command, "app.openLibrary" | "file.restoreLibrary") {
|
||||
app.model_setup = Pending::default();
|
||||
return None;
|
||||
}
|
||||
if command == "modelSetup.cancel" {
|
||||
if params.get("kind").and_then(Value::as_str) != Some("denoise") {
|
||||
return Some(Err("modelSetup.cancel: use kind denoise".into()));
|
||||
}
|
||||
app.model_setup.denoise = None;
|
||||
app.ui.status = tr("Pending photo action cancelled").into();
|
||||
return Some(Ok(json!({"cancelled": true})));
|
||||
}
|
||||
if command == "denoise.models.downloadCancel" {
|
||||
app.model_setup.denoise = None;
|
||||
}
|
||||
if command != "denoise.toggle" {
|
||||
return None;
|
||||
}
|
||||
let id = match params.get("id") {
|
||||
Some(v) => match v.as_u64() {
|
||||
Some(id) => PhotoId(id),
|
||||
None => return Some(Err("denoise.toggle: id must be a photo id".into())),
|
||||
},
|
||||
None => match app.session.active() {
|
||||
Some(id) => id,
|
||||
None => return Some(Err("select a raw photo".into())),
|
||||
},
|
||||
};
|
||||
let enabled = app.session.develop_of(id).is_some_and(|d| d.enhance.denoise_enabled());
|
||||
let on = match params.get("enabled") {
|
||||
Some(v) => match v.as_bool() {
|
||||
Some(on) => on,
|
||||
None => return Some(Err("denoise.toggle: enabled must be true or false".into())),
|
||||
},
|
||||
None => !enabled && !denoise_requested(app, id),
|
||||
};
|
||||
if !on {
|
||||
app.model_setup.denoise = None;
|
||||
return Some(app.session.execute("denoise.toggle", &json!({"id": id.0, "enabled": false})).map_err(|e| e.to_string()));
|
||||
}
|
||||
let _ = app.session.execute("denoise.status", &json!({"id": id.0}));
|
||||
if !matches!(app.session.denoise_photo_state(id), PhotoState::NoModel) {
|
||||
return None;
|
||||
}
|
||||
if app.session.execute("denoise.models.list", &json!({})).ok().is_none_or(|v| v["dir"].is_null()) {
|
||||
return None;
|
||||
}
|
||||
Some(Request::capture(app, id).map(|request| {
|
||||
app.model_setup.denoise = Some(request);
|
||||
app.model_setup.next_check = 0.0;
|
||||
app.ui.dialog = Some(Dialog::Settings { tab: "denoise".into() });
|
||||
app.ui.status = tr("Install a denoise model to enable AI Denoise on this photo").into();
|
||||
json!({"setupRequired": true, "photo": id.0})
|
||||
}))
|
||||
}
|
||||
|
||||
/// Show the pending model-setup note for `kind` in the model dialog, with a button that cancels
|
||||
/// the pending action. Does nothing unless a valid denoise setup is waiting.
|
||||
pub(crate) fn notice(app: &mut LightcraftApp, ui: &mut egui::Ui, kind: &str) {
|
||||
if kind != "denoise" || !app.model_setup.denoise.as_ref().is_some_and(|r| r.valid(app)) {
|
||||
return;
|
||||
}
|
||||
ui.add(egui::Label::new(tr("After installation, AI Denoise will turn on for the requesting photo.")).wrap());
|
||||
let r = ui.small_button(tr("Cancel pending action"));
|
||||
crate::widgets::register(ui, "modelSetup:cancel:denoise", r.rect);
|
||||
if r.clicked() {
|
||||
let _ = app.run("modelSetup.cancel", json!({"kind": "denoise"}));
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
|
||||
/// The model setup was dismissed with nothing on the way: neither Settings nor a model's terms
|
||||
/// are showing, no model download or installation is running, and the photo still has no model.
|
||||
fn abandoned(app: &mut LightcraftApp) -> bool {
|
||||
if matches!(app.ui.dialog, Some(Dialog::Settings { .. } | Dialog::DenoiseModel { .. })) {
|
||||
return false;
|
||||
}
|
||||
let Some(photo) = app.model_setup.denoise.as_ref().map(|r| r.photo) else { return false };
|
||||
if !matches!(app.session.denoise_photo_state(photo), PhotoState::NoModel) {
|
||||
return false;
|
||||
}
|
||||
let Ok(v) = app.session.execute("denoise.models.downloads", &json!({})) else { return false };
|
||||
!v["downloads"].as_array().into_iter().flatten().any(|d| matches!(d["state"].as_str(), Some("running" | "done" | "installing" | "installed")))
|
||||
}
|
||||
|
||||
/// Advance a pending model setup. An abandoned setup is cancelled on any call (the
|
||||
/// abandonment/download probe is not throttled); while another interaction is open it waits, and
|
||||
/// otherwise it checks the photo's model state at most every 250 ms. A photo that still has no
|
||||
/// model (or cannot use one) keeps waiting; otherwise denoise is enabled and the outcome reported
|
||||
/// in the status line.
|
||||
pub(crate) fn pump(app: &mut LightcraftApp, ctx: &egui::Context, now: f64) {
|
||||
if app.model_setup.denoise.is_none() {
|
||||
return;
|
||||
}
|
||||
if abandoned(app) {
|
||||
// the setup was closed without installing anything: the switch goes back off (issue #922)
|
||||
app.model_setup.denoise = None;
|
||||
app.ui.status = tr("Pending photo action cancelled").into();
|
||||
return;
|
||||
}
|
||||
if app.session.interaction.is_some() {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(250));
|
||||
return;
|
||||
}
|
||||
if now < app.model_setup.next_check {
|
||||
return;
|
||||
}
|
||||
app.model_setup.next_check = now + 0.25;
|
||||
let Some(request) = app.model_setup.denoise.take() else { return };
|
||||
if !request.valid(app) {
|
||||
app.ui.status = tr("Pending photo action cancelled because its library or photo changed").into();
|
||||
return;
|
||||
}
|
||||
if matches!(app.session.denoise_photo_state(request.photo), PhotoState::NoModel | PhotoState::NotApplicable) {
|
||||
app.model_setup.denoise = Some(request);
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(250));
|
||||
return;
|
||||
}
|
||||
match app.run("denoise.toggle", json!({"id": request.photo.0, "enabled": true})) {
|
||||
Ok(_) => app.ui.status = tr("AI Denoise is enabled on the requesting photo").into(),
|
||||
Err(error) => app.ui.status = error,
|
||||
}
|
||||
}
|
||||
@@ -141,9 +141,9 @@ fn watch_downloads(app: &mut LightcraftApp, ctx: &egui::Context) {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(120));
|
||||
}
|
||||
|
||||
/// Per-photo AI Denoise switch, including a request waiting for model installation.
|
||||
/// Per-photo AI Denoise switch.
|
||||
pub fn detail_toggle(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, on: bool, applicable: bool) {
|
||||
let mut enabled = on || crate::model_setup::denoise_requested(app, id);
|
||||
let mut enabled = on;
|
||||
egui::Frame::NONE.inner_margin(egui::Margin { left: 24, right: 22, top: 6, bottom: 2 }).show(ui, |ui| {
|
||||
let r = ui.add_enabled(applicable, egui::Checkbox::new(&mut enabled, crate::i18n::tr("AI Denoise")));
|
||||
register(ui, "denoise:enabled", r.rect);
|
||||
@@ -180,17 +180,6 @@ pub fn detail_status(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, am
|
||||
};
|
||||
match state {
|
||||
PhotoState::NotApplicable | PhotoState::Ready => {}
|
||||
PhotoState::NoModel => {
|
||||
egui::Frame::NONE.inner_margin(pad).show(ui, |ui| {
|
||||
note(ui, "AI Denoise needs a model. Install one in Settings.", t.text_dim);
|
||||
ui.add_space(2.0);
|
||||
let r = ui.small_button(crate::i18n::tr("Set up AI Denoise…"));
|
||||
register(ui, "denoise:setup", r.rect);
|
||||
if r.clicked() {
|
||||
let _ = app.run("denoise.toggle", json!({"id": id.0, "enabled": true}));
|
||||
}
|
||||
});
|
||||
}
|
||||
PhotoState::Idle => {
|
||||
if amount > 0.0 && app.session.denoise_auto() {
|
||||
// the pump has not met this photo yet: let it come round soon instead of waiting out its pause
|
||||
@@ -250,20 +239,22 @@ pub fn detail_status(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, am
|
||||
pub fn settings_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
let list = models(app, ui.ctx());
|
||||
heading(ui, t, "AI Denoise");
|
||||
crate::model_setup::notice(app, ui, "denoise");
|
||||
if list["dir"].is_null() {
|
||||
hint(ui, t, "This build has nowhere to keep denoise models, so AI Denoise is not available. (The desktop app has.)");
|
||||
hint(ui, t, "This build has nowhere to keep your own denoise models, so it cannot use one. (The desktop app has.)");
|
||||
return;
|
||||
}
|
||||
hint(
|
||||
ui,
|
||||
t,
|
||||
"Cleans noise out of raw photos with an AI model, before the picture is built: the AI Denoise Amount slider under Detail sets how much of it you see. \
|
||||
"Cleans noise out of raw photos before the picture is built: the AI Denoise Amount slider under Detail sets how much of it you see. \
|
||||
Your files are never changed and no extra files are made in your library: the cleaned picture is cached data that is made again when needed.",
|
||||
);
|
||||
let runtime = list["runtime"].as_bool() == Some(true);
|
||||
if list["model"].is_null() {
|
||||
hint(ui, t, "In use: the built-in denoiser. It needs nothing installed, so turning AI Denoise on just works.");
|
||||
}
|
||||
if !runtime {
|
||||
hint(ui, t, "This build cannot run denoise models.");
|
||||
hint(ui, t, "This build cannot run your own denoise models.");
|
||||
}
|
||||
let all: Vec<Value> = list["models"].as_array().cloned().unwrap_or_default();
|
||||
let downloads = app
|
||||
@@ -271,7 +262,7 @@ pub fn settings_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
.execute("denoise.models.downloads", &json!({}))
|
||||
.map(|v| v["downloads"].as_array().cloned().unwrap_or_default())
|
||||
.unwrap_or_default();
|
||||
heading(ui, t, "Models");
|
||||
heading(ui, t, "Your own model (optional)");
|
||||
let installing = downloads.iter().any(|d| d["id"] == "local-install" && d["state"].as_str() == Some("installing"));
|
||||
let r = crate::button::Button::new("Install from file…")
|
||||
.enabled(runtime && app.services.pick_denoise_model.is_some())
|
||||
@@ -293,7 +284,11 @@ pub fn settings_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
hint(ui, t, why);
|
||||
}
|
||||
if all.is_empty() {
|
||||
hint(ui, t, "Install your own ONNX model with denoise-model.json beside it. This build offers no model downloads.");
|
||||
hint(
|
||||
ui,
|
||||
t,
|
||||
"To use a model of your own instead of the built-in denoiser, install an ONNX file with denoise-model.json beside it. This build offers no model downloads.",
|
||||
);
|
||||
}
|
||||
if let Some(job) = downloads.iter().find(|d| d["id"] == "local-install") {
|
||||
match job["state"].as_str() {
|
||||
@@ -307,7 +302,7 @@ pub fn settings_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
model_row(app, ui, t, m, dl, runtime);
|
||||
}
|
||||
if all.iter().all(|m| m["selected"] != true) && all.iter().any(|m| m["installed"] == true) {
|
||||
hint(ui, t, "AI Denoise is off: press Use on a model.");
|
||||
hint(ui, t, "The built-in denoiser is in use: press Use on a model to use that instead.");
|
||||
}
|
||||
hint(ui, t, "Works on raw files from cameras with a standard (Bayer) sensor. Other files keep their normal noise reduction.");
|
||||
work_section(app, ui, t, &list);
|
||||
@@ -523,7 +518,7 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
|
||||
app.caches.denoise.epoch += 1;
|
||||
}
|
||||
if selected {
|
||||
let r = ui.button(tr("Turn off"));
|
||||
let r = ui.button(tr("Stop using"));
|
||||
register(ui, format!("denoise:off:{id}"), r.rect);
|
||||
if r.clicked() {
|
||||
let _ = app.run("denoise.models.select", json!({"id": null}));
|
||||
|
||||
@@ -63,7 +63,6 @@ mod masking_layout;
|
||||
mod menubar;
|
||||
mod merge_preview;
|
||||
mod missing_sweep;
|
||||
mod model_setup;
|
||||
mod move_folder;
|
||||
mod offline;
|
||||
mod open_lightroom;
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
//! Synthetic setup flows: model installation must resume the requested action on its original targets.
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use lightcraft_catalog::{MediaKind, Op, Photo, PhotoId, Source};
|
||||
use lightcraft_denoise::manifest::{DenoiserManifest, Domain, Gain};
|
||||
use lightcraft_engine::Session;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{LightcraftApp, Services, model_setup, state::Dialog};
|
||||
|
||||
fn setup(name: &str) -> (LightcraftApp, PathBuf, PhotoId) {
|
||||
let dir = std::env::temp_dir().join(format!("lc-model-flow-{name}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let mut s = Session::new().with_fs();
|
||||
s.open_library(dir.join("library"), true).unwrap();
|
||||
s.set_denoise_models_dir(Some(dir.join("denoise")));
|
||||
s.execute("denoise.settings", &json!({"runOn": "cpu"})).unwrap();
|
||||
let id = PhotoId(s.catalog.photos().map(|p| p.id.0).max().unwrap() + 1);
|
||||
let mut raw = Photo::new(
|
||||
id,
|
||||
Source::File { path: dir.join("synthetic.dng").to_string_lossy().into_owned() },
|
||||
"synthetic.dng",
|
||||
"DNG",
|
||||
128,
|
||||
128,
|
||||
"2026-10-07",
|
||||
);
|
||||
raw.kind = MediaKind::Raw;
|
||||
s.commit("fixture", Op::AddPhoto { photo: Box::new(raw) }).unwrap();
|
||||
(LightcraftApp::new(s, Services::default()), dir, id)
|
||||
}
|
||||
|
||||
fn denoise_file(dir: &Path) -> PathBuf {
|
||||
let source = dir.join("source");
|
||||
std::fs::create_dir_all(&source).unwrap();
|
||||
let bytes = lightcraft_denoise::synthetic::smoothing_onnx();
|
||||
std::fs::write(source.join("model.onnx"), &bytes).unwrap();
|
||||
let m = DenoiserManifest {
|
||||
id: "test-smoothing".into(),
|
||||
name: "Synthetic smoothing".into(),
|
||||
version: "1".into(),
|
||||
licence: Default::default(),
|
||||
source: None,
|
||||
sha256: None,
|
||||
size_bytes: Some(bytes.len() as u64),
|
||||
provenance: "Synthetic tests".into(),
|
||||
domain: Domain::BayerToRgb,
|
||||
tile: 64,
|
||||
overlap: 16,
|
||||
gain: Gain::None,
|
||||
};
|
||||
std::fs::write(source.join("denoise-model.json"), serde_json::to_vec(&m).unwrap()).unwrap();
|
||||
source.join("model.onnx")
|
||||
}
|
||||
|
||||
fn install_denoise(app: &mut LightcraftApp, dir: &Path) {
|
||||
app.run("denoise.models.install", json!({"path": denoise_file(dir), "acknowledged": true})).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepting_a_local_model_installs_in_background_and_resumes_the_pending_action() {
|
||||
let (mut app, dir, raw) = setup("local-install");
|
||||
let path = denoise_file(&dir);
|
||||
app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
let info = app.run("denoise.models.inspect", json!({"path": path})).unwrap();
|
||||
assert!(crate::panels::denoise::install(&mut app, &info, false).is_err());
|
||||
assert!(!dir.join("denoise/test-smoothing/model.onnx").exists());
|
||||
let result = crate::panels::denoise::install(&mut app, &info, true).unwrap();
|
||||
assert_eq!(result["started"], "local-install");
|
||||
assert_eq!(app.ui.dialog, Some(Dialog::Settings { tab: "denoise".into() }));
|
||||
let ctx = egui::Context::default();
|
||||
// a deadline, not a count of tries: the install copies on a background thread, slow on a busy machine
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
|
||||
while std::time::Instant::now() < deadline {
|
||||
crate::panels::denoise::pump(&mut app, &ctx);
|
||||
if app.session.denoise_photo_state(raw) != lightcraft_engine::denoise::PhotoState::NoModel {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
}
|
||||
resume(&mut app);
|
||||
assert_eq!(amount(&app, raw), 50.0);
|
||||
assert!(dir.join("denoise/test-smoothing/model.onnx").is_file());
|
||||
assert!(path.is_file(), "a user-supplied original is preserved");
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
fn amount(app: &LightcraftApp, id: PhotoId) -> f64 {
|
||||
app.session.develop_of(id).unwrap().enhance.denoise
|
||||
}
|
||||
fn resume(app: &mut LightcraftApp) {
|
||||
model_setup::pump(app, &egui::Context::default(), app.tick_now());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn denoise_installation_enables_only_the_requesting_photo_once_and_is_undoable() {
|
||||
let (mut app, dir, raw) = setup("denoise");
|
||||
let other = app.session.active().unwrap();
|
||||
app.session.auto_sync = true;
|
||||
let r = app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
assert_eq!(r["setupRequired"], true);
|
||||
assert_eq!(app.ui.dialog, Some(Dialog::Settings { tab: "denoise".into() }));
|
||||
assert_eq!(amount(&app, raw), 0.0, "setup alone never changes the photo");
|
||||
app.run("library.select", json!({"ids": [other.0]})).unwrap();
|
||||
let undo = app.session.undo.len();
|
||||
install_denoise(&mut app, &dir);
|
||||
resume(&mut app);
|
||||
assert_eq!(amount(&app, raw), 50.0);
|
||||
assert_eq!(amount(&app, other), 0.0);
|
||||
assert_eq!(app.session.active(), Some(other));
|
||||
assert_eq!(app.session.undo.len(), undo + 1);
|
||||
resume(&mut app);
|
||||
assert_eq!(app.session.undo.len(), undo + 1, "a later frame cannot apply it again");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(amount(&app, raw), 0.0);
|
||||
app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
app.run("develop.set", json!({"ids": [raw.0], "control": "enhance.denoise", "value": 75})).unwrap();
|
||||
app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
assert_eq!(amount(&app, raw), 75.0, "enabling an already chosen amount keeps it");
|
||||
app.run("denoise.toggle", json!({"id": raw.0, "enabled": false})).unwrap();
|
||||
assert_eq!(amount(&app, raw), 75.0, "switching off keeps the Amount");
|
||||
assert_eq!(app.session.develop_of(raw).unwrap().denoise_amount(), 0.0, "but mixes nothing in");
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancelled_denoise_requests_do_not_apply_after_installation() {
|
||||
for (name, command, params) in [
|
||||
("cancel-action", "modelSetup.cancel", json!({"kind": "denoise"})),
|
||||
("cancel-toggle", "denoise.toggle", json!({"enabled": false})),
|
||||
("cancel-download", "denoise.models.downloadCancel", json!({"id": "rawnind-bayer"})),
|
||||
] {
|
||||
let (mut app, dir, raw) = setup(name);
|
||||
app.run("library.select", json!({"ids": [raw.0]})).unwrap();
|
||||
app.run("denoise.toggle", json!({"enabled": true})).unwrap();
|
||||
app.run(command, params).unwrap();
|
||||
install_denoise(&mut app, &dir);
|
||||
resume(&mut app);
|
||||
assert_eq!(amount(&app, raw), 0.0, "{name}");
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pending_actions_do_not_cross_libraries_or_relinked_sources() {
|
||||
for changed in ["library", "source"] {
|
||||
let (mut app, dir, raw) = setup(changed);
|
||||
app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
if changed == "library" {
|
||||
app.session.open_library(dir.join("other-library"), true).unwrap();
|
||||
} else {
|
||||
app.session
|
||||
.commit(
|
||||
"relink",
|
||||
Op::Relink {
|
||||
id: raw,
|
||||
file_name: "another.dng".into(),
|
||||
source: Source::File { path: dir.join("another.dng").to_string_lossy().into_owned() },
|
||||
format: Some("DNG".into()),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
install_denoise(&mut app, &dir);
|
||||
resume(&mut app);
|
||||
assert!(!model_setup::denoise_requested(&app, raw));
|
||||
assert!(app.session.catalog.photos().all(|p| p.develop.enhance.denoise == 0.0));
|
||||
assert!(app.ui.status.contains("cancelled"));
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_or_inapplicable_toggle_arguments_are_errors_without_changes() {
|
||||
let (mut app, dir, raw) = setup("hostile");
|
||||
let jpeg = app.session.active().unwrap();
|
||||
for params in [json!({"id": "wrong"}), json!({"id": u64::MAX}), json!({"id": raw.0, "enabled": 1}), json!({"id": jpeg.0, "enabled": true})] {
|
||||
assert!(app.run("denoise.toggle", params).is_err());
|
||||
assert_eq!(amount(&app, raw), 0.0);
|
||||
}
|
||||
assert!(app.run("modelSetup.cancel", json!({"kind": "nonsense"})).is_err());
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_installation_waits_for_an_active_slider_gesture_to_finish() {
|
||||
let (mut app, dir, raw) = setup("interaction");
|
||||
app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
app.session.begin_interaction("Exposure").unwrap();
|
||||
install_denoise(&mut app, &dir);
|
||||
resume(&mut app);
|
||||
assert_eq!(amount(&app, raw), 0.0);
|
||||
assert!(app.session.interaction.is_some());
|
||||
app.session.end_interaction().unwrap();
|
||||
resume(&mut app);
|
||||
assert_eq!(amount(&app, raw), 50.0);
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// Issue #922: closing the setup without installing a model turns the AI Denoise switch back off
|
||||
/// and drops the "Cancel pending action" offer; while the setup stays open the request waits.
|
||||
#[test]
|
||||
fn dismissing_the_setup_without_a_model_leaves_ai_denoise_off() {
|
||||
let (mut app, dir, raw) = setup("dismissed");
|
||||
let r = app.run("denoise.toggle", json!({"id": raw.0, "enabled": true})).unwrap();
|
||||
assert_eq!(r["setupRequired"], true);
|
||||
resume(&mut app);
|
||||
assert!(model_setup::denoise_requested(&app, raw), "the open setup keeps the request");
|
||||
app.ui.dialog = None;
|
||||
resume(&mut app);
|
||||
assert!(!model_setup::denoise_requested(&app, raw), "a dismissed setup leaves nothing pending");
|
||||
assert!(app.ui.status.contains("cancelled"), "{}", app.ui.status);
|
||||
// installing later changes nothing; asking again offers the setup again
|
||||
install_denoise(&mut app, &dir);
|
||||
resume(&mut app);
|
||||
assert_eq!(amount(&app, raw), 0.0);
|
||||
drop(app);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
+126
-7
@@ -6,15 +6,134 @@ preserves Amount and mixes none of the cleaned picture. It affects only the requ
|
||||
photo, independently of Auto Sync, and is undoable. Manual luminance and colour noise
|
||||
reduction remain separate controls.
|
||||
|
||||
If no model is selected, turning it on opens **Settings ▸ AI Denoise** without changing
|
||||
the photo. After installation, the pending request enables the original photo even if
|
||||
the selection changed. Cancel the pending action in Settings. Cancelled downloads,
|
||||
deleted or relinked photos, switching libraries and quitting cancel the request.
|
||||
An active slider gesture finishes before the pending action resumes.
|
||||
## The built-in denoiser
|
||||
|
||||
## Models and terms
|
||||
AI Denoise needs no set-up. Unless you choose a model of your own (below), it runs the
|
||||
**built-in denoiser** (`crates/denoise-core/src/builtin.rs`, id `builtin`): it measures
|
||||
the photo's noise level once, from blocks of all four colour planes spread over the whole mosaic (variance =
|
||||
a · signal + b; see [How the noise is measured](#how-the-noise-is-measured)), turns the noise into unit variance with a variance-stabilising transform,
|
||||
and cleans the four Bayer planes together with block-matching collaborative filtering
|
||||
(`crates/denoise-core/src/bm3d.rs`, after the published BM3D / CBM3D method). The four planes are rotated
|
||||
into a brightness plane and three colour-difference planes; 4 × 4-cell blocks of the brightness plane that look alike
|
||||
are stacked into groups (the colour planes follow the same matches, so colour noise is cleaned with the brightness).
|
||||
Each stack is transformed (a 2-D DCT of every block, a Haar transform across the stack), small coefficients are
|
||||
removed, and the blocks are put back with weights; a second step matches blocks again on that cleaner estimate and
|
||||
shrinks by a Wiener filter built from it. How hard it thresholds follows the photo's noise: gently at low noise, to
|
||||
keep fine detail, and harder as the noise grows. It then demosaics with
|
||||
edge-directed green and colour-difference red and blue. It is written for
|
||||
LightCraft, pure Rust, MIT OR Apache-2.0, has no weights and no download, and uses the
|
||||
same tiling, cache, queue, preview and export path as a model. Its tile is 256 cells with a
|
||||
16-cell overlap. The filter (the grouping, the transforms and the putting back, which are nearly all of its work) runs on
|
||||
the graphics card when there is one that agrees with the processor and is faster (`crates/gpu/src/bm3d.rs`, WGSL kernels
|
||||
in `crates/gpu/src/wgsl/bm3d_*.wgsl`); measuring the noise, the variance-stabilising transform and the demosaic stay on the
|
||||
processor. The card is set up for the first photo that may use it, like a model's: its kernels are built, a check tile is
|
||||
run on both devices and the card's filter must match the processor's to within a third of a noise deviation at the
|
||||
worst place and a thousandth on average (they differ by the rounding of the arithmetic: a few blocks whose match or
|
||||
threshold falls either side of a tie change by about a tenth), and both are timed. Settings ▸ AI Denoise ▸ Run on chooses
|
||||
Automatic (the card where it is faster), Graphics card or Processor, and says where it runs; a set-up that crashed or ran out
|
||||
of time is not tried again until you choose (Try the graphics card again). A tile the card gets wrong is run on the
|
||||
processor, and three stop the card for the session. On an RTX 4080 SUPER a tile takes 22 ms on the card against 408 ms on one
|
||||
processor thread, and the 1536 × 1024 benchmark crop 0.13 to 0.24 s against 1.0 to 2.1 s on four threads, with the very
|
||||
same scores. A change
|
||||
to the algorithm bumps `builtin::VERSION`, so cached pictures are made again. The id
|
||||
`builtin` is reserved: a model with that id is refused. It is a classical filter, not a
|
||||
trained network, so a good model can still do better on very noisy files. The earlier
|
||||
non-local-means filter (`crates/denoise-core/src/nlm.rs`) is still there as a fallback
|
||||
(`Tuning::bm3d = None`). Why block matching and not something else: see [Why block matching](#why-block-matching).
|
||||
|
||||
**No model weights are bundled.** Models live in the per-user `denoise-models` folder
|
||||
To measure a change to it, run the opt-in benchmark on a public CC0 raw (see `cargo xtask corpus`):
|
||||
`LC_DENOISE_RAW="$(git rev-parse --show-toplevel)/corpus/raw/arw-sony-a7m3-compressed.arw" LC_DENOISE_OUT=/tmp/dn cargo test --release -p lightcraft-engine --test denoise_builtin_quality -- --ignored --nocapture`
|
||||
(the path must be absolute: tests run from the crate's folder).
|
||||
It adds noise of four known levels to the raw, runs the denoiser and prints the PSNR against the
|
||||
original, plus a texture figure (how much of the true picture's fine structure the result keeps; noise
|
||||
can't inflate it); `LC_DENOISE_OUT` also writes truth | noisy | denoised PNGs. Use public files only.
|
||||
`LC_B_N`, `LC_B_STEP`, `LC_B_S`, `LC_B_K`, `LC_B_T1`, `LC_B_T2`, `LC_B_LOFF` (added to every point of the threshold curve),
|
||||
`LC_B_SIG` and `LC_B_WIENER`
|
||||
override the matching `bm3d::Params` field for a sweep; `LC_NLM=1` runs the non-local-means filter instead (then
|
||||
`LC_S1`, `LC_S2`, `LC_HL`, `LC_HH`, `LC_H2`, `LC_LIGHT`, `LC_HEAVY`, `LC_SC`, `LC_HC`, `LC_P1`, `LC_P2`,
|
||||
`LC_LOOSE` and `LC_FEW` override its `nlm::Tuning` fields).
|
||||
PSNR and texture trade off (smoothing more raises one and lowers the other), so judge a change on both and on the
|
||||
crops. On the Sony A7 III crop (PSNR gain over the noisy picture in dB / texture, light, medium, heavy, extreme noise):
|
||||
non-local means +3.70 / 0.62, +7.22 / 0.42, +9.69 / 0.22, +10.37 / 0.09; block matching +4.28 / 0.58, +7.60 / 0.44,
|
||||
+10.04 / 0.22, +10.62 / 0.12, in about the same time (1 to 2 s for the 1536 × 1024 crop on 4 cores). `LC_GPU=1` (with
|
||||
`--features denoise`) runs the block-matching filter on the graphics card instead: the same scores in 0.13 to 0.24 s on an
|
||||
RTX 4080 SUPER. The tests `lightcraft-gpu` `bm3d::tests` (the card against `bm3d::filter` on synthetic tiles, shared between
|
||||
threads) and the engine's `gpu_tests` (set-up check, fallback after wrong tiles, the processor chosen, a marker left behind)
|
||||
need a graphics card and record a skip without one.
|
||||
|
||||
### Why block matching
|
||||
|
||||
The built-in filter was chosen by measuring, on the benchmark above (the public Sony A7 III crop with noise of four known
|
||||
levels; PSNR gain over the noisy picture in dB / texture), not by taste. Candidates, all written from the published
|
||||
papers (no GPL code), in the order tried:
|
||||
|
||||
| Filter | light | medium | heavy | extreme | Time per crop (4 CPU threads) |
|
||||
|---|---|---|---|---|---|
|
||||
| Non-local means (the first built-in) | +3.70 / 0.62 | +7.22 / 0.42 | +9.69 / 0.22 | +10.37 / 0.09 | 1.1–1.7 s |
|
||||
| **Block matching, hard threshold then Wiener (BM3D / CBM3D)** | **+4.28 / 0.58** | **+7.60 / 0.44** | **+10.04 / 0.22** | **+10.62 / 0.12** | 1.1–2.1 s |
|
||||
| Weighted nuclear norm minimisation (WNNM), best setting per level | +4.68 / 0.56 | +8.14 / 0.39 | +10.04 / 0.22 | +10.35 / 0.15 | 15–20 s |
|
||||
|
||||
- **Block matching beats non-local means** on PSNR at every level and on texture at medium, heavy and extreme noise
|
||||
(only light noise keeps slightly less: 0.58 against 0.62, for 0.6 dB more). The crops show more needle and branch detail
|
||||
and no colour blotches or isolated specks. It costs about the same on the processor.
|
||||
- **WNNM**, the strongest classical method we know of (singular values of each group of blocks shrunk with weights),
|
||||
gains about 0.4 dB at light noise and 0.03 of texture at medium and extreme, and nothing at heavy noise, for about ten
|
||||
times the processing time (a 24 MP photo would take about five minutes on the processor, against about a quarter of a
|
||||
minute). Its singular values came from Jacobi rotations of each group's Gram matrix; more iterations, a smaller feedback
|
||||
and 6 × 6 blocks (115 s a crop) did not help. Not kept. Untried: patches over all four planes at once (about fourteen times
|
||||
the work per group).
|
||||
- **What the tuning showed** (for whoever changes it): the hard threshold has to rise with the noise (`Params::lambda` is a curve
|
||||
of the noise's deviation at mid-grey against the threshold: 1.2 at 0.0028, 1.9 at 0.0062, 2.3 at 0.0094, 2.65 at 0.0152, 3.2 at
|
||||
0.038, 3.5 at 0.14; a fixed value wins at one level and loses at another, see
|
||||
[Fitted on real cameras](#fitted-on-real-cameras)); a higher
|
||||
threshold on the colour planes than on the brightness plane hurts both PSNR and texture, because the colour differences
|
||||
carry real signal; 4 × 4 blocks beat 3, 5, 6 and 8 on quality (3 × 3 is a little faster, 6 × 6 and 8 × 8 much slower); the
|
||||
match tolerances and the group size (16 against 8 or 32) barely matter; a search of 8 cells and a step of 3 cost 0.1 dB
|
||||
against 12 and 2 and keep the
|
||||
processor as fast as non-local means. The Wiener step adds a little over the hard threshold alone.
|
||||
- **The first benchmark's limit:** its noise is synthetic and white, and its reference (a public raw's own mosaic) has noise of
|
||||
its own, which hides what happens at the low noise levels of real cameras. Real high-ISO raws also have correlated,
|
||||
low-frequency colour noise and banding, which none of this measures; judge a change to the real thing by eye on a
|
||||
high-ISO raw too.
|
||||
|
||||
### How the noise is measured
|
||||
|
||||
`builtin::estimate_noise` reads `(a, b)` of a photo (variance = `a · signal + b`, signal in 0..1 after black and white
|
||||
levels) from the picture itself, so no camera table is needed. Each of the four colour planes is read separately (they sit at
|
||||
different levels in a raw), cut into 12 × 12-cell blocks, and a second-difference operator (`[1 -2 1; -2 4 -2; 1 -2 1]`, which
|
||||
cancels flat and smoothly sloping signal; white noise has `36 σ²` of variance through it) gives each block's variance; texture
|
||||
and edges only add to it. At each brightness (about 300 blocks of each) the quietest 5 % of blocks are the noise, divided by
|
||||
the bias of that quantile of pure noise (0.67, measured by
|
||||
`denoise_noise_estimate::a_quantile_of_pure_noise_blocks_is_a_known_fraction_of_the_true_variance`), and a line is fitted
|
||||
through the points. The first version mixed the colour planes in each block and took the lower quarter of a plain
|
||||
neighbour difference: it read the picture's texture as noise, never below about 0.003 at mid-grey whatever the
|
||||
true noise (`estimate_noise_v1`, kept to compare). On 30 different public pictures with known noise added, the ratio of
|
||||
estimated to true deviation at mid-grey, at the ISO 6400 level of a Canon R-series body (0.0094), had a 10th to 90th percentile of
|
||||
0.97 to 1.29 against 0.94 to 1.96 for the first version, and at the ISO 1600 level (0.0062) 0.99 to 1.45 against 0.97 to 2.77
|
||||
(`LC_CORPUS=<corpus/raw> cargo test --release -p lightcraft-engine --test denoise_noise_estimate -- --ignored --nocapture`).
|
||||
A picture with no flat area at all still reads somewhat high, never low.
|
||||
|
||||
### Fitted on real cameras
|
||||
|
||||
A Canon EOS R, EOS R6 Mark III, M50 Mark II and some EF-era bodies were measured on a private library of about 8,400 raws
|
||||
(only aggregates were kept; no photo is in the repository). The deviation of the noise at mid-grey (the measure the filter
|
||||
judges a photo by) was about 0.0024 to 0.0028 at ISO 400 and below, 0.005 to 0.006 at ISO 500 to 1600, 0.009 to 0.010 at ISO 2000
|
||||
to 6400, 0.015 to 0.018 at ISO 8000 to 25600 and 0.038 above that: far lower than the first benchmark's levels (0.024 to
|
||||
0.14), so a filter tuned on those was too gentle exactly where these photos live. The curve above was fitted on clean low-ISO
|
||||
photos of those cameras with noise of their measured levels added (`LC_REAL=1`; `LC_FULL=1` measures the noise on the whole
|
||||
frame, as the app does). Against the first estimator with a constant threshold of 1.9, averaged over 10 EOS R and 5 R6 Mark III
|
||||
photos, the output reached (PSNR in dB, EOS R / R6 Mark III): ISO 400 level 43.76 / 44.93 (from 43.27 / 44.66), 1600 41.03 / 41.86
|
||||
(41.05 / 41.82), 6400 39.93 / 40.69 (39.30 / 39.74), 25600 38.36 / 38.86 (36.18 / 36.21) and 51200 level 33.83 / 34.45
|
||||
(28.42 / 28.78), with the noise left in the result ("detail" above 1) falling from 1.3 to 3.1 down to 0.73 to 0.99. The threshold
|
||||
at each level is the lowest that stays within about a quarter of a decibel of the best, so texture is kept (on the EOS R at the
|
||||
25600 level the texture figure is 0.28, against 0.25 at the highest-PSNR threshold). The first estimator also cost PSNR by itself: told the true
|
||||
noise instead of its estimate, the same filter did the right thing at every level; the new estimator is as good as that from
|
||||
ISO 6400 up.
|
||||
|
||||
## Models and terms (optional)
|
||||
|
||||
**No model weights are bundled.** Choosing a model replaces the built-in denoiser; **Stop using**
|
||||
(or removing the model) goes back to it. Models live in the per-user `denoise-models` folder
|
||||
(override with `LIGHTCRAFT_DENOISE_MODELS`). Settings provides **Install from file…**
|
||||
for a user-supplied ONNX file with a `denoise-model.json` beside it. The default build
|
||||
offers no model downloads. The separate `rawnind-model` Cargo feature enables the
|
||||
|
||||
+5
-2
@@ -1,6 +1,6 @@
|
||||
# Gaps: where LightCraft falls short of Lightroom
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-05 · **Change:** minor (gap 26: culling uses built previews, background preparation per mode; before: Contrast and Blacks calibrated in process V4, #523; PERF-STEP-STALL: flags, ratings and edits never wait for the drive; gap 1: the Canon EOS D60 is the first chart-calibrated model, its matrices from our own ColorChecker shots give its white balance a Kelvin scale; gap 20: Canon CRW decodes; LR-LIB-VIRTUALCOPY: default number exhaustion is validated before copy creation; gap 8: lens profile work is tracked in #329; gap 8: lensfun's lens database offered on the first launch and downloaded on request, looked up for the library; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; typed GPS input now rejects malformed coordinates before metadata changes; LR-MAP-TRACKLOG decodes GPX character references in coordinates, elevations and timestamps; malformed references error; CDATA stays literal; ranked gaps unchanged; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; import: checked rename-sequence exhaustion; import review: remembered thumbnail size and density-aware previews (#2237, part of #2056); pre-import loupe/keyboard culling remains open; no ranked gap closes; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 9: CI runs the tests on Linux x64 since #2667; macOS, Windows and the GPU equivalence tests still don't; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 8: Sony ILCE-7RM6 in-file distortion conversion extends to the APS-C ILCE-6700; LR-META-EXIF-FULL rejects extra EXIF clock components and preserves date fallbacks; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixedLine truncated
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-05 · **Change:** minor (gap 11: the built-in denoiser now uses block-matching collaborative filtering (better PSNR than non-local means at every noise level) and runs it on the graphics card when there is one; gap 11: AI Denoise works out of the box with a built-in denoiser; gap 26: culling uses built previews, background preparation per mode; before: Contrast and Blacks calibrated in process V4, #523; PERF-STEP-STALL: flags, ratings and edits never wait for the drive; gap 1: the Canon EOS D60 is the first chart-calibrated model, its matrices from our own ColorChecker shots give its white balance a Kelvin scale; gap 20: Canon CRW decodes; LR-LIB-VIRTUALCOPY: default number exhaustion is validated before copy creation; gap 8: lens profile work is tracked in #329; gap 8: lensfun's lens database offered on the first launch and downloaded on request, looked up for the library; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; typed GPS input now rejects malformed coordinates before metadata changes; LR-MAP-TRACKLOG decodes GPX character references in coordinates, elevations and timestamps; malformed references error; CDATA stays literal; ranked gaps unchanged; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; import: checked rename-sequence exhaustion; import review: remembered thumbnail size and density-aware previews (#2237, part of #2056); pre-import loupe/keyboard culling remains open; no ranked gap closes; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 9: CI runs the tests on Linux x64 since #2667; macOS, Windows and the GPU equivalence tests still don't; gap 8: lens profile work is tracked in #329; gap 30: the Info panel shows the selected photos' shared metadata and marks mixed fields; gap 28: ⌘⌥⇧C / ⌘⌥⇧V copy and paste metadata; gap 13: before a Lightroom catalog import the app asks merge or new library, #2672; gap 28: F8 shows / hides the right panel; import review album hierarchy, #2362; gap 20: Minolta MRW decodes; gap 10: 557 models verified with CRW and MRW; gap 15: Print Page Options — page numbers, page info, crop marks; gap 28: `\` shows / hides the Filter Bar in the grids; gap 21: Indonesian interface shipped, every message but What's New; gap 27: the Windows x64 installer verified on Windows 11; the Settings → Apps uninstall confirmation remains; gap 28: ⌘L Enable Filters switches the filter off and on; gap 15: Japanese photo and postcard paper sizes in the Print page setup and PDF; gap 8: Sony ILCE-7RM6 in-file distortion cLine truncated
|
||||
|
||||
Every known shortfall, one entry each, ranked by user impact (how many Lightroom users hit it, and
|
||||
how hard it blocks them), then by effort. **Agents pick work from the top** (the first entry nobody is
|
||||
@@ -25,7 +25,7 @@ Hours are Opus 5.5 agent wall-clock hours (see [target-app-parity.md](target-app
|
||||
| 8 B | **Lens profiles: lensfun only, no picker, no own calibration** (LR-EDIT-OPTICS-PROFILE): the desktop app offers lensfun's database (CC BY-SA 3.0, pinned, never bundled) once on the first launch and downloads it on that click or from Settings, then looks every raw up by its lens ([lens-profiles.md](lens-profiles.md)), but those profiles are not validated against Lightroom, there is no profile picker (in the file / lens database / own calibration) and no calibration wizard; in-file corrections: DNG opcodes, RW2 in-file distortion, Sony ILCE-7RM4A, ILCE-7M3, full-frame ILCE-7CR distortion (Auto only) and ILCE-7RM6 and ILCE-6700 distortion (`docs/sony-ilce7rm6-lens-corrections.md`) and Nikon Z 6II / Z 8 / Z f distortion (`docs/nikon-lens-corrections.md`); tracked in #329 | Adobe ships 3,635 lens profiles; we never use them | distortion / vignetting correction is a default step for many | 40–80 + calibration shots | [raw-parity](raw-parity.md#lens-profiles) |
|
||||
| 9 B | **Tests don't run in CI on macOS or Windows, and no CI job runs the GPU equivalence tests**: the CI gate (`ci.yml`, #2667) runs `cargo xtask ci`, which includes `cargo test`, on Linux x64 for every push to `main` and every pull request; FreeBSD runs `cargo test` nightly, on pushes to `release` and on PRs that change its workflow or `packaging/freebsd/`; the macOS and Windows jobs build packages | `.github/workflows/` (ci, freebsd, packaging-lint, release, sonarcloud, windows-arm64); the gate's runner has Mesa software Vulkan drivers installed, but `Gpu::new` refuses software adapters (`crates/gpu/src/ctx.rs`), so the CPU ↔ GPU equivalence tests skip; the linux-riscv64 release job added in 0.6.0 (#844) runs only `lightcraft-cli --version` under QEMU; #1148 (open, not merged; #2667 names it superseded) has the macOS and Windows test legs and a `LIGHTCRAFT_GPU_ALLOW_SOFTWARE` opt-in that runs the GPU tests on lavapipe, Metal and WARP | a regression that only shows on macOS or Windows, or only on a GPU, reaches users; `cargo xtask ci` runs only on Linux in CI | 6–12 | [target-app-parity](target-app-parity.md#by-dimension) |
|
||||
| 10 B | **Per-model verification thin, plus cheap per-body decode fixes**: 557 of 1,446 Adobe models verified (39%), ~86% of photographers on a verified body; Nikon 5 bodies verified, Canon 34, Leica 14 (the Q3 by a recorded check of 38 private DNGs). Cheap fixes: Z 6II packed 14-bit NEF (#769, PR #671), Sony A100 regression (#702); F828 SRF now discovered and imported as preview-only, sensor decoding still missing, DSLR-A200…A390 / A850 12-bit ARW (#535) | measured: [raw/coverage.tsv](raw/coverage.tsv) | per-body bugs (levels, crops, WB) surface only from users | 25–45 | [raw-parity](raw-parity.md#by-maker-measured) |
|
||||
| 11 | **Enhance: Raw Details, Super Resolution; AI denoise without shippable weights or X-Trans** | ENH rows 0%; denoise Bayer only, RawNIND weights GPL and opt-in | Fujifilm users get no AI denoise; nobody gets it out of the box | 30–60 + model decision | [raw-parity](raw-parity.md#demosaic-levels-crops-and-lens-metadata) |
|
||||
| 11 | **Enhance: Raw Details, Super Resolution; trained denoise weights and X-Trans** | ENH rows 0%; denoise Bayer only; the built-in denoiser is classical (block-matching collaborative filtering), RawNIND weights GPL and opt-in | Fujifilm users get no AI denoise; very noisy files gain less than from a trained model | 30–60 + model decision | [raw-parity](raw-parity.md#demosaic-levels-crops-and-lens-metadata) |
|
||||
| 12 | **Content-aware / generative remove, detect distractions, reflections removal** | REM rows 75%; patch synthesis missing | cleanup work goes back to Photoshop | 25–45 (+ generative model) | [target-app-parity](target-app-parity.md#ai) |
|
||||
| 13 | **Lightroom catalog migration is one-way and approximate**: unsupported Adobe profiles / AI settings archived, history kept as data; main-file pages read on demand up to 16 GiB, with dense-table and WAL bounds retained (#798); offline record counts and destination are now shown in a lasting import result; catalog VIDEO records match the Videos filter, with older classification repaired on reimport; before an import the app asks whether the catalog merges into the open library or goes into a new library (opt-out in Settings, #2672) | lightroom-catalog-import.md | switching users lose some looks | 8–12 | [file-format-parity](file-format-parity.md) |
|
||||
| 14 | **HDR display** (EDR / Windows HDR); the headroom limit and SDR rendition from `crs` XMP (the HDR switch, `HDREditMode`, is read). HLG AVIF export done; the display's SDR/HDR decision is tested, blocked on eframe's 8-bit surface | HDR rows 70%; LR-VIEW-HDR-DISPLAY ⬜ | HDR editing works blind on HDR monitors | 12–25 | [hardware-parity](hardware-parity.md) |
|
||||
@@ -103,6 +103,9 @@ Beta-blocking gaps (B) total **~230–430 h**; with the stability and platform w
|
||||
| 2026-10-25 | patch | LR-META-EXIF-FULL rejects extra clock components rather than projecting a plausible prefix; valid DateTimeDigitized, IFD0 DateTime and XMP fallbacks remain available, raw tag values stay visible, and the status / feature counts do not change |
|
||||
| 2026-10-25 | patch | JPEG ICC APP2 chunks are validated as a complete, uniquely numbered sequence before colour conversion; ranked gaps and readiness counts unchanged |
|
||||
| 2026-10-29 | minor | Gap 5: Object / Describe masks are enlarged along the photo's edges, so a raised Exposure no longer outlines the subject (#3272); the gap (heuristic Subject / Sky / People, no model mirror) and its hours are unchanged |
|
||||
| 2026-10-24 | minor | AI Denoise measures a photo's noise by colour channel and ignores texture, and sets its strength from it (fitted on real Canon EOS R / R6 Mark III noise levels: up to 5.5 dB closer to the original at ISO 51200, 2.2 to 2.7 dB at ISO 25600); gap 11 unchanged |
|
||||
| 2026-10-24 | minor | The built-in denoiser filters with block-matching collaborative filtering instead of non-local means (+0.25 to +0.6 dB on a public raw with added noise) and runs that filter on the graphics card where there is one (6 to 10 times faster per photo on an RTX 4080 SUPER, the same picture); gap 11 still stands (no X-Trans, no trained weights) |
|
||||
| 2026-10-23 | minor | AI Denoise runs out of the box with a built-in pure-Rust denoiser; gap 11 no longer says nobody gets denoise without installing a model |
|
||||
| 2026-10-13 | minor | Gap 20: Canon CRW decoded (clean-room derivation; EOS and G1/G6 verified pixel-exact; G5 preview) — removed from the long-tail list; hours 40–80 → 35–75 after merging main (MRW) |
|
||||
| 2026-10-24 | minor | Gap 28: ⌘⌥⇧C / ⌘⌥⇧V (Ctrl+Alt+Shift+C / V on Windows and Linux) copy and paste metadata; no key leaves the entry; hours unchanged |
|
||||
| 2026-10-24 | minor | Gap 30 shrinks: the Info panel's Show Metadata For (Target Photo / Selected Photos, `view.infoSelectedPhotos`) shows the selected photos' shared values and marks fields that differ as Mixed; the All Metadata dialog remains; 1–3 h (was 4–8) |
|
||||
|
||||
@@ -91,6 +91,14 @@ leaves them apart. The transposed convolution's merged store ran right on that c
|
||||
`nn::tests::a_layer_stores_every_pixels_channels_where_the_next_reads_them` catches the fault on such a card;
|
||||
`a_transposed_convolution_stores_every_pixels_channels_where_the_next_reads_them` checks the other store exactly.
|
||||
|
||||
FXC also cannot address two things the WGSL looks harmless with, and answers with `X3550 … forcing loop to unroll`
|
||||
and then `X3511 unable to unroll loop` (the shader module fails, so the pipeline is never made): an array handed to a
|
||||
function through a pointer (`ptr<function, array<…>>`) that the function then indexes with a loop variable, and a vector
|
||||
indexed with a loop variable on the left of an assignment (`acc[ch] = …` with `acc: vec4<f32>`). The block-matching
|
||||
kernels (`wgsl/bm3d_*.wgsl`) keep their working arrays at module scope (`var<private>`, one copy of the transforms
|
||||
generated per array, `bm3d_transform.wgsl`) and accumulate in `array<f32, 4>` instead. A GPU test that only records a
|
||||
skip when the device cannot build the kernels hides this, so read the skip note (`cargo test … -- --nocapture`).
|
||||
|
||||
**Off the startup path.** The compute device is created on a background thread once the window is
|
||||
up (`gpu::warm_up` from the first frame's settings), and never while GPU rendering is off: with
|
||||
Settings ▸ Performance ▸ *Use the GPU for rendering* unchecked (applied before the window opens),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Lightroom parity checklist
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-05 · **Change:** minor (LR-BEHAV-ACCESS: the Flatpak may talk to the accessibility bus; before: LR-PROF-IMPORT: the user's own .dcp camera profiles import, checked on a real D750 profile against Lightroom; LRC-DEV-AUTOSYNC: white balance syncs on each photo's own scale, As Shot and Auto per photo; LR-LIB-FLAG: a flag or rating never waits for the drive, PERF-STEP-STALL; LRC-LIB-VISUALSEARCH: Find Similar Photos reads the photos on a worker thread, so a large library no longer freezes the window; LR-MASK-LINEAR: masks stay on the photo's content under lens corrections, Upright, Transform and Rotate; LR-IMP-FORMATS: the Canon CRW decoder is the shared craft-libs crate `craft-crw`; LR-PROF-CAMERACOLOR: chart-measured matrices for the Canon EOS D60, its white balance in Kelvin; CRW imports name their camera; LR-BEHAV-ACCESS: the Flatpak may talk to the accessibility bus; LR-LIB-ALBUM: album commands leave out photos the library no longer has and record nothing when they add nothing; LR-BEHAV-DRAGDROP: a right-click on a text field while photos are carried from the grid opens no Cut / Copy / Paste menu; LR-BEHAV-DRAGDROP: a right-click while photos are carried from the grid opens no context menu; LR-LIB-VIRTUALCOPY: default numbering is preflighted across the requested batch and explicit names bypass suffix allocation; LR-BEHAV-DRAGDROP: only the primary button drags photos out of the grid and drops them; KEYC-RATING: deleting a keyword while Enable Filters has the filter put aside no longer leaves an empty one there; LR-BEHAV-DRAGDROP: a drop's destination is named with its parent when another folder or album has the same name; LR-VIEW-FILMSTRIP: photos drag from the filmstrip to the same sidebar targets as from the grid; LRC-LIB-LIBFOLDERS: a deep row's count follows its name in a narrow panel; LR-FILT-FLAG / LRC-LIB-FILTERBAR: the flag toggles combine, Picked + Unflagged, #2588; LR-VIEW-PHOTOGRID, LR-VIEW-FILMSTRIP, LR-VIEW-COMPARE, LR-VIEW-SURVEY, LRC-LIB-REFVIEW, LRC-LIB-PEOPLE: the active photo's selection ring shows on light themes and in Compare, Survey and the face tiles, and needs a loaded thumbnail; LR-FILT-SEARCH-META: `>=` / `<=` in fielded search tokens; MENU-FILE-CLOSE, KEY-CLOSEWINDOW: the notes say Close Window quits the app, after the same check as Quit; MENU-EDIT-SELECTNONE, MENU-EDIT-PASTESELECTED: Edit lists Select Only Active Photo after Deselect All and Paste Settings from Previous after Paste Selected Settings…; on macOS no doubled separators are left where Settings… moved to the app menu; LR-BEHAV-TITLEBAR: a double-click follows the system setting, and a panel over the bar keeps the window still; KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 go to the next / previous keyword set; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings; KEYC-METADATA: ⌘K / Ctrl+K Add Keywords; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a Line truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-05 · **Change:** minor (LR-EDIT-DETAIL-DENOISE: built-in denoiser uses block-matching collaborative filtering and runs it on the graphics card when there is one; LR-EDIT-DETAIL-DENOISE: built-in denoiser, no model needed; LR-BEHAV-ACCESS: the Flatpak may talk to the accessibility bus; before: LR-PROF-IMPORT: the user's own .dcp camera profiles import, checked on a real D750 profile against Lightroom; LRC-DEV-AUTOSYNC: white balance syncs on each photo's own scale, As Shot and Auto per photo; LR-LIB-FLAG: a flag or rating never waits for the drive, PERF-STEP-STALL; LRC-LIB-VISUALSEARCH: Find Similar Photos reads the photos on a worker thread, so a large library no longer freezes the window; LR-MASK-LINEAR: masks stay on the photo's content under lens corrections, Upright, Transform and Rotate; LR-IMP-FORMATS: the Canon CRW decoder is the shared craft-libs crate `craft-crw`; LR-PROF-CAMERACOLOR: chart-measured matrices for the Canon EOS D60, its white balance in Kelvin; CRW imports name their camera; LR-BEHAV-ACCESS: the Flatpak may talk to the accessibility bus; LR-LIB-ALBUM: album commands leave out photos the library no longer has and record nothing when they add nothing; LR-BEHAV-DRAGDROP: a right-click on a text field while photos are carried from the grid opens no Cut / Copy / Paste menu; LR-BEHAV-DRAGDROP: a right-click while photos are carried from the grid opens no context menu; LR-LIB-VIRTUALCOPY: default numbering is preflighted across the requested batch and explicit names bypass suffix allocation; LR-BEHAV-DRAGDROP: only the primary button drags photos out of the grid and drops them; KEYC-RATING: deleting a keyword while Enable Filters has the filter put aside no longer leaves an empty one there; LR-BEHAV-DRAGDROP: a drop's destination is named with its parent when another folder or album has the same name; LR-VIEW-FILMSTRIP: photos drag from the filmstrip to the same sidebar targets as from the grid; LRC-LIB-LIBFOLDERS: a deep row's count follows its name in a narrow panel; LR-FILT-FLAG / LRC-LIB-FILTERBAR: the flag toggles combine, Picked + Unflagged, #2588; LR-VIEW-PHOTOGRID, LR-VIEW-FILMSTRIP, LR-VIEW-COMPARE, LR-VIEW-SURVEY, LRC-LIB-REFVIEW, LRC-LIB-PEOPLE: the active photo's selection ring shows on light themes and in Compare, Survey and the face tiles, and needs a loaded thumbnail; LR-FILT-SEARCH-META: `>=` / `<=` in fielded search tokens; MENU-FILE-CLOSE, KEY-CLOSEWINDOW: the notes say Close Window quits the app, after the same check as Quit; MENU-EDIT-SELECTNONE, MENU-EDIT-PASTESELECTED: Edit lists Select Only Active Photo after Deselect All and Paste Settings from Previous after Paste Selected Settings…; on macOS no doubled separators are left where Settings… moved to the app menu; LR-BEHAV-TITLEBAR: a double-click follows the system setting, and a panel over the bar keeps the window still; KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 go to the next / previous keyword set; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings; KEYC-METADATA: ⌘K / Ctrl+K Add Keywords; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOMLine truncated
|
||||
|
||||
The measured, row-by-row checklist: one row per Lightroom feature, menu item and shortcut, what we
|
||||
have and what is missing. It answers *does the feature exist?* (feature breadth). Whether it is good
|
||||
@@ -207,7 +207,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
|
||||
| LR-EDIT-DETAIL-SHARPEN | Sharpening | P0 | ✅ | `ctl:detail.sharpenAmount`, `ctl:detail.sharpenRadius`, `ctl:detail.sharpenDetail`, `ctl:detail.sharpenMasking`, `crates/pipeline/src/visualize.rs` | Process V3: pixel-scale sharpening, working Radius and Detail, original-photo scale in previews and exports; V1/V2 preserve the previous rendering (`crates/pipeline/src/tests_sharpen.rs`). Alt/Option-drag previews: Amount greyscale, Radius / Detail the detail band sharpening amplifies, Masking the mask (white = sharpened) |
|
||||
| LR-EDIT-DETAIL-NR | Luminance noise reduction | P0 | ✅ | `ctl:detail.nrLuminance`, `ctl:detail.nrDetail`, `ctl:detail.nrContrast` | radii in the original's pixels, so grid, loupe and smaller exports look like the full-size render scaled down (`local::nr_params`, `Plan::detail_scale`, #960). Alt/Option-drag on Luminance, Detail and Contrast shows the photo in greyscale |
|
||||
| LR-EDIT-DETAIL-CNR | Colour noise reduction | P0 | ✅ | `ctl:detail.nrColor`, `ctl:detail.nrColorDetail`, `ctl:detail.nrColorSmoothness` | preview-size independent like luminance NR (#960) |
|
||||
| LR-EDIT-DETAIL-DENOISE | AI denoise | P2 | 🟡 | cmd:denoise.toggle, cmd:denoise.models.install, cmd:denoise.queue, ctl:enhance.denoise, `crates/denoise/`, `docs/denoise.md` | non-destructive Bayer RAW, opt-in weights, pure-Rust CPU/GPU; GPU convolution uses independently written shared scalars (Metal equivalence regression, issue #479); tiles can also run on another computer's graphics card (`lightcraft-cli denoise-serve`, `crates/denoise/src/remote.rs`); X-Trans/linear RGB, model policy and Lightroom fidelity remain; closing the model setup without installing turns the switch back off (#922) |
|
||||
| LR-EDIT-DETAIL-DENOISE | AI denoise | P2 | 🟡 | cmd:denoise.toggle, cmd:denoise.models.install, cmd:denoise.queue, ctl:enhance.denoise, `crates/denoise/`, `docs/denoise.md` | non-destructive Bayer RAW, works out of the box with a built-in classical denoiser (block-matching collaborative filtering, `crates/denoise-core/src/builtin.rs`; its filter runs on the graphics card when there is one that is faster, `crates/gpu/src/bm3d.rs`), optional user-installed weights, pure-Rust CPU/GPU; GPU convolution uses independently written shared scalars (Metal equivalence regression, issue #479); tiles can also run on another computer's graphics card (`lightcraft-cli denoise-serve`, `crates/denoise/src/remote.rs`); X-Trans/linear RGB, model policy and Lightroom fidelity remain; there is no model set-up step to abandon (#922) |
|
||||
| LR-EDIT-DETAIL-RAWDETAILS | Improved demosaic toggle | P2 | ⬜ | | |
|
||||
| LR-EDIT-DETAIL-SUPERRES | Super resolution | P2 | ⬜ | | |
|
||||
| LR-EDIT-DETAIL-AISHARPEN | AI sharpen | OOS | 🚫 | | |
|
||||
@@ -812,6 +812,9 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
|
||||
| 2026-10-25 | minor | KEYC-METADATA, LRC-LIB-KEYWORDS: ⌘⌥⇧K / Ctrl+Alt+Shift+K (`dialog.keywordShortcut`, Set Keyword Shortcut) and ⇧K (`keyword.toggleShortcut`) add and remove the keyword shortcut's keywords; Keyword Shortcut leaves LRC-LIB-KEYWORDS' Not yet list; status counts unchanged (KEYC-METADATA stays 🟡) |
|
||||
| 2026-10-27 | patch | LR-VIEW-HISTOGRAM: an edit with HDR switched off no longer shows the last HDR drag's histogram while it is dragged (#2819); status unchanged |
|
||||
| 2026-10-29 | patch | LR-VIEW-HISTOGRAM: the clipping buttons' tile and chevron come from the theme's tokens instead of a fixed dark gray, so the chevron stands 3:1 on its tile in all four themes; status counts unchanged |
|
||||
| 2026-10-24 | minor | LR-EDIT-DETAIL-DENOISE: the built-in denoiser measures noise by colour channel and ignores texture, and its strength follows the measured noise; status and counts unchanged |
|
||||
| 2026-10-24 | minor | LR-EDIT-DETAIL-DENOISE: the built-in denoiser filters with block-matching collaborative filtering instead of non-local means, and runs that filter on the graphics card where there is one; status and counts unchanged |
|
||||
| 2026-10-23 | minor | LR-EDIT-DETAIL-DENOISE: built-in denoiser, no model needed |
|
||||
| 2026-10-25 | patch | LR-BEHAV-TITLEBAR: the top bar's title-bar gestures come from craft-window's `title_bar`: a double-click follows the system setting, and a press on a button, the search field or a panel floating over the bar never moves the window; status counts unchanged |
|
||||
| 2026-10-24 | minor | KEYC-METADATA, LRC-LIB-KEYWORDS: ⌘⌥K / Ctrl+Alt+K (`tool.enablePainting`, Photo ▸ Enable Painting) paints the painter box's keyword or stops painting; status counts unchanged (KEYC-METADATA stays 🟡) |
|
||||
| 2026-10-24 | minor | KEYC-METADATA: ⌘⇧K / Ctrl+Shift+K (`panel.editKeywords`, Edit Keywords) shows the Keywords panel with its Keyword List open and opens the picked keyword in Edit Keyword Tag; status counts unchanged (KEYC-METADATA stays 🟡) |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Target-app parity: LightCraft vs Adobe Lightroom
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-26 · **Change:** minor (Canon CRW decoder shared via craft-libs `craft-crw`; Canon CRW decoded clean-room, 6 bodies verified; gap 9: CI runs the tests on Linux x64 since #2667; macOS, Windows and the GPU equivalence tests still don't; Minolta MRW decoded, 6 bodies verified; RAW: 85% of Adobe's models decode, 39% verified after the camera-coverage sweep #1327; Platforms: the Windows x64 installer verified on Windows 11) · **Target:** Adobe Lightroom Classic 15.5 (August 2026) and Lightroom 9.6 (desktop)
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-26 · **Change:** minor (AI Denoise works out of the box, numbers unchanged; Canon CRW decoder shared via craft-libs `craft-crw`; Canon CRW decoded clean-room, 6 bodies verified; gap 9: CI runs the tests on Linux x64 since #2667; macOS, Windows and the GPU equivalence tests still don't; Minolta MRW decoded, 6 bodies verified; RAW: 85% of Adobe's models decode, 39% verified after the camera-coverage sweep #1327; Platforms: the Windows x64 installer verified on Windows 11) · **Target:** Adobe Lightroom Classic 15.5 (August 2026) and Lightroom 9.6 (desktop)
|
||||
|
||||
The authoritative assessment of how close LightCraft is to Lightroom. The row-by-row checklist is
|
||||
[parity-checklist.md](parity-checklist.md); the ranked work list is [gaps.md](gaps.md); deep areas
|
||||
@@ -96,7 +96,7 @@ search embeddings; generative remove runs in Adobe's cloud.
|
||||
| People (faces, body, hair, skin…) and Landscape masks | — | ⬜ |
|
||||
| Object / Describe masks | SAM 3 in pure Rust (Metal / CPU); opt-in 3.4 GB download, no mirror configured | 🟡 |
|
||||
| Depth range mask, Lens Blur | — | ⬜ |
|
||||
| AI Denoise | Bayer only, pure-Rust CPU / GPU, user-installed weights | 🟡 |
|
||||
| AI Denoise | Bayer only, built-in classical denoiser out of the box, optional user-installed weights, pure-Rust CPU / GPU | 🟡 |
|
||||
| Raw Details, Super Resolution | — | ⬜ |
|
||||
| Generative remove, distractions, reflections | — (generative is out of scope: cloud) | ⬜ |
|
||||
| Dust detection | ✅ | ✅ |
|
||||
@@ -301,6 +301,7 @@ P2 items 12–25 h; look tuning, performance, packaging, hardening 25–45 h.
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-24 | patch | Stability, the stability discount, the Beta-needs list and the estimate history: tests run in CI on Linux x64 since #2667 (FreeBSD nightly), not on macOS or Windows (gap 9); percentages and hours unchanged |
|
||||
| 2026-10-23 | minor | AI Denoise runs without a model (built-in denoiser); percentages unchanged, since it is a classical filter and Bayer-only |
|
||||
| 2026-10-13 | minor | Canon CRW decoded (clean-room, craft-libs `crates/crw/clean-room/`): 551 models verified with the coverage sweep (557 with MRW after merging main), Canon preview rows 21 → 6; RAW decoding unchanged |
|
||||
| 2026-10-19 | patch | Stability note: tests run in CI on Linux x64 (every PR) as well as FreeBSD; macOS and Windows remain (gap 9) |
|
||||
| 2026-10-19 | minor | Localization ~55% → ~64% (mean of the 12 key languages): Indonesian (`id`) catalog, every message but What's New; full target 61.2% → 61.5% (still ~61%) |
|
||||
|
||||
+30
-1
@@ -306,6 +306,24 @@
|
||||
|
||||
## 2026-10-24
|
||||
|
||||
### AI Denoise follows the photo's real noise
|
||||
- The built-in denoiser used to read a photo's fine texture as noise, so it always believed a photo was at least as noisy as
|
||||
about ISO 12800 and over-smoothed quiet photos while under-cleaning noisy ones. It now measures each colour channel
|
||||
separately, ignores texture, and sets its strength from the noise it actually finds. On clean photos from a Canon EOS R and
|
||||
an R6 Mark III with noise added at real ISO levels, the result at ISO 25600 is 2.2 to 2.7 dB closer to the original, and at
|
||||
ISO 51200 about 5.5 dB closer; at ISO 6400 it is 0.6 to 1.0 dB closer, and quiet photos are no longer smoothed
|
||||
needlessly. Photos denoised before are denoised again when they are next needed. See [AI Denoise](denoise.md).
|
||||
|
||||
### Better built-in AI Denoise
|
||||
- The built-in denoiser now cleans with block-matching collaborative filtering: similar blocks of the picture are
|
||||
grouped, transformed together and thresholded, so more fine detail survives at the same level of cleaning. On a
|
||||
public raw with added noise it scores 0.25 to 0.6 dB higher than before at every noise level and keeps more
|
||||
texture at medium to extreme noise (medium: 44 % of it against 42 %; extreme: 12 % against 9 %), a little less at
|
||||
light noise (58 % against 62 %), with no colour blotches or isolated specks. It is as fast as the old filter on the processor, and when the computer has a graphics card that is faster
|
||||
it runs there: on an RTX 4080 SUPER a photo's tiles go about 6 to 10 times faster, with the same picture (Settings ▸ AI
|
||||
Denoise ▸ Run on chooses; Automatic times both). Photos
|
||||
denoised before are denoised again the next time they are needed. See [AI Denoise](denoise.md).
|
||||
|
||||
### A right-click on a text field while you carry photos opens no menu
|
||||
- While you drag photos from the grid, a right-click on a text field, such as the search box, opens no Cut, Copy and
|
||||
Paste menu. Before, the menu opened over the field the photos were on. Right-clicking a field without a drag works
|
||||
@@ -387,6 +405,17 @@
|
||||
|
||||
## 2026-10-23
|
||||
|
||||
### AI Denoise works out of the box
|
||||
- Turning on AI Denoise no longer asks for an ONNX model and a `denoise-model.json`: LightCraft's own built-in
|
||||
denoiser runs automatically. Installing a model of your own is optional (Settings ▸ AI Denoise ▸ Your own model);
|
||||
Stop using returns to the built-in one. The set-up prompt and its "resume after installing" flow are gone. See
|
||||
[AI Denoise](denoise.md).
|
||||
- The built-in denoiser measures the photo's noise once, cleans the four colour planes together on variance-stabilised
|
||||
data (so colour blotches go too), and cleans harder, with a second pass, the noisier the photo is. Colour noise gets
|
||||
a wider pass of its own, and in heavy noise isolated specks are smoothed away. On a public raw with added noise it
|
||||
scores 3.7 to 10.4 dB higher than the noisy picture, the most at heavy noise, and keeps more fine texture there
|
||||
than before (heavy noise: 22 % of it against 20 %; extreme: 9 % against 7 %).
|
||||
|
||||
### Export subfolders stay inside the export folder
|
||||
- An export subfolder (typed in the Export dialog, saved in a preset or passed to `export`) can no longer lead
|
||||
outside the chosen folder (issue #2571). `..` and `.` parts and a leading `/` are dropped, and `\` and `:` become
|
||||
@@ -1838,7 +1867,7 @@
|
||||
|
||||
### AI RAW denoise
|
||||
- Detail has a per-photo AI Denoise switch and Amount. Bayer RAW photos use a disposable cache, with matching previews and exports and pure-Rust CPU/GPU inference.
|
||||
- Models are installed separately after accepting their terms; no weights are bundled. See [setup and limitations](denoise.md).
|
||||
- Optional models are installed separately after accepting their terms; no weights are bundled. See [setup and limitations](denoise.md).
|
||||
|
||||
### Library keyboard culling
|
||||
- Colour labels tint thumbnail surrounds in Square Grid and the Detail filmstrip, and a translucent footer along the bottom of the photo in Photo Grid. Label confirmations use a matching pale colour.
|
||||
|
||||
Reference in new issue
Block a user