Import TIFF through the server and survive a wedged raw decoder
Browsers have no TIFF decoder, so TIFF import failed at createImageBitmap and the develop canvas asked for the undecodable original. TIFF now takes the raw proxy path (original stored, sharp writes the JPEG proxy) and the editor reads that proxy. LibRaw demosaic and preview calls are bounded so one bad file falls back to the embedded preview instead of hanging.
This commit is contained in:
@@ -1481,7 +1481,13 @@ export function NavigatorPanel({
|
||||
{photo.name}
|
||||
</div>
|
||||
<div className="muted small navigator-meta">
|
||||
{photo.raw ? (photo.decode === 'embedded' ? 'Raw · camera preview' : 'Raw · demosaiced') : 'JPEG/PNG'}{' '}
|
||||
{photo.raw
|
||||
? photo.decode === 'embedded'
|
||||
? 'Raw · camera preview'
|
||||
: 'Raw · demosaiced'
|
||||
: photo.decode === 'sharp'
|
||||
? 'TIFF · server JPEG'
|
||||
: 'JPEG/PNG'}{' '}
|
||||
· {photo.width}×{photo.height}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ export interface SessionUser {
|
||||
|
||||
export interface UploadResult {
|
||||
raw: boolean;
|
||||
engine?: 'libraw' | 'embedded';
|
||||
engine?: 'libraw' | 'embedded' | 'sharp';
|
||||
width?: number;
|
||||
height?: number;
|
||||
mime?: string;
|
||||
@@ -153,7 +153,7 @@ export function reprocessRawPhoto(
|
||||
): Promise<{
|
||||
width: number;
|
||||
height: number;
|
||||
engine?: 'libraw' | 'embedded';
|
||||
engine?: 'libraw' | 'embedded' | 'sharp';
|
||||
note?: string | null;
|
||||
previewVersion?: number;
|
||||
previewUrl?: string;
|
||||
|
||||
+5
-1
@@ -7,7 +7,11 @@ const cache = new Map<string, ImageBitmap>();
|
||||
|
||||
/** Where to fetch the original (or raw proxy) when it is not cached on this device. */
|
||||
export function remoteAssetUrl(photo: PhotoRecord): string {
|
||||
if (photo.raw) return photo.previewUrl || `/api/photos/${encodeURIComponent(photo.id)}/preview`;
|
||||
// Server-decoded formats (TIFF today) keep a browser-readable JPEG proxy just
|
||||
// like raws; their original cannot be decoded by createImageBitmap.
|
||||
if (photo.raw || photo.decode === 'sharp') {
|
||||
return photo.previewUrl || `/api/photos/${encodeURIComponent(photo.id)}/preview`;
|
||||
}
|
||||
return `/api/photos/${encodeURIComponent(photo.id)}/original`;
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -4,7 +4,7 @@ import type { PhotoMeta, PhotoRecord } from '../types';
|
||||
import { putAsset, putPhoto } from './db';
|
||||
import { defaultEdits, normalizePhoto } from './edits';
|
||||
import { defaultForMeta, loadCameraLensDefaults, type CameraLensDefault } from './lensDefaults';
|
||||
import { isRawFile, RAW_EXTENSIONS } from './raw';
|
||||
import { isRawFile, isTiffFile, RAW_EXTENSIONS } from './raw';
|
||||
|
||||
export interface ImportProgress {
|
||||
done: number;
|
||||
@@ -125,6 +125,8 @@ async function importRaw(
|
||||
keywords: string[],
|
||||
cloud: CloudImport,
|
||||
defaults: CameraLensDefault[],
|
||||
/** TIFF goes through the same proxy path but is not a raw container. */
|
||||
raw = true,
|
||||
): Promise<PhotoRecord> {
|
||||
const id = uid();
|
||||
const upload = await cloud.uploadOriginal(id, file, file.name);
|
||||
@@ -158,7 +160,7 @@ async function importRaw(
|
||||
keywords,
|
||||
edits,
|
||||
history: [{ label: 'Import', ts: Date.now(), edits }],
|
||||
raw: true,
|
||||
raw,
|
||||
decode: upload.engine,
|
||||
previewUrl,
|
||||
});
|
||||
@@ -242,9 +244,10 @@ export async function importFiles(
|
||||
await mapLimit(images, cloud ? IMPORT_CONCURRENCY : 2, async (file, index) => {
|
||||
if (signal?.aborted) return;
|
||||
try {
|
||||
const photo = isRawFile(file)
|
||||
const viaServer = isRawFile(file) || isTiffFile(file);
|
||||
const photo = viaServer
|
||||
? cloud
|
||||
? await importRaw(file, eventId, keywords, cloud, defaults)
|
||||
? await importRaw(file, eventId, keywords, cloud, defaults, isRawFile(file))
|
||||
: (() => {
|
||||
throw new Error('Raw files need the Luminary server. Sign in, then import again.');
|
||||
})()
|
||||
|
||||
+17
-2
@@ -7,12 +7,27 @@ export const RAW_EXTENSIONS = new Set([
|
||||
'rw2', 'raw', 'rwl',
|
||||
'raf',
|
||||
'pef', 'dng',
|
||||
'srw', '3fr', 'fff', 'iiq', 'x3f', 'erf', 'k25', 'kdc', 'dcr', 'mos', 'mrw', 'mef',
|
||||
'srw', '3fr', 'fff', 'iiq', 'x3f', 'erf', 'k25', 'kdc', 'dcr', 'mos', 'mrw', 'mef', 'sraw',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Standard images the browser cannot decode itself. They take the same server
|
||||
* path as raws: the original is stored and the server writes a JPEG proxy.
|
||||
* Chrome and Firefox have no TIFF decoder, so a TIFF left to the browser is a
|
||||
* silent import failure.
|
||||
*/
|
||||
export const SERVER_IMAGE_EXTENSIONS = new Set(['tif', 'tiff']);
|
||||
|
||||
export function isTiffFile(file: File): boolean {
|
||||
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
|
||||
return SERVER_IMAGE_EXTENSIONS.has(ext);
|
||||
}
|
||||
|
||||
export function isRawFile(file: File): boolean {
|
||||
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
|
||||
return RAW_EXTENSIONS.has(ext);
|
||||
}
|
||||
|
||||
export const RAW_ACCEPT = [...RAW_EXTENSIONS].map((e) => `.${e}`).join(',');
|
||||
export const RAW_ACCEPT = [...RAW_EXTENSIONS, ...SERVER_IMAGE_EXTENSIONS]
|
||||
.map((e) => `.${e}`)
|
||||
.join(',');
|
||||
|
||||
+1
-1
@@ -320,7 +320,7 @@ export interface PhotoRecord {
|
||||
/** true when the original is a camera raw decoded by the server */
|
||||
raw?: boolean;
|
||||
/** how the editable proxy was produced */
|
||||
decode?: 'libraw' | 'embedded';
|
||||
decode?: 'libraw' | 'embedded' | 'sharp';
|
||||
/** server URL for the editable proxy (raw only) */
|
||||
previewUrl?: string;
|
||||
/** server URL for the grid thumbnail */
|
||||
|
||||
Reference in New Issue
Block a user