Files
luminary/src/lib/colorSpace.test.ts
T
bhursey 0c113e7a91 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>
2026-11-28 03:59:55 +00:00

50 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { convertImageData, convertSrgbEncoded } from './colorSpace';
import { profileFor } from './icc';
describe('output colour spaces', () => {
it('leaves white unchanged in every space', () => {
for (const space of ['srgb', 'p3', 'adobe'] as const) {
const [r, g, b] = convertSrgbEncoded(1, 1, 1, space);
expect(r).toBeCloseTo(1, 3);
expect(g).toBeCloseTo(1, 3);
expect(b).toBeCloseTo(1, 3);
}
});
it('maps sRGB red into the wider P3 and Adobe gamuts', () => {
const p3 = convertSrgbEncoded(1, 0, 0, 'p3');
expect(p3[0]).toBeCloseTo(0.918, 2);
expect(p3[1]).toBeCloseTo(0.202, 1);
const adobe = convertSrgbEncoded(1, 0, 0, 'adobe');
expect(adobe[0]).toBeCloseTo(0.859, 2);
expect(adobe[1]).toBeCloseTo(0, 5);
});
it('preserves alpha while converting a byte buffer', () => {
const data = new Uint8ClampedArray([255, 0, 0, 128]);
convertImageData(data, 'p3');
expect(data[0]).toBeGreaterThan(220);
expect(data[1]).toBeGreaterThan(20);
expect(data[3]).toBe(128);
});
it('writes a profile whose description and curve match the space', () => {
const p3 = profileFor('p3');
expect(String.fromCharCode(...p3.subarray(36, 40))).toBe('acsp');
const adobe = profileFor('adobe');
const view = new DataView(adobe.buffer);
const count = view.getUint32(128, false);
let rtrc = -1;
for (let i = 0; i < count; i++) {
const at = 132 + i * 12;
if (String.fromCharCode(...adobe.subarray(at, at + 4)) === 'rTRC') {
rtrc = view.getUint32(at + 4, false);
}
}
expect(rtrc).toBeGreaterThan(0);
expect(view.getUint32(rtrc + 8, false)).toBe(1);
expect(view.getUint16(rtrc + 12, false)).toBe(563);
});
});