@@ -2195,8 +2195,7 @@ void process(dt_iop_module_t *self,
21952195#endif
21962196 }
21972197
2198- if (data -> illuminant_type == DT_ILLUMINANT_CAMERA || data -> illuminant_type == DT_ILLUMINANT_FROM_WB )
2199- {
2198+ if (data -> illuminant_type == DT_ILLUMINANT_CAMERA ) {
22002199 // The camera illuminant is a behaviour rather than a preset of
22012200 // values: it uses whatever is in the RAW EXIF. But it depends on
22022201 // what temperature.c is doing and needs to be updated
@@ -2215,6 +2214,21 @@ void process(dt_iop_module_t *self,
22152214 dt_aligned_pixel_t XYZ ;
22162215 illuminant_xy_to_XYZ (x , y , XYZ );
22172216
2217+ // Convert illuminant from XYZ to Bradford modified LMS
2218+ convert_any_XYZ_to_LMS (XYZ , data -> illuminant , data -> adaptation );
2219+ data -> illuminant [3 ] = 0.f ;
2220+ }
2221+ }
2222+ else if (data -> illuminant_type == DT_ILLUMINANT_FROM_WB )
2223+ {
2224+ float x , y ;
2225+
2226+ if (find_temperature_from_wb_coeffs (& (self -> dev -> image_storage ), self -> dev -> chroma .wb_coeffs , & (x ), & (y )))
2227+ {
2228+ // Convert illuminant from xyY to XYZ
2229+ dt_aligned_pixel_t XYZ ;
2230+ illuminant_xy_to_XYZ (x , y , XYZ );
2231+
22182232 // Convert illuminant from XYZ to Bradford modified LMS
22192233 convert_any_XYZ_to_LMS (XYZ , data -> illuminant , data -> adaptation );
22202234 data -> illuminant [3 ] = 0.f ;
@@ -2306,7 +2320,7 @@ int process_cl(dt_iop_module_t *self,
23062320 if (piece -> pipe -> type & DT_DEV_PIXELPIPE_PREVIEW )
23072321 _declare_cat_on_pipe (self , FALSE);
23082322
2309- if (d -> illuminant_type == DT_ILLUMINANT_CAMERA || d -> illuminant_type == DT_ILLUMINANT_FROM_WB )
2323+ if (d -> illuminant_type == DT_ILLUMINANT_CAMERA )
23102324 {
23112325 // The camera illuminant is a behaviour rather than a preset of
23122326 // values: it uses whatever is in the RAW EXIF. But it depends on
@@ -2331,6 +2345,29 @@ int process_cl(dt_iop_module_t *self,
23312345 d -> illuminant [3 ] = 0.f ;
23322346 }
23332347 }
2348+ else if (d -> illuminant_type == DT_ILLUMINANT_FROM_WB )
2349+ {
2350+ // The camera illuminant is a behaviour rather than a preset of
2351+ // values: it uses whatever is in the RAW EXIF. But it depends on
2352+ // what temperature.c is doing and needs to be updated
2353+ // accordingly, to give a consistent result. We initialise the
2354+ // CAT defaults using the temperature coeffs at startup, but if
2355+ // temperature is changed later, we get no notification of the
2356+ // change here, so we can't update the defaults. So we need to
2357+ // re-run the detection at runtime…
2358+ float x , y ;
2359+
2360+ if (find_temperature_from_wb_coeffs (& (self -> dev -> image_storage ), self -> dev -> chroma .wb_coeffs , & (x ), & (y )))
2361+ {
2362+ // Convert illuminant from xyY to XYZ
2363+ dt_aligned_pixel_t XYZ ;
2364+ illuminant_xy_to_XYZ (x , y , XYZ );
2365+
2366+ // Convert illuminant from XYZ to Bradford modified LMS
2367+ convert_any_XYZ_to_LMS (XYZ , d -> illuminant , d -> adaptation );
2368+ d -> illuminant [3 ] = 0.f ;
2369+ }
2370+ }
23342371
23352372 cl_int err = CL_MEM_OBJECT_ALLOCATION_FAILURE ;
23362373
@@ -3989,7 +4026,7 @@ void gui_changed(dt_iop_module_t *self,
39894026 if (previous )
39904027 {
39914028 const dt_illuminant_t * prev_illuminant = (dt_illuminant_t * )previous ;
3992- if (* prev_illuminant == DT_ILLUMINANT_CAMERA || * prev_illuminant == DT_ILLUMINANT_FROM_WB )
4029+ if (* prev_illuminant == DT_ILLUMINANT_CAMERA )
39934030 {
39944031 // If illuminant was previously set with "as set in camera",
39954032 // when changing it, we need to ensure the temperature and
@@ -4004,6 +4041,19 @@ void gui_changed(dt_iop_module_t *self,
40044041 & (p -> x ), & (p -> y ));
40054042 _check_if_close_to_daylight (p -> x , p -> y , & (p -> temperature ), NULL , & (p -> adaptation ));
40064043 }
4044+ if (* prev_illuminant == DT_ILLUMINANT_FROM_WB )
4045+ {
4046+ // If illuminant was previously set with "as set in camera",
4047+ // when changing it, we need to ensure the temperature and
4048+ // chromaticity are inited with the correct values taken from
4049+ // camera EXIF. Otherwise, if using a preset defining
4050+ // illuminant = "as set in camera", temperature and
4051+ // chromaticity are inited with the preset content when
4052+ // illuminant is changed.
4053+ find_temperature_from_wb_coeffs (& (self -> dev -> image_storage ), self -> dev -> chroma .wb_coeffs ,
4054+ & (p -> x ), & (p -> y ));
4055+ _check_if_close_to_daylight (p -> x , p -> y , & (p -> temperature ), NULL , & (p -> adaptation ));
4056+ }
40074057 }
40084058
40094059 if (p -> illuminant == DT_ILLUMINANT_D )
@@ -4012,7 +4062,7 @@ void gui_changed(dt_iop_module_t *self,
40124062 if (p -> illuminant == DT_ILLUMINANT_BB )
40134063 p -> temperature = g -> last_bb_temperature ;
40144064
4015- if (p -> illuminant == DT_ILLUMINANT_CAMERA || p -> illuminant == DT_ILLUMINANT_FROM_WB )
4065+ if (p -> illuminant == DT_ILLUMINANT_CAMERA )
40164066 {
40174067 // Get camera WB and update illuminant
40184068 dt_aligned_pixel_t custom_wb ;
@@ -4024,6 +4074,15 @@ void gui_changed(dt_iop_module_t *self,
40244074 if (found )
40254075 dt_control_log (_ ("white balance successfully extracted from raw image" ));
40264076 }
4077+ if (p -> illuminant == DT_ILLUMINANT_FROM_WB )
4078+ {
4079+ const gboolean found = find_temperature_from_wb_coeffs (& (self -> dev -> image_storage ),
4080+ self -> dev -> chroma .wb_coeffs , & (p -> x ), & (p -> y ));
4081+ _check_if_close_to_daylight (p -> x , p -> y , & (p -> temperature ), NULL , & (p -> adaptation ));
4082+
4083+ if (found )
4084+ dt_control_log (_ ("white balance successfully extracted from white balance module" ));
4085+ }
40274086#ifdef AI_ACTIVATED
40284087 else if (p -> illuminant == DT_ILLUMINANT_DETECT_EDGES
40294088 || p -> illuminant == DT_ILLUMINANT_DETECT_SURFACES )
0 commit comments