From e41fcd7ae1fc66c2204b8a91b203337a4d530f30 Mon Sep 17 00:00:00 2001 From: spark Date: Mon, 19 Oct 2026 23:45:02 +0100 Subject: [PATCH] Stop greying whites with a highlight pull that was never measured on the photo. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auto always asked for highlights −66 and shadows +52, a raw-file recipe. On a camera JPEG that flattens faces. The pull now stops at −20 and the lift at +30, and one slider can be copied on its own. --- apps/api/src/autopilot/look.ts | 19 ++++--- apps/api/src/autopilot/service.ts | 2 +- apps/api/src/composition/planFrame.ts | 4 +- apps/api/test/look.test.ts | 15 +++-- apps/app/src/develop/SyncSettings.tsx | 79 +++++++++++++++++++++------ apps/app/src/develop/copySettings.ts | 17 +++--- apps/app/src/i18n.ts | 2 +- apps/app/src/offline/autopilot.ts | 2 +- apps/app/src/offline/plan.test.ts | 7 +-- apps/app/src/pages/DevelopPage.tsx | 4 +- apps/app/src/pages/LibraryPage.tsx | 4 +- docs/photo-editing-rules.md | 5 +- 12 files changed, 104 insertions(+), 56 deletions(-) diff --git a/apps/api/src/autopilot/look.ts b/apps/api/src/autopilot/look.ts index 60ecf95..464a79e 100644 --- a/apps/api/src/autopilot/look.ts +++ b/apps/api/src/autopilot/look.ts @@ -49,15 +49,18 @@ export function noiseReduction(iso: number | null | undefined): Record 0) return measured; - return measured * strength; +const HIGHLIGHT_PULL = 20; +const SHADOW_LIFT = 30; + +export function toneApplied(key: string, measured: number, strength: number): number { + let value = measured * strength; + if ((key === "light.highlights" || key === "light.whites") && value < -HIGHLIGHT_PULL) value = -HIGHLIGHT_PULL; + if (key === "light.shadows" && value > SHADOW_LIFT) value = SHADOW_LIFT; + return Math.round(value * 100) / 100; } /** Local contrast and sharpening. Their kernel is a fraction of the whole frame, so a tight crop shows them enlarged. */ diff --git a/apps/api/src/autopilot/service.ts b/apps/api/src/autopilot/service.ts index 948bd12..83b2b79 100644 --- a/apps/api/src/autopilot/service.ts +++ b/apps/api/src/autopilot/service.ts @@ -117,7 +117,7 @@ export class AutopilotService { if (engine && (settings.tone || settings.whiteBalance || settings.level)) { const auto = await engine.auto(preview, null); rawAngle = auto.angle; - values = measuredValues(auto.values, settings, reportage, photo.iso, style?.offsets ?? {}); + values = measuredValues(auto.values, settings, photo.iso, style?.offsets ?? {}); } const angle = levelAngle(rawAngle, settings.level); const load = this.deps.detector(); diff --git a/apps/api/src/composition/planFrame.ts b/apps/api/src/composition/planFrame.ts index 3cad880..79f0960 100644 --- a/apps/api/src/composition/planFrame.ts +++ b/apps/api/src/composition/planFrame.ts @@ -30,11 +30,11 @@ export function levelAngle(angle: number | null, enabled: boolean): number { /** * White balance, tone and the finishing look, before the crop scales detail. Null when none of those are on: * the same gate the server uses (it measures only when tone, white balance or level is enabled). + * Highlight and shadow figures are capped in `toneApplied`: Auto's recipe is not a reading of this photo. */ export function measuredValues( auto: Record, settings: PlanSettings, - reportage: boolean, iso: number | null, offsets: Record, ): Record | null { @@ -43,7 +43,7 @@ export function measuredValues( if (settings.whiteBalance) for (const k of WB_KEYS) if (auto[k] !== undefined) values[k] = auto[k]! + (offsets[k] ?? 0); if (settings.tone) { for (const k of TONE_KEYS) { - const v = toneApplied(k, auto[k] ?? 0, settings.toneStrength, reportage) + (offsets[k] ?? 0); + const v = toneApplied(k, auto[k] ?? 0, settings.toneStrength) + (offsets[k] ?? 0); if (v) values[k] = Math.round(v * 100) / 100; } } diff --git a/apps/api/test/look.test.ts b/apps/api/test/look.test.ts index 0f02caa..b42bc15 100644 --- a/apps/api/test/look.test.ts +++ b/apps/api/test/look.test.ts @@ -12,14 +12,13 @@ describe("autopilot look", () => { expect(Object.keys(agency).some((k) => k.startsWith("vignette."))).toBe(false); }); - it("opens blocked shadows and pulls blown highlights in full for reportage, and only that way", () => { - expect(toneApplied("light.highlights", -40, 0.75, true)).toBe(-40); - expect(toneApplied("light.shadows", 35, 0.75, true)).toBe(35); - expect(toneApplied("light.whites", -20, 0.75, true)).toBe(-20); - expect(toneApplied("light.highlights", 10, 0.75, true)).toBe(7.5); - expect(toneApplied("light.shadows", -10, 0.75, true)).toBe(-7.5); - expect(toneApplied("light.exposure", 0.4, 0.75, true)).toBeCloseTo(0.3); - expect(toneApplied("light.highlights", -40, 0.75, false)).toBe(-30); + 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", () => { diff --git a/apps/app/src/develop/SyncSettings.tsx b/apps/app/src/develop/SyncSettings.tsx index e23f4ff..1d03c18 100644 --- a/apps/app/src/develop/SyncSettings.tsx +++ b/apps/app/src/develop/SyncSettings.tsx @@ -1,14 +1,33 @@ +import { controlsForModule, type Module } from "@photoreport/contracts"; import { useState } from "react"; -import type { Module } from "@photoreport/contracts"; import { t } from "../i18n.js"; import { SYNC_MODULES } from "./copySettings.js"; -/** Copy chosen groups from the active photo onto the other selected ones. Crop starts off. */ -export function SyncSettingsButton({ count, disabled, onApply }: { count: number; disabled?: boolean; onApply: (modules: Module[]) => Promise }) { +const BASIC_IDS = controlsForModule("basic").map((c) => c.id); + +export interface SyncPick { + controls: string[]; + crop: boolean; +} + +function labelOf(id: string): string { + const labels = t.dev.labels as Record; + return labels[id] ?? id; +} + +/** Copy chosen controls from the active photo onto the other selected ones. Crop starts off. Basic starts on, and each of its sliders can be ticked alone. */ +export function SyncSettingsButton({ count, disabled, onApply }: { count: number; disabled?: boolean; onApply: (pick: SyncPick) => Promise }) { const [open, setOpen] = useState(false); - const [picked, setPicked] = useState(["basic"]); + const [picked, setPicked] = useState(BASIC_IDS); + const [crop, setCrop] = useState(false); const [busy, setBusy] = useState(false); - const toggle = (module: Module) => setPicked((cur) => (cur.includes(module) ? cur.filter((m) => m !== module) : [...cur, module])); + const has = (id: string) => picked.includes(id); + const toggle = (id: string) => setPicked((cur) => (cur.includes(id) ? cur.filter((x) => x !== id) : [...cur, id])); + const toggleModule = (module: Module) => { + const ids = controlsForModule(module).map((c) => c.id); + const all = ids.every((id) => picked.includes(id)); + setPicked((cur) => (all ? cur.filter((id) => !ids.includes(id)) : [...new Set([...cur, ...ids])])); + }; return (