33 for(
int j = 0; j < roi_out->
height; j++)
34 for(
int i = 0;
i < roi_out->
width;
i++)
36 if(
i == 3 && j >= 3 && j < roi_out->
height - 3)
i = roi_out->
width - 3;
37 if(
i == roi_out->
width)
break;
38 memset(sum, 0,
sizeof(
float) * 8);
39 for(
int y = j - 1; y != j + 2; y++)
40 for(
int x =
i - 1;
x !=
i + 2;
x++)
42 const int yy = y + roi_out->
y, xx =
x + roi_out->
x;
43 if((yy >= 0) && (xx >= 0) && (yy < roi_in->
height) && (xx < roi_in->
width))
45 const int f =
FC(y,
x, filters);
46 sum[
f] += in[(size_t)yy * roi_in->
width + xx];
50 const int f =
FC(j,
i, filters);
51 for(
int c = 0;
c < 3;
c++)
53 if(
c !=
f && sum[
c + 4] > 0.0f)
54 out[4 * ((size_t)j * roi_out->
width +
i) +
c] = sum[
c] / sum[
c + 4];
57 = in[((size_t)j + roi_out->
y) * roi_in->
width +
i + roi_out->
x];
62 const float *input = in;
66 if(med_in == NULL)
return 1;
73#pragma omp parallel for default(none) \
74 dt_omp_firstprivate(filters, out, roi_in, roi_out) \
78 for(
int j = 3; j < roi_out->
height - 3; j++)
80 float *buf =
out + (size_t)4 * roi_out->
width * j + 4 * 3;
81 const float *buf_in = input + (size_t)roi_in->
width * (j + roi_out->
y) + 3 + roi_out->
x;
82 for(
int i = 3;
i < roi_out->
width - 3;
i++)
84 const int c =
FC(j,
i, filters);
85 dt_aligned_pixel_t color;
86 const float pc = buf_in[0];
92 const float pym = buf_in[-roi_in->
width * 1];
93 const float pym2 = buf_in[-roi_in->
width * 2];
94 const float pym3 = buf_in[-roi_in->
width * 3];
95 const float pyM = buf_in[+roi_in->
width * 1];
96 const float pyM2 = buf_in[+roi_in->
width * 2];
97 const float pyM3 = buf_in[+roi_in->
width * 3];
98 const float pxm = buf_in[-1];
99 const float pxm2 = buf_in[-2];
100 const float pxm3 = buf_in[-3];
101 const float pxM = buf_in[+1];
102 const float pxM2 = buf_in[+2];
103 const float pxM3 = buf_in[+3];
105 const float guessx = (pxm + pc + pxM) * 2.0f - pxM2 - pxm2;
106 const float diffx = (fabsf(pxm2 - pc) + fabsf(pxM2 - pc) + fabsf(pxm - pxM)) * 3.0f
107 + (fabsf(pxM3 - pxM) + fabsf(pxm3 - pxm)) * 2.0f;
108 const float guessy = (pym + pc + pyM) * 2.0f - pyM2 - pym2;
109 const float diffy = (fabsf(pym2 - pc) + fabsf(pyM2 - pc) + fabsf(pym - pyM)) * 3.0f
110 + (fabsf(pyM3 - pyM) + fabsf(pym3 - pym)) * 2.0f;
114 const float m = fminf(pym, pyM);
115 const float M = fmaxf(pym, pyM);
116 color[1] = fmaxf(fminf(guessy * .25f,
M),
m);
120 const float m = fminf(pxm, pxM);
121 const float M = fmaxf(pxm, pxM);
122 color[1] = fmaxf(fminf(guessx * .25f,
M),
m);
131 memcpy(buf, color,
sizeof(
float) * 4);
140#pragma omp parallel for default(none) \
141 dt_omp_firstprivate(filters, out, roi_out) \
144 for(
int j = 1; j < roi_out->
height - 1; j++)
146 float *buf =
out + (size_t)4 * roi_out->
width * j + 4;
147 for(
int i = 1;
i < roi_out->
width - 1;
i++)
150 const int c =
FC(j,
i, filters);
151 dt_aligned_pixel_t color = { buf[0], buf[1], buf[2], buf[3] };
155 if(__builtin_expect(
c & 1, 1))
159 const float *nt = buf - 4 * roi_out->
width;
160 const float *nb = buf + 4 * roi_out->
width;
161 const float *nl = buf - 4;
162 const float *nr = buf + 4;
163 if(
FC(j,
i + 1, filters) == 0)
165 color[2] = (nt[2] + nb[2] + 2.0f * color[1] - nt[1] - nb[1]) * .5f;
166 color[0] = (nl[0] + nr[0] + 2.0f * color[1] - nl[1] - nr[1]) * .5f;
171 color[0] = (nt[0] + nb[0] + 2.0f * color[1] - nt[1] - nb[1]) * .5f;
172 color[2] = (nl[2] + nr[2] + 2.0f * color[1] - nl[1] - nr[1]) * .5f;
178 const float *ntl = buf - 4 - 4 * roi_out->
width;
179 const float *ntr = buf + 4 - 4 * roi_out->
width;
180 const float *nbl = buf - 4 + 4 * roi_out->
width;
181 const float *nbr = buf + 4 + 4 * roi_out->
width;
186 const float diff1 = fabsf(ntl[2] - nbr[2]) + fabsf(ntl[1] - color[1]) + fabsf(nbr[1] - color[1]);
187 const float guess1 = ntl[2] + nbr[2] + 2.0f * color[1] - ntl[1] - nbr[1];
188 const float diff2 = fabsf(ntr[2] - nbl[2]) + fabsf(ntr[1] - color[1]) + fabsf(nbl[1] - color[1]);
189 const float guess2 = ntr[2] + nbl[2] + 2.0f * color[1] - ntr[1] - nbl[1];
191 color[2] = guess2 * .5f;
192 else if(diff1 < diff2)
193 color[2] = guess1 * .5f;
195 color[2] = (guess1 + guess2) * .25f;
199 const float diff1 = fabsf(ntl[0] - nbr[0]) + fabsf(ntl[1] - color[1]) + fabsf(nbr[1] - color[1]);
200 const float guess1 = ntl[0] + nbr[0] + 2.0f * color[1] - ntl[1] - nbr[1];
201 const float diff2 = fabsf(ntr[0] - nbl[0]) + fabsf(ntr[1] - color[1]) + fabsf(nbl[1] - color[1]);
202 const float guess2 = ntr[0] + nbl[0] + 2.0f * color[1] - ntr[1] - nbl[1];
204 color[0] = guess2 * .5f;
205 else if(diff1 < diff2)
206 color[0] = guess1 * .5f;
208 color[0] = (guess1 + guess2) * .25f;
212 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:194
const double thrs
Definition chart/main.c:54
static int FC(const int row, const int col, const unsigned int filters)
Definition data/kernels/common.h:47
static int 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:24