23 const dt_iop_roi_t *
const roi_in,
const uint32_t filters,
24 const uint8_t (*
const xtrans)[6])
26 const int colors = (filters == 9) ? 3 : 4;
31 for(
int col = 0; col < roi_out->
width; col++)
34 uint8_t count[4] = { 0 };
35 if(col == 1 &&
row >= 1 && row < roi_out->
height - 1) col = roi_out->
width - 1;
37 for(
int y =
row - 1; y !=
row + 2; y++)
38 for(
int x = col - 1;
x != col + 2;
x++)
39 if(y >= 0 &&
x >= 0 && y < roi_in->
height && x < roi_in->
width)
41 const int f =
fcol(y + roi_in->
y,
x + roi_in->
x, filters, xtrans);
42 sum[
f] += in[y * roi_in->
width +
x];
45 const int f =
fcol(
row + roi_in->
y, col + roi_in->
x, filters, xtrans);
49 for(
int c = 0; c <
colors; c++)
51 if(c !=
f && count[c] != 0)
52 out[4 * (
row * roi_out->
width + col) + c] = sum[c] / count[c];
71 int(*
const lookup)[16][32] = malloc(
sizeof(
int) * 16 * 16 * 32);
73 const int size = (filters == 9) ? 6 : 16;
76 for(
int col = 0; col <
size; col++)
80 const int f =
fcol(
row + roi_in->
y, col + roi_in->
x, filters, xtrans);
82 for(
int y = -1; y <= 1; y++)
83 for(
int x = -1;
x <= 1;
x++)
85 const int weight = 1 << ((y == 0) + (
x == 0));
86 const int color =
fcol(
row + y + roi_in->
y, col +
x + roi_in->
x, filters, xtrans);
87 if(color ==
f)
continue;
88 *ip++ = (roi_in->
width * y +
x);
94 for(
int c = 0; c <
colors; c++)
108 const float *buf_in = in + roi_in->
width *
row + 1;
109 for(
int col = 1; col < roi_out->
width - 1; col++)
114 for(
int i = *ip++;
i--; ip += 3) sum[ip[2]] += buf_in[ip[0]] * ip[1];
116 for(
int i =
colors; --
i; ip += 2) buf[*ip] = sum[ip[0]] / ip[1];
131 const float tmp = (b); \
137 const int num_passes,
const float threshold)
142 const int lim[5] = { 0, 1, 2, 1, 0 };
143 for(
int pass = 0; pass < num_passes; pass++)
150 if(
FC(
row, col, filters) != 1 &&
FC(
row, col, filters) != 3) col++;
151 float *pixo =
out + (size_t)roi->
width *
row + col;
152 const float *pixi = in + (size_t)roi->
width *
row + col;
153 for(; col < roi->
width - 3; col += 2)
156 for(
int k = 0,
i = 0;
i < 5;
i++)
158 for(
int j = -lim[
i]; j <= lim[
i]; j += 2)
162 med[
k++] = pixi[roi->
width * (
i - 2) + j];
166 med[
k++] = 64.0f + pixi[roi->
width * (
i - 2) + j];
169 for(
int i = 0;
i < 8;
i++)
170 for(
int ii =
i + 1; ii < 9; ii++)
171 if(med[
i] > med[ii])
SWAP(med[
i], med[ii]);
172 pixo[0] = (cnt == 1 ? med[4] - 64.0f : med[(cnt - 1) / 2]);
183 const int num_passes,
const float threshold)
188#define SWAPmed(I, J) \
189 if(med[I] > med[J]) SWAP(med[I], med[J])
194 const int width4 = 4 * roi_out->
width;
196 for(
int pass = 0; pass < num_passes; pass++)
198 for(
int c = 0; c < 3; c += 2)
202 for(
int j = 0; j < roi_out->
height; j++)
203 for(
int i = 0;
i < roi_out->
width;
i++, outp += 4) outp[3] = outp[c];
206 for(
int j = 1; j < roi_out->
height - 1; j++)
208 float *outp =
out + (size_t)4 * j * roi_out->
width + 4;
209 for(
int i = 1;
i < roi_out->
width - 1;
i++, outp += 4)
212 outp[-width4 - 4 + 3] - outp[-width4 - 4 + 1], outp[-width4 + 0 + 3] - outp[-width4 + 0 + 1],
213 outp[-width4 + 4 + 3] - outp[-width4 + 4 + 1], outp[-4 + 3] - outp[-4 + 1],
214 outp[+0 + 3] - outp[+0 + 1], outp[+4 + 3] - outp[+4 + 1],
215 outp[+width4 - 4 + 3] - outp[+width4 - 4 + 1], outp[+width4 + 0 + 3] - outp[+width4 + 0 + 1],
216 outp[+width4 + 4 + 3] - outp[+width4 + 4 + 1],
238 outp[c] = fmaxf(med[4] + outp[1], 0.0f);
249 const uint32_t filters,
const int x,
const int y,
const float thr)
251 const float maximum = 1.0f;
254 if(
FC(oj + y, oi +
x, filters) != 1) oj++;
255 if(
FC(oj + y, oi +
x, filters) != 1) oi++;
256 if(
FC(oj + y, oi +
x, filters) != 1) oj--;
260 for(
size_t j = oj; j <
height - 2; j += 2)
262 for(
size_t i = oi;
i <
width - 2;
i += 2)
264 const float o1_1 = in[(j - 1) *
width +
i - 1];
265 const float o1_2 = in[(j - 1) *
width +
i + 1];
266 const float o1_3 = in[(j + 1) *
width +
i - 1];
267 const float o1_4 = in[(j + 1) *
width +
i + 1];
268 const float o2_1 = in[(j - 2) *
width +
i];
269 const float o2_2 = in[(j + 2) *
width +
i];
270 const float o2_3 = in[j *
width +
i - 2];
271 const float o2_4 = in[j *
width +
i + 2];
273 const float m1 = (o1_1 + o1_2 + o1_3 + o1_4) / 4.0f;
274 const float m2 = (o2_1 + o2_2 + o2_3 + o2_4) / 4.0f;
279 if((m2 > 0.0f) && (m1 > 0.0f) && (m1 / m2 < maximum * 2.0f))
281 const float c1 = (fabsf(o1_1 - o1_2) + fabsf(o1_1 - o1_3) + fabsf(o1_1 - o1_4) + fabsf(o1_2 - o1_3)
282 + fabsf(o1_3 - o1_4) + fabsf(o1_2 - o1_4)) / 6.0f;
283 const float c2 = (fabsf(o2_1 - o2_2) + fabsf(o2_1 - o2_3) + fabsf(o2_1 - o2_4) + fabsf(o2_2 - o2_3)
284 + fabsf(o2_3 - o2_4) + fabsf(o2_2 - o2_4)) / 6.0f;
285 if((in[j *
width +
i] < maximum * 0.95f) && (
c1 < maximum * thr) && (
c2 < maximum * thr))
297 const uint32_t filters,
const int x,
const int y)
301 double sum1 = 0.0, sum2 = 0.0, gr_ratio;
303 if((
FC(oj + y, oi +
x, filters) & 1) != 1) oi++;
304 const int g2_offset = oi ? -1 : 1;
307 for(
size_t j = oj; j < (
height - 1); j += 2)
309 for(
size_t i = oi;
i < (
width - 1 - g2_offset);
i += 2)
311 sum1 += in[j *
width +
i];
312 sum2 += in[(j + 1) *
width +
i + g2_offset];
316 if(sum1 > 0.0 && sum2 > 0.0)
317 gr_ratio = sum2 / sum1;
321 for(
int j = oj; j < (
height - 1); j += 2)
323 for(
int i = oi;
i < (
width - 1 - g2_offset);
i += 2)
340 const int devid = pipe->
devid;
351 .cellsize = 4 *
sizeof(float), .overhead = 0,
352 .sizex = 1 << 8, .sizey = 1 << 8 };
358 cl_mem dev_t1 = dev_out;
359 cl_mem dev_t2 = dev_tmp;
361 for(
int pass = 0; pass < passes; pass++)
364 size_t local[] = { locopt.
sizex, locopt.
sizey, 1 };
370 sizeof(
float) * 4 * (locopt.
sizex + 2) * (locopt.
sizey + 2), NULL);
372 if(err != CL_SUCCESS)
goto error;
382 if(dev_t1 == dev_tmp)
385 size_t origin[] = { 0, 0, 0 };
388 if(err != CL_SUCCESS)
goto error;
407 const int devid = pipe->
devid;
411 cl_mem dev_tmp = NULL;
414 cl_mem dev_in1 = NULL;
415 cl_mem dev_out1 = NULL;
416 cl_mem dev_in2 = NULL;
417 cl_mem dev_out2 = NULL;
418 float *sumsum = NULL;
453 .cellsize = 2 *
sizeof(float), .overhead = 0,
454 .sizex = 1 << 4, .sizey = 1 << 4 };
462 const int bufsize = (bwidth / flocopt.
sizex) * (bheight / flocopt.
sizey);
467 size_t fsizes[3] = { bwidth, bheight, 1 };
468 size_t flocal[3] = { flocopt.
sizex, flocopt.
sizey, 1 };
477 sizeof(
float) * 2 * flocopt.
sizex * flocopt.
sizey, NULL);
480 if(err != CL_SUCCESS)
goto error;
484 .cellsize =
sizeof(float) * 2, .overhead = 0,
485 .sizex = 1 << 16, .sizey = 1 };
495 size_t ssizes[3] = { (size_t)reducesize * slocopt.
sizex, 1, 1 };
496 size_t slocal[3] = { slocopt.
sizex, 1, 1 };
503 if(err != CL_SUCCESS)
goto error;
508 sizeof(
float) * 2 * reducesize, CL_TRUE);
509 if(err != CL_SUCCESS)
goto error;
511 float sum1 = 0.0f, sum2 = 0.0f;
512 for(
int k = 0;
k < reducesize;
k++)
514 sum1 += sumsum[2 *
k];
515 sum2 += sumsum[2 *
k + 1];
518 const float gr_ratio = (sum1 > 0.0f && sum2 > 0.0f) ? sum2 / sum1 : 1.0f;
530 if(err != CL_SUCCESS)
goto error;
540 .cellsize = 1 *
sizeof(float), .overhead = 0,
541 .sizex = 1 << 8, .sizey = 1 << 8 };
547 size_t local[3] = { locopt.
sizex, locopt.
sizey, 1 };
557 sizeof(
float) * (locopt.
sizex + 4) * (locopt.
sizey + 4), NULL);
559 if(err != CL_SUCCESS)
goto error;
static void error(char *msg)
Definition ashift_lsd.c:202
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
static __DT_CLONE_TARGETS__ void green_equilibration_lavg(float *out, const float *const in, const int width, const int height, const uint32_t filters, const int x, const int y, const float thr)
Definition basic.c:248
static int green_equilibration_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, const dt_iop_roi_t *const roi_in)
Definition basic.c:400
static __DT_CLONE_TARGETS__ void lin_interpolate(float *out, const float *const in, const dt_iop_roi_t *const roi_out, const dt_iop_roi_t *const roi_in, const uint32_t filters, const uint8_t(*const xtrans)[6])
Definition basic.c:22
#define SWAPmed(I, J)
Definition basic.c:188
static void pre_median(float *out, const float *const in, const dt_iop_roi_t *const roi, const uint32_t filters, const int num_passes, const float threshold)
Definition basic.c:182
static __DT_CLONE_TARGETS__ void pre_median_b(float *out, const float *const in, const dt_iop_roi_t *const roi, const uint32_t filters, const int num_passes, const float threshold)
Definition basic.c:136
#define SWAP(a, b)
Definition basic.c:129
static __DT_CLONE_TARGETS__ void green_equilibration_favg(float *out, const float *const in, const int width, const int height, const uint32_t filters, const int x, const int y)
Definition basic.c:296
static __DT_CLONE_TARGETS__ void color_smoothing(float *out, const dt_iop_roi_t *const roi_out, const int num_passes)
Definition basic.c:192
static int color_smoothing_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, const dt_iop_roi_t *const roi_out, const int passes)
Definition basic.c:334
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
static float lookup(read_only image2d_t lut, const float x)
Definition color_conversion.h:84
const float i
Definition colorspaces_inline_conversions.h:440
const dt_aligned_pixel_t f
Definition colorspaces_inline_conversions.h:102
const float threshold
Definition colorspaces_inline_conversions.h:176
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
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1448
@ DT_DEBUG_OPENCL
Definition darktable.h:721
#define dt_free(ptr)
Definition darktable.h:456
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:453
#define dt_pixelpipe_cache_alloc_align_float(pixels, pipe)
Definition darktable.h:442
#define __DT_CLONE_TARGETS__
Definition darktable.h:367
#define __OMP_PARALLEL_FOR__(...)
Definition darktable.h:258
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
static int FC(const int row, const int col, const unsigned int filters)
Definition data/kernels/common.h:47
#define REDUCESIZE
Definition demosaic.c:102
@ DT_IOP_GREEN_EQ_LOCAL
Definition demosaic.c:136
@ DT_IOP_GREEN_EQ_FULL
Definition demosaic.c:137
@ DT_IOP_GREEN_EQ_BOTH
Definition demosaic.c:138
@ DT_IOP_GREEN_EQ_NO
Definition demosaic.c:135
static void weight(const float *c1, const float *c2, const float sharpen, dt_aligned_pixel_t weight)
Definition eaw.c:30
const dt_collection_filter_flag_t colors[6]
Definition filter.c:295
static void dt_iop_image_copy_by_size(float *const __restrict__ out, const float *const __restrict__ in, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.h:87
static int fcol(const int row, const int col, const uint32_t filters, const uint8_t(*const xtrans)[6])
Definition imageop_math.h:222
static const float x
Definition iop_profile.h:235
const int t
Definition iop_profile.h:225
float *const restrict const size_t k
Definition luminance_mask.h:78
size_t size
Definition mipmap_cache.c:3
float dt_aligned_pixel_t[4]
Definition noiseprofile.c:28
int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors)
Definition opencl.c:2970
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
Definition opencl.c:1951
void * dt_opencl_alloc_device_buffer(const int devid, const size_t size)
Definition opencl.c:2359
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
Definition opencl.c:2286
int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst, size_t *region)
Definition opencl.c:2076
int dt_opencl_read_buffer_from_device(const int devid, void *host, void *device, const size_t offset, const size_t size, const int blocking)
Definition opencl.c:2124
int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg)
Definition opencl.c:1942
int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes, const size_t *local)
Definition opencl.c:1957
void dt_opencl_release_mem_object(cl_mem mem)
Definition opencl.c:2198
#define ROUNDUP(a, n)
Definition opencl.h:78
#define ROUNDUPDHT(a, b)
Definition opencl.h:82
#define ROUNDUPDWD(a, b)
Definition opencl.h:81
Definition pixelpipe_hb.h:96
dt_iop_buffer_dsc_t dsc_in
Definition pixelpipe_hb.h:142
struct dt_iop_module_t *void * data
Definition pixelpipe_hb.h:97
Definition pixelpipe_hb.h:218
int devid
Definition pixelpipe_hb.h:308
dt_image_t image_storage
Definition develop.h:248
float exif_iso
Definition image.h:254
uint32_t filters
Definition format.h:60
Definition demosaic.c:228
uint32_t green_eq
Definition demosaic.c:229
Definition demosaic.c:162
int kernel_green_eq_favg_apply
Definition demosaic.c:167
int kernel_green_eq_favg_reduce_second
Definition demosaic.c:166
int kernel_color_smoothing
Definition demosaic.c:176
int kernel_green_eq_lavg
Definition demosaic.c:164
int kernel_green_eq_favg_reduce_first
Definition demosaic.c:165
struct dt_develop_t * dev
Definition imageop.h:298
dt_iop_global_data_t * global_data
Definition imageop.h:316
Region of interest passed through the pixelpipe.
Definition imageop.h:72
int x
Definition imageop.h:73
int width
Definition imageop.h:73
int height
Definition imageop.h:73
int y
Definition imageop.h:73
const int xoffset
Definition opencl.h:270
int sizey
Definition opencl.h:277
int sizex
Definition opencl.h:276
#define c2
Definition colorspaces_inline_conversions.h:796
#define c1
Definition colorspaces_inline_conversions.h:795
#define MIN(a, b)
Definition thinplate.c:32