Skip to content

feat(rawler): expose as-shot white balance temperature - #5

Open
dimafa wants to merge 1 commit into
CyberTimon:mainfrom
dimafa:fix/as-shot-temperature
Open

feat(rawler): expose as-shot white balance temperature#5
dimafa wants to merge 1 commit into
CyberTimon:mainfrom
dimafa:fix/as-shot-temperature

Conversation

@dimafa

@dimafa dimafa commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • add Decoder::as_shot_temperature for retrieving as-shot white-balance temperature in Kelvin
  • support ARW, CR2, CR3, DNG, NEF, and NRW files
  • prefer Canon's recorded ColorTempAsShot value for CR2/CR3, with coefficient-based estimation as a fallback
  • estimate temperature for Sony, DNG, and Nikon files from as-shot white-balance coefficients and camera color matrices
  • add focused tests for Canon ColorData layouts, dual-illuminant interpolation, invalid inputs, and a Nikon Z f reference case

Motivation

RapidRAW's Lightroom XMP sidecar importer needs the RAW file's as-shot temperature to convert custom Lightroom white balance using mired differences. Rawler already extracts the required native white-balance coefficients and calibration matrices, but did not expose their corresponding temperature.

Implementation

The Decoder trait gains an optional as_shot_temperature method. Unsupported decoders return None by default.

For Canon CR2 and CR3 files, the decoder reads ColorTempAsShot from the existing ColorData maker-note layouts and validates that it is within a plausible range. If it is absent or invalid, the decoder falls back to the shared estimator.

For ARW, DNG, NEF, and NRW files, the estimator converts the camera neutral to CIE xy using the available color matrices. Dual-illuminant matrices are interpolated in reciprocal-temperature space, and correlated color temperature is calculated in CIE 1960 UCS space.

The value is exposed separately from RawMetadata, avoiding changes to serialized metadata and the repository's existing sample snapshots.

Validation

Passed with Rust 1.88.0 on macOS arm64:

  • cargo check
  • cargo build --all-features
  • cargo check --all-features
  • focused Canon, matrix-interpolation, invalid-input, and Nikon Z f regression tests
  • all 57 pre-existing rawler library tests after temporarily typing the existing tile-test vector as u16; that unrelated temporary correction was reverted
  • direct rustfmt checks for the changed implementation and test files
  • git diff --check

The unmodified repository's full cargo test is currently blocked by a pre-existing test-only type inference error at rawler/src/tiles.rs:334: the vector is inferred as i32, while SubPixel is implemented for u8, u16, and f32. The external sample database suite was not run because RAWLER_RAWDB was unavailable.

@dimafa
dimafa marked this pull request as ready for review August 3, 2026 13:35
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