Skip to content

fix: use forked libraw-wasm + JPEG fallback for unsupported RAW#96

Merged
lexluthor0304 merged 2 commits into
mainfrom
fix/use-forked-libraw-wasm
May 27, 2026
Merged

fix: use forked libraw-wasm + JPEG fallback for unsupported RAW#96
lexluthor0304 merged 2 commits into
mainfrom
fix/use-forked-libraw-wasm

Conversation

@lexluthor0304

Copy link
Copy Markdown
Owner

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.2 bundles 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-wasmgithub:lexluthor0304/LibRaw-Wasm
  • Rebuilt with LibRaw 0.22.1 (pinned), adding support for Z f, Z8, Z6-III, Z30, plus Canon R1/R5 II, Sony A9-III, Fuji X-T50, and many more

2. Defensive JPEG preview fallback

  • rawFileLoader.js: When raw.imageData() returns empty (e.g. dcraw_make_mem_image() NULL), fall back to the embedded camera-rendered JPEG preview instead of showing a generic error
  • Same 6048×4032 resolution, 8-bit precision (vs 16-bit from LibRaw)

How to switch back

When the upstream PR (ybouane/LibRaw-Wasm#15) is merged and published:

npm install libraw-wasm@latest

Revert the package.json change.

Test plan

  • Nikon Z f NEF loads via JPEG fallback (6048×4032, 8-bit)
  • Sony ARW decodes correctly via LibRaw (16-bit)
  • No regression for standard image formats

🤖 Generated with Claude Code

lexluthor0304 and others added 2 commits May 27, 2026 10:37
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>
@vercel

vercel Bot commented May 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
negative-converter Building Building Preview, Comment May 27, 2026 1:48am

@lexluthor0304 lexluthor0304 merged commit 0e3444e into main May 27, 2026
10 checks passed
@lexluthor0304 lexluthor0304 deleted the fix/use-forked-libraw-wasm branch May 27, 2026 01:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +240 to +242
if (!result || !result.data) {
console.error('[RAW] imageData returned empty result', result);
return await handleTimeoutFallback();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant