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:
@@ -71,3 +71,70 @@ export async function computeAutoEdits(thumb: string): Promise<Partial<Edits>> {
|
||||
return { contrast: 12, shadows: 12, highlights: -12, vibrance: 8 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grey-world auto white balance. It averages the unclipped midtones, then
|
||||
* searches the two WB sliders for the multipliers that neutralise them. This is
|
||||
* a starting point for mixed or unknown light, not a substitute for the
|
||||
* eyedropper on a known neutral.
|
||||
*/
|
||||
export async function computeAutoWhiteBalance(
|
||||
thumb: string,
|
||||
): Promise<{ temp: number; tint: number }> {
|
||||
try {
|
||||
const img = new Image();
|
||||
img.src = thumb;
|
||||
await img.decode();
|
||||
const w = 96;
|
||||
const h = Math.max(1, Math.round((img.height / img.width) * w)) || 96;
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) throw new Error('Canvas unavailable');
|
||||
ctx.drawImage(img, 0, 0, w, h);
|
||||
const { data } = ctx.getImageData(0, 0, w, h);
|
||||
|
||||
let r = 0;
|
||||
let g = 0;
|
||||
let b = 0;
|
||||
let count = 0;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
const rr = data[i];
|
||||
const gg = data[i + 1];
|
||||
const bb = data[i + 2];
|
||||
const sum = rr + gg + bb;
|
||||
// Clipped highlights and near-black pixels carry no reliable cast.
|
||||
if (sum > 735 || sum < 24) continue;
|
||||
r += rr;
|
||||
g += gg;
|
||||
b += bb;
|
||||
count += 1;
|
||||
}
|
||||
if (!count) return { temp: 0, tint: 0 };
|
||||
|
||||
const ar = r / count / 255;
|
||||
const ag = g / count / 255;
|
||||
const ab = b / count / 255;
|
||||
let best = { temp: 0, tint: 0, err: Number.POSITIVE_INFINITY };
|
||||
for (let temp = -100; temp <= 100; temp += 4) {
|
||||
for (let tint = -100; tint <= 100; tint += 4) {
|
||||
const t = temp / 100;
|
||||
const ti = tint / 100;
|
||||
// Same channel multipliers the grade shader applies.
|
||||
const mr = 1 + 0.3 * t + 0.06 * ti;
|
||||
const mg = 1 - 0.16 * ti;
|
||||
const mb = 1 - 0.26 * t + 0.06 * ti;
|
||||
const rr = ar * mr;
|
||||
const gg = ag * mg;
|
||||
const bb = ab * mb;
|
||||
const mean = (rr + gg + bb) / 3;
|
||||
const err = (rr - mean) ** 2 + (gg - mean) ** 2 + (bb - mean) ** 2;
|
||||
if (err < best.err) best = { temp, tint, err };
|
||||
}
|
||||
}
|
||||
return { temp: best.temp, tint: best.tint };
|
||||
} catch {
|
||||
return { temp: 0, tint: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user