16 for(
int j = 0; j < roi_out->
height; j++)
17 for(
int i = 0; i < roi_out->
width; i++)
19 if(i == 3 && j >= 3 && j < roi_out->
height - 3) i = roi_out->
width - 3;
20 if(i == roi_out->
width)
break;
21 memset(sum, 0,
sizeof(
float) * 8);
22 for(
int y = j - 1; y != j + 2; y++)
23 for(
int x = i - 1; x != i + 2; x++)
25 const int yy = y + roi_out->
y, xx = x + roi_out->
x;
26 if((yy >= 0) && (xx >= 0) && (yy < roi_in->
height) && (xx < roi_in->
width))
28 const int f =
FC(y, x, filters);
29 sum[
f] += in[(size_t)yy * roi_in->
width + xx];
33 const int f =
FC(j, i, filters);
34 for(
int c = 0; c < 3; c++)
36 if(c !=
f && sum[c + 4] > 0.0f)
37 out[4 * ((size_t)j * roi_out->
width + i) + c] = sum[c] / sum[c + 4];
39 out[4 * ((size_t)j * roi_out->
width + i) + c]
40 = in[((size_t)j + roi_out->
y) * roi_in->
width + i + roi_out->
x];
45 const float *input = in;
49 if(med_in == NULL)
return;
56#pragma omp parallel for default(none) \
57 dt_omp_firstprivate(filters, out, roi_in, roi_out) \
61 for(
int j = 3; j < roi_out->
height - 3; j++)
63 float *buf = out + (size_t)4 * roi_out->
width * j + 4 * 3;
64 const float *buf_in = input + (size_t)roi_in->
width * (j + roi_out->
y) + 3 + roi_out->
x;
65 for(
int i = 3; i < roi_out->
width - 3; i++)
67 const int c =
FC(j, i, filters);
68 dt_aligned_pixel_t color;
69 const float pc = buf_in[0];
75 const float pym = buf_in[-roi_in->
width * 1];
76 const float pym2 = buf_in[-roi_in->
width * 2];
77 const float pym3 = buf_in[-roi_in->
width * 3];
78 const float pyM = buf_in[+roi_in->
width * 1];
79 const float pyM2 = buf_in[+roi_in->
width * 2];
80 const float pyM3 = buf_in[+roi_in->
width * 3];
81 const float pxm = buf_in[-1];
82 const float pxm2 = buf_in[-2];
83 const float pxm3 = buf_in[-3];
84 const float pxM = buf_in[+1];
85 const float pxM2 = buf_in[+2];
86 const float pxM3 = buf_in[+3];
88 const float guessx = (pxm + pc + pxM) * 2.0f - pxM2 - pxm2;
89 const float diffx = (fabsf(pxm2 - pc) + fabsf(pxM2 - pc) + fabsf(pxm - pxM)) * 3.0f
90 + (fabsf(pxM3 - pxM) + fabsf(pxm3 - pxm)) * 2.0f;
91 const float guessy = (pym + pc + pyM) * 2.0f - pyM2 - pym2;
92 const float diffy = (fabsf(pym2 - pc) + fabsf(pyM2 - pc) + fabsf(pym - pyM)) * 3.0f
93 + (fabsf(pyM3 - pyM) + fabsf(pym3 - pym)) * 2.0f;
97 const float m = fminf(pym, pyM);
98 const float M = fmaxf(pym, pyM);
99 color[1] = fmaxf(fminf(guessy * .25f, M),
m);
103 const float m = fminf(pxm, pxM);
104 const float M = fmaxf(pxm, pxM);
105 color[1] = fmaxf(fminf(guessx * .25f, M),
m);
114 memcpy(buf, color,
sizeof(
float) * 4);
123#pragma omp parallel for default(none) \
124 dt_omp_firstprivate(filters, out, roi_out) \
127 for(
int j = 1; j < roi_out->
height - 1; j++)
129 float *buf = out + (size_t)4 * roi_out->
width * j + 4;
130 for(
int i = 1; i < roi_out->
width - 1; i++)
133 const int c =
FC(j, i, filters);
134 dt_aligned_pixel_t color = { buf[0], buf[1], buf[2], buf[3] };
138 if(__builtin_expect(c & 1, 1))
142 const float *nt = buf - 4 * roi_out->
width;
143 const float *nb = buf + 4 * roi_out->
width;
144 const float *nl = buf - 4;
145 const float *nr = buf + 4;
146 if(
FC(j, i + 1, filters) == 0)
148 color[2] = (nt[2] + nb[2] + 2.0f * color[1] - nt[1] - nb[1]) * .5f;
149 color[0] = (nl[0] + nr[0] + 2.0f * color[1] - nl[1] - nr[1]) * .5f;
154 color[0] = (nt[0] + nb[0] + 2.0f * color[1] - nt[1] - nb[1]) * .5f;
155 color[2] = (nl[2] + nr[2] + 2.0f * color[1] - nl[1] - nr[1]) * .5f;
161 const float *ntl = buf - 4 - 4 * roi_out->
width;
162 const float *ntr = buf + 4 - 4 * roi_out->
width;
163 const float *nbl = buf - 4 + 4 * roi_out->
width;
164 const float *nbr = buf + 4 + 4 * roi_out->
width;
169 const float diff1 = fabsf(ntl[2] - nbr[2]) + fabsf(ntl[1] - color[1]) + fabsf(nbr[1] - color[1]);
170 const float guess1 = ntl[2] + nbr[2] + 2.0f * color[1] - ntl[1] - nbr[1];
171 const float diff2 = fabsf(ntr[2] - nbl[2]) + fabsf(ntr[1] - color[1]) + fabsf(nbl[1] - color[1]);
172 const float guess2 = ntr[2] + nbl[2] + 2.0f * color[1] - ntr[1] - nbl[1];
174 color[2] = guess2 * .5f;
175 else if(diff1 < diff2)
176 color[2] = guess1 * .5f;
178 color[2] = (guess1 + guess2) * .25f;
182 const float diff1 = fabsf(ntl[0] - nbr[0]) + fabsf(ntl[1] - color[1]) + fabsf(nbr[1] - color[1]);
183 const float guess1 = ntl[0] + nbr[0] + 2.0f * color[1] - ntl[1] - nbr[1];
184 const float diff2 = fabsf(ntr[0] - nbl[0]) + fabsf(ntr[1] - color[1]) + fabsf(nbl[1] - color[1]);
185 const float guess2 = ntr[0] + nbl[0] + 2.0f * color[1] - ntr[1] - nbl[1];
187 color[0] = guess2 * .5f;
188 else if(diff1 < diff2)
189 color[0] = guess1 * .5f;
191 color[0] = (guess1 + guess2) * .25f;
195 memcpy(buf, color,
sizeof(
float) * 4);
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:177
const double thrs
Definition chart/main.c:41
static void demosaic_ppg(float *const 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 float thrs)
Definition ppg.c:7