Skip to content

Read the Olympus preview as GetOlympusPreviewImage does - #19

Open
kunpai wants to merge 1 commit into
google:masterfrom
kunpai:olympus-preview-as-get-olympus-preview-image
Open

kunpai wants to merge 1 commit into
google:masterfrom
kunpai:olympus-preview-as-get-olympus-preview-image

Conversation

@kunpai

@kunpai kunpai commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Read the Olympus preview as GetOlympusPreviewImage does

NOTE: #24 answers both questions the port's way. C++'s GetOlympusPreviewImage now reads the full size from RawProcessing even when an earlier step fails, and writes the preview offset and length only when both read. On master with #24, all four rows below agree, with the Rust column's values on both sides, so this PR can be closed once #24 is merged.

Problem

GetOlympusPreviewImage (C++, Rust) reads an ORF's preview offset and length from the MakerNote's CameraSettings IFD, and the full image size from the RawProcessing IFD's AspectFrame. OrfGetPreviewData ignores whether it succeeds, as the port does, so the caller gets whatever it wrote before it stopped. The two differ in two ways:

  1. C++ returns at the first step that fails: a thumbnail entry that does not read, no CameraSettings IFD, or no PreviewImageStart or PreviewImageLength in it. It then never reads the full size. The port runs the thumbnail, CameraSettings and RawProcessing steps each on its own, so it reads the full size anyway.
  2. C++ does not check whether PreviewImageStart and PreviewImageLength read. It adds the MakerNote's offset to whatever the preview offset holds, and keeps the length it had. The port writes both only when both read.

For example, an ORF whose MakerNote starts at byte 1,024, with a 35-byte preview at 1,792 and an AspectFrame of 4032×3024, with one entry changed:

# C++ Rust
1 CameraSettings IFD with no entries no preview; full size 0×0 no preview; full size 4032×3024
1 thumbnail entry of type BYTE, not UNDEFINED no preview; full size 0×0 preview at 1,792, 35 bytes; full size 4032×3024
2 PreviewImageStart with 2 values preview at 1,024, 35 bytes no preview
2 PreviewImageLength with 2 values preview at 1,792, 0 bytes no preview

In the examples for (2), the full size is 4032×3024 on both sides. With PreviewImageStart unreadable, C++'s preview offset is the 0 it held plus the MakerNote's 1,024, so the preview starts at the MakerNote itself.

Question

Which behaviour do we want: C++'s or the Rust port's? Specifically:

  1. GetOlympusPreviewImage, a step before the full size fails: should it stop there, leaving the full size unset (like the C++ library), or still read the full size from RawProcessing (like the Rust port)?
  2. GetOlympusPreviewImage, PreviewImageStart or PreviewImageLength does not read: should it still write the preview offset (plus the MakerNote's offset) and length (like the C++ library), or write neither (like the Rust port)?

This PR implements C++'s behaviour.

Fix

get_olympus_preview_image returns where GetOlympusPreviewImage returns false, and writes the preview fields as it does:

  • Thumbnail entry (1): an entry that does not read returns an error instead of being skipped.
  • CameraSettings (1): unless the CameraSettings IFD parses and has both preview tags, the function returns before RawProcessing.
  • Preview offset and length (2): each is written when it reads, and the MakerNote's offset is added to the preview offset either way. The examples above then match C++.

Replayed before and after:

# C++ Rust main Rust patched
1 CameraSettings IFD with no entries full size 0×0 full size 4032×3024 full size 0×0
1 thumbnail entry of type BYTE no preview; 0×0 preview at 1,792, 35 bytes; 4032×3024 no preview; 0×0
2 PreviewImageStart with 2 values preview at 1,024, 35 bytes no preview preview at 1,024, 35 bytes
2 PreviewImageLength with 2 values preview at 1,792, 0 bytes no preview preview at 1,792, 0 bytes

Of the campaigns' inputs, 10 ORFs differ from C++ in these fields on main and none with this PR; no other input changes. The port's tests pass unchanged (44 + 174).

Notes for review:

  • C++'s results here seem unintended: OrfGetPreviewData omits the error because "some images do not contain any preview data", yet such an ORF also loses its full size in C++; and in (2) C++ reports a preview that starts at the MakerNote or has no bytes. To keep the port's behavior, we can close this PR.
  • get_olympus_preview_image is public: it now returns an error where GetOlympusPreviewImage returns false. extract_orf ignores the result, as OrfGetPreviewData does.
  • output_type also differs on these files, before and after. Use piex's RawImageTypes numbers in the cxx bridge #9 covers that.

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