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:
+162
-10
@@ -17,6 +17,8 @@
|
||||
* table layouts are read, because printer profiles ship in both.
|
||||
*/
|
||||
|
||||
import type { ProofIntent } from '../types';
|
||||
|
||||
const D50_WHITE = [0.9642, 1, 0.8249] as const;
|
||||
|
||||
/** Linear sRGB (D50 adapted) to XYZ, matching the primaries in `icc.ts`. */
|
||||
@@ -67,6 +69,10 @@ export interface IccProfile {
|
||||
pcs: Pcs;
|
||||
a2b: IccTransform | null;
|
||||
b2a: IccTransform | null;
|
||||
/** Device→PCS tables by intent: perceptual, relative colorimetric, saturation. */
|
||||
a2bIntents: (IccTransform | null)[];
|
||||
/** PCS→device tables by intent, in the same order. */
|
||||
b2aIntents: (IccTransform | null)[];
|
||||
}
|
||||
|
||||
export interface SoftProofCube {
|
||||
@@ -482,15 +488,20 @@ export function parseIcc(bytes: Uint8Array): IccProfile | null {
|
||||
};
|
||||
|
||||
const description = tags.get('desc');
|
||||
const a2bIntents = [transform('A2B0', true), transform('A2B1', true), transform('A2B2', true)];
|
||||
const b2aIntents = [transform('B2A0', false), transform('B2A1', false), transform('B2A2', false)];
|
||||
return {
|
||||
name: (description && parseDescription(view, description.at, description.size)) || 'ICC profile',
|
||||
profileClass: ascii(12),
|
||||
colourSpace,
|
||||
pcs,
|
||||
// Perceptual first, then relative colorimetric: a printer profile often
|
||||
// ships one and not the other.
|
||||
a2b: transform('A2B0', true) ?? transform('A2B1', true),
|
||||
b2a: transform('B2A0', false) ?? transform('B2A1', false),
|
||||
// ships one and not the other. The full table set is kept as well, so the
|
||||
// proof can be rebuilt for a different rendering intent.
|
||||
a2b: a2bIntents[0] ?? a2bIntents[1],
|
||||
b2a: b2aIntents[0] ?? b2aIntents[1],
|
||||
a2bIntents,
|
||||
b2aIntents,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -512,12 +523,40 @@ export const GAMUT_DELTA = 2.5;
|
||||
* the tables the round trip needs, because silently showing the paper
|
||||
* approximation instead would misrepresent what was loaded.
|
||||
*/
|
||||
const INTENT_SLOT: Record<ProofIntent, number> = {
|
||||
perceptual: 0,
|
||||
relative: 1,
|
||||
saturation: 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* The table pair for an intent. Perceptual uses the primary pair, which is what
|
||||
* a profile that only ships one set provides and what hand-built profiles in
|
||||
* tests carry. Other intents need both of their own tables; falling back to the
|
||||
* perceptual pair keeps a profile that omits saturation usable (many output
|
||||
* profiles do) instead of refusing to proof at all.
|
||||
*/
|
||||
function tablesForIntent(
|
||||
profile: IccProfile,
|
||||
intent: ProofIntent,
|
||||
): { a2b: IccTransform; b2a: IccTransform } | null {
|
||||
if (INTENT_SLOT[intent] === 0) {
|
||||
return profile.a2b && profile.b2a ? { a2b: profile.a2b, b2a: profile.b2a } : null;
|
||||
}
|
||||
const slot = INTENT_SLOT[intent];
|
||||
const a2b = profile.a2bIntents?.[slot] ?? profile.a2b;
|
||||
const b2a = profile.b2aIntents?.[slot] ?? profile.b2a;
|
||||
return a2b && b2a ? { a2b, b2a } : null;
|
||||
}
|
||||
|
||||
export function buildProofCube(
|
||||
profile: IccProfile,
|
||||
size = 33,
|
||||
gamutDelta = GAMUT_DELTA,
|
||||
intent: ProofIntent = 'perceptual',
|
||||
): SoftProofCube {
|
||||
if (!profile.a2b || !profile.b2a) {
|
||||
const tables = tablesForIntent(profile, intent);
|
||||
if (!tables) {
|
||||
throw new Error('This profile has no A2B/B2A tables, so it cannot be soft proofed');
|
||||
}
|
||||
const edge = Math.max(2, Math.min(65, Math.round(size)));
|
||||
@@ -536,8 +575,8 @@ export function buildProofCube(
|
||||
const lab = xyzToLab(xyz);
|
||||
const pcs = encodePcs(profile.pcs, lab, xyz);
|
||||
// Into the printer, then back out: what the paper can actually show.
|
||||
const device = evaluate(profile.b2a, pcs);
|
||||
const printed = evaluate(profile.a2b, device);
|
||||
const device = evaluate(tables.b2a, pcs);
|
||||
const printed = evaluate(tables.a2b, device);
|
||||
const back = decodePcs(profile.pcs, printed);
|
||||
const rgb = multiply3(XYZ_TO_RGB, back.xyz);
|
||||
data[at++] = clamp01(linearToSrgb(rgb[0]));
|
||||
@@ -567,20 +606,133 @@ export function buildProofCube(
|
||||
* a megabyte and does not belong in a photo record.
|
||||
*/
|
||||
let active: SoftProofCube | null = null;
|
||||
/**
|
||||
* The bytes behind the active cube. Kept so changing the rendering intent can
|
||||
* rebuild the table without asking for the file again, and so the profile can
|
||||
* be restored in the next session.
|
||||
*/
|
||||
let activeBytes: Uint8Array | null = null;
|
||||
|
||||
/** Clears the active profile; the bytes go too, so an intent change cannot
|
||||
* silently re-install a profile the user switched off. */
|
||||
export function setActiveProofCube(cube: SoftProofCube | null) {
|
||||
active = cube;
|
||||
if (!cube) activeBytes = null;
|
||||
}
|
||||
|
||||
export function getActiveProofCube(): SoftProofCube | null {
|
||||
return active;
|
||||
}
|
||||
|
||||
/** Parses a .icc/.icm file and makes it the session's proof profile. */
|
||||
export function loadProofProfile(bytes: Uint8Array, size = 33): SoftProofCube {
|
||||
function activate(bytes: Uint8Array, size: number, intent: ProofIntent): SoftProofCube {
|
||||
const profile = parseIcc(bytes);
|
||||
if (!profile) throw new Error('That file is not an ICC profile');
|
||||
const cube = buildProofCube(profile, size);
|
||||
setActiveProofCube(cube);
|
||||
const cube = buildProofCube(profile, size, GAMUT_DELTA, intent);
|
||||
activeBytes = bytes.slice();
|
||||
active = cube;
|
||||
return cube;
|
||||
}
|
||||
|
||||
/** Parses a .icc/.icm file and makes it the active proof profile. */
|
||||
export function loadProofProfile(
|
||||
bytes: Uint8Array,
|
||||
size = 33,
|
||||
intent: ProofIntent = 'perceptual',
|
||||
): SoftProofCube {
|
||||
return activate(bytes, size, intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds the active profile for a different intent. Returns null when no
|
||||
* profile is loaded, so the caller can leave the paper simulation alone.
|
||||
*/
|
||||
export function rebuildProofCube(intent: ProofIntent, size = 33): SoftProofCube | null {
|
||||
if (!activeBytes) return null;
|
||||
try {
|
||||
return activate(activeBytes, size, intent);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------- persisted proof profile */
|
||||
|
||||
const PROOF_DB = 'lumenroom.proof';
|
||||
const PROOF_STORE = 'profile';
|
||||
const PROOF_KEY = 'active';
|
||||
|
||||
let proofDb: Promise<IDBDatabase> | null = null;
|
||||
|
||||
/**
|
||||
* A one-store database for the loaded printer profile. It is separate from the
|
||||
* catalogue so a server-backed workspace can remember the profile on this
|
||||
* device without writing a megabyte into a photo record or the SQLite catalog.
|
||||
*/
|
||||
function openProofDb(): Promise<IDBDatabase> {
|
||||
if (proofDb) return proofDb;
|
||||
proofDb = new Promise((resolve, reject) => {
|
||||
if (typeof indexedDB === 'undefined') {
|
||||
reject(new Error('IndexedDB is unavailable'));
|
||||
return;
|
||||
}
|
||||
const req = indexedDB.open(PROOF_DB, 1);
|
||||
req.onupgradeneeded = () => {
|
||||
if (!req.result.objectStoreNames.contains(PROOF_STORE)) {
|
||||
req.result.createObjectStore(PROOF_STORE);
|
||||
}
|
||||
};
|
||||
req.onsuccess = () => resolve(req.result);
|
||||
req.onerror = () => reject(req.error ?? new Error('Unable to open the proof profile store'));
|
||||
});
|
||||
return proofDb;
|
||||
}
|
||||
|
||||
/** Remembers the active profile for the next session; failures are harmless. */
|
||||
export async function persistProofProfile(): Promise<void> {
|
||||
if (!activeBytes) return;
|
||||
try {
|
||||
const db = await openProofDb();
|
||||
const bytes = activeBytes.slice();
|
||||
const name = active?.name ?? 'ICC profile';
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const tx = db.transaction(PROOF_STORE, 'readwrite');
|
||||
tx.objectStore(PROOF_STORE).put({ name, bytes }, PROOF_KEY);
|
||||
tx.oncomplete = () => resolve();
|
||||
tx.onerror = () => reject(tx.error ?? new Error('Could not save the proof profile'));
|
||||
});
|
||||
} catch {
|
||||
/* Private mode or no IndexedDB: the profile still lasts for this session. */
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearPersistedProofProfile(): Promise<void> {
|
||||
try {
|
||||
const db = await openProofDb();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const tx = db.transaction(PROOF_STORE, 'readwrite');
|
||||
tx.objectStore(PROOF_STORE).delete(PROOF_KEY);
|
||||
tx.oncomplete = () => resolve();
|
||||
tx.onerror = () => reject(tx.error ?? new Error('Could not clear the proof profile'));
|
||||
});
|
||||
} catch {
|
||||
/* nothing persisted to clear */
|
||||
}
|
||||
}
|
||||
|
||||
/** Loads the profile saved by a previous session and rebuilds its cube. */
|
||||
export async function restoreProofProfile(
|
||||
intent: ProofIntent = 'perceptual',
|
||||
): Promise<SoftProofCube | null> {
|
||||
try {
|
||||
const db = await openProofDb();
|
||||
const stored = await new Promise<{ bytes?: Uint8Array } | undefined>((resolve, reject) => {
|
||||
const req = db.transaction(PROOF_STORE, 'readonly').objectStore(PROOF_STORE).get(PROOF_KEY);
|
||||
req.onsuccess = () => resolve(req.result);
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
if (!stored?.bytes) return null;
|
||||
return activate(stored.bytes, 33, intent);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user