Land camera-native raw profiles, real ICC soft proofing and 16-bit proxies.
Camera profiles, proofing tables and the half-float sidecar all have to agree with the pixels the editor actually grades, so they land together with the preset filter menu that was unusable while thumbnails streamed in. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { PhotoRecord } from '../types';
|
||||
import { getAsset, putAsset } from './db';
|
||||
import { parsePreview16, type Preview16 } from './preview16';
|
||||
|
||||
const CACHE_LIMIT = 6;
|
||||
const cache = new Map<string, ImageBitmap>();
|
||||
@@ -93,11 +94,59 @@ export function evictBitmap(photoId: string) {
|
||||
bmp.close();
|
||||
}
|
||||
|
||||
const hdrCache = new Map<string, Preview16 | null>();
|
||||
|
||||
/** Version stamp from the preview URL, so a reprocess invalidates the sidecar too. */
|
||||
function preview16Url(photo: PhotoRecord): string {
|
||||
const base = `/api/photos/${encodeURIComponent(photo.id)}/preview16`;
|
||||
const query = (photo.previewUrl ?? '').split('?')[1];
|
||||
return query ? `${base}?${query}` : base;
|
||||
}
|
||||
|
||||
/**
|
||||
* The 16-bit samples behind a raw proxy, or null when there are none.
|
||||
*
|
||||
* Null is normal, not an error: photos imported before the sidecar existed,
|
||||
* non-raw files and oversized fetches all end up grading the JPEG. Only a 404
|
||||
* is remembered, so a dropped connection is retried on the next look.
|
||||
*/
|
||||
export async function get16BitSource(photo: PhotoRecord): Promise<Preview16 | null> {
|
||||
if (!photo.raw) return null;
|
||||
const hit = hdrCache.get(photo.id);
|
||||
if (hit !== undefined) return hit;
|
||||
let parsed: Preview16 | null = null;
|
||||
let missing = false;
|
||||
try {
|
||||
const res = await fetch(preview16Url(photo), { credentials: 'same-origin' });
|
||||
if (!res.ok) {
|
||||
missing = true;
|
||||
} else {
|
||||
parsed = await parsePreview16(await res.arrayBuffer());
|
||||
missing = parsed === null;
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (parsed) {
|
||||
hdrCache.set(photo.id, parsed);
|
||||
// Each sidecar is up to ~100 MB of typed array, so only the last two stay.
|
||||
while (hdrCache.size > 2) {
|
||||
const first = hdrCache.keys().next();
|
||||
if (first.done) break;
|
||||
hdrCache.delete(first.value);
|
||||
}
|
||||
} else if (missing) {
|
||||
hdrCache.set(photo.id, null);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export function clearBitmapCache() {
|
||||
for (const bmp of cache.values()) bmp.close();
|
||||
cache.clear();
|
||||
for (const bmp of denoisedCache.values()) bmp.close();
|
||||
denoisedCache.clear();
|
||||
hdrCache.clear();
|
||||
}
|
||||
|
||||
const denoisedCache = new Map<string, ImageBitmap>();
|
||||
|
||||
Reference in New Issue
Block a user