63 const float *
const restrict clut,
const uint16_t level,
64 const float normalization)
66 const int level2 = level * level;
67 const float safe_normalization = fmaxf(normalization, 1e-6f);
69 for(
size_t k = 0;
k < (size_t)(pixel_nb * 4);
k += 4)
71 const float *
const input = in +
k;
72 float *
const output =
out +
k;
78 _prepare_lut_input(input, normalized, residual, rgbd, rgbi, level, safe_normalization);
80 const int color = rgbi[0] + rgbi[1] * level + rgbi[2] * level2;
81 const int i000 = color * 3;
82 const int i100 = i000 + 3;
83 const int i010 = (color + level) * 3;
84 const int i110 = i010 + 3;
85 const int i001 = (color + level2) * 3;
86 const int i101 = i001 + 3;
87 const int i011 = (color + level + level2) * 3;
88 const int i111 = i011 + 3;
94 output[0] = (1 - rgbd[0]) * clut[i000] + (rgbd[0] - rgbd[1]) * clut[i100]
95 + (rgbd[1] - rgbd[2]) * clut[i110] + rgbd[2] * clut[i111];
96 output[1] = (1 - rgbd[0]) * clut[i000 + 1] + (rgbd[0] - rgbd[1]) * clut[i100 + 1]
97 + (rgbd[1] - rgbd[2]) * clut[i110 + 1] + rgbd[2] * clut[i111 + 1];
98 output[2] = (1 - rgbd[0]) * clut[i000 + 2] + (rgbd[0] - rgbd[1]) * clut[i100 + 2]
99 + (rgbd[1] - rgbd[2]) * clut[i110 + 2] + rgbd[2] * clut[i111 + 2];
101 else if(rgbd[0] > rgbd[2])
103 output[0] = (1 - rgbd[0]) * clut[i000] + (rgbd[0] - rgbd[2]) * clut[i100]
104 + (rgbd[2] - rgbd[1]) * clut[i101] + rgbd[1] * clut[i111];
105 output[1] = (1 - rgbd[0]) * clut[i000 + 1] + (rgbd[0] - rgbd[2]) * clut[i100 + 1]
106 + (rgbd[2] - rgbd[1]) * clut[i101 + 1] + rgbd[1] * clut[i111 + 1];
107 output[2] = (1 - rgbd[0]) * clut[i000 + 2] + (rgbd[0] - rgbd[2]) * clut[i100 + 2]
108 + (rgbd[2] - rgbd[1]) * clut[i101 + 2] + rgbd[1] * clut[i111 + 2];
112 output[0] = (1 - rgbd[2]) * clut[i000] + (rgbd[2] - rgbd[0]) * clut[i001]
113 + (rgbd[0] - rgbd[1]) * clut[i101] + rgbd[1] * clut[i111];
114 output[1] = (1 - rgbd[2]) * clut[i000 + 1] + (rgbd[2] - rgbd[0]) * clut[i001 + 1]
115 + (rgbd[0] - rgbd[1]) * clut[i101 + 1] + rgbd[1] * clut[i111 + 1];
116 output[2] = (1 - rgbd[2]) * clut[i000 + 2] + (rgbd[2] - rgbd[0]) * clut[i001 + 2]
117 + (rgbd[0] - rgbd[1]) * clut[i101 + 2] + rgbd[1] * clut[i111 + 2];
122 if(rgbd[2] > rgbd[1])
124 output[0] = (1 - rgbd[2]) * clut[i000] + (rgbd[2] - rgbd[1]) * clut[i001]
125 + (rgbd[1] - rgbd[0]) * clut[i011] + rgbd[0] * clut[i111];
126 output[1] = (1 - rgbd[2]) * clut[i000 + 1] + (rgbd[2] - rgbd[1]) * clut[i001 + 1]
127 + (rgbd[1] - rgbd[0]) * clut[i011 + 1] + rgbd[0] * clut[i111 + 1];
128 output[2] = (1 - rgbd[2]) * clut[i000 + 2] + (rgbd[2] - rgbd[1]) * clut[i001 + 2]
129 + (rgbd[1] - rgbd[0]) * clut[i011 + 2] + rgbd[0] * clut[i111 + 2];
131 else if(rgbd[2] > rgbd[0])
133 output[0] = (1 - rgbd[1]) * clut[i000] + (rgbd[1] - rgbd[2]) * clut[i010]
134 + (rgbd[2] - rgbd[0]) * clut[i011] + rgbd[0] * clut[i111];
135 output[1] = (1 - rgbd[1]) * clut[i000 + 1] + (rgbd[1] - rgbd[2]) * clut[i010 + 1]
136 + (rgbd[2] - rgbd[0]) * clut[i011 + 1] + rgbd[0] * clut[i111 + 1];
137 output[2] = (1 - rgbd[1]) * clut[i000 + 2] + (rgbd[1] - rgbd[2]) * clut[i010 + 2]
138 + (rgbd[2] - rgbd[0]) * clut[i011 + 2] + rgbd[0] * clut[i111 + 2];
142 output[0] = (1 - rgbd[1]) * clut[i000] + (rgbd[1] - rgbd[0]) * clut[i010]
143 + (rgbd[0] - rgbd[2]) * clut[i110] + rgbd[2] * clut[i111];
144 output[1] = (1 - rgbd[1]) * clut[i000 + 1] + (rgbd[1] - rgbd[0]) * clut[i010 + 1]
145 + (rgbd[0] - rgbd[2]) * clut[i110 + 1] + rgbd[2] * clut[i111 + 1];
146 output[2] = (1 - rgbd[1]) * clut[i000 + 2] + (rgbd[1] - rgbd[0]) * clut[i010 + 2]
147 + (rgbd[0] - rgbd[2]) * clut[i110 + 2] + rgbd[2] * clut[i111 + 2];
151 _finish_lut_output(input, output, residual, safe_normalization);
157 const float *
const restrict clut,
const uint16_t level,
158 const float normalization)
160 const int level2 = level * level;
161 const float safe_normalization = fmaxf(normalization, 1e-6f);
163 for(
size_t k = 0;
k < (size_t)(pixel_nb * 4);
k += 4)
165 const float *
const input = in +
k;
166 float *
const output =
out +
k;
173 _prepare_lut_input(input, normalized, residual, rgbd, rgbi, level, safe_normalization);
175 const int color = rgbi[0] + rgbi[1] * level + rgbi[2] * level2;
177 int j = (color + 1) * 3;
179 tmp[0] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
180 tmp[1] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
181 tmp[2] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
183 i = (color + level) * 3;
184 j = (color + level + 1) * 3;
186 tmp[3] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
187 tmp[4] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
188 tmp[5] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
190 output[0] = tmp[0] * (1 - rgbd[1]) + tmp[3] * rgbd[1];
191 output[1] = tmp[1] * (1 - rgbd[1]) + tmp[4] * rgbd[1];
192 output[2] = tmp[2] * (1 - rgbd[1]) + tmp[5] * rgbd[1];
194 i = (color + level2) * 3;
195 j = (color + level2 + 1) * 3;
197 tmp[0] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
198 tmp[1] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
199 tmp[2] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
201 i = (color + level + level2) * 3;
202 j = (color + level + level2 + 1) * 3;
204 tmp[3] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
205 tmp[4] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
206 tmp[5] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
208 tmp[0] = tmp[0] * (1 - rgbd[1]) + tmp[3] * rgbd[1];
209 tmp[1] = tmp[1] * (1 - rgbd[1]) + tmp[4] * rgbd[1];
210 tmp[2] = tmp[2] * (1 - rgbd[1]) + tmp[5] * rgbd[1];
212 output[0] = output[0] * (1 - rgbd[2]) + tmp[0] * rgbd[2];
213 output[1] = output[1] * (1 - rgbd[2]) + tmp[1] * rgbd[2];
214 output[2] = output[2] * (1 - rgbd[2]) + tmp[2] * rgbd[2];
216 _finish_lut_output(input, output, residual, safe_normalization);
222 const float *
const restrict clut,
const uint16_t level,
223 const float normalization)
225 const int level2 = level * level;
226 const float safe_normalization = fmaxf(normalization, 1e-6f);
228 for(
size_t k = 0;
k < (size_t)(pixel_nb * 4);
k += 4)
230 const float *
const input = in +
k;
231 float *
const output =
out +
k;
237 _prepare_lut_input(input, normalized, residual, rgbd, rgbi, level, safe_normalization);
239 const int color = rgbi[0] + rgbi[1] * level + rgbi[2] * level2;
240 const int i000 = color * 3;
241 const int i100 = i000 + 3;
242 const int i010 = (color + level) * 3;
243 const int i110 = i010 + 3;
244 const int i001 = (color + level2) * 3;
245 const int i101 = i001 + 3;
246 const int i011 = (color + level + level2) * 3;
247 const int i111 = i011 + 3;
249 if(rgbd[1] > rgbd[0] && rgbd[2] > rgbd[0])
251 output[0] = clut[i000] + (clut[i111] - clut[i011]) * rgbd[0] + (clut[i010] - clut[i000]) * rgbd[1]
252 + (clut[i001] - clut[i000]) * rgbd[2]
253 + (clut[i011] - clut[i001] - clut[i010] + clut[i000]) * rgbd[1] * rgbd[2];
254 output[1] = clut[i000 + 1] + (clut[i111 + 1] - clut[i011 + 1]) * rgbd[0]
255 + (clut[i010 + 1] - clut[i000 + 1]) * rgbd[1]
256 + (clut[i001 + 1] - clut[i000 + 1]) * rgbd[2]
257 + (clut[i011 + 1] - clut[i001 + 1] - clut[i010 + 1] + clut[i000 + 1]) * rgbd[1] * rgbd[2];
258 output[2] = clut[i000 + 2] + (clut[i111 + 2] - clut[i011 + 2]) * rgbd[0]
259 + (clut[i010 + 2] - clut[i000 + 2]) * rgbd[1]
260 + (clut[i001 + 2] - clut[i000 + 2]) * rgbd[2]
261 + (clut[i011 + 2] - clut[i001 + 2] - clut[i010 + 2] + clut[i000 + 2]) * rgbd[1] * rgbd[2];
263 else if(rgbd[0] > rgbd[1] && rgbd[2] > rgbd[1])
265 output[0] = clut[i000] + (clut[i100] - clut[i000]) * rgbd[0] + (clut[i111] - clut[i101]) * rgbd[1]
266 + (clut[i001] - clut[i000]) * rgbd[2]
267 + (clut[i101] - clut[i001] - clut[i100] + clut[i000]) * rgbd[0] * rgbd[2];
268 output[1] = clut[i000 + 1] + (clut[i100 + 1] - clut[i000 + 1]) * rgbd[0]
269 + (clut[i111 + 1] - clut[i101 + 1]) * rgbd[1]
270 + (clut[i001 + 1] - clut[i000 + 1]) * rgbd[2]
271 + (clut[i101 + 1] - clut[i001 + 1] - clut[i100 + 1] + clut[i000 + 1]) * rgbd[0] * rgbd[2];
272 output[2] = clut[i000 + 2] + (clut[i100 + 2] - clut[i000 + 2]) * rgbd[0]
273 + (clut[i111 + 2] - clut[i101 + 2]) * rgbd[1]
274 + (clut[i001 + 2] - clut[i000 + 2]) * rgbd[2]
275 + (clut[i101 + 2] - clut[i001 + 2] - clut[i100 + 2] + clut[i000 + 2]) * rgbd[0] * rgbd[2];
279 output[0] = clut[i000] + (clut[i100] - clut[i000]) * rgbd[0] + (clut[i010] - clut[i000]) * rgbd[1]
280 + (clut[i111] - clut[i110]) * rgbd[2]
281 + (clut[i110] - clut[i100] - clut[i010] + clut[i000]) * rgbd[0] * rgbd[1];
282 output[1] = clut[i000 + 1] + (clut[i100 + 1] - clut[i000 + 1]) * rgbd[0]
283 + (clut[i010 + 1] - clut[i000 + 1]) * rgbd[1]
284 + (clut[i111 + 1] - clut[i110 + 1]) * rgbd[2]
285 + (clut[i110 + 1] - clut[i100 + 1] - clut[i010 + 1] + clut[i000 + 1]) * rgbd[0] * rgbd[1];
286 output[2] = clut[i000 + 2] + (clut[i100 + 2] - clut[i000 + 2]) * rgbd[0]
287 + (clut[i010 + 2] - clut[i000 + 2]) * rgbd[1]
288 + (clut[i111 + 2] - clut[i110 + 2]) * rgbd[2]
289 + (clut[i110 + 2] - clut[i100 + 2] - clut[i010 + 2] + clut[i000 + 2]) * rgbd[0] * rgbd[1];
292 _finish_lut_output(input, output, residual, safe_normalization);
void dt_lut3d_apply(const float *const in, float *const out, const size_t pixel_nb, const float *const clut, const uint16_t level, const float normalization, const dt_lut3d_interpolation_t interpolation)
Apply one interpolation model over a packed RGB CLUT.