31 for(
int j = 0; j < roi_out->
height; j++)
32 for(
int i = 0;
i < roi_out->
width;
i++)
34 if(
i == 3 && j >= 3 && j < roi_out->
height - 3)
i = roi_out->
width - 3;
35 if(
i == roi_out->
width)
break;
36 memset(sum, 0,
sizeof(
float) * 8);
37 for(
int y = j - 1; y != j + 2; y++)
38 for(
int x =
i - 1;
x !=
i + 2;
x++)
40 const int yy = y + roi_out->
y, xx =
x + roi_out->
x;
41 if((yy >= 0) && (xx >= 0) && (yy < roi_in->
height) && (xx < roi_in->
width))
43 const int f =
FC(y,
x, filters);
44 sum[
f] += in[(size_t)yy * roi_in->
width + xx];
48 const int f =
FC(j,
i, filters);
49 for(
int c = 0; c < 3; c++)
51 if(c !=
f && sum[c + 4] > 0.0f)
52 out[4 * ((size_t)j * roi_out->
width +
i) + c] = sum[c] / sum[c + 4];
54 out[4 * ((size_t)j * roi_out->
width +
i) + c]
55 = in[((size_t)j + roi_out->
y) * roi_in->
width +
i + roi_out->
x];
60 const float *input = in;
71 for(
int j = 3; j < roi_out->
height - 3; j++)
73 float *buf =
out + (size_t)4 * roi_out->
width * j + 4 * 3;
74 const float *buf_in = input + (size_t)roi_in->
width * (j + roi_out->
y) + 3 + roi_out->
x;
75 for(
int i = 3;
i < roi_out->
width - 3;
i++)
77 const int c =
FC(j,
i, filters);
79 const float pc = buf_in[0];
85 const float pym = buf_in[-roi_in->
width * 1];
86 const float pym2 = buf_in[-roi_in->
width * 2];
87 const float pym3 = buf_in[-roi_in->
width * 3];
88 const float pyM = buf_in[+roi_in->
width * 1];
89 const float pyM2 = buf_in[+roi_in->
width * 2];
90 const float pyM3 = buf_in[+roi_in->
width * 3];
91 const float pxm = buf_in[-1];
92 const float pxm2 = buf_in[-2];
93 const float pxm3 = buf_in[-3];
94 const float pxM = buf_in[+1];
95 const float pxM2 = buf_in[+2];
96 const float pxM3 = buf_in[+3];
98 const float guessx = (pxm + pc + pxM) * 2.0f - pxM2 - pxm2;
99 const float diffx = (fabsf(pxm2 - pc) + fabsf(pxM2 - pc) + fabsf(pxm - pxM)) * 3.0f
100 + (fabsf(pxM3 - pxM) + fabsf(pxm3 - pxm)) * 2.0f;
101 const float guessy = (pym + pc + pyM) * 2.0f - pyM2 - pym2;
102 const float diffy = (fabsf(pym2 - pc) + fabsf(pyM2 - pc) + fabsf(pym - pyM)) * 3.0f
103 + (fabsf(pyM3 - pyM) + fabsf(pym3 - pym)) * 2.0f;
107 const float m = fminf(pym, pyM);
108 const float M = fmaxf(pym, pyM);
109 color[1] = fmaxf(fminf(guessy * .25f,
M),
m);
113 const float m = fminf(pxm, pxM);
114 const float M = fmaxf(pxm, pxM);
115 color[1] = fmaxf(fminf(guessx * .25f,
M),
m);
124 memcpy(buf, color,
sizeof(
float) * 4);
134 for(
int j = 1; j < roi_out->
height - 1; j++)
136 float *buf =
out + (size_t)4 * roi_out->
width * j + 4;
137 for(
int i = 1;
i < roi_out->
width - 1;
i++)
140 const int c =
FC(j,
i, filters);
145 if(__builtin_expect(c & 1, 1))
149 const float *nt = buf - 4 * roi_out->
width;
150 const float *nb = buf + 4 * roi_out->
width;
151 const float *nl = buf - 4;
152 const float *nr = buf + 4;
153 if(
FC(j,
i + 1, filters) == 0)
155 color[2] = (nt[2] + nb[2] + 2.0f * color[1] - nt[1] - nb[1]) * .5f;
156 color[0] = (nl[0] + nr[0] + 2.0f * color[1] - nl[1] - nr[1]) * .5f;
161 color[0] = (nt[0] + nb[0] + 2.0f * color[1] - nt[1] - nb[1]) * .5f;
162 color[2] = (nl[2] + nr[2] + 2.0f * color[1] - nl[1] - nr[1]) * .5f;
168 const float *ntl = buf - 4 - 4 * roi_out->
width;
169 const float *ntr = buf + 4 - 4 * roi_out->
width;
170 const float *nbl = buf - 4 + 4 * roi_out->
width;
171 const float *nbr = buf + 4 + 4 * roi_out->
width;
176 const float diff1 = fabsf(ntl[2] - nbr[2]) + fabsf(ntl[1] - color[1]) + fabsf(nbr[1] - color[1]);
177 const float guess1 = ntl[2] + nbr[2] + 2.0f * color[1] - ntl[1] - nbr[1];
178 const float diff2 = fabsf(ntr[2] - nbl[2]) + fabsf(ntr[1] - color[1]) + fabsf(nbl[1] - color[1]);
179 const float guess2 = ntr[2] + nbl[2] + 2.0f * color[1] - ntr[1] - nbl[1];
181 color[2] = guess2 * .5f;
182 else if(diff1 < diff2)
183 color[2] = guess1 * .5f;
185 color[2] = (guess1 + guess2) * .25f;
189 const float diff1 = fabsf(ntl[0] - nbr[0]) + fabsf(ntl[1] - color[1]) + fabsf(nbr[1] - color[1]);
190 const float guess1 = ntl[0] + nbr[0] + 2.0f * color[1] - ntl[1] - nbr[1];
191 const float diff2 = fabsf(ntr[0] - nbl[0]) + fabsf(ntr[1] - color[1]) + fabsf(nbl[1] - color[1]);
192 const float guess2 = ntr[0] + nbl[0] + 2.0f * color[1] - ntr[1] - nbl[1];
194 color[0] = guess2 * .5f;
195 else if(diff1 < diff2)
196 color[0] = guess1 * .5f;
198 color[0] = (guess1 + guess2) * .25f;
202 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:182
const double thrs
Definition chart/main.c:54
#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
static __DT_CLONE_TARGETS__ 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:22