Skip to content

[refactor] avoid Kelvin/mired round-trip in DNG solver (#273) - #277

Merged
antond-weta merged 1 commit into
AcademySoftwareFoundation:mainfrom
thc1006:refactor/issue-273-mired-helper
Sep 13, 2026
Merged

antond-weta merged 1 commit into
AcademySoftwareFoundation:mainfrom
thc1006:refactor/issue-273-mired-helper

Conversation

@thc1006

@thc1006 thc1006 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Description

XYZ_to_color_temperature interpolated the Robertson table in mired, converted the result to Kelvin and clamped it to [2000, 50000] K. Its only caller, find_camera_to_XYZ_matrix, converted the result straight back to mired (#273).

This PR replaces the private helper with XYZ_to_mired, which returns the interpolated value in mired, clamped to the equivalent [20, 500] mired range (1e6 / 50000 and 1e6 / 2000 are exact doubles, so the clamped values are identical to before). Inside the range the solver now sees the interpolated value itself instead of 1e6 / (1e6 / mired), which removes a rounding error of about one ulp; the solver golden (Found illuminant: 5317k. and the expected matrix) is unchanged.

The Kelvin helper had no other callers and is removed. It was only declared in rawtoaces_core_priv.h, so no installed header, binding or documentation changes. color_temperature_to_XYZ still takes Kelvin; happy to follow up on that separately if a mired variant is wanted.

Rebased onto the current main.

Resolves #273.

Tests

The three testIDT_XYZToColorTemperature* tests in tests/testDNGIdt.cpp are replaced with direct mired tests of XYZ_to_mired:

  • testIDT_XYZToMired - interior value, 179.7053420705 mired (the reciprocal of the previous 5564.6648479019 K golden).
  • testIDT_XYZToMired_LowerClamp - first Robertson entry clamps to 20 mired.
  • testIDT_XYZToMired_UpperClamp - past the last Robertson entry clamps to 500 mired.

testIDT_FindCameraToXYZMtx is untouched and guards the solver output against any drift from removing the round-trip. (The 5317k value it pins turned out to be wrong for an unrelated reason, see #325 and #327; this PR keeps it on purpose, it only removes the round-trip and does not change what the solver computes.)

Verified locally on Ubuntu 24.04 (gcc 13.3, C++17, Eigen + Ceres + lensfun, shared libs): build with -Werror -Wall -Wextra -pedantic, all 17 ctest targets, cmake --install and tests/config_tests. Also clang 18 with RTA_SANITISER_MODE=address running tests/run_valid.sh (no reports), CodeChecker (clangsa + clang-tidy) and cppcheck on rawtoaces_core.cpp (no new findings), and clang-format 16 (no diffs).

Checklist:

  • I have read the contribution guidelines.
  • I have read the Policy on AI Coding Assistants and if I used AI coding assistants, I have an Assisted-by: TOOL / MODEL line in the pull request description above.
  • I have updated the documentation, if applicable. (Private helper only; no documentation changes needed.)
  • I have ensured that the change is tested somewhere in the testsuite (adding new test cases if necessary).
  • My code follows the prevailing code style of this project. If I haven't already run clang-format before submitting, I definitely will look at the CI test that runs clang-format and fix anything that it highlights as being nonconforming.

Assisted-by: Claude Code / Claude Opus 5 (Used to rebase onto current main, apply the review feedback, rewrite the tests and run the CI steps locally; I reviewed every change before pushing.)

Copilot AI review requested due to automatic review settings May 9, 2026 13:42
@linux-foundation-easycla

linux-foundation-easycla Bot commented May 9, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: thc1006 / name: thc1006 (d2b457f)

@thc1006
thc1006 force-pushed the refactor/issue-273-mired-helper branch from 2a50053 to d2b457f Compare May 9, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

auto neutral_XYZ = mulVector( camera_to_XYZ_matrix, neutral_RGB );
auto neutral_CCT = XYZ_to_color_temperature( neutral_XYZ );
auto neutral_mired = kelvin_to_mired( neutral_CCT );
auto neutral_mired = XYZ_to_mired( neutral_XYZ );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the existing functionality as the neutral_mired is now unclamped.

As this place is the only one using the function, I would move the clamp inside XYZ_to_mired and get rid of XYZ_to_color_temperature, even if that would require modifying the unit tests.

@thc1006 thc1006 Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch. The old caller observed the Kelvin clamp after converting the result back to mired, so using the raw interpolation changed the solver semantics.

I've moved the equivalent [20, 500] mired clamp into XYZ_to_mired, removed the Kelvin helper (it had no other callers), and replaced the Kelvin tests with direct mired tests for the interior value and both clamped ends. The change is rebased onto the current main, and the existing DNG solver golden is unchanged.

@codecov-commenter

codecov-commenter commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.00%. Comparing base (1f53c01) to head (4169129).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #277      +/-   ##
==========================================
- Coverage   92.01%   92.00%   -0.01%     
==========================================
  Files          17       17              
  Lines        3830     3828       -2     
  Branches      567      567              
==========================================
- Hits         3524     3522       -2     
  Misses        306      306              
Files with missing lines Coverage Δ
src/rawtoaces_core/rawtoaces_core.cpp 98.56% <100.00%> (-0.01%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1f53c01...4169129. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@antond-weta antond-weta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…reFoundation#273)

XYZ_to_color_temperature interpolated the Robertson table in mired,
converted the result to Kelvin and clamped it to [2000, 50000] K, and
its only caller, find_camera_to_XYZ_matrix, converted the result
straight back to mired.

Replace it with XYZ_to_mired, which returns the interpolated value in
mired, clamped to the equivalent [20, 500] mired range, so the solver
keeps its previous clamping semantics without the reciprocal round-trip.
Inside the range the result is now the interpolated value itself rather
than 1e6 / (1e6 / mired), which removes a rounding error of about one
ulp; the solver golden in the unit tests is unchanged.

The Kelvin helper had no other callers and is removed. Its unit tests
are replaced with direct mired tests covering an interior value and
both clamped ends of the range.

Resolves AcademySoftwareFoundation#273.

Assisted-by: Claude Code / Claude Opus 5
Claude-Session: https://claude.ai/code/session_01UUqNrkHJbRcyzA8NxvSsoQ
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@antond-weta
antond-weta force-pushed the refactor/issue-273-mired-helper branch from 8d2cb91 to 4169129 Compare September 13, 2026 22:16
@antond-weta
antond-weta merged commit 667395b into AcademySoftwareFoundation:main Sep 13, 2026
26 checks passed
@thc1006
thc1006 deleted the refactor/issue-273-mired-helper branch September 14, 2026 02:15
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.

[core] Clarify Kelvin vs mired around XYZ_to_color_temperature (avoid redundant round-trips)

4 participants