30#define BSPLINE_FSIZE 5
34#define B_SPLINE_SIGMA 1.0553651328015339f
40 return 2.f /
sqf(sigma);
45#define B_SPLINE_TO_LAPLACIAN 3.182727439285017f
46#define B_SPLINE_TO_LAPLACIAN_2 10.129753952777762f
66 float radius = sigma_filter;
67 while(radius < sigma_final)
70 radius = sqrtf(
sqf(radius) +
sqf((
float)(1 << s) * sigma_filter));
77 return (
size - 1u) / 2u + 1u;
82#pragma omp declare simd aligned(buf, indices, result:64)
85 dt_aligned_pixel_t result,
const gboolean clip_negatives)
99 result[
c] =
MAX(0.0f, filter[0] * buf[indices[0] +
c] +
100 filter[1] * buf[indices[1] +
c] +
101 filter[2] * buf[indices[2] +
c] +
102 filter[3] * buf[indices[3] +
c] +
103 filter[4] * buf[indices[4] +
c]);
110 result[
c] = filter[0] * buf[indices[0] +
c] +
111 filter[1] * buf[indices[1] +
c] +
112 filter[2] * buf[indices[2] +
c] +
113 filter[3] * buf[indices[3] +
c] +
114 filter[4] * buf[indices[4] +
c];
120#pragma omp declare simd aligned(in, temp)
123 size_t row,
size_t width,
size_t height,
int mult,
const gboolean clip_negatives)
128 indices[0] = 4 *
width *
MAX((
int)
row - 2 * mult, 0);
133 for(
size_t j = 0; j <
width; j++)
141#pragma omp declare simd aligned(temp, out)
144 size_t col,
size_t width,
int mult,
const gboolean clip_negatives)
149 indices[0] = 4 *
MAX((
int)col - 2 * mult, 0);
150 indices[1] = 4 *
MAX((
int)col - mult, 0);
151 indices[2] = 4 * col;
152 indices[3] = 4 *
MIN(col + mult,
width-1);
153 indices[4] = 4 *
MIN(col + 2 * mult,
width-1);
160#pragma omp declare simd aligned(temp, out)
163 const size_t col,
const size_t width,
164 const gboolean clip_negatives)
169 const size_t center = col * 2u;
171 indices[0] = 4 *
MAX((
int)center - 2, 0);
172 indices[1] = 4 *
MAX((
int)center - 1, 0);
173 indices[2] = 4 * center;
174 indices[3] = 4 *
MIN(center + 1,
width - 1);
175 indices[4] = 4 *
MIN(center + 2,
width - 1);
180#pragma omp declare simd aligned(in, out:64) aligned(tempbuf:16)
184 float *
const restrict tempbuf,
const size_t padded_size,
185 const gboolean clip_negatives)
189 const gboolean use_replicated_boundary = (coarse_width > 2u && coarse_height > 2u);
199#pragma omp parallel for default(none) \
200 dt_omp_firstprivate(width, height, coarse_width, coarse_height, padded_size, clip_negatives, use_replicated_boundary) \
201 dt_omp_sharedconst(in, out, tempbuf, filter) \
204 for(
size_t row = 0;
row < coarse_height; ++
row)
206 for(
size_t col = 0; col < coarse_width; ++col)
208 dt_aligned_pixel_t accum = { 0.f };
209 const size_t sample_row = use_replicated_boundary ? CLAMP((
int)
row, 1, (
int)coarse_height - 2) :
row;
210 const size_t sample_col = use_replicated_boundary ? CLAMP((
int)col, 1, (
int)coarse_width - 2) : col;
211 const size_t center_row = sample_row * 2u;
212 const size_t center_col = sample_col * 2u;
217 for(
int jj = -2; jj <= 2; ++jj)
219 const size_t yy = CLAMP((
int)center_row + jj, 0, (
int)
height - 1);
220 for(
int ii = -2; ii <= 2; ++ii)
222 const size_t xx = CLAMP((
int)center_col + ii, 0, (
int)
width - 1);
223 const float weight = filter[ii + 2] * filter[jj + 2];
224 const size_t index = 4 * (yy *
width + xx);
230 const size_t out_index = 4 * (
row * coarse_width + col);
234 out[out_index +
c] =
MAX(accum[
c], 0.f);
245#pragma omp declare simd aligned(in, out:64)
249 const gboolean clip_negatives)
253 const gboolean use_replicated_boundary = (
width > 2u &&
height > 2u && coarse_width > 1u && coarse_height > 1u);
261#pragma omp parallel for default(none) \
262 dt_omp_firstprivate(width, height, coarse_width, coarse_height, clip_negatives, use_replicated_boundary) \
263 dt_omp_sharedconst(in, out, filter) \
268 for(
size_t col = 0; col <
width; ++col)
270 size_t sample_row =
row;
271 size_t sample_col = col;
272 if(use_replicated_boundary)
276 sample_row = CLAMP((
int)
row, 1, (
int)max_row);
277 sample_col = CLAMP((
int)col, 1, (
int)max_col);
280 const size_t center_row = sample_row >> 1;
281 const size_t center_col = sample_col >> 1;
282 dt_aligned_pixel_t accum = { 0.f };
286 switch((sample_col & 1u) + 2u * (sample_row & 1u))
290 for(
int jj = -1; jj <= 1; ++jj)
291 for(
int ii = -1; ii <= 1; ++ii)
293 const size_t yy = center_row + jj;
294 const size_t xx = center_col + ii;
295 const float weight = 4.f * filter[2 * (jj + 1)] * filter[2 * (ii + 1)];
296 const size_t index = 4 * (yy * coarse_width + xx);
304 for(
int jj = -1; jj <= 1; ++jj)
305 for(
int ii = 0; ii <= 1; ++ii)
307 const size_t yy = center_row + jj;
308 const size_t xx = center_col + ii;
309 const float weight = 4.f * filter[2 * (jj + 1)] * filter[2 * ii + 1];
310 const size_t index = 4 * (yy * coarse_width + xx);
318 for(
int jj = 0; jj <= 1; ++jj)
319 for(
int ii = -1; ii <= 1; ++ii)
321 const size_t yy = center_row + jj;
322 const size_t xx = center_col + ii;
323 const float weight = 4.f * filter[2 * jj + 1] * filter[2 * (ii + 1)];
324 const size_t index = 4 * (yy * coarse_width + xx);
332 for(
int jj = 0; jj <= 1; ++jj)
333 for(
int ii = 0; ii <= 1; ++ii)
335 const size_t yy = center_row + jj;
336 const size_t xx = center_col + ii;
337 const float weight = 4.f * filter[2 * jj + 1] * filter[2 * ii + 1];
338 const size_t index = 4 * (yy * coarse_width + xx);
346 const size_t out_index = 4 * (
row *
width + col);
350 out[out_index +
c] =
MAX(accum[
c], 0.f);
360#pragma omp declare simd aligned(in, out:64) aligned(tempbuf:16)
363 float *
const restrict tempbuf,
364 const size_t width,
const size_t height,
const int mult,
const gboolean clip_negatives)
368 #pragma omp parallel for default(none) \
369 dt_omp_firstprivate(width, height, mult) \
370 dt_omp_sharedconst(out, in, tempbuf, clip_negatives) \
382 for(
size_t j = 0; j <
width; j++)
390#pragma omp declare simd aligned(in, HF, LF:64) aligned(tempbuf:16)
393 float *
const restrict HF,
394 float *
const restrict LF,
395 const size_t width,
const size_t height,
const int mult,
396 float *
const tempbuf,
size_t padded_size)
400#pragma omp parallel for default(none) \
401 dt_omp_firstprivate(width, height, mult, padded_size) \
402 dt_omp_sharedconst(in, HF, LF, tempbuf) \
414 for(
size_t j = 0; j <
width; j++)
416 const size_t index = 4U * (
i *
width + j);
420 HF[index +
c] = in[index +
c] - LF[index +
c];
#define TRUE
Definition ashift_lsd.c:162
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
static unsigned int num_steps_to_reach_equivalent_sigma(const float sigma_filter, const float sigma_final)
Definition bspline.h:61
static void _bspline_horizontal_decimated(const float *const restrict temp, float *const restrict out, const size_t col, const size_t width, const gboolean clip_negatives)
Definition bspline.h:162
static void reduce_2D_Bspline(const float *const restrict in, float *const restrict out, const size_t width, const size_t height, float *const restrict tempbuf, const size_t padded_size, const gboolean clip_negatives)
Definition bspline.h:182
static void _bspline_horizontal(const float *const restrict temp, float *const restrict out, size_t col, size_t width, int mult, const gboolean clip_negatives)
Definition bspline.h:143
static void sparse_scalar_product(const dt_aligned_pixel_t buf, const size_t indices[5], dt_aligned_pixel_t result, const gboolean clip_negatives)
Definition bspline.h:84
static float equivalent_sigma_at_step(const float sigma, const unsigned int s)
Definition bspline.h:48
static void blur_2D_Bspline(const float *const restrict in, float *const restrict out, float *const restrict tempbuf, const size_t width, const size_t height, const int mult, const gboolean clip_negatives)
Definition bspline.h:362
static void expand_2D_Bspline(const float *const restrict in, float *const restrict out, const size_t width, const size_t height, const gboolean clip_negatives)
Definition bspline.h:247
#define BSPLINE_FSIZE
Definition bspline.h:30
static float normalize_laplacian(const float sigma)
Definition bspline.h:36
static void decompose_2D_Bspline(const float *const restrict in, float *const restrict HF, float *const restrict LF, const size_t width, const size_t height, const int mult, float *const tempbuf, size_t padded_size)
Definition bspline.h:392
static size_t decimated_bspline_size(const size_t size)
Definition bspline.h:75
static void _bspline_vertical_pass(const float *const restrict in, float *const restrict temp, size_t row, size_t width, size_t height, int mult, const gboolean clip_negatives)
Definition bspline.h:122
const float i
Definition colorspaces_inline_conversions.h:669
const float c
Definition colorspaces_inline_conversions.h:1365
static const dt_colormatrix_t dt_aligned_pixel_t out
Definition colorspaces_inline_conversions.h:184
static const int row
Definition colorspaces_inline_conversions.h:175
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
#define DT_ALIGNED_ARRAY
Definition darktable.h:312
#define for_each_channel(_var,...)
Definition darktable.h:582
static void copy_pixel_nontemporal(float *const __restrict__ out, const float *const __restrict__ in)
Definition darktable.h:597
static int dt_get_thread_num()
Definition darktable.h:269
#define dt_get_perthread(buf, padsize)
Definition darktable.h:967
#define for_four_channels(_var,...)
Definition darktable.h:584
static int dwt_interleave_rows(const int rowid, const int height, const int stride)
Definition dwt.h:93
static void weight(const float *c1, const float *c2, const float sharpen, dt_aligned_pixel_t weight)
Definition eaw.c:33
static float sqf(const float x)
Definition math.h:223
size_t size
Definition mipmap_cache.c:3
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29