A tight crop was dropping a ball held out to the side and a second player, and a learnt cut could chop a body the frame had kept. Reportage stays open, open eyes win a sequence, and a Canon file that still has the camera level uses that roll. The library menu, sort, and event-day folder go out with the same change.
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { cameraLevelAngle } from "./cameraLevel.js";
|
|
|
|
/**
|
|
* A tiny JPEG laid out like a Canon file: IFD0 points at the Exif IFD, and that IFD
|
|
* holds the maker note. LevelInfo says the camera rolled clockwise by `clockwise` degrees.
|
|
*/
|
|
function jpegWithRoll(clockwise: number): ArrayBuffer {
|
|
const raw = Math.round(-clockwise * 10);
|
|
const tiff = new Uint8Array(94);
|
|
const view = new DataView(tiff.buffer);
|
|
view.setUint16(0, 0x4949, true);
|
|
view.setUint16(2, 42, true);
|
|
view.setUint32(4, 8, true);
|
|
view.setUint16(8, 1, true);
|
|
view.setUint16(10, 0x8769, true);
|
|
view.setUint16(12, 4, true);
|
|
view.setUint32(14, 1, true);
|
|
view.setUint32(18, 26, true);
|
|
view.setUint16(26, 1, true);
|
|
view.setUint16(28, 0x927c, true);
|
|
view.setUint16(30, 7, true);
|
|
view.setUint32(32, 50, true);
|
|
view.setUint32(36, 44, true);
|
|
view.setUint16(44, 1, true);
|
|
view.setUint16(46, 0x4059, true);
|
|
view.setUint16(48, 7, true);
|
|
view.setUint32(50, 32, true);
|
|
view.setUint32(54, 62, true);
|
|
view.setInt32(62 + 12, raw, true);
|
|
view.setInt32(62 + 16, 0, true);
|
|
const app = new Uint8Array(2 + 2 + 6 + tiff.length);
|
|
const out = new DataView(app.buffer);
|
|
out.setUint16(0, 0xffe1);
|
|
out.setUint16(2, app.length - 2);
|
|
app.set([0x45, 0x78, 0x69, 0x66, 0, 0], 4);
|
|
app.set(tiff, 10);
|
|
const jpeg = new Uint8Array(2 + app.length + 2);
|
|
jpeg[0] = 0xff;
|
|
jpeg[1] = 0xd8;
|
|
jpeg.set(app, 2);
|
|
jpeg[jpeg.length - 2] = 0xff;
|
|
jpeg[jpeg.length - 1] = 0xd9;
|
|
return jpeg.buffer;
|
|
}
|
|
|
|
describe("camera level", () => {
|
|
it("turns a clockwise Canon roll into the crop angle that cancels it", () => {
|
|
expect(cameraLevelAngle(jpegWithRoll(1.5))).toBe(-1.5);
|
|
});
|
|
|
|
it("keeps a level camera level, so a wall cannot tilt the frame", () => {
|
|
expect(cameraLevelAngle(jpegWithRoll(0))).toBe(0);
|
|
});
|
|
|
|
it("ignores a portrait roll and a file with no level", () => {
|
|
expect(cameraLevelAngle(jpegWithRoll(90))).toBeNull();
|
|
expect(cameraLevelAngle(new Uint8Array([0xff, 0xd8, 0xff, 0xd9]).buffer)).toBeNull();
|
|
});
|
|
});
|