[refactor] avoid Kelvin/mired round-trip in DNG solver (#273) - #277
antond-weta merged 1 commit into
Conversation
|
|
2a50053 to
d2b457f
Compare
| 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 ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d2b457f to
8d2cb91
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
…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>
8d2cb91 to
4169129
Compare
Description
XYZ_to_color_temperatureinterpolated 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 / 50000and1e6 / 2000are exact doubles, so the clamped values are identical to before). Inside the range the solver now sees the interpolated value itself instead of1e6 / (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_XYZstill 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 intests/testDNGIdt.cppare replaced with direct mired tests ofXYZ_to_mired:testIDT_XYZToMired- interior value,179.7053420705mired (the reciprocal of the previous5564.6648479019K golden).testIDT_XYZToMired_LowerClamp- first Robertson entry clamps to20mired.testIDT_XYZToMired_UpperClamp- past the last Robertson entry clamps to500mired.testIDT_FindCameraToXYZMtxis 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 --installandtests/config_tests. Also clang 18 withRTA_SANITISER_MODE=addressrunningtests/run_valid.sh(no reports), CodeChecker (clangsa + clang-tidy) and cppcheck onrawtoaces_core.cpp(no new findings), and clang-format 16 (no diffs).Checklist:
Assisted-by: TOOL / MODELline in the pull request description above.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.)