Land camera-native raw profiles, real ICC soft proofing and 16-bit proxies.

Camera profiles, proofing tables and the half-float sidecar all have to agree
with the pixels the editor actually grades, so they land together with the
preset filter menu that was unusable while thumbnails streamed in.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-28 03:59:55 +00:00
parent 6dfddffc14
commit 0c113e7a91
53 changed files with 9217 additions and 476 deletions
+70 -3
View File
@@ -96,11 +96,27 @@ export function thumbTransform(photo: PhotoRecord, boxAspect = 4 / 3): string {
/** The shader carries a fixed spot array; more than this would silently drop. */
export const MAX_HEAL_SPOTS = 24;
/** Four masks are packed into one RGBA texture. */
export const MAX_LOCAL_LAYERS = 4;
/** Eight masks are packed into two RGBA textures. */
export const MAX_LOCAL_LAYERS = 8;
export function defaultLocalAdjust(): LocalLayer['adjust'] {
return { exposure: 0, contrast: 0, highlights: 0, shadows: 0, temp: 0, tint: 0, saturation: 0 };
return {
exposure: 0,
contrast: 0,
highlights: 0,
shadows: 0,
whites: 0,
blacks: 0,
temp: 0,
tint: 0,
saturation: 0,
vibrance: 0,
hue: 0,
texture: 0,
clarity: 0,
dehaze: 0,
sharpen: 0,
};
}
export function defaultLocalLayer(kind: LocalMaskKind, index: number): LocalLayer {
@@ -108,6 +124,7 @@ export function defaultLocalLayer(kind: LocalMaskKind, index: number): LocalLaye
id: `local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
name: `Local ${index + 1}`,
kind,
mode: 'add',
inverted: false,
feather: 50,
brush: { strokes: [] },
@@ -146,6 +163,7 @@ export function defaultEdits(): Edits {
return {
temp: 0,
tint: 0,
kelvin: null,
exposure: 0,
recovery: 0,
contrast: 0,
@@ -158,6 +176,7 @@ export function defaultEdits(): Edits {
dehaze: 0,
vibrance: 0,
saturation: 0,
redscale: 0,
bw: false,
bwFilter: 'none',
bwFilterAmount: 100,
@@ -167,6 +186,7 @@ export function defaultEdits(): Edits {
green: identityCurve(),
blue: identityCurve(),
},
levels: { black: 0, white: 100, gamma: 1 },
parametric: { highlights: 0, lights: 0, darks: 0, blacks: 0 },
hsl: {
hue: HUE_BANDS.map(() => 0),
@@ -180,6 +200,7 @@ export function defaultEdits(): Edits {
},
sharpen: { amount: 0, radius: 1, detail: 25, mask: 0, lensSoftness: 0 },
proof: { enabled: false, paper: 'matte', blackPoint: 2, gamut: false },
cameraProfile: null,
noise: { luminance: 0, detail: 50, chroma: 0, chromaDetail: 50 },
aiDenoise: { amount: 100, key: null, model: 'guided' },
defringe: { purple: 0, green: 0 },
@@ -264,6 +285,8 @@ function localLayers(input: unknown): LocalLayer[] {
id: typeof layer.id === 'string' && layer.id ? layer.id : `local-${out.length}`,
name: typeof layer.name === 'string' && layer.name.trim() ? layer.name.slice(0, 40) : `Local ${out.length + 1}`,
kind,
mode:
layer.mode === 'subtract' || layer.mode === 'intersect' ? layer.mode : 'add',
inverted: !!layer.inverted,
feather: num(layer.feather, 50, 0, 100),
brush: { strokes: localStrokes(layer.brush?.strokes) },
@@ -293,9 +316,17 @@ function localLayers(input: unknown): LocalLayer[] {
contrast: num(adjust.contrast, 0, -100, 100),
highlights: num(adjust.highlights, 0, -100, 100),
shadows: num(adjust.shadows, 0, -100, 100),
whites: num(adjust.whites, 0, -100, 100),
blacks: num(adjust.blacks, 0, -100, 100),
temp: num(adjust.temp, 0, -100, 100),
tint: num(adjust.tint, 0, -100, 100),
saturation: num(adjust.saturation, 0, -100, 100),
vibrance: num(adjust.vibrance, 0, -100, 100),
hue: num(adjust.hue, 180, -180, 180),
texture: num(adjust.texture, 0, -100, 100),
clarity: num(adjust.clarity, 0, -100, 100),
dehaze: num(adjust.dehaze, 0, -100, 100),
sharpen: num(adjust.sharpen, 0, -100, 100),
},
});
}
@@ -338,10 +369,28 @@ function lensProfile(input: unknown): LensProfile | undefined {
};
}
/**
* Keeps a stored camera profile usable: a profile with a missing or non-finite
* matrix would black out the photo, so it is dropped instead.
*/
export function normalizeCameraProfile(value: unknown): Edits['cameraProfile'] {
if (!value || typeof value !== 'object') return null;
const raw = value as { name?: unknown; matrix?: unknown };
if (!Array.isArray(raw.matrix)) return null;
const matrix = raw.matrix.slice(0, 9).map(Number);
if (matrix.length !== 9 || !matrix.every(Number.isFinite)) return null;
const name =
typeof raw.name === 'string' && raw.name.trim()
? raw.name.trim().slice(0, 80)
: 'Camera profile';
return { name, matrix };
}
export function normalizeEdits(input: Partial<Edits> | undefined | null): Edits {
const d = defaultEdits();
if (!input) return d;
const curve = (input.curve ?? {}) as Partial<Edits['curve']>;
const levels = (input.levels ?? {}) as Partial<Edits['levels']>;
const parametric = (input.parametric ?? {}) as Partial<Edits['parametric']>;
const grading = (input.grading ?? {}) as Partial<Edits['grading']>;
const sharpen = (input.sharpen ?? {}) as Partial<Edits['sharpen']>;
@@ -355,6 +404,7 @@ export function normalizeEdits(input: Partial<Edits> | undefined | null): Edits
return {
...d,
...input,
cameraProfile: normalizeCameraProfile(input.cameraProfile),
aiDenoise: {
amount: num(aiDenoise.amount, d.aiDenoise.amount, 0, 100),
key: typeof aiDenoise.key === 'string' && aiDenoise.key ? aiDenoise.key : null,
@@ -362,6 +412,10 @@ export function normalizeEdits(input: Partial<Edits> | undefined | null): Edits
},
temp: num(input.temp, 0, -100, 100),
tint: num(input.tint, 0, -100, 100),
kelvin:
typeof input.kelvin === 'number' && Number.isFinite(input.kelvin)
? clamp(input.kelvin, 1500, 15000)
: null,
exposure: num(input.exposure, 0, -5, 5),
recovery: num(input.recovery, 0, 0, 100),
contrast: num(input.contrast, 0, -100, 100),
@@ -374,6 +428,7 @@ export function normalizeEdits(input: Partial<Edits> | undefined | null): Edits
dehaze: num(input.dehaze, 0, -100, 100),
vibrance: num(input.vibrance, 0, -100, 100),
saturation: num(input.saturation, 0, -100, 100),
redscale: num(input.redscale, 0, 0, 100),
bw: !!input.bw,
bwFilter: BW_FILTERS.some((f) => f.id === input.bwFilter) ? (input.bwFilter as BwFilter) : 'none',
bwFilterAmount: num(input.bwFilterAmount, d.bwFilterAmount, 0, 100),
@@ -383,6 +438,14 @@ export function normalizeEdits(input: Partial<Edits> | undefined | null): Edits
green: sanitizeCurve(curve.green),
blue: sanitizeCurve(curve.blue),
},
levels: {
black: num(levels.black, 0, 0, 45),
white: Math.max(
num(levels.black, 0, 0, 45) + 5,
num(levels.white, 100, 55, 100),
),
gamma: num(levels.gamma, 1, 0.3, 3),
},
parametric: {
highlights: num(parametric.highlights, 0, -100, 100),
lights: num(parametric.lights, 0, -100, 100),
@@ -489,6 +552,10 @@ export function normalizePhoto(input: Partial<PhotoRecord> & { id: string }): Ph
decode: input.decode,
previewUrl: input.previewUrl,
thumbUrl: input.thumbUrl,
previewVersion:
typeof input.previewVersion === 'number' && Number.isFinite(input.previewVersion)
? input.previewVersion
: undefined,
proofAt: typeof input.proofAt === 'number' && Number.isFinite(input.proofAt) ? input.proofAt : undefined,
name: input.name ?? 'Untitled',
width: input.width ?? 0,