Skip to content

Add support for extracting JPEG previews from RAW files#257

Open
dochoss wants to merge 2 commits into
VERT-sh:mainfrom
Keystone-Studio-Development:main
Open

Add support for extracting JPEG previews from RAW files#257
dochoss wants to merge 2 commits into
VERT-sh:mainfrom
Keystone-Studio-Development:main

Conversation

@dochoss

@dochoss dochoss commented May 28, 2026

Copy link
Copy Markdown

What

Adds support for converting TIFF-based camera RAW files (DNG, NEF, CR2, ARW, RAF, ORF, PEF, RW2, NRW, SRW, 3FR, ERF, MEF, MOS, MRW, SR2, SRF, DCR) into any image format VERT already supports.

Why

magick-wasm does not ship libraw/dcraw, so when ImageMagick is handed a RAW file in the browser it interprets the sensor's Bayer mosaic as RGB pixels — the result is a rainbow-coloured mess instead of the user's photo. Reported visually by users dropping .dng files in expecting PNG/JPG output.

How

  • New src/lib/util/parse/raw.ts — a small, dependency-free TIFF directory walker that finds the largest embedded JPEG preview in the RAW file. It checks both the modern path (JPEG-compressed strips inside a SubIFD, where DNG keeps its full-resolution preview) and the legacy JPEGInterchangeFormat tag pair (CR2 IFD0 preview, older NEFs). Candidates are validated against the JPEG SOI marker (FF D8) before being returned.
  • Modified src/lib/workers/magick.ts — when the input is a known RAW format, the worker extracts the embedded preview and re-enters the existing pipeline as a JPEG. autoOrient() is called on the resulting image so EXIF orientation gets baked into the pixels (PNG/WebP have no orientation tag — without this, portrait photos came out sideways). If no preview is found, returns a friendly error instead of garbled output.
  • Modified docs/FAQ.md — added a short entry explaining the behaviour and its tradeoffs.

No new dependencies, no changes to package.json, no changes to the existing supportedFormats list (RAW formats were already declared readable: true).

Tradeoffs / scope

  • Output resolution = embedded preview resolution, which on modern phones and most cameras is full-res. On some older DSLRs the embedded preview is smaller than the sensor — accepted tradeoff vs. shipping a multi-MB libraw WASM build.
  • The preview carries the camera's baked-in white balance and tone curve, so output looks like the camera's own JPEG rather than a "neutral" RAW develop. This is what users almost always want; noted in the FAQ.
  • Canon .cr3 is an ISO BMFF container (not TIFF) and will surface the friendly "no preview found" error. Left in the supported-formats list as-is; a future CR3 parser would be a small follow-up.

Testing

  • Manual: IMG_0520.DNG → PNG and → JPG both produce the correct upright image (previously PNG was a rainbow mosaic; after the orientation fix, both are upright).
  • Negative path: a file with no embedded preview surfaces a clear error toast instead of garbled output.

AI NOTE

AI was used to generate these changes, but all code was manually verified by a human (me!) and tested in the final running version of the application. Clear comments and documentation were added that can be easily verified.

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