fix(raw): stop the develop from handing the studio zero bytes

libraw-wasm moves the buffer it is given into its worker, so raw.open() detaches
the caller's array. developRaw read its embedded JPEG preview as a view of that
same array, so the open emptied the preview, Skia rejected the detached buffer
and the catch returned the emptied preview as the develop - every RAW opened from
the LIBRARY reached the studio as 0 bytes and the app said "Could not develop
this RAW file. Try again, or use its JPG."

Hand the worker a copy instead, in the develop and in the thumbnail path. The
EXIF stamps read off the caller's bytes afterwards are intact again.

The ORF check now hands the bytes over in the transfer list the way the package
does, so it fails on any develop that forgets this.
This commit is contained in:
2026-10-06 16:16:28 +07:00
parent 16c098cd6a
commit 8ed094cd9e
2 changed files with 18 additions and 9 deletions
+4 -6
View File
@@ -24,8 +24,9 @@ const transpile = (path) =>
// `self.onmessage` / `self.postMessage`, where Node has parentPort. So the worker
// is booted behind a shim that renames one into the other, and the package's own
// message protocol ({ id, fn, args } / { id, out, error }) is spoken here.
// The worker is handed the file bytes copy itself — the transfer list would
// detach the caller's.
// The file bytes are handed over in the transfer list exactly as the package
// does — so opening detaches them, and this check fails on any develop that
// forgets to keep the caller's array intact.
const LIBRAW_NODE_SRC = `
import { Worker } from 'node:worker_threads';
@@ -68,10 +69,7 @@ export default class LibRaw {
this.worker.postMessage({ id, fn, args }, transfer);
});
}
open(bytes, settings) {
const copy = Uint8Array.from(bytes);
return this.run('open', copy, settings);
}
open(bytes, settings) { return this.run('open', bytes, settings); }
metadata(full) { return this.run('metadata', !!full); }
imageData() { return this.run('imageData'); }
thumbnailData() { return this.run('thumbnailData'); }