64 const float *
const restrict clut,
const uint16_t level,
65 const float normalization)
67 const int level2 = level * level;
68 const float safe_normalization = fmaxf(normalization, 1e-6f);
70 for(
size_t k = 0;
k < (size_t)(pixel_nb * 4);
k += 4)
72 const float *
const input =
in +
k;
73 float *
const output =
out +
k;
79 _prepare_lut_input(input, normalized, residual, rgbd, rgbi, level, safe_normalization);
81 const int color = rgbi[0] + rgbi[1] * level + rgbi[2] * level2;
82 const int i000 =
color * 3;
83 const int i100 = i000 + 3;
84 const int i010 = (
color + level) * 3;
85 const int i110 = i010 + 3;
86 const int i001 = (
color + level2) * 3;
87 const int i101 = i001 + 3;
88 const int i011 = (
color + level + level2) * 3;
89 const int i111 = i011 + 3;
95 output[0] = (1 - rgbd[0]) * clut[i000] + (rgbd[0] - rgbd[1]) * clut[i100]
96 + (rgbd[1] - rgbd[2]) * clut[i110] + rgbd[2] * clut[i111];
97 output[1] = (1 - rgbd[0]) * clut[i000 + 1] + (rgbd[0] - rgbd[1]) * clut[i100 + 1]
98 + (rgbd[1] - rgbd[2]) * clut[i110 + 1] + rgbd[2] * clut[i111 + 1];
99 output[2] = (1 - rgbd[0]) * clut[i000 + 2] + (rgbd[0] - rgbd[1]) * clut[i100 + 2]
100 + (rgbd[1] - rgbd[2]) * clut[i110 + 2] + rgbd[2] * clut[i111 + 2];
102 else if(rgbd[0] > rgbd[2])
104 output[0] = (1 - rgbd[0]) * clut[i000] + (rgbd[0] - rgbd[2]) * clut[i100]
105 + (rgbd[2] - rgbd[1]) * clut[i101] + rgbd[1] * clut[i111];
106 output[1] = (1 - rgbd[0]) * clut[i000 + 1] + (rgbd[0] - rgbd[2]) * clut[i100 + 1]
107 + (rgbd[2] - rgbd[1]) * clut[i101 + 1] + rgbd[1] * clut[i111 + 1];
108 output[2] = (1 - rgbd[0]) * clut[i000 + 2] + (rgbd[0] - rgbd[2]) * clut[i100 + 2]
109 + (rgbd[2] - rgbd[1]) * clut[i101 + 2] + rgbd[1] * clut[i111 + 2];
113 output[0] = (1 - rgbd[2]) * clut[i000] + (rgbd[2] - rgbd[0]) * clut[i001]
114 + (rgbd[0] - rgbd[1]) * clut[i101] + rgbd[1] * clut[i111];
115 output[1] = (1 - rgbd[2]) * clut[i000 + 1] + (rgbd[2] - rgbd[0]) * clut[i001 + 1]
116 + (rgbd[0] - rgbd[1]) * clut[i101 + 1] + rgbd[1] * clut[i111 + 1];
117 output[2] = (1 - rgbd[2]) * clut[i000 + 2] + (rgbd[2] - rgbd[0]) * clut[i001 + 2]
118 + (rgbd[0] - rgbd[1]) * clut[i101 + 2] + rgbd[1] * clut[i111 + 2];
123 if(rgbd[2] > rgbd[1])
125 output[0] = (1 - rgbd[2]) * clut[i000] + (rgbd[2] - rgbd[1]) * clut[i001]
126 + (rgbd[1] - rgbd[0]) * clut[i011] + rgbd[0] * clut[i111];
127 output[1] = (1 - rgbd[2]) * clut[i000 + 1] + (rgbd[2] - rgbd[1]) * clut[i001 + 1]
128 + (rgbd[1] - rgbd[0]) * clut[i011 + 1] + rgbd[0] * clut[i111 + 1];
129 output[2] = (1 - rgbd[2]) * clut[i000 + 2] + (rgbd[2] - rgbd[1]) * clut[i001 + 2]
130 + (rgbd[1] - rgbd[0]) * clut[i011 + 2] + rgbd[0] * clut[i111 + 2];
132 else if(rgbd[2] > rgbd[0])
134 output[0] = (1 - rgbd[1]) * clut[i000] + (rgbd[1] - rgbd[2]) * clut[i010]
135 + (rgbd[2] - rgbd[0]) * clut[i011] + rgbd[0] * clut[i111];
136 output[1] = (1 - rgbd[1]) * clut[i000 + 1] + (rgbd[1] - rgbd[2]) * clut[i010 + 1]
137 + (rgbd[2] - rgbd[0]) * clut[i011 + 1] + rgbd[0] * clut[i111 + 1];
138 output[2] = (1 - rgbd[1]) * clut[i000 + 2] + (rgbd[1] - rgbd[2]) * clut[i010 + 2]
139 + (rgbd[2] - rgbd[0]) * clut[i011 + 2] + rgbd[0] * clut[i111 + 2];
143 output[0] = (1 - rgbd[1]) * clut[i000] + (rgbd[1] - rgbd[0]) * clut[i010]
144 + (rgbd[0] - rgbd[2]) * clut[i110] + rgbd[2] * clut[i111];
145 output[1] = (1 - rgbd[1]) * clut[i000 + 1] + (rgbd[1] - rgbd[0]) * clut[i010 + 1]
146 + (rgbd[0] - rgbd[2]) * clut[i110 + 1] + rgbd[2] * clut[i111 + 1];
147 output[2] = (1 - rgbd[1]) * clut[i000 + 2] + (rgbd[1] - rgbd[0]) * clut[i010 + 2]
148 + (rgbd[0] - rgbd[2]) * clut[i110 + 2] + rgbd[2] * clut[i111 + 2];
152 _finish_lut_output(input, output, residual, safe_normalization);
158 const float *
const restrict clut,
const uint16_t level,
159 const float normalization)
161 const int level2 = level * level;
162 const float safe_normalization = fmaxf(normalization, 1e-6f);
164 for(
size_t k = 0;
k < (size_t)(pixel_nb * 4);
k += 4)
166 const float *
const input =
in +
k;
167 float *
const output =
out +
k;
174 _prepare_lut_input(input, normalized, residual, rgbd, rgbi, level, safe_normalization);
176 const int color = rgbi[0] + rgbi[1] * level + rgbi[2] * level2;
178 int j = (
color + 1) * 3;
180 tmp[0] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
181 tmp[1] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
182 tmp[2] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
185 j = (
color + level + 1) * 3;
187 tmp[3] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
188 tmp[4] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
189 tmp[5] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
191 output[0] = tmp[0] * (1 - rgbd[1]) + tmp[3] * rgbd[1];
192 output[1] = tmp[1] * (1 - rgbd[1]) + tmp[4] * rgbd[1];
193 output[2] = tmp[2] * (1 - rgbd[1]) + tmp[5] * rgbd[1];
196 j = (
color + level2 + 1) * 3;
198 tmp[0] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
199 tmp[1] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
200 tmp[2] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
202 i = (
color + level + level2) * 3;
203 j = (
color + level + level2 + 1) * 3;
205 tmp[3] = clut[
i] * (1 - rgbd[0]) + clut[j] * rgbd[0];
206 tmp[4] = clut[
i + 1] * (1 - rgbd[0]) + clut[j + 1] * rgbd[0];
207 tmp[5] = clut[
i + 2] * (1 - rgbd[0]) + clut[j + 2] * rgbd[0];
209 tmp[0] = tmp[0] * (1 - rgbd[1]) + tmp[3] * rgbd[1];
210 tmp[1] = tmp[1] * (1 - rgbd[1]) + tmp[4] * rgbd[1];
211 tmp[2] = tmp[2] * (1 - rgbd[1]) + tmp[5] * rgbd[1];
213 output[0] = output[0] * (1 - rgbd[2]) + tmp[0] * rgbd[2];
214 output[1] = output[1] * (1 - rgbd[2]) + tmp[1] * rgbd[2];
215 output[2] = output[2] * (1 - rgbd[2]) + tmp[2] * rgbd[2];
217 _finish_lut_output(input, output, residual, safe_normalization);
223 const float *
const restrict clut,
const uint16_t level,
224 const float normalization)
226 const int level2 = level * level;
227 const float safe_normalization = fmaxf(normalization, 1e-6f);
229 for(
size_t k = 0;
k < (size_t)(pixel_nb * 4);
k += 4)
231 const float *
const input =
in +
k;
232 float *
const output =
out +
k;
238 _prepare_lut_input(input, normalized, residual, rgbd, rgbi, level, safe_normalization);
240 const int color = rgbi[0] + rgbi[1] * level + rgbi[2] * level2;
241 const int i000 =
color * 3;
242 const int i100 = i000 + 3;
243 const int i010 = (
color + level) * 3;
244 const int i110 = i010 + 3;
245 const int i001 = (
color + level2) * 3;
246 const int i101 = i001 + 3;
247 const int i011 = (
color + level + level2) * 3;
248 const int i111 = i011 + 3;
250 if(rgbd[1] > rgbd[0] && rgbd[2] > rgbd[0])
252 output[0] = clut[i000] + (clut[i111] - clut[i011]) * rgbd[0] + (clut[i010] - clut[i000]) * rgbd[1]
253 + (clut[i001] - clut[i000]) * rgbd[2]
254 + (clut[i011] - clut[i001] - clut[i010] + clut[i000]) * rgbd[1] * rgbd[2];
255 output[1] = clut[i000 + 1] + (clut[i111 + 1] - clut[i011 + 1]) * rgbd[0]
256 + (clut[i010 + 1] - clut[i000 + 1]) * rgbd[1]
257 + (clut[i001 + 1] - clut[i000 + 1]) * rgbd[2]
258 + (clut[i011 + 1] - clut[i001 + 1] - clut[i010 + 1] + clut[i000 + 1]) * rgbd[1] * rgbd[2];
259 output[2] = clut[i000 + 2] + (clut[i111 + 2] - clut[i011 + 2]) * rgbd[0]
260 + (clut[i010 + 2] - clut[i000 + 2]) * rgbd[1]
261 + (clut[i001 + 2] - clut[i000 + 2]) * rgbd[2]
262 + (clut[i011 + 2] - clut[i001 + 2] - clut[i010 + 2] + clut[i000 + 2]) * rgbd[1] * rgbd[2];
264 else if(rgbd[0] > rgbd[1] && rgbd[2] > rgbd[1])
266 output[0] = clut[i000] + (clut[i100] - clut[i000]) * rgbd[0] + (clut[i111] - clut[i101]) * rgbd[1]
267 + (clut[i001] - clut[i000]) * rgbd[2]
268 + (clut[i101] - clut[i001] - clut[i100] + clut[i000]) * rgbd[0] * rgbd[2];
269 output[1] = clut[i000 + 1] + (clut[i100 + 1] - clut[i000 + 1]) * rgbd[0]
270 + (clut[i111 + 1] - clut[i101 + 1]) * rgbd[1]
271 + (clut[i001 + 1] - clut[i000 + 1]) * rgbd[2]
272 + (clut[i101 + 1] - clut[i001 + 1] - clut[i100 + 1] + clut[i000 + 1]) * rgbd[0] * rgbd[2];
273 output[2] = clut[i000 + 2] + (clut[i100 + 2] - clut[i000 + 2]) * rgbd[0]
274 + (clut[i111 + 2] - clut[i101 + 2]) * rgbd[1]
275 + (clut[i001 + 2] - clut[i000 + 2]) * rgbd[2]
276 + (clut[i101 + 2] - clut[i001 + 2] - clut[i100 + 2] + clut[i000 + 2]) * rgbd[0] * rgbd[2];
280 output[0] = clut[i000] + (clut[i100] - clut[i000]) * rgbd[0] + (clut[i010] - clut[i000]) * rgbd[1]
281 + (clut[i111] - clut[i110]) * rgbd[2]
282 + (clut[i110] - clut[i100] - clut[i010] + clut[i000]) * rgbd[0] * rgbd[1];
283 output[1] = clut[i000 + 1] + (clut[i100 + 1] - clut[i000 + 1]) * rgbd[0]
284 + (clut[i010 + 1] - clut[i000 + 1]) * rgbd[1]
285 + (clut[i111 + 1] - clut[i110 + 1]) * rgbd[2]
286 + (clut[i110 + 1] - clut[i100 + 1] - clut[i010 + 1] + clut[i000 + 1]) * rgbd[0] * rgbd[1];
287 output[2] = clut[i000 + 2] + (clut[i100 + 2] - clut[i000 + 2]) * rgbd[0]
288 + (clut[i010 + 2] - clut[i000 + 2]) * rgbd[1]
289 + (clut[i111 + 2] - clut[i110 + 2]) * rgbd[2]
290 + (clut[i110 + 2] - clut[i100 + 2] - clut[i010 + 2] + clut[i000 + 2]) * rgbd[0] * rgbd[1];
293 _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.