81 constexpr float eps = 0.008856f;
82 constexpr float kap = 903.3f;
84 const __m128 iref = _mm_setr_ps(1.f /
ref.x, 1.f /
ref.y, 1.f /
ref.z, 0.f);
85 __m128
v = _mm_loadu_ps(&
x);
86 v = _mm_mul_ps(
v, iref);
88 const __m128 f3 = _mm_set1_ps(3.f);
89 __m128 est = _mm_add_ps(_mm_set1_ps(0.25f), _mm_mul_ps(
v, _mm_set1_ps(0.75f)));
90 __m128 estsq = _mm_mul_ps(est, est);
91 est = _mm_sub_ps(est, _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(estsq, est),
v),
92 _mm_rcp_ps(_mm_mul_ps(estsq, f3))));
93 estsq = _mm_mul_ps(est, est);
94 est = _mm_sub_ps(est, _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(estsq, est),
v),
95 _mm_rcp_ps(_mm_mul_ps(estsq, f3))));
96 estsq = _mm_mul_ps(est, est);
97 est = _mm_sub_ps(est, _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(estsq, est),
v),
98 _mm_rcp_ps(_mm_mul_ps(estsq, f3))));
99 estsq = _mm_mul_ps(est, est);
100 est = _mm_sub_ps(est, _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(estsq, est),
v),
101 _mm_rcp_ps(_mm_mul_ps(estsq, f3))));
103 __m128 kapmul = _mm_mul_ps(_mm_add_ps(_mm_mul_ps(
v, _mm_set1_ps(kap)), _mm_set1_ps(16.f)),
104 _mm_set1_ps(1.f / 116.f));
105 __m128 cmpgt = _mm_cmpgt_ps(
v, _mm_set1_ps(eps));
106#if defined(__SSE4_1__)
107 v = _mm_blendv_ps(kapmul, est, cmpgt);
109 v = _mm_or_ps(_mm_and_ps(cmpgt, est), _mm_andnot_ps(cmpgt, kapmul));
111 alignas(16)
float out[4];
112 _mm_store_ps(
out,
v);
113 const float L = 116.f *
out[1] - 16.f;
114 const float a = 500.f * (
out[0] -
out[1]);
115 const float b = 200.f * (
out[1] -
out[2]);
117 float xr =
x * (1.f /
ref.x);
118 float yr =
y * (1.f /
ref.y);
119 float zr =
z * (1.f /
ref.z);
125 fx = (kap * xr + 16.f) * (1.f / 116.f);
129 fy = (kap * yr + 16.f) * (1.f / 116.f);
133 fz = (kap * zr + 16.f) * (1.f / 116.f);
135 const float L = 116.f * fy - 16.f;
136 const float a = 500.f * (fx - fy);
137 const float b = 200.f * (fy - fz);
140 return QColorVector(L * (1.f / 100.f), (
a + 128.f) * (1.f / 255.f), (
b + 128.f) * (1.f / 255.f));