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
+57
View File
@@ -161,6 +161,63 @@ export function encodePng16(rgb16, width, height, matrix = null) {
chunk('IEND', Buffer.alloc(0)),
]);
}
/** The camera matrix carried in a 16-bit sidecar's `rgbCam` tEXt chunk. */
export function png16Matrix(png) {
const needle = Buffer.from('rgbCam\0', 'latin1');
const at = png.indexOf(needle);
if (at < 0) return null;
const start = at + needle.length;
// The text runs to the end of the tEXt chunk, and the chunk's CRC is binary
// and may contain a NUL. Stop at the first byte that cannot be part of the
// comma-separated number list instead of searching for a terminator.
let end = start;
while (end < png.length) {
const code = png[end];
const numeric =
(code >= 0x30 && code <= 0x39) || // 0-9
code === 0x2e || // .
code === 0x2c || // ,
code === 0x2d || // -
code === 0x2b || // +
code === 0x65 || // e
code === 0x45; // E
if (!numeric) break;
end++;
}
const values = png.toString('latin1', start, end).split(',').map(Number);
return values.length === 9 && values.every(Number.isFinite) ? values : null;
}
/**
* A camera-native grid thumbnail, resized from the 16-bit sidecar with sharp's
* 16-bit path. The grid normally renders the sRGB JPEG, whose body matrix is
* already baked in; this gives the client camera samples small enough to fetch
* per tile, so a per-photo DCP profile shows everywhere the photo does. The
* `rgbCam` tag is rewritten so the client still knows how to convert them.
*/
export async function cameraThumb16(png16, width, height, matrix = null) {
const sharp = await loadSharp();
if (!sharp || width < 1 || height < 1) return null;
try {
const { data, info } = await sharp(png16)
.resize({ width, height, fit: 'fill' })
.raw({ depth: 'ushort' })
.toBuffer({ resolveWithObject: true });
if (info.channels !== 3 || info.depth !== 'ushort') return null;
// Copy through a fresh buffer: a raw output offset is not guaranteed to be
// 16-bit aligned, and Uint16Array refuses an odd byteOffset.
const samples = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
return encodePng16(
new Uint16Array(samples),
info.width,
info.height,
matrix ?? png16Matrix(png16),
);
} catch {
return null;
}
}
export async function encodeRgb(rgb, width, height, quality = 92, maxEdge = 0) {
const sharp = await loadSharp();
if (!sharp) {