Add support for extracting JPEG previews from RAW files#257
Open
dochoss wants to merge 2 commits into
Open
Conversation
feat: add support for extracting JPEG previews from RAW camera files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-wasmdoes not shiplibraw/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.dngfiles in expecting PNG/JPG output.How
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 legacyJPEGInterchangeFormattag pair (CR2 IFD0 preview, older NEFs). Candidates are validated against the JPEG SOI marker (FF D8) before being returned.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.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 existingsupportedFormatslist (RAW formats were already declaredreadable: true).Tradeoffs / scope
librawWASM build..cr3is 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
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).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.