import type { DenoiseProgress } from './api'; import type { Edits } from '../types'; /** One of the base denoisers the AI denoise panel can render with. */ export type DenoiseModel = Edits['aiDenoise']['model']; export type AiDenoise = Edits['aiDenoise']; /** * The models in panel order. `guided` is the default and the fast one; the two * learned/classical alternates are additive, so the list is also the contract * the picker and the help text are built from. */ export const DENOISE_MODELS: { value: DenoiseModel; label: string; title: string }[] = [ { value: 'guided', label: 'Guided', title: 'Guided filter — fast, keeps the most fine texture' }, { value: 'scunet', label: 'SCUNet', title: 'SCUNet — learned model, removes the most grain, smooths more' }, { value: 'nlm', label: 'NLM', title: 'Non-local means — slower, between Guided and SCUNet' }, ]; export function denoiseModelLabel(model: DenoiseModel): string { return DENOISE_MODELS.find((option) => option.value === model)?.label ?? 'Guided'; } /** Human names for the pipeline stages the worker reports. */ const STAGE_LABELS: Record = { analyse: 'reading the noise profile', base: 'denoising', gate: 'mapping detail', render: 'blending the result', }; /** * One line describing a running render. The stage names and the tile counter * come from the worker, so this is real progress rather than a spinner -- the * elapsed time is only the fallback for the first second or two. */ export function denoiseProgressLabel( progress: DenoiseProgress | null | undefined, model: DenoiseModel, elapsedSeconds: number, ): string { const seconds = Math.max(0, Math.round(elapsedSeconds)); const stage = progress?.stage ? (STAGE_LABELS[progress.stage] ?? 'working') : 'starting'; const tiles = progress?.stage === 'base' && progress.total ? ` ${Math.min(progress.done ?? 0, progress.total)}/${progress.total} tiles` : ''; return `Rendering with ${denoiseModelLabel(model)} · ${stage}${tiles} · ${seconds}s elapsed`; } /** * Commit a finished render to the edit. The cache key belongs to the base that * produced it, so the picker follows that base: a caller holding an older copy * of the edit cannot put the previous model back in front of a fresh key. */ export function withDenoiseRender(ai: AiDenoise, base: DenoiseModel, key: string): AiDenoise { return { ...ai, model: base, key }; }