fix: use forked libraw-wasm + JPEG fallback for unsupported RAW#96
Conversation
When LibRaw's dcraw_make_mem_image() returns NULL (e.g., for unsupported compression variants on recognized cameras like Nikon Z f), the result object is empty/undefined. Previously this fell through to a destructure TypeError and a generic "Error loading file". Now it triggers the embedded JPEG preview fallback, allowing the image to load at 8-bit precision. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Switch from npm registry package to GitHub fork. Why: The npm package libraw-wasm@1.1.2 bundles a WASM binary compiled from an older LibRaw version that does not support cameras released after ~2022, including Nikon Z f, Z8, Z6-III, and others. This causes NEF files from these cameras to fail with a generic error. Our fork (lexluthor0304/LibRaw-Wasm) rebuilds with LibRaw 0.22.1 which recognizes these cameras. A PR has been submitted upstream: ybouane/LibRaw-Wasm#15 How to switch back: When the upstream PR is merged and a new npm version is released, revert this commit and run: npm install libraw-wasm@latest See also: fix in rawFileLoader.js that adds JPEG preview fallback when raw.imageData() returns empty, providing a graceful degradation path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7446a3c4f9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!result || !result.data) { | ||
| console.error('[RAW] imageData returned empty result', result); | ||
| return await handleTimeoutFallback(); |
There was a problem hiding this comment.
Treat zero-length image data as empty
When raw.imageData() returns a result object whose data is an empty typed array, this guard does not take the JPEG fallback because typed arrays are truthy. The code then continues into the RGB conversion path, where reads from the empty array become zeroes and the app can display a black image instead of falling back for unsupported RAW files. Please also validate that result.data.length is non-zero, ideally against the expected width * height payload size.
Useful? React with 👍 / 👎.
Summary
Use a forked build of
libraw-wasm(rebased on LibRaw 0.22.1) to add support for newer cameras including Nikon Z f, Z8, Z6-III, while adding a defensive JPEG preview fallback for any RAW files that LibRaw cannot fully decode.Problem
The npm package
libraw-wasm@1.1.2bundles a WASM binary from an older LibRaw that does not recognize cameras released after ~2022. Nikon Z f NEF files fail with a generic "Error loading file."Changes
1. Switch to forked libraw-wasm
package.json:libraw-wasm→github:lexluthor0304/LibRaw-Wasm2. Defensive JPEG preview fallback
rawFileLoader.js: Whenraw.imageData()returns empty (e.g.dcraw_make_mem_image()NULL), fall back to the embedded camera-rendered JPEG preview instead of showing a generic errorHow to switch back
When the upstream PR (ybouane/LibRaw-Wasm#15) is merged and published:
Revert the package.json change.
Test plan
🤖 Generated with Claude Code