Skip to content

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

@soswow

Description

@soswow

Summary

XYZ_to_color_temperature interpolates in mired space (using robertson_mired_table), converts the result to Kelvin via mired_to_kelvin, clamps, and returns Kelvin. Downstream code often immediately converts that Kelvin value back to mired with kelvin_to_mired (for example when weighting matrices). That is an extra round-trip that may be unnecessary or lossy from a numerical/design standpoint.

Background (for newcomers)

Correlated color temperature (CCT) appears both as Kelvin and as mired (micro reciprocal Kelvin, (10^6/\mathrm{K})) in this codebase. Helpers live in src/rawtoaces_core/rawtoaces_core.cpp: kelvin_to_mired, mired_to_kelvin, and XYZ_to_color_temperature. Some call sites take XYZ → CCT (Kelvin) → mired again within the same workflow.

This issue asks for a design cleanup (and tests as appropriate): clarify whether the Kelvin return is the right API, whether some paths should stay in mired until later, or whether the duplication is intentional and should be documented. Do not change behaviour blindly—justify any change with tests or references.

Where to look

  • src/rawtoaces_core/rawtoaces_core.cppXYZ_to_color_temperature (interpolation over robertson_mired_table, then mired_to_kelvin, clamp ~2000–50000 K).
  • Same file — call sites such as neutral CCT: XYZ_to_color_temperature then kelvin_to_mired (see search for neutral_CCT / kelvin_to_mired).
  • src/rawtoaces_core/rawtoaces_core_priv.h — declarations exposed for unit tests.
  • tests/testDNGIdt.cpp — existing tests touching XYZ_to_color_temperature / kelvin–mired helpers.

Suggested direction (not a prescription)

  • Trace all callers of XYZ_to_color_temperature and note Kelvin vs mired expectations.
  • Decide: reduce redundant conversions, narrow API (if maintainers agree), or document why Kelvin at the boundary is required.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions