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;
94 result[c] =
MAX(0.0f, filter[0] * buf[indices[0] + c] +
95 filter[1] * buf[indices[1] + c] +
96 filter[2] * buf[indices[2] + c] +
97 filter[3] * buf[indices[3] + c] +
98 filter[4] * buf[indices[4] + c]);
105 result[c] = filter[0] * buf[indices[0] + c] +
106 filter[1] * buf[indices[1] + c] +
107 filter[2] * buf[indices[2] + c] +
108 filter[3] * buf[indices[3] + c] +
109 filter[4] * buf[indices[4] + c];
114 size_t row,
size_t width,
size_t height,
int mult,
const gboolean clip_negatives)
119 indices[0] = 4 *
width *
MAX((
int)
row - 2 * mult, 0);
124 for(
size_t j = 0; j <
width; j++)
133 size_t col,
size_t width,
int mult, const gboolean clip_negatives)
138 indices[0] = 4 *
MAX((
int)col - 2 * mult, 0);
139 indices[1] = 4 *
MAX((
int)col - mult, 0);
140 indices[2] = 4 * col;
141 indices[3] = 4 *
MIN(col + mult,
width-1);
142 indices[4] = 4 *
MIN(col + 2 * mult,
width-1);
150 const
size_t col, const
size_t width,
151 const gboolean clip_negatives)
156 const size_t center = col * 2u;
158 indices[0] = 4 *
MAX((
int)center - 2, 0);
159 indices[1] = 4 *
MAX((
int)center - 1, 0);
160 indices[2] = 4 * center;
161 indices[3] = 4 *
MIN(center + 1,
width - 1);
162 indices[4] = 4 *
MIN(center + 2,
width - 1);
167 float *
const restrict tempbuf,
const size_t padded_size,
168 const gboolean clip_negatives)
172 const gboolean use_replicated_boundary = (coarse_width > 2u && coarse_height > 2u);
181 for(
size_t row = 0;
row < coarse_height; ++
row)
183 for(
size_t col = 0; col < coarse_width; ++col)
186 const size_t sample_row = use_replicated_boundary ? CLAMP((
int)
row, 1, (
int)coarse_height - 2) :
row;
187 const size_t sample_col = use_replicated_boundary ? CLAMP((
int)col, 1, (
int)coarse_width - 2) : col;
188 const size_t center_row = sample_row * 2u;
189 const size_t center_col = sample_col * 2u;
194 for(
int jj = -2; jj <= 2; ++jj)
196 const size_t yy = CLAMP((
int)center_row + jj, 0, (
int)
height - 1);
197 for(
int ii = -2; ii <= 2; ++ii)
199 const size_t xx = CLAMP((
int)center_col + ii, 0, (
int)
width - 1);
200 const float weight = filter[ii + 2] * filter[jj + 2];
201 const size_t index = 4 * (yy *
width + xx);
203 accum[c] +=
weight * in[index + c];
207 const size_t out_index = 4 * (
row * coarse_width + col);
211 out[out_index + c] =
MAX(accum[c], 0.f);
222 const gboolean clip_negatives)
226 const gboolean use_replicated_boundary = (
width > 2u &&
height > 2u && coarse_width > 1u && coarse_height > 1u);
234 for(
size_t col = 0; col <
width; ++col)
236 size_t sample_row =
row;
237 size_t sample_col = col;
238 if(use_replicated_boundary)
242 sample_row = CLAMP((
int)
row, 1, (
int)max_row);
243 sample_col = CLAMP((
int)col, 1, (
int)max_col);
246 const size_t center_row = sample_row >> 1;
247 const size_t center_col = sample_col >> 1;
252 switch((sample_col & 1u) + 2u * (sample_row & 1u))
256 for(
int jj = -1; jj <= 1; ++jj)
257 for(
int ii = -1; ii <= 1; ++ii)
259 const size_t yy = center_row + jj;
260 const size_t xx = center_col + ii;
261 const float weight = 4.f * filter[2 * (jj + 1)] * filter[2 * (ii + 1)];
262 const size_t index = 4 * (yy * coarse_width + xx);
264 accum[c] +=
weight * in[index + c];
270 for(
int jj = -1; jj <= 1; ++jj)
271 for(
int ii = 0; ii <= 1; ++ii)
273 const size_t yy = center_row + jj;
274 const size_t xx = center_col + ii;
275 const float weight = 4.f * filter[2 * (jj + 1)] * filter[2 * ii + 1];
276 const size_t index = 4 * (yy * coarse_width + xx);
278 accum[c] +=
weight * in[index + c];
284 for(
int jj = 0; jj <= 1; ++jj)
285 for(
int ii = -1; ii <= 1; ++ii)
287 const size_t yy = center_row + jj;
288 const size_t xx = center_col + ii;
289 const float weight = 4.f * filter[2 * jj + 1] * filter[2 * (ii + 1)];
290 const size_t index = 4 * (yy * coarse_width + xx);
292 accum[c] +=
weight * in[index + c];
298 for(
int jj = 0; jj <= 1; ++jj)
299 for(
int ii = 0; ii <= 1; ++ii)
301 const size_t yy = center_row + jj;
302 const size_t xx = center_col + ii;
303 const float weight = 4.f * filter[2 * jj + 1] * filter[2 * ii + 1];
304 const size_t index = 4 * (yy * coarse_width + xx);
306 accum[c] +=
weight * in[index + c];
312 const size_t out_index = 4 * (
row *
width + col);
316 out[out_index + c] =
MAX(accum[c], 0.f);
326 float *
const restrict tempbuf,
327 const size_t width,
const size_t height,
const int mult,
const gboolean clip_negatives)
340 for(
size_t j = 0; j <
width; j++)
348 float *
const restrict HF,
349 float *
const restrict LF,
350 const size_t width,
const size_t height,
const int mult,
351 float *
const tempbuf,
size_t padded_size)
364 for(
size_t j = 0; j <
width; j++)
366 const size_t index = 4U * (
i *
width + j);
370 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:149
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:165
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:132
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:79
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:325
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:220
#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:347
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:113
const float i
Definition colorspaces_inline_conversions.h:440
const dt_colormatrix_t dt_aligned_pixel_t out
Definition colorspaces_inline_conversions.h:42
static const int row
Definition colorspaces_inline_conversions.h:35
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
#define DT_ALIGNED_ARRAY
Definition darktable.h:388
#define for_each_channel(_var,...)
Definition darktable.h:662
static void copy_pixel_nontemporal(float *const __restrict__ out, const float *const __restrict__ in)
Definition darktable.h:677
static int dt_get_thread_num()
Definition darktable.h:291
#define __OMP_DECLARE_SIMD__(...)
Definition darktable.h:263
#define dt_get_perthread(buf, padsize)
Definition darktable.h:1034
#define for_four_channels(_var,...)
Definition darktable.h:664
#define __OMP_PARALLEL_FOR__(...)
Definition darktable.h:258
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:30
size_t size
Definition mipmap_cache.c:3
float dt_aligned_pixel_t[4]
Definition noiseprofile.c:28
const float sigma
Definition src/develop/noise_generator.h:71
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29