87 { 0.37208f, 0.37529f },
88 { 0.40910f, 0.39430f },
89 { 0.44018f, 0.40329f },
90 { 0.31379f, 0.34531f },
91 { 0.37790f, 0.38835f },
92 { 0.31292f, 0.32933f },
93 { 0.34588f, 0.35875f },
94 { 0.37417f, 0.37281f },
95 { 0.34609f, 0.35986f },
96 { 0.38052f, 0.37713f },
97 { 0.43695f, 0.40441f } };
109 { 0.4357f, 0.4012f },
110 { 0.3756f, 0.3723f },
111 { 0.3422f, 0.3502f },
112 { 0.3118f, 0.3236f },
113 { 0.4474f, 0.4066f },
114 { 0.4557f, 0.4211f },
115 { 0.4560f, 0.4548f },
116 { 0.3781f, 0.3775f }};
119#pragma omp declare simd
121static inline float xy_to_CCT(
const float x,
const float y)
127 const float n = (x - 0.3366f)/(y - 0.1735f);
128 return -949.86315f + 6253.80338f * expf(-n / 0.92159f) + 28.70599f * expf(-n / 0.20039f) + 0.00004f * expf(-n / 0.07125f);
133#pragma omp declare simd
141 if(t >= 4000.f && t <= 7000.0f)
142 x_temp = ((-4.6070e9f / t + 2.9678e6f) / t + 0.09911e3f) / t + 0.244063f;
143 else if(t > 7000.f && t <= 25000.f)
144 x_temp = ((-2.0064e9f / t + 1.9018e6f) / t + 0.24748e3f) / t + 0.237040f;
146 y_temp = (-3.f * x_temp + 2.87f) * x_temp - 0.275f;
154#pragma omp declare simd
162 if(t >= 1667.f && t <= 4000.f)
163 x_temp = ((-0.2661239e9f / t - 0.2343589e6f) / t + 0.8776956e3f) / t + 0.179910f;
164 else if(t > 4000.f && t <= 25000.f)
165 x_temp = ((-3.0258469e9f / t + 2.1070379e6f) / t + 0.2226347e3f) / t + 0.240390f;
167 if(t >= 1667.f && t <= 2222.f)
168 y_temp = ((-1.1063814f * x_temp - 1.34811020f) * x_temp + 2.18555832f) * x_temp - 0.20219683f;
169 else if(t > 2222.f && t <= 4000.f)
170 y_temp = ((-0.9549476f * x_temp - 1.37418593f) * x_temp + 2.09137015f) * x_temp - 0.16748867f;
171 else if(t > 4000.f && t <= 25000.f)
172 y_temp = (( 3.0817580f * x_temp - 5.87338670f) * x_temp + 3.75112997f) * x_temp - 0.37001483f;
180#pragma omp declare simd
186 XYZ[2] = (1.f - x - y) / y;
191#pragma omp declare simd
196 dt_aligned_pixel_t XYZ;
204 const float max_RGB = fmaxf(fmaxf(RGB[0], RGB[1]), RGB[2]);
205 for(
int c = 0; c < 3; c++) RGB[c] = fmaxf(RGB[c] / max_RGB, 0.f);
210#pragma omp declare simd
226 float *chroma_x,
float *chroma_y);
231 const dt_aligned_pixel_t custom_wb,
232 float *x_out,
float *y_out,
293 if(y != 0.f && x != 0.f)
break;
301 if(y != 0.f && x != 0.f)
break;
319 if(x != 0.f && y != 0.f)
334 dt_aligned_pixel_t XYZ, LMS;
337 XYZ[0] = CAM_to_XYZ[0][0] / WB[0] + CAM_to_XYZ[1][0] / WB[1] + CAM_to_XYZ[2][0] / WB[2];
338 XYZ[1] = CAM_to_XYZ[0][1] / WB[0] + CAM_to_XYZ[1][1] / WB[1] + CAM_to_XYZ[2][1] / WB[2];
339 XYZ[2] = CAM_to_XYZ[0][2] / WB[0] + CAM_to_XYZ[1][2] / WB[1] + CAM_to_XYZ[2][2] / WB[2];
342 static const dt_aligned_pixel_t D65 = { 0.941238f, 1.040633f, 1.088932f, 0.f };
343 const float p = powf(1.088932f / 0.818155f, 0.0834f);
354 *x = XYZ[0] / (XYZ[0] + XYZ[1] + XYZ[2]);
355 *y = XYZ[1] / (XYZ[0] + XYZ[1] + XYZ[2]);
363 for(
int i = 0; i < 3; i++)
365 for(
int j = 0; j < 6; j++)
366 work[i][j] = j == i+3;
367 for(
int j = 0; j < 3; j++)
368 for(
int k = 0; k <
size; k++)
369 work[i][j] += in[k][i] * in[k][j];
371 for(
int i = 0; i < 3; i++)
373 float num = work[i][i];
374 for(
int j = 0; j < 6; j++)
376 for(
int k = 0; k < 3; k++)
380 for(
int j = 0; j < 6; j++)
381 work[k][j] -= work[i][j] * num;
384 for(
int i = 0; i <
size; i++)
385 for(
int j = 0; j < 3; j++)
388 for(
int k = 0; k < 3; k++)
389 out[i][j] += work[j][k+3] * in[i][k];
395 float *chroma_x,
float *chroma_y)
397 if(img == NULL)
return FALSE;
400 int has_valid_coeffs =
TRUE;
404 for(
int k = 0; has_valid_coeffs && k < num_coeffs; k++)
407 if(!has_valid_coeffs)
return FALSE;
415 for(
size_t k = 0; k < 4; k++) WB[k] *= custom_wb[k];
418 float XYZ_to_CAM[4][3];
419 XYZ_to_CAM[0][0] = NAN;
439 for(
int k=0; k<4; k++)
440 for(
int i=0; i<3; i++)
444 if(isnan(XYZ_to_CAM[0][0]))
return FALSE;
448 float CAM_to_XYZ[4][3];
449 CAM_to_XYZ[0][0] = NAN;
451 if(isnan(CAM_to_XYZ[0][0]))
return FALSE;
463#pragma omp declare simd
471 if(t >= 1667.f && t <= 2222.f)
472 n = (-3.3191442f * x - 2.69622040f) * x + 2.18555832f;
473 else if(t > 2222.f && t <= 4000.f)
474 n = (-2.8648428f * x - 2.74837186f) * x + 2.09137015f;
475 else if(t > 4000.f && t < 25000.f)
476 n = (9.2452740f * x - 11.7467734f) * x + 3.75112997f;
482#pragma omp declare simd
485 float *x_out,
float *y_out)
489 const float norm = sqrtf(1.f + n * n);
490 *x_out = x + tint * n / norm;
491 *y_out = y - tint / norm;
496#pragma omp declare simd
502 const float norm = sqrtf(1.f + n * n);
505 const float tint = -(y - y_bb) * norm;
511#pragma omp declare simd
513static inline void xy_to_uv(
const float xy[2],
float uv[2])
517 const float denom = 12.f * xy[1] - 1.882f * xy[0] + 2.9088f;
518 uv[0] = 5.5932f * xy[0] + 1.9116 * xy[1];
519 uv[1] = 7.8972f * xy[1];
545 if(n.radius < r.radius)
return n;
551#pragma omp declare reduction(pairmin:struct pair:omp_out=pair_min(omp_out,omp_in)) \
552 initializer(omp_priv = { FLT_MAX, 0.0f })
561 static const float T_min = 1667.f;
562 static const float T_max = 25000.f;
563 static const float T_range = T_max - T_min;
564 static const size_t LUT_samples = 1<<16;
566 struct pair min_radius = { FLT_MAX, 0.0f };
568#if !(defined(__apple_build_version__) && __apple_build_version__ < 11030000)
570#pragma omp parallel for default(none) \
571 dt_omp_firstprivate(x, y, T_min, T_range, LUT_samples) reduction(pairmin:min_radius)\
572 schedule(simd:static)
575 for(
size_t i = 0; i < LUT_samples; i++)
578 const float step = powf((
float)i / (
float)(LUT_samples - 1), 4.0f);
581 const float T = T_min + step * T_range;
595 min_radius =
pair_min(min_radius, radius_tmp);
#define TRUE
Definition ashift_lsd.c:151
#define FALSE
Definition ashift_lsd.c:147
static float4 convert_XYZ_to_bradford_LMS(const float4 XYZ)
Definition colorspace.h:639
static void bradford_adapt_D50(float4 *lms_in, const float4 origin_illuminant, const float p, const int full)
Definition colorspace.h:679
static float4 convert_bradford_LMS_to_XYZ(const float4 LMS)
Definition colorspace.h:649
static void dt_XYZ_to_Rec709_D50(const dt_aligned_pixel_t XYZ, dt_aligned_pixel_t sRGB)
Definition colorspaces_inline_conversions.h:400
gboolean dt_image_is_matrix_correction_supported(const dt_image_t *img)
Definition common/image.c:185
@ DT_IMAGE_4BAYER
Definition common/image.h:81
#define DT_ALIGNED_ARRAY
Definition darktable.h:270
static int illuminant_to_xy(const dt_illuminant_t illuminant, const dt_image_t *img, const dt_aligned_pixel_t custom_wb, float *x_out, float *y_out, const float t, const dt_illuminant_fluo_t fluo, const dt_illuminant_led_t iled)
Definition illuminants.h:229
dt_illuminant_t
Definition illuminants.h:27
@ DT_ILLUMINANT_A
Definition illuminants.h:29
@ DT_ILLUMINANT_PIPE
Definition illuminants.h:28
@ DT_ILLUMINANT_CAMERA
Definition illuminants.h:38
@ DT_ILLUMINANT_BB
Definition illuminants.h:34
@ DT_ILLUMINANT_F
Definition illuminants.h:32
@ DT_ILLUMINANT_CUSTOM
Definition illuminants.h:35
@ DT_ILLUMINANT_LED
Definition illuminants.h:33
@ DT_ILLUMINANT_DETECT_EDGES
Definition illuminants.h:37
@ DT_ILLUMINANT_E
Definition illuminants.h:31
@ DT_ILLUMINANT_LAST
Definition illuminants.h:39
@ DT_ILLUMINANT_DETECT_SURFACES
Definition illuminants.h:36
@ DT_ILLUMINANT_D
Definition illuminants.h:30
static void WB_coeffs_to_illuminant_xy(const float CAM_to_XYZ[4][3], const dt_aligned_pixel_t WB, float *x, float *y)
Definition illuminants.h:330
static void illuminant_CCT_to_RGB(const float t, dt_aligned_pixel_t RGB)
Definition illuminants.h:212
static void illuminant_xy_to_RGB(const float x, const float y, dt_aligned_pixel_t RGB)
Definition illuminants.h:193
static void illuminant_xy_to_XYZ(const float x, const float y, dt_aligned_pixel_t XYZ)
Definition illuminants.h:182
static float xy_to_CCT(const float x, const float y)
Definition illuminants.h:121
static void CCT_to_xy_daylight(const float t, float *x, float *y)
Definition illuminants.h:135
dt_illuminant_led_t
Definition illuminants.h:62
@ DT_ILLUMINANT_LED_BH1
Definition illuminants.h:68
@ DT_ILLUMINANT_LED_B5
Definition illuminants.h:67
@ DT_ILLUMINANT_LED_B2
Definition illuminants.h:64
@ DT_ILLUMINANT_LED_B1
Definition illuminants.h:63
@ DT_ILLUMINANT_LED_LAST
Definition illuminants.h:72
@ DT_ILLUMINANT_LED_V1
Definition illuminants.h:70
@ DT_ILLUMINANT_LED_B3
Definition illuminants.h:65
@ DT_ILLUMINANT_LED_B4
Definition illuminants.h:66
@ DT_ILLUMINANT_LED_V2
Definition illuminants.h:71
@ DT_ILLUMINANT_LED_RGB1
Definition illuminants.h:69
static float CCT_reverse_lookup(const float x, const float y)
Definition illuminants.h:555
static float get_tint_from_tinted_xy(const float x, const float y, const float t)
Definition illuminants.h:498
static float planckian_normal(const float x, const float t)
Definition illuminants.h:465
static int find_temperature_from_raw_coeffs(const dt_image_t *img, const dt_aligned_pixel_t custom_wb, float *chroma_x, float *chroma_y)
Definition illuminants.h:394
static void CCT_to_xy_blackbody(const float t, float *x, float *y)
Definition illuminants.h:156
static float fluorescent[DT_ILLUMINANT_FLUO_LAST][2]
Definition illuminants.h:86
static void matrice_pseudoinverse(float(*in)[3], float(*out)[3], int size)
Definition illuminants.h:359
dt_illuminant_fluo_t
Definition illuminants.h:44
@ DT_ILLUMINANT_FLUO_F6
Definition illuminants.h:50
@ DT_ILLUMINANT_FLUO_F4
Definition illuminants.h:48
@ DT_ILLUMINANT_FLUO_F1
Definition illuminants.h:45
@ DT_ILLUMINANT_FLUO_F5
Definition illuminants.h:49
@ DT_ILLUMINANT_FLUO_F2
Definition illuminants.h:46
@ DT_ILLUMINANT_FLUO_F3
Definition illuminants.h:47
@ DT_ILLUMINANT_FLUO_F12
Definition illuminants.h:56
@ DT_ILLUMINANT_FLUO_F8
Definition illuminants.h:52
@ DT_ILLUMINANT_FLUO_F9
Definition illuminants.h:53
@ DT_ILLUMINANT_FLUO_LAST
Definition illuminants.h:57
@ DT_ILLUMINANT_FLUO_F11
Definition illuminants.h:55
@ DT_ILLUMINANT_FLUO_F7
Definition illuminants.h:51
@ DT_ILLUMINANT_FLUO_F10
Definition illuminants.h:54
static void blackbody_xy_to_tinted_xy(const float x, const float y, const float t, const float tint, float *x_out, float *y_out)
Definition illuminants.h:484
static void xy_to_uv(const float xy[2], float uv[2])
Definition illuminants.h:513
static float led[DT_ILLUMINANT_LED_LAST][2]
Definition illuminants.h:108
struct pair pair_min(struct pair r, struct pair n)
Definition illuminants.h:542
static float dt_fast_hypotf(const float x, const float y)
Definition math.h:272
size_t size
Definition mipmap_cache.c:3
Definition common/image.h:195
int32_t flags
Definition common/image.h:227
float d65_color_matrix[9]
Definition common/image.h:236
float adobe_XYZ_to_CAM[4][3]
Definition common/image.h:259
dt_aligned_pixel_t wb_coeffs
Definition common/image.h:256
Definition illuminants.h:537
float temperature
Definition illuminants.h:539
float radius
Definition illuminants.h:538