Skip to content

Keep the caller's size in GetDngInformation when there is no DefaultCropSize, as C++ does - #35

Open
kunpai wants to merge 1 commit into
google:masterfrom
kunpai:dng-information-without-crop-size
Open

kunpai wants to merge 1 commit into
google:masterfrom
kunpai:dng-information-without-crop-size

Conversation

@kunpai

@kunpai kunpai commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Keep the caller's size in GetDngInformation when there is no DefaultCropSize, as C++ does

Problem

GetDngInformation (C++, Rust) reads a DNG's full width and height and its CFA pattern size, first from IFD0 and then from the first SubIFD. The size comes from GetFullDimension32 (C++, Rust), which here can only find DefaultCropSize, the one size tag GetDngInformation asks the parser for. When the directory has no DefaultCropSize:

For example, a DNG whose raw SubIFD has CFARepeatPatternDim 2×2 and whose DefaultCropSize (4000×3000) has its tag changed to 0xC610, which piex does not read, called with width 640, height 480 and an empty cfa_pattern_dim:

C++ Rust
return value true false
width × height 640×480 (the caller's) 640×480 (the caller's)
cfa_pattern_dim {2, 2} {}

Called with width and height 0, both return false. With the tag in place, both return true with 4000×3000.

Question

Which behaviour do we want: C++'s or the Rust port's? Specifically, should GetDngInformation return true (like the C++ library), or return false (like the Rust port)?

This PR implements C++'s behaviour.

Fix

In get_dng_info_internal, a TagNotFound from get_full_dimension32 now passes when the caller's width and height are both nonzero, as C++ does:

-    if let Ok((w, h)) = parser.get_full_dimension32(target_dir) {
-        if w > 0 && h > 0 {
+    match parser.get_full_dimension32(target_dir) {
+        Ok((w, h)) if w > 0 && h > 0 => {
             *width = w;
             *height = h;
-        } else {
-            return false;
         }
-    } else {
-        return false;
+        Err(TiffError::TagNotFound { .. }) if *width > 0 && *height > 0 => {}
+        _ => return false,
     }

The example above then returns what C++ returns. Replayed before and after:

C++ Rust main Rust patched
return value true false true
width × height 640×480 640×480 640×480
cfa_pattern_dim {2, 2} {} {2, 2}

Notes for review:

  • C++'s answer seems like a bug: the width and height it returns are the caller's, not the file's. A comment in C++'s GetFullCropDimension says the same about returning true there without writing. To keep the port's behavior, we can close this PR.
  • Only callers that pass a nonzero width and height see a change. The C++ API on the port passes the caller's values through. The Rust API get_dng_information starts from 0×0, so it returns false as before.
  • The port's tests pass unchanged (44 + 174).

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