Offer SCUNet and NLM alongside the guided denoise

The AI denoise panel now picks between three bases: the existing guided
filter, non-local means and a learned SCUNet model run through
onnxruntime-node on overlapping tiles. The base is part of the render key, so
each model keeps its own cached render and switching back is instant, and jobs
report stage and tile progress instead of a bare spinner.

onnxruntime-node is pinned to 1.23.0, the last release that ships both macOS
architectures, and every Docker and desktop install skips its CUDA download
because only the CPU binaries in the package are used. The SCUNet weights and
ONNX Runtime are added to the third-party notices, the deb copyright file and
the README's denoise, API and redistribution sections.
This commit is contained in:
2026-12-01 04:03:53 +00:00
parent b34d34dacb
commit f7942d0bd0
26 changed files with 945 additions and 161 deletions
+84
View File
@@ -0,0 +1,84 @@
import { describe, expect, it } from 'vitest';
import { defaultEdits, normalizeEdits } from './edits';
import {
DENOISE_MODELS,
denoiseModelLabel,
denoiseProgressLabel,
withDenoiseRender,
} from './denoiseModels';
describe('AI denoise edit normalization', () => {
it('keeps the model the user picked', () => {
for (const model of ['guided', 'scunet', 'nlm'] as const) {
expect(normalizeEdits({ aiDenoise: { model } } as never).aiDenoise.model).toBe(model);
}
});
it('defaults an unknown or missing model to guided', () => {
expect(normalizeEdits({}).aiDenoise.model).toBe('guided');
expect(normalizeEdits({ aiDenoise: {} } as never).aiDenoise.model).toBe('guided');
expect(normalizeEdits({ aiDenoise: { model: 'swinir' } } as never).aiDenoise.model).toBe(
'guided',
);
});
it('keeps the render key and the amount, and drops an unusable key', () => {
const kept = normalizeEdits({ aiDenoise: { model: 'nlm', key: 'abc123', amount: 40 } } as never);
expect(kept.aiDenoise).toEqual({ model: 'nlm', key: 'abc123', amount: 40 });
const dropped = normalizeEdits({ aiDenoise: { key: '' } } as never);
expect(dropped.aiDenoise.key).toBeNull();
});
});
describe('AI denoise model selection', () => {
it('commits the render under the base that produced it', () => {
// The regression: the panel's completion path used to spread a copy of the
// edit captured before the chip click, which put the previous model back.
const previous = { ...defaultEdits().aiDenoise, model: 'guided' as const, amount: 70 };
const next = withDenoiseRender(previous, 'scunet', 'key-scunet');
expect(next).toEqual({ model: 'scunet', key: 'key-scunet', amount: 70 });
expect(previous).toEqual({ model: 'guided', key: null, amount: 70 });
});
it('keeps a stale picker honest for every base', () => {
const previous = { ...defaultEdits().aiDenoise, model: 'guided' as const };
for (const option of DENOISE_MODELS) {
expect(withDenoiseRender(previous, option.value, `key-${option.value}`).model).toBe(
option.value,
);
}
});
it('names the stage and tile count a running render reports', () => {
expect(denoiseProgressLabel({ stage: 'base', done: 12, total: 40 }, 'scunet', 31)).toBe(
'Rendering with SCUNet · denoising 12/40 tiles · 31s elapsed',
);
expect(denoiseProgressLabel({ stage: 'gate' }, 'guided', 7.4)).toBe(
'Rendering with Guided · mapping detail · 7s elapsed',
);
// No tile counter for the classical models, and no stage at all before the
// first poll lands.
expect(denoiseProgressLabel({ stage: 'base' }, 'nlm', 2)).toBe(
'Rendering with NLM · denoising · 2s elapsed',
);
expect(denoiseProgressLabel(null, 'scunet', 0)).toBe(
'Rendering with SCUNet · starting · 0s elapsed',
);
// A worker that over-counts cannot report past the end of the run.
expect(denoiseProgressLabel({ stage: 'base', done: 99, total: 40 }, 'scunet', 90)).toContain(
'40/40 tiles',
);
});
it('offers each selectable model exactly once, with a label', () => {
const values = DENOISE_MODELS.map((option) => option.value);
expect(new Set(values).size).toBe(values.length);
expect(values).toEqual(['guided', 'scunet', 'nlm']);
for (const option of DENOISE_MODELS) {
expect(option.label, option.value).toBeTruthy();
expect(option.title, option.value).toBeTruthy();
expect(denoiseModelLabel(option.value)).toBe(option.label);
}
});
});