Show camera profiles in every view and remember proof and DCP settings.

A profile chosen for a raw only changed Develop and exports, so the grid,
Compare and preset previews could disagree with the file. They now grade
camera-native samples, while the proof profile persists with a rendering
intent and DCP matrices can be reused per camera body.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-28 04:04:44 +00:00
parent 0c113e7a91
commit 637629385a
16 changed files with 720 additions and 39 deletions
+22 -3
View File
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from 'react';
import { getBitmap } from '../lib/images';
import { get16BitSource, getBitmap } from '../lib/images';
import type { Preview16 } from '../lib/preview16';
import { rotatedBounds, Renderer } from '../gl/renderer';
import { buildLensCorrection, type LensCorrection } from '../lib/lensfun';
import type { PhotoRecord } from '../types';
@@ -15,6 +16,7 @@ function CompareTile({ photo, onOpen }: { photo: PhotoRecord; onOpen: (id: strin
const boxRef = useRef<HTMLDivElement>(null);
const rendererRef = useRef<Renderer | null>(null);
const [bitmap, setBitmap] = useState<ImageBitmap | null>(null);
const [hdr, setHdr] = useState<Preview16 | null>(null);
const [box, setBox] = useState({ w: 0, h: 0 });
const [lensCorrection, setLensCorrection] = useState<LensCorrection | null>(null);
const [error, setError] = useState<string | null>(null);
@@ -29,6 +31,23 @@ function CompareTile({ photo, onOpen }: { photo: PhotoRecord; onOpen: (id: strin
};
}, [photo]);
// Compare renders the full proxy, so the matching 16-bit sidecar is what lets
// a per-photo camera profile show here exactly as it does in Develop. Without
// a profile the JPEG already carries the body matrix, so skip the big fetch.
useEffect(() => {
let alive = true;
if (!photo.edits.cameraProfile) {
setHdr(null);
return;
}
get16BitSource(photo)
.then((next) => alive && setHdr(next))
.catch(() => alive && setHdr(null));
return () => {
alive = false;
};
}, [photo]);
useEffect(() => {
let alive = true;
if (!photo.edits.lens || !bitmap) {
@@ -98,14 +117,14 @@ function CompareTile({ photo, onOpen }: { photo: PhotoRecord; onOpen: (id: strin
lens: lensCorrection,
};
try {
renderer.setImage(bitmap);
renderer.setImage(bitmap, hdr);
renderer.render(photo.edits, opts);
} catch (err) {
setError(err instanceof Error ? err.message : 'Rendering failed');
}
});
return () => cancelAnimationFrame(raf);
}, [bitmap, box, photo, lensCorrection]);
}, [bitmap, box, photo, lensCorrection, hdr]);
return (
<figure className="compare-tile" onDoubleClick={() => onOpen(photo.id)}>
+20
View File
@@ -8,6 +8,7 @@ import {
} from '../lib/edits';
import { subscribeClipPreview } from '../lib/clipPreview';
import { get16BitSource, getBitmap, getDenoisedBitmap } from '../lib/images';
import { rebuildProofCube, restoreProofProfile } from '../lib/softProof';
import type { Preview16 } from '../lib/preview16';
import { useMediaQuery } from '../lib/useMediaQuery';
import { usePersistentState } from '../lib/usePersistentState';
@@ -627,6 +628,25 @@ export default function Develop({
return () => cancelAnimationFrame(raf);
}, [bitmap, drawPreview]);
// The printer profile lives outside the edit record, so restoring it and
// following an intent change are handled here rather than by the proof panel.
useEffect(() => {
let alive = true;
void restoreProofProfile(edits.proof.intent).then((cube) => {
if (alive && cube) setProofProfile(cube.name);
});
return () => {
alive = false;
};
// Restore once; intent changes are picked up by the effect below.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const cube = rebuildProofCube(edits.proof.intent);
if (cube) setProofProfile(cube.name);
}, [edits.proof.intent]);
/* ------------------------------------------------------------ zoom & pan */
const applyZoom = useCallback((rawPct: number | 'fit', point?: { x: number; y: number }) => {
+77 -3
View File
@@ -21,8 +21,21 @@ import { getBitmap } from '../lib/images';
import { grainSampleWindow, rotatedBounds, Renderer } from '../gl/renderer';
import { applyFilmVariant, FILM_VARIANTS, PRESET_CATEGORIES, type FilmVariant } from '../lib/presets';
import { usePersistentState } from '../lib/usePersistentState';
import { loadProofProfile, setActiveProofCube, type SoftProofCube } from '../lib/softProof';
import {
clearPersistedProofProfile,
loadProofProfile,
persistProofProfile,
setActiveProofCube,
type SoftProofCube,
} from '../lib/softProof';
import { dcpRgbCam, parseDcp } from '../lib/dcp';
import {
loadSavedCameraProfiles,
removeCameraProfile,
saveCameraProfile,
savedProfilesForCamera,
type SavedCameraProfile,
} from '../lib/dcpLibrary';
import { usePresetThumbs } from './PresetThumbs';
import { availableFor, findLensForMeta, searchLens, type LensSearchResult } from '../lib/lensfun';
import {
@@ -2178,6 +2191,12 @@ export function CameraProfilePanel({
}: PanelSetProps & { cameraNative?: boolean }) {
const [error, setError] = useState<string | null>(null);
const profile = edits.cameraProfile;
const camera = photo.meta?.camera ?? '';
// Saved per camera body: the matrix describes the sensor, so every frame from
// the same body can reuse it without opening the .dcp file again.
const [saved, setSaved] = useState<SavedCameraProfile[]>(() => loadSavedCameraProfiles());
const matching = useMemo(() => savedProfilesForCamera(saved, camera), [saved, camera]);
const applied = matching.find((entry) => entry.name === profile?.name);
const load = async (file: File) => {
if (!cameraNative) return;
@@ -2188,6 +2207,7 @@ export function CameraProfilePanel({
if (!matrix) throw new Error('This profile has no usable colour matrix');
setError(null);
set({ cameraProfile: { name: parsed.name, matrix } }, 'Camera profile');
setSaved(saveCameraProfile({ name: parsed.name, camera: camera || parsed.camera, matrix }));
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not read that profile');
}
@@ -2219,7 +2239,7 @@ export function CameraProfilePanel({
className="btn ghost small"
onClick={() => {
setError(null);
set({ cameraProfile: null }, 'Body camera profile');
set({ cameraProfile: null }, 'Body camera matrix');
}}
>
Use body matrix
@@ -2227,6 +2247,38 @@ export function CameraProfilePanel({
)}
</div>
)}
{matching.length > 0 && (
<label className="field">
<span>Saved for this camera</span>
<select
value=""
onChange={(e) => {
const entry = matching.find((item) => item.id === e.target.value);
if (!entry) return;
setError(null);
set({ cameraProfile: { name: entry.name, matrix: entry.matrix } }, 'Camera profile');
}}
>
<option value="">Choose a saved profile…</option>
{matching.map((entry) => (
<option key={entry.id} value={entry.id}>
{entry.name}
</option>
))}
</select>
</label>
)}
{applied && (
<button
className="btn ghost small"
onClick={() => {
setSaved(removeCameraProfile(applied.id));
setError(null);
}}
>
Forget saved {applied.name}
</button>
)}
<p className="muted small panel-hint">
{!cameraNative
? 'This proxy was decoded straight to sRGB, so there are no camera samples to profile. Reprocess the RAW to enable camera profiles.'
@@ -2254,7 +2306,10 @@ export function ProofPanel({
const loadProfile = async (file: File) => {
try {
const cube = loadProofProfile(new Uint8Array(await file.arrayBuffer()));
const bytes = new Uint8Array(await file.arrayBuffer());
const cube = loadProofProfile(bytes, 33, proof.intent);
// Persisting is best-effort: the cube is live even when IndexedDB is not.
void persistProofProfile();
setProfileError(null);
onProofProfile?.(cube);
} catch (err) {
@@ -2293,6 +2348,24 @@ export function ProofPanel({
<option value="newsprint">Newsprint</option>
</select>
</label>
<label className="field">
<span>Rendering intent</span>
<select
value={proof.intent}
onChange={(e) =>
set(
{ proof: { ...proof, intent: e.target.value as typeof proof.intent } },
'Rendering intent',
)
}
disabled={!proof.enabled}
title="Which printer table pair the proof uses. Relative colorimetric is what most print shops expect; saturation is often absent from paper profiles and falls back to perceptual."
>
<option value="perceptual">Perceptual</option>
<option value="relative">Relative colorimetric</option>
<option value="saturation">Saturation</option>
</select>
</label>
<Slider
label="Paper black"
min={0}
@@ -2324,6 +2397,7 @@ export function ProofPanel({
className="btn ghost small"
onClick={() => {
setActiveProofCube(null);
void clearPersistedProofProfile();
setProfileError(null);
onProofProfile?.(null);
}}
+13 -7
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { normalizeEdits } from '../lib/edits';
import { getBitmap } from '../lib/images';
import { get16BitSource, getBitmap } from '../lib/images';
import { Renderer, rotatedBounds } from '../gl/renderer';
import type { PhotoRecord, Preset } from '../types';
@@ -14,7 +14,8 @@ const CACHE_LIMIT = 900;
const THUMB_EDGE = 200;
/** The crop is part of the key so a turn, straighten or flip refreshes the tiles. */
const keyOf = (photoId: string, presetId: string, crop: string) => `${photoId}|${presetId}|${crop}`;
const keyOf = (photoId: string, presetId: string, crop: string, source: string) =>
`${photoId}|${presetId}|${crop}|${source}`;
export function usePresetThumbs(photo: PhotoRecord, presets: Preset[]): Record<string, string> {
const [thumbs, setThumbs] = useState<Record<string, string>>({});
@@ -23,6 +24,10 @@ export function usePresetThumbs(photo: PhotoRecord, presets: Preset[]): Record<s
const presetKey = presets.map((p) => p.id).join('|');
const crop = photo.edits.crop;
const cropKey = [crop.x, crop.y, crop.w, crop.h, crop.angle, crop.quarter, crop.flipH, crop.flipV].join(',');
// The preset previews keep the photo's camera profile, so a reprocess or a
// different profile has to invalidate tiles the same way a crop does.
const profile = photo.edits.cameraProfile;
const sourceKey = `${photo.previewVersion ?? 0}|${profile ? profile.matrix.join(',') : ''}`;
useEffect(() => {
let alive = true;
@@ -31,7 +36,7 @@ export function usePresetThumbs(photo: PhotoRecord, presets: Preset[]): Record<s
const known: Record<string, string> = {};
for (const preset of presets) {
const hit = cache.get(keyOf(photo.id, preset.id, cropKey));
const hit = cache.get(keyOf(photo.id, preset.id, cropKey, sourceKey));
if (hit) known[preset.id] = hit;
}
setThumbs(known);
@@ -43,6 +48,7 @@ export function usePresetThumbs(photo: PhotoRecord, presets: Preset[]): Record<s
try {
const bitmap = await getBitmap(photo);
if (!alive) return;
const hdr = profile ? await get16BitSource(photo).catch(() => null) : null;
renderer = new Renderer(canvas);
// Every tile shows the photo as it is framed now, so a turned photo's
// presets are turned too.
@@ -52,18 +58,18 @@ export function usePresetThumbs(photo: PhotoRecord, presets: Preset[]): Record<s
const scale = THUMB_EDGE / Math.max(cropW, cropH);
const width = Math.max(1, Math.round(cropW * scale));
const height = Math.max(1, Math.round(cropH * scale));
renderer.setImage(bitmap);
renderer.setImage(bitmap, hdr);
for (const preset of pending) {
if (!alive) break;
try {
renderer.render({ ...normalizeEdits(preset.edits), crop }, {
renderer.render({ ...normalizeEdits(preset.edits), crop, cameraProfile: profile }, {
width,
height,
upscale: Math.max(width / cropW, height / cropH) > 1.05,
});
const url = canvas.toDataURL('image/jpeg', 0.72);
cache.set(keyOf(photo.id, preset.id, cropKey), url);
cache.set(keyOf(photo.id, preset.id, cropKey, sourceKey), url);
setThumbs((prev) => ({ ...prev, [preset.id]: url }));
} catch {
// One bad preset must not stop the rest of the grid.
@@ -85,7 +91,7 @@ export function usePresetThumbs(photo: PhotoRecord, presets: Preset[]): Record<s
renderer?.dispose();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [photo.id, presetKey, cropKey]);
}, [photo.id, presetKey, cropKey, sourceKey]);
return thumbs;
}