Run the camera-to-sRGB pass on a worker thread

At four parallel imports the synchronous colour conversion was the widest
serial section left in the pipeline. The frame buffers now live on
SharedArrayBuffer, so a worker writes the same memory the encoder reads
and the main thread is free for the decoder pool and zlib.
This commit is contained in:
2026-12-02 04:02:33 +00:00
parent 7f0838156b
commit d24cbf26b8
3 changed files with 79 additions and 4 deletions
+17
View File
@@ -0,0 +1,17 @@
/**
* Off-main-thread camera-to-proxy conversion.
*
* `cameraToProxy` is a pixel loop over the whole frame: 2.4 s on a 24 MP decode
* here, and four parallel imports serialised on it. The buffers arrive as
* SharedArrayBuffer views, so the worker mutates the frame in place and nothing
* is copied across the thread boundary.
*/
import { parentPort, workerData } from 'node:worker_threads';
import { cameraToProxy } from './color.mjs';
try {
const gain = cameraToProxy(workerData.rgb16, workerData.rgb8, workerData.matrix);
parentPort.postMessage({ gain });
} catch (error) {
parentPort.postMessage({ error: error instanceof Error ? error.message : String(error) });
}