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
+51
View File
@@ -4,6 +4,7 @@ import { describe, expect, it } from 'vitest';
import {
RAW_EXTENSIONS,
decodeRaw,
extractEmbeddedJpegs,
decodeStill,
isRawName,
isStillName,
@@ -52,6 +53,56 @@ describe('raw format coverage', () => {
});
});
const JPEG_SOI = Buffer.from([0xff, 0xd8, 0xff]);
const JPEG_EOI = Buffer.from([0xff, 0xd9]);
/** A JPEG-shaped run of `total` bytes with no nested markers. */
function jpegBytes(total) {
return Buffer.concat([JPEG_SOI, Buffer.alloc(Math.max(1, total - 5), 0x11), JPEG_EOI]);
}
describe('embedded preview fallback', () => {
it('lists candidates largest first and ignores thumbnail-sized runs', () => {
const small = jpegBytes(9000);
const big = jpegBytes(90000);
const tiny = jpegBytes(1200);
const buffer = Buffer.concat([
Buffer.alloc(128),
small,
Buffer.alloc(32),
big,
Buffer.alloc(32),
tiny,
Buffer.alloc(32),
]);
const lengths = extractEmbeddedJpegs(buffer).map((jpeg) => jpeg.length);
// Splitting candidates at every end-of-image marker can yield over-long
// slices that span two images; those fail to decode and are skipped. What
// matters is that both real previews are offered, largest first, and that
// thumbnail-sized runs are not.
expect(lengths).toEqual([...lengths].sort((a, b) => b - a));
expect(lengths).toContain(big.length);
expect(lengths).toContain(small.length);
expect(lengths).not.toContain(tiny.length);
});
it('does not let a nested EXIF thumbnail truncate the full preview', () => {
// Regression: the scan used to stop at the thumbnail's end-of-image, so the
// "preview" it stored was a cut-off JPEG that sharp refused to decode and
// the import ended up as a 0x0 photo.
const thumb = jpegBytes(6000);
const outer = Buffer.concat([
JPEG_SOI,
Buffer.alloc(2000, 0x11),
thumb,
Buffer.alloc(40000, 0x11),
JPEG_EOI,
]);
const found = extractEmbeddedJpegs(Buffer.concat([Buffer.alloc(64), outer]));
expect(found[0].length).toBe(outer.length);
});
});
describe('TIFF decoding', () => {
it('turns a TIFF into a JPEG proxy', async () => {
const { default: sharp } = await import('sharp');