Skip to content

Thumbnail camera RAW from its embedded JPEG - #186

Open
dhh wants to merge 6 commits into
mainfrom
raw-thumbnails-embedded
Open

dhh wants to merge 6 commits into
mainfrom
raw-thumbnails-embedded

Conversation

@dhh

@dhh dhh commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Based on #66 by @thisisgm, with the review fixes from that branch.

Most camera RAW files were a blank tile unless a RAW thumbnailer was installed, or went through LibRaw by way of Qt's raw plugin, which decodes the whole sensor (and threw on CR2s, #164). The camera stores a finished JPEG inside each file, and a bounded reader of the TIFF directories now finds the largest one in a CR2, NEF, NRW, ARW, SR2, DNG or PEF, so nothing is decoded from the sensor data and nothing is linked in. A preview that does not decode is passed over for the next largest, all within one read limit. A preview is turned by the orientation its own directory names (IFD0, past any fill bytes before the JPEG's marker), and by the file's when it names none. An installed thumbnailer still answers first, and a broken file is refused rather than guessed at: offsets, counts and lengths are checked against named limits, a preview claiming more than 250 million pixels is skipped before decoding, and the number of header reads is capped as well as their bytes. CR3, RAF, ORF, RW2 and SRW keep their JPEG in other containers and still show an icon.

Finding no preview inside isn't remembered as a failure, so a RAW thumbnailer installed later still draws the file. The failure markers' round goes to 3, so RAW files an older Folio gave up on are tried once more; the same change is in #175 and #176, so they merge in any order.

One RAW file from each of twelve cameras, main above and this branch below (from #66):

Camera RAW before and after

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Adds thumbnails from the JPEG previews stored inside supported camera RAW files.

  • Camera RAW tiles can use embedded JPEG previews.
  • Files marked by older thumbnail failures get another try.

No new actionable issues found. The earlier failure-cache finding is addressed.

Reviews (3) · Last reviewed commit: "Let a RAW thumbnailer installed later dr..." · Reviewed by Greptile

Comment thread src/thumbnails.cpp Resolved
thisisgm and others added 6 commits November 18, 2026 17:25
A CR2, NEF, NRW, ARW, SR2, DNG or PEF showed a blank tile unless a RAW
thumbnailer was installed. The camera stores a finished JPEG in each,
and a bounded reader of the TIFF directories now finds the largest
one. An installed thumbnailer still answers first.
One orientation was kept for the whole file, so a preview whose
directory names a turn of its own was turned by IFD0's instead. Each
embedded JPEG now carries its directory's orientation, and takes the
file's only when its directory names none.
A JPEG may put 0xFF fill bytes ahead of a marker, and the Exif segment
of one that did was missed, so an upright preview got the RAW's turn.
And the walk followed IFD0's next pointer into IFD1, the Exif
thumbnail's directory, whose orientation then passed for the picture's.
Only IFD0's own Orientation is read now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A preview is no longer ranked when its frame header claims more than 250
million pixels, more than any camera's; a few KiB claiming 57000 by 56000
otherwise ranked first and cost a 270 MB decode that failed, up to sixteen
times per file.

The header budget now caps the number of reads as well as their bytes: each
read is its own system call, a round trip on a network mount, and crafted
directories reached some 60,000 tiny reads within the byte budget.

The embedded JPEG is read into a buffer with room for the Exif segment, so
putting the segment in front no longer copies up to 64 MiB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files that failed only because of what's fixed here (a name holding a
%, a helper that never started, a camera RAW Folio couldn't read) kept
their failure markers, and those hold a file back before any of the
fixes are reached, so they stayed blank until the file changed. The
markers' round goes to 3, so each is tried once more. The same change
is in each of the thumbnail fixes, so they merge in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A camera RAW whose embedded JPEG couldn't be found was remembered as
failed, so installing a RAW thumbnailer afterwards changed nothing
until the file did. Finding no preview inside isn't remembered now; the
reader is bounded, so looking again costs little.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh force-pushed the raw-thumbnails-embedded branch from 82ff430 to 077bce2 Compare November 18, 2026 16:27
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.

2 participants