[refactor] avoid Kelvin/mired round-trip in DNG solver (#273) - #277
Open
thc1006 wants to merge 1 commit into
Open
[refactor] avoid Kelvin/mired round-trip in DNG solver (#273)#277thc1006 wants to merge 1 commit into
thc1006 wants to merge 1 commit into
Conversation
|
|
…reFoundation#273) XYZ_to_color_temperature internally interpolates against robertson_mired_table in mired, then converts to Kelvin and clamps to [2000, 50000] K. Its only in-tree caller, find_camera_to_XYZ_matrix, divides that Kelvin result back into mired, producing a redundant mired -> Kelvin -> mired round-trip flagged by issue AcademySoftwareFoundation#273. Add a private helper XYZ_to_mired that returns the unclamped mired value from the same Robertson interpolation. Keep XYZ_to_color_temperature as a thin wrapper that applies the [2000, 50000] K clamp via mired_to_kelvin; its public contract and existing test golden numbers are preserved (the clamp bounds correspond exactly to robertson_mired_table[2] and robertson_mired_table[26] -- 1e6/2000 = 500.0 and 1e6/50000 = 20.0 are exact double-precision reciprocals). Switch find_camera_to_XYZ_matrix to call the mired helper directly so the binary search no longer round-trips through Kelvin. Add testIDT_XYZToMired pinning the mired return path against the same XYZ input the existing testIDT_XYZToColorTemperature uses, with a cross-check that the wrapper still produces the equivalent Kelvin. Resolves AcademySoftwareFoundation#273. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
force-pushed
the
refactor/issue-273-mired-helper
branch
from
May 9, 2026 13:55
2a50053 to
d2b457f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
XYZ_to_color_temperatureinterpolates in mired then converts to Kelvin andclamps to
[2000, 50000]. Its only in-tree caller,find_camera_to_XYZ_matrix,divides that Kelvin back into mired immediately, producing a redundant
mired -> Kelvin -> miredround-trip flagged by #273.This PR adds a private helper
XYZ_to_miredreturning the unclamped miredvalue, refactors
XYZ_to_color_temperatureinto a wrapper that preserves theexisting Kelvin signature and clamp, and switches the caller to use the mired
helper directly. Public contract and existing test golden numbers unchanged.
Resolves #273.
What changes
src/rawtoaces_core/rawtoaces_core_priv.h: addXYZ_to_mireddeclaration.src/rawtoaces_core/rawtoaces_core.cpp: split the existing function intoXYZ_to_mired(the Robertson interpolation, unclamped) plus a two-lineXYZ_to_color_temperaturewrapper that doesmired_to_kelvinand the[2000, 50000]K clamp. Switchfind_camera_to_XYZ_matrixto call themired helper directly.
tests/testDNGIdt.cpp: addtestIDT_XYZToMiredpinning the mired returnfor the same XYZ input as the existing Kelvin test, with a cross-check that
the wrapper agrees with
clamp(mired_to_kelvin(mired), 2000, 50000).3 files, +48/-12.
Why this shape (and not a rename)
The wrapper is preserved on purpose:
[2000, 50000]corresponds exactly to mired anchorsrobertson_mired_table[2] = 20androbertson_mired_table[26] = 500, and1e6/2000 = 500.0and1e6/50000 = 20.0are exact double-precisionreciprocals. So the wrapper preserves observable behaviour bit-for-bit.
testIDT_XYZToColorTemperature*golden numbers continue toverify with the same
1e-5tolerance; no test re-derivation was needed.user-reportable CCT (EXIF / DNG metadata /
light_source_to_color_temp).If a hard rename to a mired-only API is preferred, it is a one-step
deprecation of the wrapper on top of this PR.
Verification
Built and tested inside
aswf/ci-rawtoaces:2026.2(the same image the VFX2026 CI lane uses), C++20, conan toolchain,
RTA_ENABLE_LENSFUN=ON,ENABLE_SHARED=ON.cmake --install+tests/config_testsctest 2/2 pass.RTA_SANITISER_MODE=addressDebug build: 15/15 pass for tests notpre-affected by an unrelated lensfun ASan issue
(
Test_LensCorrection,Test_Python_ImageConverter::test_conversion).That issue reproduces on
mainwithout these changes; trace islfModifier::AddColorCallbackallocating 32 B vs~lfModifierdeleting24 B inside
liblensfun.so.1(RHEL/Rockylensfun-0.3.2-15.el8),with no rawtoaces frame other than the lens-correction call site.
clang-format --dry-run --Werrorclean over the entire C++ tree usingclang-format 16.0.6 (the version pinned by
clang-format-check.yml).Out of scope
color_temperature_to_XYZhas the same Kelvin/miredasymmetry. Happy to file a follow-up to symmetrise it.
DCO
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>