Skip to content

Use piex's RawImageTypes numbers in the cxx bridge - #9

Closed
kunpai wants to merge 1 commit into
google:masterfrom
kunpai:raw-image-type-numbers
Closed

kunpai wants to merge 1 commit into
google:masterfrom
kunpai:raw-image-type-numbers

Conversation

@kunpai

@kunpai kunpai commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Use piex's RawImageTypes numbers in the cxx bridge

Problem

RecognizeRawImageTypeLite, IsOfType, GetNumberOfBytesForIsOfType, IsRaw(type) and GetPreviewImageData's output_type (C++, Rust) pass a piex::image_type_recognition::RawImageTypes across the API. The port's own RawImageType has five formats piex's enum does not have (Erf, PhaseOne, Pxn, Raw3fr, Rdc), inserted in alphabetical order, so every value after Dng is shifted (from_u32). The bridge passes the port's numbers across unchanged, in both directions:

For example:

# C++ Rust
1 GetPreviewImageData on a NEF output_type 10, kNefImage 11, which is kNrwImage
2 RecognizeRawImageTypeLite on an RW2 header (MM\0U) 17, kRw2Image 22, which RawImageTypes has no value for
3 IsOfType(MM\0U, kRw2Image) true false (the port's 17 is Qtk)
4 GetNumberOfBytesForIsOfType(kOrfImage) 3,000 4,000 (the port's 12 is Nrw)
5 a TIFF header with EPSON in it (an ERF) RecognizeRawImageTypeLite 0, kNonRawImage; IsRaw false 7, which is kKdcImage; IsRaw true

A caller that names or routes files by type (for example, a file browser that labels each one) shows a NEF as NRW, an ORF as PEF, a PEF as QTK and a RAF as SRW. The port's Phase One and RDC values read as a RAF and as no value at all.

Question

Which behaviour do we want: C++'s or the Rust port's? Specifically, should the bridge use piex's RawImageTypes numbers, and report ERF, 3FR, Phase One, PXN and RDC as kNonRawImage (like the C++ library), or the port's own RawImageType numbers (like the Rust port)?

This PR implements C++'s behaviour.

Fix

This PR changes rust/src/cxx_bridge.rs to follow piex's numbering:

  • One table of piex's order (1-5): CXX_RAW_IMAGE_TYPES lists the port's types in RawImageTypes order. to_cxx gives a type's index there, and 0 (kNonRawImage) for the five types the enum lacks. from_cxx gives the type at an index.
  • Every crossing uses it (1-4): rust_get_preview_image_data writes to_cxx of the type (both writes), rust_recognize_raw_image_type_lite returns it, and rust_is_raw_type, rust_is_of_type and rust_get_number_of_bytes_for_is_of_type read the caller's value with from_cxx.
  • IsRaw(stream) (5): rust_is_raw counts a header as raw only when its type has a value in piex's enum, as IsRawLite does in C++.

The examples above then return what C++ returns. Replayed before and after (x86-64):

# C++ Rust main Rust patched
1 output_type 10 (also ORF 12, PEF 13, RAF 15) 11 (ORF 13, PEF 14, RAF 18) 10 (ORF 12, PEF 13, RAF 15)
2 17 22 17
3 true false true
4 3,000 (and 256 for kSrwImage) 4,000 (and 8) 3,000 (and 256)
5 0, IsRaw false (same for 3FR, Phase One, PXN, RDC headers) 7, IsRaw true (19, 15, 16, 21) 0, IsRaw false

Notes for review:

  • The port's checkers for ERF, 3FR, Phase One, PXN and RDC stay. Their answers no longer reach a C++ caller as a raw type, because piex has no checker or enum value for them. Reporting them would need new RawImageTypes values, which is a change to piex's API.
  • IsRaw(type) for a value outside the enum is a separate difference (C++ asserts). Abort in IsRaw(type) for a value outside RawImageTypes, as C++ does #10 covers it. Both PRs change rust_is_raw_type, so whichever lands second needs a rebase.
  • IsRaw(20) to IsRaw(24) go from true to false with this PR: 20 to 24 are the port's enumerators but not piex's. C++ asserts on them; Abort in IsRaw(type) for a value outside RawImageTypes, as C++ does #10 covers that. IsOfType and GetNumberOfBytesForIsOfType for them become false and 0, as in C++.
  • The port's tests pass unchanged (44 + 174).

The port's RawImageType has five formats piex's enum lacks, so every
type after Dng has a higher number than in RawImageTypes, and the bridge
passed those numbers to and from C++ unchanged. Translate through a
table in RawImageTypes order, as C++ callers expect.
@ShaddyDC

ShaddyDC commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Hey, this is a good find, but I think this is outdated after our latest export. Sorry about that. I'll close this for now, but feel free to reopen or open a new one if you find another instance like this in your next scan.

@ShaddyDC ShaddyDC closed this Nov 6, 2026
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