Apply a camera profile to every raw from the same camera body
A DCP matrix describes the sensor, so a profile chosen for one frame belongs to all camera-native raws from that body; the panel offers the bulk apply when the library holds more photos than the one on screen. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
import { subscribeClipPreview } from '../lib/clipPreview';
|
import { subscribeClipPreview } from '../lib/clipPreview';
|
||||||
import { get16BitSource, getBitmap, getDenoisedBitmap } from '../lib/images';
|
import { get16BitSource, getBitmap, getDenoisedBitmap } from '../lib/images';
|
||||||
import { rebuildProofCube, restoreProofProfile } from '../lib/softProof';
|
import { rebuildProofCube, restoreProofProfile } from '../lib/softProof';
|
||||||
|
import { photosForCamera } from '../lib/dcpLibrary';
|
||||||
import type { Preview16 } from '../lib/preview16';
|
import type { Preview16 } from '../lib/preview16';
|
||||||
import { useMediaQuery } from '../lib/useMediaQuery';
|
import { useMediaQuery } from '../lib/useMediaQuery';
|
||||||
import { usePersistentState } from '../lib/usePersistentState';
|
import { usePersistentState } from '../lib/usePersistentState';
|
||||||
@@ -271,6 +272,13 @@ export default function Develop({
|
|||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
const edits = photo.edits;
|
const edits = photo.edits;
|
||||||
|
// A DCP matrix describes the sensor, so one profile can serve every raw from
|
||||||
|
// the same body; the panel offers a bulk apply only when there is more than
|
||||||
|
// this photo to update.
|
||||||
|
const cameraProfileTargets = useMemo(
|
||||||
|
() => photosForCamera(photos, photo.meta?.camera),
|
||||||
|
[photos, photo.meta?.camera],
|
||||||
|
);
|
||||||
const activeLocal = (edits.local ?? []).find((layer) => layer.id === localSelected) ?? null;
|
const activeLocal = (edits.local ?? []).find((layer) => layer.id === localSelected) ?? null;
|
||||||
const zoomed = zoom.pct !== 'fit';
|
const zoomed = zoom.pct !== 'fit';
|
||||||
|
|
||||||
@@ -1555,6 +1563,29 @@ export default function Develop({
|
|||||||
photo={photo}
|
photo={photo}
|
||||||
set={setEdits}
|
set={setEdits}
|
||||||
cameraNative={Boolean(hdrSource?.rgbCam)}
|
cameraNative={Boolean(hdrSource?.rgbCam)}
|
||||||
|
cameraPhotoCount={cameraProfileTargets.length}
|
||||||
|
onApplyToCamera={
|
||||||
|
onUpdateEdits
|
||||||
|
? (profile) => {
|
||||||
|
const count = cameraProfileTargets.length;
|
||||||
|
const camera = photo.meta?.camera || 'this camera';
|
||||||
|
if (
|
||||||
|
!window.confirm(
|
||||||
|
`Apply “${profile.name}” to ${count} photos from ${camera}? ` +
|
||||||
|
'This replaces any camera profile they already use.',
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
onUpdateEdits(
|
||||||
|
cameraProfileTargets.map((target) => target.id),
|
||||||
|
{ cameraProfile: profile },
|
||||||
|
'Camera profile',
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<ProofPanel
|
<ProofPanel
|
||||||
edits={edits}
|
edits={edits}
|
||||||
|
|||||||
@@ -2211,8 +2211,17 @@ export function CameraProfilePanel({
|
|||||||
photo,
|
photo,
|
||||||
set,
|
set,
|
||||||
cameraNative = false,
|
cameraNative = false,
|
||||||
}: PanelSetProps & { cameraNative?: boolean }) {
|
cameraPhotoCount = 0,
|
||||||
|
onApplyToCamera,
|
||||||
|
}: PanelSetProps & {
|
||||||
|
cameraNative?: boolean;
|
||||||
|
/** Camera-native raws from this body, including the photo on screen. */
|
||||||
|
cameraPhotoCount?: number;
|
||||||
|
/** Apply the current profile to every photo from this camera body. */
|
||||||
|
onApplyToCamera?: (profile: { name: string; matrix: number[] }) => boolean | void;
|
||||||
|
}) {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [appliedAll, setAppliedAll] = useState<number | null>(null);
|
||||||
const profile = edits.cameraProfile;
|
const profile = edits.cameraProfile;
|
||||||
const camera = photo.meta?.camera ?? '';
|
const camera = photo.meta?.camera ?? '';
|
||||||
// Saved per camera body: the matrix describes the sensor, so every frame from
|
// Saved per camera body: the matrix describes the sensor, so every frame from
|
||||||
@@ -2291,6 +2300,22 @@ export function CameraProfilePanel({
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
|
{profile && onApplyToCamera && cameraPhotoCount > 1 && (
|
||||||
|
<button
|
||||||
|
className="btn ghost small"
|
||||||
|
onClick={() => {
|
||||||
|
const done = onApplyToCamera({ name: profile.name, matrix: profile.matrix });
|
||||||
|
if (done !== false) setAppliedAll(cameraPhotoCount);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Apply “{profile.name}” to {cameraPhotoCount} photos
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{appliedAll !== null && (
|
||||||
|
<p className="muted small panel-hint">
|
||||||
|
Applied to {appliedAll} photos from this camera.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
{applied && (
|
{applied && (
|
||||||
<button
|
<button
|
||||||
className="btn ghost small"
|
className="btn ghost small"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import {
|
import {
|
||||||
loadSavedCameraProfiles,
|
loadSavedCameraProfiles,
|
||||||
|
photosForCamera,
|
||||||
removeCameraProfile,
|
removeCameraProfile,
|
||||||
saveCameraProfile,
|
saveCameraProfile,
|
||||||
savedProfilesForCamera,
|
savedProfilesForCamera,
|
||||||
@@ -50,6 +51,19 @@ describe('camera profile library', () => {
|
|||||||
expect(loadSavedCameraProfiles(store)).toHaveLength(0);
|
expect(loadSavedCameraProfiles(store)).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('collects the camera-native raws of one body for a bulk apply', () => {
|
||||||
|
const photos = [
|
||||||
|
{ id: 'a', raw: true, decode: 'libraw', meta: { camera: 'NIKON CORPORATION D700' } },
|
||||||
|
{ id: 'b', raw: true, decode: 'libraw', meta: { camera: 'Nikon D700' } },
|
||||||
|
{ id: 'c', raw: true, decode: 'embedded', meta: { camera: 'Nikon D700' } },
|
||||||
|
{ id: 'd', raw: false, meta: { camera: 'Nikon D700' } },
|
||||||
|
{ id: 'e', raw: true, decode: 'libraw', deletedAt: 1, meta: { camera: 'Nikon D700' } },
|
||||||
|
{ id: 'f', raw: true, decode: 'libraw', meta: { camera: 'Canon EOS 5D' } },
|
||||||
|
];
|
||||||
|
expect(photosForCamera(photos, 'Nikon D700').map((photo) => photo.id)).toEqual(['a', 'b']);
|
||||||
|
expect(photosForCamera(photos, '')).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('refuses a matrix that is not nine finite numbers', () => {
|
it('refuses a matrix that is not nine finite numbers', () => {
|
||||||
const store = memoryStore();
|
const store = memoryStore();
|
||||||
const saved = saveCameraProfile({ name: 'Bad', camera: 'Nikon D700', matrix: [1, 2, 3] }, store);
|
const saved = saveCameraProfile({ name: 'Bad', camera: 'Nikon D700', matrix: [1, 2, 3] }, store);
|
||||||
|
|||||||
@@ -114,6 +114,35 @@ export function removeCameraProfile(
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Minimal photo shape needed to pick the raws of one body. */
|
||||||
|
export interface CameraProfileTarget {
|
||||||
|
id: string;
|
||||||
|
raw?: boolean;
|
||||||
|
decode?: string;
|
||||||
|
deletedAt?: number;
|
||||||
|
meta?: { camera?: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every live camera-native raw from the same body, including the one on screen.
|
||||||
|
* A JPEG, or a raw the server decoded straight to sRGB, already has its colour
|
||||||
|
* baked in, so a camera profile has nothing to act on there.
|
||||||
|
*/
|
||||||
|
export function photosForCamera<T extends CameraProfileTarget>(
|
||||||
|
photos: T[],
|
||||||
|
camera?: string,
|
||||||
|
): T[] {
|
||||||
|
const key = cameraKey(camera);
|
||||||
|
if (!key) return [];
|
||||||
|
return photos.filter(
|
||||||
|
(photo) =>
|
||||||
|
photo.raw &&
|
||||||
|
photo.decode !== 'embedded' &&
|
||||||
|
!photo.deletedAt &&
|
||||||
|
cameraKey(photo.meta?.camera) === key,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Profiles that belong to this body, most recently saved first. */
|
/** Profiles that belong to this body, most recently saved first. */
|
||||||
export function savedProfilesForCamera(
|
export function savedProfilesForCamera(
|
||||||
profiles: SavedCameraProfile[],
|
profiles: SavedCameraProfile[],
|
||||||
|
|||||||
Reference in New Issue
Block a user