import { describe, expect, it } from "vitest"; import { cropLongFraction, detailForCrop, lookValues, noiseReduction, toneApplied } from "../src/autopilot/look.js"; describe("autopilot look", () => { it("gives the agency look punchier colour than the natural one, and nothing for none", () => { const agency = lookValues("agency", 400); const natural = lookValues("natural", 400); expect(agency["color.vibrance"]!).toBeGreaterThan(natural["color.vibrance"]!); expect(agency["detail.sharpenAmount"]).toBe(40); expect(lookValues("none", 6400)).toEqual({}); // Never a vignette: the ethics rules forbid darkening the background. expect(Object.keys(agency).some((k) => k.startsWith("vignette."))).toBe(false); }); it("keeps the fixed highlight and shadow recipe from greying a JPEG", () => { expect(toneApplied("light.highlights", -66, 0.75)).toBe(-20); expect(toneApplied("light.shadows", 52, 0.75)).toBe(30); expect(toneApplied("light.whites", -40, 0.75)).toBe(-20); expect(toneApplied("light.highlights", -10, 0.75)).toBe(-7.5); expect(toneApplied("light.contrast", 68, 0.75)).toBe(51); expect(toneApplied("light.exposure", -0.25, 0.75)).toBeCloseTo(-0.19); }); it("keeps structure and sharpen in proportion to the frame a crop keeps", () => { const whole = { x0: 0, y0: 0, x1: 1, y1: 1 }; const tight = { x0: 0.3, y0: 0.2, x1: 0.7, y1: 0.7 }; const look = lookValues("agency", 400); expect(detailForCrop(look, whole, 6000, 4000)["detail.sharpenAmount"]).toBe(40); expect(detailForCrop(look, null, 6000, 4000)["effects.clarity"]).toBe(8); const kept = cropLongFraction(tight, 6000, 4000); expect(kept).toBeCloseTo(0.4); const scaled = detailForCrop(look, tight, 6000, 4000); expect(scaled["detail.sharpenAmount"]).toBeCloseTo(16); expect(scaled["effects.clarity"]).toBeCloseTo(3.2); expect(scaled["color.vibrance"]).toBe(18); const close = detailForCrop(look, { x0: 0.4, y0: 0.4, x1: 0.5, y1: 0.5 }, 6000, 4000); expect(close["detail.sharpenAmount"]).toBeCloseTo(40 / 3, 1); }); it("reduces noise more as the ISO climbs", () => { expect(noiseReduction(800)["detail.nrLuminance"]).toBeUndefined(); expect(noiseReduction(3200)["detail.nrLuminance"]!).toBeLessThan(noiseReduction(12800)["detail.nrLuminance"]!); }); });