Kaleido-Desktop/src/app/settings.ts
Elijah 5b6c063ff1 Use nlmeans and FSRCNNX 16 for the Quality upscaling tier
ArtCNN is tuned for animation and looked unnatural on live action, and
its first Direct3D compile took about a minute per model. Quality now
denoises with AN3223's nlmeans (general-purpose profile, any size) and
upscales with FSRCNNX 16-0-4-1, trained on general imagery, at any
enlargement. Both compile in seconds; 1080p in a maximized 1440p window
measured 3.2 ms per frame.

The first-compile notice now covers any shader set not yet compiled on
the machine but only shows after three seconds, and a set with nothing
to verify at the current size clears it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 19:51:47 -07:00

154 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { create } from 'zustand';
import { persist } from 'zustand/middleware';
export type Quality = 'original' | '2160' | '1080' | '720' | '480';
export type SkipMode = 'off' | 'button' | 'auto';
export type SubtitleMode = 'auto' | 'always' | 'forced' | 'off';
export type SubtitleEdge = 'outline' | 'shadow' | 'raised' | 'none';
export type SubtitleBox = 'none' | 'translucent' | 'solid';
export type SubtitlePosition = 'low' | 'normal' | 'high';
export type Upscaling = 'off' | 'performance' | 'balanced' | 'quality';
export interface Preferences {
// Playback
quality: Quality;
remoteQuality: Quality;
hwdec: boolean;
hdrPassthrough: boolean;
autoplayNext: boolean;
countdownSeconds: number;
skipIntro: SkipMode;
skipCredits: SkipMode;
watchedPercent: number;
audioLanguage: string;
subtitleMode: SubtitleMode;
subtitleLanguage: string;
subtitleScale: number;
subtitleColor: string;
subtitleEdge: SubtitleEdge;
subtitleBox: SubtitleBox;
subtitleBold: boolean;
subtitlePosition: SubtitlePosition;
volume: number;
seekStep: number;
/** Video enhancement, chosen in the player, and its optional stages. */
upscaling: Upscaling;
enhanceDeband: boolean;
enhanceSharpen: boolean;
enhanceDenoise: boolean;
// Interface
startPage: 'home' | 'movies' | 'shows';
colorWash: boolean;
reducedMotion: boolean;
posterSize: 'compact' | 'comfortable' | 'large';
heroRotation: boolean;
themeMusic: boolean;
themeVolume: number;
// Libraries shown for Movies and TV Shows
movieSection: string;
showSection: string;
// Downloads
downloadDir: string;
// Remembered library views per section
libraryViews: Record<string, { sort: string; filters: Record<string, string> }>;
}
export const defaults: Preferences = {
quality: 'original',
remoteQuality: '1080',
hwdec: true,
hdrPassthrough: true,
autoplayNext: true,
countdownSeconds: 8,
skipIntro: 'button',
skipCredits: 'button',
watchedPercent: 90,
audioLanguage: '',
subtitleMode: 'auto',
subtitleLanguage: '',
subtitleScale: 1,
subtitleColor: '#FFFFFF',
subtitleEdge: 'outline',
subtitleBox: 'none',
subtitleBold: false,
subtitlePosition: 'normal',
volume: 100,
seekStep: 10,
upscaling: 'off',
enhanceDeband: true,
enhanceSharpen: true,
enhanceDenoise: true,
startPage: 'home',
colorWash: true,
reducedMotion: false,
posterSize: 'comfortable',
heroRotation: true,
themeMusic: false,
themeVolume: 30,
movieSection: '',
showSection: '',
downloadDir: '',
libraryViews: {},
};
interface SettingsState extends Preferences {
set<K extends keyof Preferences>(key: K, value: Preferences[K]): void;
reset(): void;
}
export const useSettings = create<SettingsState>()(
persist(
(set) => ({
...defaults,
set: (key, value) => set({ [key]: value } as Partial<SettingsState>),
reset: () => set({ ...defaults }),
}),
{
name: 'kaleido.settings',
version: 2,
migrate: (persisted, version) => {
const p = (persisted ?? {}) as Record<string, unknown>;
// 1 → 2: the subtitle background switch became a box style.
if (version < 2 && 'subtitleBackground' in p) {
p.subtitleBox = p.subtitleBackground ? 'translucent' : 'none';
delete p.subtitleBackground;
}
return p as unknown as SettingsState;
},
},
),
);
export const QUALITY_LABEL: Record<Quality, string> = {
original: 'Original quality',
'2160': '4K (40 Mbps)',
'1080': '1080p (20 Mbps)',
'720': '720p (4 Mbps)',
'480': '480p (1.5 Mbps)',
};
export const QUALITY_PROFILE: Record<Exclude<Quality, 'original'>, { kbps: number; width: number; height: number }> = {
'2160': { kbps: 40000, width: 3840, height: 2160 },
'1080': { kbps: 20000, width: 1920, height: 1080 },
'720': { kbps: 4000, width: 1280, height: 720 },
'480': { kbps: 1500, width: 854, height: 480 },
};
export const SUBTITLE_COLORS: { value: string; label: string }[] = [
{ value: '#FFFFFF', label: 'White' },
{ value: '#FFE14D', label: 'Yellow' },
{ value: '#7FE3F0', label: 'Cyan' },
{ value: '#9BE58A', label: 'Green' },
{ value: '#F4A6D7', label: 'Pink' },
{ value: '#BFC5CA', label: 'Grey' },
];
/** Bottom margin in mpv's scaled pixels (720 = window height). */
export const SUBTITLE_MARGIN: Record<SubtitlePosition, number> = { low: 14, normal: 34, high: 80 };
export const UPSCALING: Record<Upscaling, { label: string; detail: string }> = {
off: { label: 'Off', detail: 'mpv’s standard scaling' },
performance: { label: 'Performance', detail: 'Sharp scaling, debanding and light sharpening' },
balanced: { label: 'Balanced', detail: 'Neural upscaling (FSRCNNX), colour reconstruction, debanding and sharpening' },
quality: { label: 'Quality', detail: 'nlmeans denoising, larger neural upscaler (FSRCNNX 16), colour reconstruction, debanding and sharpening. Needs a capable GPU' },
};