100 if(border <= 0)
return;
101 const int max_col =
width - border - 1;
105 float *
const rowptr = mask + (size_t)(
row *
width);
106 for(
int i = 0;
i < border;
i++)
108 rowptr[
i] = rowptr[border];
109 rowptr[
width -
i - 1] = rowptr[max_col];
112 const float *
const top_row = mask + (size_t)(border *
width);
113 const float *
const bot_row = mask + (size_t)(
height - border - 1) *
width;
115 for(
int col = 0; col <
width; col++)
117 const int c =
MIN(max_col,
MAX(col, border));
118 const float top = top_row[c];
119 const float bot = bot_row[c];
120 for(
int i = 0;
i < border;
i++)
131 const float temp = -2.0f * sqf(
sigma);
132 const float range = sqf(3.0f * 0.84f);
134 for(
int k = -2;
k <= 2;
k++)
136 for(
int j = -2; j <= 2; j++)
138 if((sqf(
k) + sqf(j)) <= range)
140 kernel[
k + 2][j + 2] = expf((sqf(
k) + sqf(j)) / temp);
147 for(
int i = 0;
i < 5;
i++)
148 for(
int j = 0; j < 5; j++)
158#define FAST_BLUR_5 ( \
159 blurmat[0] * ((src[i - w2 - 1] + src[i - w2 + 1]) + (src[i - w1 - 2] + src[i - w1 + 2]) + (src[i + w1 - 2] + src[i + w1 + 2]) + (src[i + w2 - 1] + src[i + w2 + 1])) + \
160 blurmat[1] * (src[i - w2] + src[i - 2] + src[i + 2] + src[i + w2]) + \
161 blurmat[2] * (src[i - w1 - 1] + src[i - w1 + 1] + src[i + w1 - 1] + src[i + w1 + 1]) + \
162 blurmat[3] * (src[i - w1] + src[i - 1] + src[i + 1] + src[i + w1]) + \
163 blurmat[4] * src[i] )
168 const float temp = -2.0f * sqf(
sigma);
169 const float range = sqf(3.0f * 1.5f);
171 for(
int k = -4;
k <= 4;
k++)
173 for(
int j = -4; j <= 4; j++)
175 if((sqf(
k) + sqf(j)) <= range)
177 kernel[
k + 4][j + 4] = expf((sqf(
k) + sqf(j)) / temp);
184 for(
int i = 0;
i < 9;
i++)
185 for(
int j = 0; j < 9; j++)
205#define FAST_BLUR_9 ( \
206 blurmat[12] * (src[i - w4 - 2] + src[i - w4 + 2] + src[i - w2 - 4] + src[i - w2 + 4] + src[i + w2 - 4] + src[i + w2 + 4] + src[i + w4 - 2] + src[i + w4 + 2]) + \
207 blurmat[11] * (src[i - w4 - 1] + src[i - w4 + 1] + src[i - w1 - 4] + src[i - w1 + 4] + src[i + w1 - 4] + src[i + w1 + 4] + src[i + w4 - 1] + src[i + w4 + 1]) + \
208 blurmat[10] * (src[i - w4] + src[i - 4] + src[i + 4] + src[i + w4]) + \
209 blurmat[9] * (src[i - w3 - 3] + src[i - w3 + 3] + src[i + w3 - 3] + src[i + w3 + 3]) + \
210 blurmat[8] * (src[i - w3 - 2] + src[i - w3 + 2] + src[i - w2 - 3] + src[i - w2 + 3] + src[i + w2 - 3] + src[i + w2 + 3] + src[i + w3 - 2] + src[i + w3 + 2]) + \
211 blurmat[7] * (src[i - w3 - 1] + src[i - w3 + 1] + src[i - w1 - 3] + src[i - w1 + 3] + src[i + w1 - 3] + src[i + w1 + 3] + src[i + w3 - 1] + src[i + w3 + 1]) + \
212 blurmat[6] * (src[i - w3] + src[i - 3] + src[i + 3] + src[i + w3]) + \
213 blurmat[5] * (src[i - w2 - 2] + src[i - w2 + 2] + src[i + w2 - 2] + src[i + w2 + 2]) + \
214 blurmat[4] * (src[i - w2 - 1] + src[i - w2 + 1] + src[i - w1 - 2] + src[i - w1 + 2] + src[i + w1 - 2] + src[i + w1 + 2] + src[i + w2 - 1] + src[i + w2 + 1]) + \
215 blurmat[3] * (src[i - w2] + src[i - 2] + src[i + 2] + src[i + w2]) + \
216 blurmat[2] * (src[i - w1 - 1] + src[i - w1 + 1] + src[i + w1 - 1] + src[i + w1 + 1]) + \
217 blurmat[1] * (src[i - w1] + src[i - 1] + src[i + 1] + src[i + w1]) + \
218 blurmat[0] * src[i] )
233 for(
int col = 4; col <
width - 4; col++)
235 const int i = row_off + col;
245 const float temp = -2.0f * sqf(
sigma);
246 const float range = sqf(3.0f * 2.0f);
248 for(
int k = -6;
k <= 6;
k++)
250 for(
int j = -6; j <= 6; j++)
252 if((sqf(
k) + sqf(j)) <= range)
254 kernel[
k + 6][j + 6] = expf((sqf(
k) + sqf(j)) / temp);
261 for(
int i = 0;
i < 13;
i++)
262 for(
int j = 0; j < 13; j++)
294 for(
int idx =0; idx < msize; idx++)
296 const float val = 0.333333333f * (fmaxf(src[4 * idx], 0.0f) / wb[0] + fmaxf(src[4 * idx + 1], 0.0f) / wb[1] + fmaxf(src[4 * idx + 2], 0.0f) / wb[2]);
297 tmp[idx] = sqrtf(val);
300 const float scale = 1.0f / 16.0f;
304 for(
int col = 1, idx =
row *
width + col; col <
width - 1; col++, idx++)
307 const float gx = 47.0f * (tmp[idx-
width-1] - tmp[idx-
width+1])
308 + 162.0f * (tmp[idx-1] - tmp[idx+1])
309 + 47.0f * (tmp[idx+
width-1] - tmp[idx+
width+1]);
310 const float gy = 47.0f * (tmp[idx-
width-1] - tmp[idx+
width-1])
312 + 47.0f * (tmp[idx-
width+1] - tmp[idx+
width+1]);
313 const float gradient_magnitude = dt_fast_hypotf(gx / 256.0f, gy / 256.0f);
314 mask[idx] = scale * gradient_magnitude;
328 return 1.0f / (1.0f + dt_fast_expf(16.0f - (16.0f /
threshold) * val));
335 for(
int idx = 0; idx < msize; idx++)
338 tmp[idx] = detail ? blend : 1.0f - blend;
const dt_colormatrix_t dt_aligned_pixel_t out
__DT_CLONE_TARGETS__ void dt_masks_calc_rawdetail_mask(float *const restrict src, float *const restrict mask, float *const restrict tmp, const int width, const int height, const dt_aligned_pixel_t wb)
void dt_masks_blur_9x9_coeff(float *c, const float sigma)
void dt_masks_blur_9x9(float *const restrict src, float *const restrict out, const int width, const int height, const float sigma)
void _masks_blur_13x13_coeff(float *c, const float sigma)
__DT_CLONE_TARGETS__ void dt_masks_extend_border(float *const restrict mask, const int width, const int height, const int border)
void dt_masks_calc_detail_mask(float *const restrict src, float *const restrict out, float *const restrict tmp, const int width, const int height, const float threshold, const gboolean detail)
static float calcBlendFactor(float val, float threshold)
void _masks_blur_5x5_coeff(float *c, const float sigma)
static float kernel(const float *x, const float *y)
float *const restrict const size_t k
The detail-mask pixel math: a Scharr-style detail estimate over a raw or scene-referred buffer,...
#define __OMP_FOR_SIMD__(...)
#define __OMP_PARALLEL_FOR_SIMD__(...)
DT_ALIGNED_PIXEL float dt_aligned_pixel_t[4]
#define __DT_CLONE_TARGETS__