Files
luminary/src/lib/xmp.test.ts
T
bhursey b884616889 Group local mask shapes into editable components.
A local adjustment is now a list of shapes composited in order (add, subtract,
intersect) instead of a single shape, so dodging and burning can be built from
several brushes, gradients and auto masks without spending layer channels.
Existing edits migrate on load: the flat layer fields become components[0],
keeping geometry, invert, feather and the layer's blend mode unchanged. The
panel gains a shape list with active-shape editing, and the render gate now
asserts a subtract shape clears the group while an intersect keeps it.
2026-11-28 16:09:14 +00:00

58 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { defaultEdits, defaultLocalLayer, normalizeEdits } from './edits';
import { editsToXmp, xmpFileName, xmpToEdits } from './xmp';
describe('xmp sidecars', () => {
it('round-trips every develop field exactly', () => {
const edits = defaultEdits();
edits.exposure = 0.65;
edits.temp = -14;
edits.kelvin = 4200;
edits.contrast = 22;
edits.parametric.darks = -17;
edits.hsl.hue[3] = 12;
edits.grain.roughness = 71;
const mask = defaultLocalLayer('linear', 0);
if (mask.components[0]) mask.components[0].linear = { x1: 0.1, y1: 0.2, x2: 0.8, y2: 0.9 };
edits.local = [mask];
const xml = editsToXmp(edits);
const back = xmpToEdits(xml, defaultEdits());
expect(back.source).toBe('luminary');
// Sanitising on the way in is allowed; it must not change any value.
expect(back.edits).toEqual(normalizeEdits(edits));
});
it('reads crs fields written by Lightroom', () => {
const xml = `<?xpacket begin=""?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" crs:Exposure2012="1.25" crs:Contrast2012="-18" crs:Clarity2012="34" crs:GrainAmount="40" crs:ConvertToGrayscale="True"/></rdf:RDF></x:xmpmeta>`;
const base = defaultEdits();
base.saturation = 9;
const result = xmpToEdits(xml, base);
expect(result.source).toBe('lightroom');
expect(result.edits.exposure).toBe(1.25);
expect(result.edits.contrast).toBe(-18);
expect(result.edits.clarity).toBe(34);
expect(result.edits.grain.amount).toBe(40);
expect(result.edits.bw).toBe(true);
// Fields the sidecar does not mention keep the photo's own settings.
expect(result.edits.saturation).toBe(9);
});
it('reads an absolute Kelvin temperature written by Lightroom', () => {
const xml = `<?xpacket begin=""?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" crs:Temperature="3800" crs:Tint="12" crs:Exposure2012="0.4"/></rdf:RDF></x:xmpmeta>`;
const result = xmpToEdits(xml, defaultEdits());
expect(result.edits.kelvin).toBe(3800);
expect(result.edits.tint).toBe(12);
expect(result.applied).toContain('Temperature');
});
it('rejects a file that is not a sidecar', () => {
expect(() => xmpToEdits('<html></html>', defaultEdits())).toThrow(/not an XMP/);
});
it('names the sidecar after the photo', () => {
expect(xmpFileName('DSC0123.ARW')).toBe('DSC0123.xmp');
expect(xmpFileName('no-extension')).toBe('no-extension.xmp');
});
});