Lightroom turns the stored corners around the crop centre, so writing the levelled rectangle made the crop Custom. The file now stores those corners, the original is found by its own hash, and edits already queued go out while the socket stays up.
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { fromLightroomEdges, toLightroomEdges } from "./lightroomCrop.js";
|
|
|
|
/** PSR12211.JPG: a 3:2 crop with a strong straighten. Written raw, Lightroom levelled it to about 1.21. */
|
|
const shot = { left: 0.024609, top: 0.078821, right: 0.799609, bottom: 0.853821 };
|
|
const angle = -5.9;
|
|
const width = 6000;
|
|
const height = 4000;
|
|
|
|
function sides(rect: { left: number; top: number; right: number; bottom: number }): { w: number; h: number } {
|
|
return { w: rect.right - rect.left, h: rect.bottom - rect.top };
|
|
}
|
|
|
|
describe("Lightroom crop corners", () => {
|
|
it("keeps the photograph's aspect after Lightroom levels the straighten", () => {
|
|
const stored = toLightroomEdges(shot, angle, width, height);
|
|
const shown = fromLightroomEdges(stored, angle, width, height);
|
|
const got = sides(shown);
|
|
expect(Math.abs(got.w - got.h)).toBeLessThan(0.0001);
|
|
expect(stored.left).toBeGreaterThanOrEqual(0);
|
|
expect(stored.top).toBeGreaterThanOrEqual(0);
|
|
expect(stored.right).toBeLessThanOrEqual(1);
|
|
expect(stored.bottom).toBeLessThanOrEqual(1);
|
|
const pxW = got.w * width;
|
|
const pxH = got.h * height;
|
|
expect(pxW / pxH).toBeCloseTo(width / height, 3);
|
|
});
|
|
|
|
it("shrinks a crop that would leave the photo once it is turned", () => {
|
|
const full = { left: 0.01, top: 0.01, right: 0.99, bottom: 0.99 };
|
|
const stored = toLightroomEdges(full, 2.64, width, height);
|
|
expect(stored.left).toBeGreaterThanOrEqual(0);
|
|
expect(stored.top).toBeGreaterThanOrEqual(0);
|
|
expect(stored.right).toBeLessThanOrEqual(1);
|
|
expect(stored.bottom).toBeLessThanOrEqual(1);
|
|
const shown = fromLightroomEdges(stored, 2.64, width, height);
|
|
const got = sides(shown);
|
|
expect(Math.abs(got.w - got.h)).toBeLessThan(0.0001);
|
|
expect(got.w).toBeLessThan(0.98);
|
|
});
|
|
|
|
it("leaves a level crop untouched", () => {
|
|
const rect = { left: 0.1, top: 0.1, right: 0.8, bottom: 0.8 };
|
|
expect(toLightroomEdges(rect, 0, width, height)).toEqual(rect);
|
|
expect(fromLightroomEdges(rect, 0, width, height)).toEqual(rect);
|
|
});
|
|
});
|