Skip to content

colorcalibration also for manual wb#20304

Open
kofa73 wants to merge 10 commits intodarktable-org:masterfrom
kofa73:colorcalibration-also-for-manual-wb
Open

colorcalibration also for manual wb#20304
kofa73 wants to merge 10 commits intodarktable-org:masterfrom
kofa73:colorcalibration-also-for-manual-wb

Conversation

@kofa73
Copy link
Copy Markdown
Contributor

@kofa73 kofa73 commented Feb 8, 2026

Addresses #19873

  • added a new checkbox, prepare data for color calibration to white balance temperature.c to explicitly control the late_correction flag in 'user' / 'manual' modes

    • the checkbox is only visible in such modes (late_correction is always off in 'camera reference' mode, always on in 'as-shot to reference')
    • if switching from 'camera reference' or 'as-shot to reference' to a 'user' mode, the checkbox is automatically ticked if color calibration is enabled
  • replaced reference chr->as_shot with chr->wb_coeffs in highlights.c, colorin.c, opposed.c and segbased.c

  • illuminants.h:

    • added a new illuminant, DT_ILLUMINANT_FROM_WB, plus handling in conditionals, similar to DT_ILLUMINANT_CAMERA, but relying on dev->chroma->wb_coeffs
    • find_temperature_from_raw_coeffs:
      • renamed to find_temperature_from_as_shot_coeffs
      • extracted the logic to find_temperature_from_wb_coeffs, to allow directly using coefficients from temperature.c, instead of always going through ratios relative to the D65 values
      • added param wb_coeffs to illuminant_to_xy for absolute coefficients from temperature.c; renamed param custom_wb to correction_ratios to express what it represents; passed to find_temperature_from_wb_coeffs in DT_ILLUMINANT_FROM_WB mode
  • channelmixerrgb.c:

    • _dev_is_D65_chroma no longer needs as_shot multipliers in late_correction mode
    • renamed _get_white_balance_coeff to _get_d65_correction_ratios
    • wired up the calls to find_temperature_from_wb_coeffs to handle DT_ILLUMINANT_FROM_WB

    Draft for now, to allow discussion (and I haven't tested much, but wanted to make the changes visible to others; plus, I need to clean up some temp files)

@ralfbrown
Copy link
Copy Markdown
Collaborator

Did you intend to include cmixer_orig.c.txt in the PR?
And are the two .md files in the right place?

@kofa73
Copy link
Copy Markdown
Contributor Author

kofa73 commented Feb 9, 2026

Did you intend to include cmixer_orig.c.txt in the PR? And are the two .md files in the right place?

See the end of the description:

Draft for now, to allow discussion (and I haven't tested much, but wanted to make the changes visible to others; plus, I need to clean up some temp files)

@TurboGit TurboGit marked this pull request as draft February 9, 2026 16:07
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from 6631dc3 to be0ad7a Compare February 9, 2026 17:41
@kofa73
Copy link
Copy Markdown
Contributor Author

kofa73 commented Feb 9, 2026

@ralfbrown : extra files removed, thank for your patience

@kofa73 kofa73 marked this pull request as ready for review February 13, 2026 19:33
@kofa73 kofa73 changed the title Draft: colorcalibration also for manual wb colorcalibration also for manual wb Feb 13, 2026
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch 2 times, most recently from ce74cf6 to daae18d Compare February 14, 2026 13:34
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from daae18d to 5474b61 Compare February 21, 2026 10:32
@jenshannoschwalm
Copy link
Copy Markdown
Collaborator

A first complete code reading and remembering your comments before; generally i think this is a minor but very good improvement and will certainly help with some issues. Also it make the intention more clear and fixes some common misunderstandings.

I spotted some places like this:

dt_aligned_pixel_t correction;
  for_four_channels(k)
  {
    if(late && chr->wb_coeffs[k] > 1e-6f)
      correction[k] = chr->D65coeffs[k] / chr->wb_coeffs[k];
    else
      correction[k] = 1.0f;
  }

Could you explain if/why this is nevessary or is it just code-style?

@kofa73
Copy link
Copy Markdown
Contributor Author

kofa73 commented Feb 28, 2026

The key is the line:

correction[k] = chr->D65coeffs[k] / chr->wb_coeffs[k];

This used to be something like (below is one concrete example):

chr->D65coeffs[0] / chr->as_shot[0]

The new denominator comes from chr->wb_coeffs[k] (value set in temperature.c), which means it may be set using one of the sliders. The sliders may have a value of 0, so we must protect the division:

typedef struct dt_iop_temperature_params_t
{
  float red;     // $MIN: 0.0 $MAX: 8.0
  float green;   // $MIN: 0.0 $MAX: 8.0
  float blue;    // $MIN: 0.0 $MAX: 8.0
  float various; // $MIN: 0.0 $MAX: 8.0
  int preset;
} dt_iop_temperature_params_t;

One option would be to restrict the values to MIN: 0.1 or so, then we can avoid adding the protection everywhere.

If I misunderstood the question, please let me know.

@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from 5474b61 to 6d612e0 Compare February 28, 2026 05:44
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from fa618ac to 6156826 Compare February 28, 2026 13:26
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from 152cb16 to b529102 Compare March 6, 2026 18:23
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from b529102 to 994a97c Compare March 28, 2026 08:46
kofa73 added 9 commits April 4, 2026 19:09
…eckbox; populate dev->chroma->late_correction based on checkbox-driven late_correction flag for 'legacy' modes (DT_IOP_TEMP_AS_SHOT, DT_IOP_TEMP_SPOT, DT_IOP_TEMP_USER)
…coeffs into find_temperature_from_wb_coeffs, find_temperature_from_as_shot_coeffs; added handling to channelmixerrgb.c + altered logic for 'late correction' check
…alidate wb_coeffs for find_temperature_from_wb_coeffs as well as in find_temperature_from_as_shot_coeffs; fix copy-pasted comment in channelmixerrgb.c#gui_changed
@kofa73 kofa73 force-pushed the colorcalibration-also-for-manual-wb branch from 994a97c to 5217b8c Compare April 4, 2026 17:13
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.

3 participants