Speed up raw imports and add a per-import 16-bit toggle

Import raws four at a time to match the decoder pool, compress the 16-bit
sidecar with RLE on the libuv pool, and demosaic X-Trans files in a single
Markesteijn pass so Fuji imports no longer queue into decode timeouts. The
import dialog now offers 16-bit (default) or 8-bit per import, sent as
`?sidecar=0`, and the camera thumbnail and embedded-preview fallbacks no
longer drop to 8-bit samples or store a 0x0 photo.
This commit is contained in:
2026-12-02 03:25:53 +00:00
parent ea7b5b846c
commit fa0a7e64ef
11 changed files with 464 additions and 101 deletions
+26 -3
View File
@@ -88,17 +88,40 @@ class LibRawPool {
}
}
/** Run `fn` with a decoder instance; the instance returns to the pool after. */
async use(fn) {
/**
* Run `fn` with a decoder instance; the instance returns to the pool after.
*
* `timeoutMs` covers only the work, never the wait for a free worker: a job
* that sat in the queue is not slow, and timing it from the call site made
* parallel imports fail in waves. A timed-out worker is still chewing on the
* abandoned job, so it is destroyed rather than handed to the next caller.
*/
async use(fn, { timeoutMs = 0, label = 'LibRaw' } = {}) {
const lib = await this.acquire();
let healthy = true;
let timer = null;
try {
return await fn(lib);
if (!timeoutMs) return await fn(lib);
const guard = new Promise((_, reject) => {
timer = setTimeout(
() => reject(new Error(`${label} timed out on this file`)),
timeoutMs,
);
});
try {
return await Promise.race([fn(lib), guard]);
} catch (err) {
if (timer && /timed out/.test(String(err?.message ?? '')) && err instanceof Error) {
healthy = false;
}
throw err;
}
} catch (err) {
// A dead worker keeps failing, so recycle it instead of handing it back.
if (/worker|terminated|disposed|memory/i.test(String(err?.message ?? ''))) healthy = false;
throw err;
} finally {
if (timer) clearTimeout(timer);
this.release(lib, healthy);
}
}