Show edited renders in thumbnails and paste to a filmstrip selection
The grid and filmstrip only ever showed the import thumbnail, so edits and virtual copies looked untouched. Edited tiles now render client-side with the same shader as the canvas, once each, from the small cached thumbnail. The filmstrip also gains Cmd/Shift multi-select so Paste, Copy and Reset can act on several photos from the toolbar or the right-click menu.
This commit is contained in:
+3
-1
@@ -2156,7 +2156,9 @@ export default function App() {
|
|||||||
onUpdate={updatePhoto}
|
onUpdate={updatePhoto}
|
||||||
clipboard={clipboard}
|
clipboard={clipboard}
|
||||||
onCopy={copySettings}
|
onCopy={copySettings}
|
||||||
onPaste={() => openPaste([activePhoto.id])}
|
onCopyOf={copySettingsOf}
|
||||||
|
onPaste={(ids) => openPaste(ids?.length ? ids : [activePhoto.id])}
|
||||||
|
onResetSelection={resetEdits}
|
||||||
localClipboard={localClipboard}
|
localClipboard={localClipboard}
|
||||||
onLocalClipboard={setLocalClipboard}
|
onLocalClipboard={setLocalClipboard}
|
||||||
onExport={openExport}
|
onExport={openExport}
|
||||||
|
|||||||
+135
-24
@@ -5,7 +5,6 @@ import {
|
|||||||
defaultLocalLayer,
|
defaultLocalLayer,
|
||||||
MAX_HEAL_SPOTS,
|
MAX_HEAL_SPOTS,
|
||||||
MAX_LOCAL_LAYERS,
|
MAX_LOCAL_LAYERS,
|
||||||
thumbTransform,
|
|
||||||
} from '../lib/edits';
|
} from '../lib/edits';
|
||||||
import { subscribeClipPreview } from '../lib/clipPreview';
|
import { subscribeClipPreview } from '../lib/clipPreview';
|
||||||
import { getBitmap, getDenoisedBitmap } from '../lib/images';
|
import { getBitmap, getDenoisedBitmap } from '../lib/images';
|
||||||
@@ -42,6 +41,7 @@ import type {
|
|||||||
Snapshot,
|
Snapshot,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import ContextMenu, { type MenuEntry } from './ContextMenu';
|
import ContextMenu, { type MenuEntry } from './ContextMenu';
|
||||||
|
import EditedImage from './EditedImage';
|
||||||
import CropOverlay from './CropOverlay';
|
import CropOverlay from './CropOverlay';
|
||||||
import Histogram from './Histogram';
|
import Histogram from './Histogram';
|
||||||
import {
|
import {
|
||||||
@@ -123,7 +123,12 @@ interface Props {
|
|||||||
onUpdate: (id: string, patch: Partial<PhotoRecord>, historyLabel?: string) => void;
|
onUpdate: (id: string, patch: Partial<PhotoRecord>, historyLabel?: string) => void;
|
||||||
clipboard: Edits | null;
|
clipboard: Edits | null;
|
||||||
onCopy: () => void;
|
onCopy: () => void;
|
||||||
onPaste: () => void;
|
/** Copy settings from a named filmstrip photo instead of the canvas photo. */
|
||||||
|
onCopyOf?: (id: string) => void;
|
||||||
|
/** Paste the copied settings; no ids means the photo on the canvas. */
|
||||||
|
onPaste: (ids?: string[]) => void;
|
||||||
|
/** Reset several photos at once, without a per-photo confirmation. */
|
||||||
|
onResetSelection?: (ids: string[]) => void;
|
||||||
localClipboard: LocalLayer | null;
|
localClipboard: LocalLayer | null;
|
||||||
onLocalClipboard: (layer: LocalLayer | null) => void;
|
onLocalClipboard: (layer: LocalLayer | null) => void;
|
||||||
onExport: () => void;
|
onExport: () => void;
|
||||||
@@ -153,7 +158,9 @@ export default function Develop({
|
|||||||
onUpdate,
|
onUpdate,
|
||||||
clipboard,
|
clipboard,
|
||||||
onCopy,
|
onCopy,
|
||||||
|
onCopyOf,
|
||||||
onPaste,
|
onPaste,
|
||||||
|
onResetSelection,
|
||||||
localClipboard,
|
localClipboard,
|
||||||
onLocalClipboard,
|
onLocalClipboard,
|
||||||
onExport,
|
onExport,
|
||||||
@@ -202,6 +209,10 @@ export default function Develop({
|
|||||||
const toggleStrip = () => (mobile ? setMobileStripOpen((open) => !open) : setStripOpen((open) => !open));
|
const toggleStrip = () => (mobile ? setMobileStripOpen((open) => !open) : setStripOpen((open) => !open));
|
||||||
const [filmMinRating, setFilmMinRating] = useState(0);
|
const [filmMinRating, setFilmMinRating] = useState(0);
|
||||||
const [filmFlag, setFilmFlag] = useState<Flag | 'any'>('any');
|
const [filmFlag, setFilmFlag] = useState<Flag | 'any'>('any');
|
||||||
|
// Filmstrip multi-select. The canvas keeps its own photo; this is the set a
|
||||||
|
// paste applies to, exactly like Lightroom's filmstrip selection.
|
||||||
|
const [filmSel, setFilmSel] = useState<string[]>([photo.id]);
|
||||||
|
const [filmAnchor, setFilmAnchor] = useState(photo.id);
|
||||||
const [showOriginal, setShowOriginal] = useState(false);
|
const [showOriginal, setShowOriginal] = useState(false);
|
||||||
const [histVersion, setHistVersion] = useState(0);
|
const [histVersion, setHistVersion] = useState(0);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -214,7 +225,12 @@ export default function Develop({
|
|||||||
const [panning, setPanning] = useState(false);
|
const [panning, setPanning] = useState(false);
|
||||||
const [navigatorView, setNavigatorView] = useState<Rect | null>(null);
|
const [navigatorView, setNavigatorView] = useState<Rect | null>(null);
|
||||||
const [readout, setReadout] = useState({ shown: 100, fit: 100 });
|
const [readout, setReadout] = useState({ shown: 100, fit: 100 });
|
||||||
const [menu, setMenu] = useState<{ x: number; y: number; kind: 'canvas' | 'film' } | null>(null);
|
const [menu, setMenu] = useState<{
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
kind: 'canvas' | 'film';
|
||||||
|
ids?: string[];
|
||||||
|
} | null>(null);
|
||||||
const [healMode, setHealMode] = useState(false);
|
const [healMode, setHealMode] = useState(false);
|
||||||
const [brushPx, setBrushPx] = useState(56);
|
const [brushPx, setBrushPx] = useState(56);
|
||||||
const [healFeather, setHealFeather] = useState(50);
|
const [healFeather, setHealFeather] = useState(50);
|
||||||
@@ -273,6 +289,49 @@ export default function Develop({
|
|||||||
[filmPhotos, onSelect, photo.id],
|
[filmPhotos, onSelect, photo.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// The photo on the canvas is always part of the selection, so a fresh filmstrip
|
||||||
|
// starts with just that frame. Cmd/Shift clicks grow the set without moving it.
|
||||||
|
useEffect(() => {
|
||||||
|
setFilmSel([photo.id]);
|
||||||
|
setFilmAnchor(photo.id);
|
||||||
|
}, [photo.id]);
|
||||||
|
|
||||||
|
// A cull filter can hide part of the selection; drop those frames rather than
|
||||||
|
// pasting settings into photos that are no longer on screen.
|
||||||
|
useEffect(() => {
|
||||||
|
setFilmSel((prev) => {
|
||||||
|
const visible = new Set(filmPhotos.map((item) => item.id));
|
||||||
|
const next = prev.filter((id) => visible.has(id));
|
||||||
|
return next.length === prev.length ? prev : next;
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [filmMinRating, filmFlag]);
|
||||||
|
|
||||||
|
const clickFilm = (p: PhotoRecord, e: React.MouseEvent) => {
|
||||||
|
if (e.shiftKey) {
|
||||||
|
const a = filmPhotos.findIndex((item) => item.id === filmAnchor);
|
||||||
|
const b = filmPhotos.findIndex((item) => item.id === p.id);
|
||||||
|
if (a >= 0 && b >= 0) {
|
||||||
|
const [lo, hi] = a < b ? [a, b] : [b, a];
|
||||||
|
setFilmSel(filmPhotos.slice(lo, hi + 1).map((item) => item.id));
|
||||||
|
} else {
|
||||||
|
setFilmSel([p.id]);
|
||||||
|
setFilmAnchor(p.id);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.metaKey || e.ctrlKey) {
|
||||||
|
setFilmSel((prev) =>
|
||||||
|
prev.includes(p.id) ? prev.filter((id) => id !== p.id) : [...prev, p.id],
|
||||||
|
);
|
||||||
|
setFilmAnchor(p.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setFilmSel([p.id]);
|
||||||
|
setFilmAnchor(p.id);
|
||||||
|
onSelect(p.id);
|
||||||
|
};
|
||||||
|
|
||||||
const moveLensSplit = (e: React.PointerEvent<HTMLButtonElement>) => {
|
const moveLensSplit = (e: React.PointerEvent<HTMLButtonElement>) => {
|
||||||
const rect = e.currentTarget.parentElement?.getBoundingClientRect();
|
const rect = e.currentTarget.parentElement?.getBoundingClientRect();
|
||||||
if (!rect || rect.width <= 0) return;
|
if (!rect || rect.width <= 0) return;
|
||||||
@@ -1283,7 +1342,7 @@ export default function Develop({
|
|||||||
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'c') {
|
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'c') {
|
||||||
onCopy();
|
onCopy();
|
||||||
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'v') {
|
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'v') {
|
||||||
onPaste();
|
onPaste(filmSel);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const up = (e: KeyboardEvent) => {
|
const up = (e: KeyboardEvent) => {
|
||||||
@@ -1306,6 +1365,7 @@ export default function Develop({
|
|||||||
navigateFilm,
|
navigateFilm,
|
||||||
onCopy,
|
onCopy,
|
||||||
onPaste,
|
onPaste,
|
||||||
|
filmSel,
|
||||||
undo,
|
undo,
|
||||||
redo,
|
redo,
|
||||||
applyZoom,
|
applyZoom,
|
||||||
@@ -1456,7 +1516,7 @@ export default function Develop({
|
|||||||
{ label: 'Before / After', shortcut: '\\', onSelect: () => setShowOriginal((v) => !v) },
|
{ label: 'Before / After', shortcut: '\\', onSelect: () => setShowOriginal((v) => !v) },
|
||||||
'separator',
|
'separator',
|
||||||
{ label: 'Copy settings', shortcut: '⌘C', onSelect: onCopy },
|
{ label: 'Copy settings', shortcut: '⌘C', onSelect: onCopy },
|
||||||
{ label: 'Paste settings', shortcut: '⌘V', onSelect: onPaste, disabled: !clipboard },
|
{ label: 'Paste settings', shortcut: '⌘V', onSelect: () => onPaste([photo.id]), disabled: !clipboard },
|
||||||
{ label: 'Reset settings', onSelect: resetAll },
|
{ label: 'Reset settings', onSelect: resetAll },
|
||||||
'separator',
|
'separator',
|
||||||
...(canPushImmich && onPushImmich
|
...(canPushImmich && onPushImmich
|
||||||
@@ -1469,10 +1529,38 @@ export default function Develop({
|
|||||||
{ label: 'Delete photo…', danger: true, onSelect: onDelete },
|
{ label: 'Delete photo…', danger: true, onSelect: onDelete },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Right-clicking one of several selected frames acts on the whole selection;
|
||||||
|
// right-clicking outside it acts on that frame alone.
|
||||||
|
const filmMenuIds = menu?.kind === 'film' && menu.ids?.length ? menu.ids : [photo.id];
|
||||||
const filmMenu: MenuEntry[] = [
|
const filmMenu: MenuEntry[] = [
|
||||||
{ label: 'Copy settings', onSelect: onCopy },
|
{
|
||||||
{ label: 'Paste settings', onSelect: onPaste, disabled: !clipboard },
|
label: 'Open in Develop',
|
||||||
{ label: 'Reset settings', onSelect: resetAll },
|
disabled: filmMenuIds.includes(photo.id),
|
||||||
|
onSelect: () => onSelect(filmMenuIds[0]),
|
||||||
|
},
|
||||||
|
'separator',
|
||||||
|
{
|
||||||
|
label: 'Copy settings',
|
||||||
|
onSelect: () => (onCopyOf ? onCopyOf(filmMenuIds[0]) : onCopy()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label:
|
||||||
|
filmMenuIds.length > 1
|
||||||
|
? `Paste settings to ${filmMenuIds.length} photos…`
|
||||||
|
: 'Paste settings',
|
||||||
|
onSelect: () => onPaste(filmMenuIds),
|
||||||
|
disabled: !clipboard,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label:
|
||||||
|
filmMenuIds.length > 1
|
||||||
|
? `Reset adjustments on ${filmMenuIds.length} photos`
|
||||||
|
: 'Reset settings',
|
||||||
|
onSelect: () =>
|
||||||
|
filmMenuIds.length > 1 && onResetSelection
|
||||||
|
? onResetSelection(filmMenuIds)
|
||||||
|
: resetAll(),
|
||||||
|
},
|
||||||
'separator',
|
'separator',
|
||||||
...(canPushImmich && onPushImmich
|
...(canPushImmich && onPushImmich
|
||||||
? ([{ label: 'Send edit to Immich', onSelect: onPushImmich }] as MenuEntry[])
|
? ([{ label: 'Send edit to Immich', onSelect: onPushImmich }] as MenuEntry[])
|
||||||
@@ -1525,8 +1613,17 @@ export default function Develop({
|
|||||||
<button className="btn ghost small" onClick={onVirtualCopy} title="Create a virtual copy with its own edits">
|
<button className="btn ghost small" onClick={onVirtualCopy} title="Create a virtual copy with its own edits">
|
||||||
Virtual copy
|
Virtual copy
|
||||||
</button>
|
</button>
|
||||||
<button className="btn ghost small" onClick={onPaste} disabled={!clipboard} title="Paste develop settings (⌘V)">
|
<button
|
||||||
Paste
|
className="btn ghost small"
|
||||||
|
onClick={() => onPaste(filmSel)}
|
||||||
|
disabled={!clipboard || !filmSel.length}
|
||||||
|
title={
|
||||||
|
filmSel.length > 1
|
||||||
|
? `Paste develop settings to ${filmSel.length} selected photos (⌘V)`
|
||||||
|
: 'Paste develop settings (⌘V)'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Paste{filmSel.length > 1 ? ` (${filmSel.length})` : ''}
|
||||||
</button>
|
</button>
|
||||||
<button className="btn ghost small" onClick={undo} disabled={!canUndo} title="Undo (⌘Z)">
|
<button className="btn ghost small" onClick={undo} disabled={!canUndo} title="Undo (⌘Z)">
|
||||||
Undo
|
Undo
|
||||||
@@ -2225,8 +2322,13 @@ export default function Develop({
|
|||||||
<button type="button" className="btn ghost small" onClick={onCopy}>
|
<button type="button" className="btn ghost small" onClick={onCopy}>
|
||||||
Copy
|
Copy
|
||||||
</button>
|
</button>
|
||||||
<button type="button" className="btn ghost small" onClick={onPaste} disabled={!clipboard}>
|
<button
|
||||||
Paste
|
type="button"
|
||||||
|
className="btn ghost small"
|
||||||
|
onClick={() => onPaste(filmSel)}
|
||||||
|
disabled={!clipboard || !filmSel.length}
|
||||||
|
>
|
||||||
|
Paste{filmSel.length > 1 ? ` (${filmSel.length})` : ''}
|
||||||
</button>
|
</button>
|
||||||
<button type="button" className="btn ghost small" onClick={resetAll}>
|
<button type="button" className="btn ghost small" onClick={resetAll}>
|
||||||
Reset
|
Reset
|
||||||
@@ -2352,6 +2454,9 @@ export default function Develop({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="spacer" />
|
<div className="spacer" />
|
||||||
|
{filmSel.length > 1 && (
|
||||||
|
<span className="film-count">{filmSel.length} selected</span>
|
||||||
|
)}
|
||||||
<span className="film-count">
|
<span className="film-count">
|
||||||
{filmPhotos.length} / {photos.length}
|
{filmPhotos.length} / {photos.length}
|
||||||
</span>
|
</span>
|
||||||
@@ -2362,22 +2467,28 @@ export default function Develop({
|
|||||||
{filmPhotos.map((p) => (
|
{filmPhotos.map((p) => (
|
||||||
<button
|
<button
|
||||||
key={p.id}
|
key={p.id}
|
||||||
className={`film ${p.id === photo.id ? 'active' : ''}`}
|
className={`film ${p.id === photo.id ? 'active' : ''} ${
|
||||||
onClick={() => onSelect(p.id)}
|
filmSel.includes(p.id) ? 'selected' : ''
|
||||||
|
}`}
|
||||||
|
onClick={(e) => clickFilm(p, e)}
|
||||||
onContextMenu={(e) => {
|
onContextMenu={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (p.id !== photo.id) onSelect(p.id);
|
const inSelection = filmSel.includes(p.id);
|
||||||
setMenu({ x: e.clientX, y: e.clientY, kind: 'film' });
|
const ids = inSelection ? filmSel : [p.id];
|
||||||
|
if (!inSelection) {
|
||||||
|
setFilmSel([p.id]);
|
||||||
|
setFilmAnchor(p.id);
|
||||||
|
if (p.id !== photo.id) onSelect(p.id);
|
||||||
|
}
|
||||||
|
setMenu({ x: e.clientX, y: e.clientY, kind: 'film', ids });
|
||||||
}}
|
}}
|
||||||
title={p.name}
|
title={
|
||||||
|
filmSel.length > 1 && filmSel.includes(p.id)
|
||||||
|
? `${p.name} · ${filmSel.length} selected`
|
||||||
|
: `${p.name} · Shift-click or Ctrl-click to select more`
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<img
|
<EditedImage photo={p} alt={p.name} boxAspect={3 / 2} />
|
||||||
src={p.thumbUrl ?? p.thumb}
|
|
||||||
alt={p.name}
|
|
||||||
loading="lazy"
|
|
||||||
draggable={false}
|
|
||||||
style={{ transform: thumbTransform(p, 3 / 2) }}
|
|
||||||
/>
|
|
||||||
{p.rating > 0 && <span className="film-rating">{'★'.repeat(p.rating)}</span>}
|
{p.rating > 0 && <span className="film-rating">{'★'.repeat(p.rating)}</span>}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { thumbTransform } from '../lib/edits';
|
||||||
|
import { useEditedThumb } from '../lib/editThumbs';
|
||||||
|
import type { PhotoRecord } from '../types';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
photo: PhotoRecord;
|
||||||
|
/** Aspect of the tile the picture fills; the rotation transform needs it. */
|
||||||
|
boxAspect?: number;
|
||||||
|
alt?: string;
|
||||||
|
loading?: 'lazy' | 'eager';
|
||||||
|
draggable?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A thumbnail that follows the photo's edits.
|
||||||
|
*
|
||||||
|
* Edited photos get a freshly rendered small JPEG; everything else keeps the
|
||||||
|
* server/import thumbnail and the CSS orientation transform. Rendering starts
|
||||||
|
* only when the tile is close to the viewport.
|
||||||
|
*/
|
||||||
|
export default function EditedImage({
|
||||||
|
photo,
|
||||||
|
boxAspect = 4 / 3,
|
||||||
|
alt,
|
||||||
|
loading = 'lazy',
|
||||||
|
draggable = false,
|
||||||
|
}: Props) {
|
||||||
|
const ref = useRef<HTMLImageElement>(null);
|
||||||
|
const [nearView, setNearView] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
if (typeof IntersectionObserver === 'undefined') {
|
||||||
|
setNearView(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
(entries) => {
|
||||||
|
if (!entries.some((entry) => entry.isIntersecting)) return;
|
||||||
|
setNearView(true);
|
||||||
|
observer.disconnect();
|
||||||
|
},
|
||||||
|
{ rootMargin: '400px' },
|
||||||
|
);
|
||||||
|
observer.observe(el);
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const edited = useEditedThumb(photo, nearView);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
ref={ref}
|
||||||
|
src={edited ?? photo.thumbUrl ?? photo.thumb}
|
||||||
|
alt={alt ?? photo.name}
|
||||||
|
loading={loading}
|
||||||
|
draggable={draggable}
|
||||||
|
// A rendered tile already has the crop, turn and flips baked in.
|
||||||
|
style={{ transform: edited ? 'none' : thumbTransform(photo, boxAspect) }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { COLOR_LABELS, isEdited, thumbTransform } from '../lib/edits';
|
import { COLOR_LABELS, isEdited } from '../lib/edits';
|
||||||
import { draggedPhotoIds, endDrag, PHOTO_DRAG, startPhotoDrag } from '../lib/drag';
|
import { draggedPhotoIds, endDrag, PHOTO_DRAG, startPhotoDrag } from '../lib/drag';
|
||||||
import type { ColorLabel, Flag, PhotoRecord } from '../types';
|
import type { ColorLabel, Flag, PhotoRecord } from '../types';
|
||||||
import Stars, { ColorSwatches, FlagButtons } from './Stars';
|
import Stars, { ColorSwatches, FlagButtons } from './Stars';
|
||||||
|
import EditedImage from './EditedImage';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
photos: PhotoRecord[];
|
photos: PhotoRecord[];
|
||||||
@@ -443,13 +444,7 @@ export default function LibraryGrid({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="card-thumb">
|
<div className="card-thumb">
|
||||||
<img
|
<EditedImage photo={p} alt={p.name} />
|
||||||
src={p.thumbUrl ?? p.thumb}
|
|
||||||
alt={p.name}
|
|
||||||
loading="lazy"
|
|
||||||
draggable={false}
|
|
||||||
style={{ transform: thumbTransform(p) }}
|
|
||||||
/>
|
|
||||||
<div className="card-badges">
|
<div className="card-badges">
|
||||||
{p.flag === 'pick' && <span className="badge pick">✓</span>}
|
{p.flag === 'pick' && <span className="badge pick">✓</span>}
|
||||||
{p.flag === 'reject' && <span className="badge reject">✕</span>}
|
{p.flag === 'reject' && <span className="badge reject">✕</span>}
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import type { Edits, PhotoRecord } from '../types';
|
||||||
|
import { isEdited } from './edits';
|
||||||
|
import { Renderer, rotatedBounds } from '../gl/renderer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thumbnails of edited photos.
|
||||||
|
*
|
||||||
|
* The server thumbnail is always the *undeveloped* frame, so the grid and the
|
||||||
|
* filmstrip would otherwise show the import look no matter how far a photo was
|
||||||
|
* edited. These are rendered on demand with the same shader the canvas uses,
|
||||||
|
* from the already-cached small thumbnail (not the multi-megapixel proxy), and
|
||||||
|
* kept as data URLs. One renderer does every tile: a WebGL context per picture
|
||||||
|
* would exhaust the browser's limit long before a shoot.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Long edge of a rendered thumb; twice the largest card, so it stays sharp. */
|
||||||
|
const RENDER_EDGE = 384;
|
||||||
|
const CACHE_LIMIT = 700;
|
||||||
|
|
||||||
|
const cache = new Map<string, string>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits are immutable: every change stores a new object (undo re-uses an old
|
||||||
|
* one). A per-object version number is therefore a cheap, exact cache key — far
|
||||||
|
* cheaper than serializing the whole edit for every visible card on every render.
|
||||||
|
*/
|
||||||
|
const versions = new WeakMap<Edits, number>();
|
||||||
|
let versionSeq = 0;
|
||||||
|
|
||||||
|
function versionOf(edits: Edits): number {
|
||||||
|
let version = versions.get(edits);
|
||||||
|
if (version === undefined) {
|
||||||
|
version = ++versionSeq;
|
||||||
|
versions.set(edits, version);
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyOf(photo: PhotoRecord): string {
|
||||||
|
return `${photo.id}|${versionOf(photo.edits)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let renderer: Renderer | null = null;
|
||||||
|
let rendererFailed = false;
|
||||||
|
|
||||||
|
function getRenderer(): Renderer | null {
|
||||||
|
if (renderer) return renderer;
|
||||||
|
if (rendererFailed) return null;
|
||||||
|
try {
|
||||||
|
renderer = new Renderer(document.createElement('canvas'));
|
||||||
|
} catch {
|
||||||
|
// No WebGL2: tiles quietly keep their plain thumbnails.
|
||||||
|
rendererFailed = true;
|
||||||
|
}
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The small picture the browser already has, decoded for the shader. */
|
||||||
|
async function loadThumb(photo: PhotoRecord): Promise<ImageBitmap | null> {
|
||||||
|
const src = photo.thumbUrl ?? photo.thumb;
|
||||||
|
if (!src) return null;
|
||||||
|
try {
|
||||||
|
const res = await fetch(src, { credentials: 'same-origin' });
|
||||||
|
if (!res.ok) return null;
|
||||||
|
return await createImageBitmap(await res.blob(), { imageOrientation: 'from-image' });
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderThumb(photo: PhotoRecord): Promise<string | null> {
|
||||||
|
const r = getRenderer();
|
||||||
|
if (!r) return null;
|
||||||
|
const bitmap = await loadThumb(photo);
|
||||||
|
if (!bitmap) return null;
|
||||||
|
try {
|
||||||
|
const crop = photo.edits.crop;
|
||||||
|
const frame = rotatedBounds(bitmap.width, bitmap.height, crop.angle, crop.quarter);
|
||||||
|
const cropW = Math.max(1, frame.w * crop.w);
|
||||||
|
const cropH = Math.max(1, frame.h * crop.h);
|
||||||
|
const scale = Math.min(2, RENDER_EDGE / Math.max(cropW, cropH));
|
||||||
|
const width = Math.max(16, Math.round(cropW * scale));
|
||||||
|
const height = Math.max(16, Math.round(cropH * scale));
|
||||||
|
r.setImage(bitmap);
|
||||||
|
// `lens: null` clears the previous photo's calibration maps: this renderer
|
||||||
|
// is shared, and a stale map would warp the next thumbnail.
|
||||||
|
r.render(photo.edits, { width, height, lens: null, upscale: scale > 1.02 });
|
||||||
|
return r.canvas.toDataURL('image/jpeg', 0.74);
|
||||||
|
} finally {
|
||||||
|
bitmap.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Job {
|
||||||
|
photo: PhotoRecord;
|
||||||
|
key: string;
|
||||||
|
waiters: ((url: string | null) => void)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const jobs: Job[] = [];
|
||||||
|
let pumping = false;
|
||||||
|
|
||||||
|
function enqueue(photo: PhotoRecord, key: string): Promise<string | null> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const existing = jobs.find((job) => job.key === key);
|
||||||
|
if (existing) {
|
||||||
|
existing.waiters.push(resolve);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
jobs.push({ photo, key, waiters: [resolve] });
|
||||||
|
void pump();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One render at a time, yielding between tiles so the UI stays responsive. */
|
||||||
|
async function pump() {
|
||||||
|
if (pumping) return;
|
||||||
|
pumping = true;
|
||||||
|
while (jobs.length) {
|
||||||
|
const job = jobs.shift()!;
|
||||||
|
let url: string | null = null;
|
||||||
|
try {
|
||||||
|
url = await renderThumb(job.photo);
|
||||||
|
} catch {
|
||||||
|
url = null;
|
||||||
|
}
|
||||||
|
if (url) {
|
||||||
|
cache.set(job.key, url);
|
||||||
|
while (cache.size > CACHE_LIMIT) {
|
||||||
|
const first = cache.keys().next();
|
||||||
|
if (first.done) break;
|
||||||
|
cache.delete(first.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const waiter of job.waiters) waiter(url);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
}
|
||||||
|
pumping = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The edited thumbnail for a photo, or null while there is none to show.
|
||||||
|
*
|
||||||
|
* Only edited photos are rendered, and only once the tile is near the viewport
|
||||||
|
* (`enabled`), so a long shoot does not pay for pictures nobody can see. Until
|
||||||
|
* a render lands the caller keeps showing the plain thumbnail.
|
||||||
|
*/
|
||||||
|
export function useEditedThumb(photo: PhotoRecord, enabled = true): string | null {
|
||||||
|
const key = isEdited(photo.edits) ? keyOf(photo) : '';
|
||||||
|
const [src, setSrc] = useState<string | null>(() => (key ? cache.get(key) ?? null : null));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!key) {
|
||||||
|
setSrc(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hit = cache.get(key);
|
||||||
|
if (hit) {
|
||||||
|
setSrc(hit);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!enabled) return;
|
||||||
|
let alive = true;
|
||||||
|
// Coalesce slider drags: only the setting you stopped on gets rendered.
|
||||||
|
const timer = window.setTimeout(() => {
|
||||||
|
void enqueue(photo, key).then((url) => {
|
||||||
|
if (alive && url) setSrc(url);
|
||||||
|
});
|
||||||
|
}, 120);
|
||||||
|
return () => {
|
||||||
|
alive = false;
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
};
|
||||||
|
}, [key, photo, enabled]);
|
||||||
|
|
||||||
|
return src;
|
||||||
|
}
|
||||||
@@ -1565,6 +1565,15 @@ figcaption {
|
|||||||
box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 1px var(--accent);
|
box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 1px var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Additional photos in a multi-select, as opposed to the one on the canvas. */
|
||||||
|
.film.selected {
|
||||||
|
box-shadow: inset 0 0 0 2px #cfcfda;
|
||||||
|
}
|
||||||
|
|
||||||
|
.film.selected.active {
|
||||||
|
box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 1px var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
.film-rating {
|
.film-rating {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 2px;
|
bottom: 2px;
|
||||||
|
|||||||
Reference in New Issue
Block a user