| @@ -45,6 +45,7 @@ typedef struct ATADenoiseContext { · 44 unmodified lines |
| 45 | 45 | |
| 46 | 46 | float fthra[4], fthrb[4]; |
| 47 | 47 | int thra[4], thrb[4]; |
| 48 | + int algorithm; |
| 48 | 49 | |
| 49 | 50 | int planes; |
| 50 | 51 | int nb_planes; |
| @@ -74,6 +75,9 @@ static const AVOption atadenoise_options[] = { · 23 unmodified lines |
| 74 | 75 | { "2b", "set threshold B for 3rd plane", OFFSET(fthrb[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS }, |
| 75 | 76 | { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=9}, 5, SIZE, FLAGS }, |
| 76 | 77 | { "p", "set what planes to filter", OFFSET(planes), AV_OPT_TYPE_FLAGS, {.i64=7}, 0, 15, FLAGS }, |
| 78 | + { "a", "set variant of algorithm", OFFSET(algorithm),AV_OPT_TYPE_INT, {.i64=PARALLEL}, 0, NB_ATAA-1, FLAGS, "a" }, |
| 79 | + { "p", "parallel", 0, AV_OPT_TYPE_CONST, {.i64=PARALLEL}, 0, 0, FLAGS, "a" }, |
| 80 | + { "s", "serial", 0, AV_OPT_TYPE_CONST, {.i64=SERIAL}, 0, 0, FLAGS, "a" }, |
| 77 | 81 | { NULL } |
| 78 | 82 | }; |
| 79 | 83 | |
| @@ -175,6 +179,55 @@ static void filter_row##name(const uint8_t *ssrc, uint8_t *ddst, \ · 95 unmodified lines |
| 175 | 179 | FILTER_ROW(uint8_t, 8) |
| 176 | 180 | FILTER_ROW(uint16_t, 16) |
| 177 | 181 | |
| 182 | +#define FILTER_ROW_SERIAL(type, name) \ |
| 183 | +static void filter_row##name##_serial(const uint8_t *ssrc, uint8_t *ddst, \ |
| 184 | + const uint8_t *ssrcf[SIZE], \ |
| 185 | + int w, int mid, int size, \ |
| 186 | + int thra, int thrb) \ |
| 187 | +{ \ |
| 188 | + const type *src = (const type *)ssrc; \ |
| 189 | + const type **srcf = (const type **)ssrcf; \ |
| 190 | + type *dst = (type *)ddst; \ |
| 191 | + \ |
| 192 | + for (int x = 0; x < w; x++) { \ |
| 193 | + const int srcx = src[x]; \ |
| 194 | + unsigned lsumdiff = 0, rsumdiff = 0; \ |
| 195 | + unsigned ldiff, rdiff; \ |
| 196 | + unsigned sum = srcx; \ |
| 197 | + int l = 0, r = 0; \ |
| 198 | + int srcjx, srcix; \ |
| 199 | + \ |
| 200 | + for (int j = mid - 1; j >= 0; j--) { \ |
| 201 | + srcjx = srcf[j][x]; \ |
| 202 | + \ |
| 203 | + ldiff = FFABS(srcx - srcjx); \ |
| 204 | + lsumdiff += ldiff; \ |
| 205 | + if (ldiff > thra || \ |
| 206 | + lsumdiff > thrb) \ |
| 207 | + break; \ |
| 208 | + l++; \ |
| 209 | + sum += srcjx; \ |
| 210 | + } \ |
| 211 | + \ |
| 212 | + for (int i = mid + 1; i < size; i++) { \ |
| 213 | + srcix = srcf[i][x]; \ |
| 214 | + \ |
| 215 | + rdiff = FFABS(srcx - srcix); \ |
| 216 | + rsumdiff += rdiff; \ |
| 217 | + if (rdiff > thra || \ |
| 218 | + rsumdiff > thrb) \ |
| 219 | + break; \ |
| 220 | + r++; \ |
| 221 | + sum += srcix; \ |
| 222 | + } \ |
| 223 | + \ |
| 224 | + dst[x] = (sum + ((r + l + 1) >> 1)) / (r + l + 1); \ |
| 225 | + } \ |
| 226 | +} |
| 227 | + |
| 228 | +FILTER_ROW_SERIAL(uint8_t, 8) |
| 229 | +FILTER_ROW_SERIAL(uint16_t, 16) |
| 230 | + |
| 178 | 231 | static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| 179 | 232 | { |
| 180 | 233 | ATADenoiseContext *s = ctx->priv; |
| @@ -238,9 +291,9 @@ static int config_input(AVFilterLink *inlink) · 57 unmodified lines |
| 238 | 291 | depth = desc->comp[0].depth; |
| 239 | 292 | s->filter_slice = filter_slice; |
| 240 | 293 | if (depth == 8) |
| 241 | | − s->dsp.filter_row = filter_row8; |
| 294 | + s->dsp.filter_row = s->algorithm == PARALLEL ? filter_row8 : filter_row8_serial; |
| 242 | 295 | else |
| 243 | | − s->dsp.filter_row = filter_row16; |
| 296 | + s->dsp.filter_row = s->algorithm == PARALLEL ? filter_row16 : filter_row16_serial; |
| 244 | 297 | |
| 245 | 298 | s->thra[0] = s->fthra[0] * (1 << depth) - 1; |
| 246 | 299 | s->thra[1] = s->fthra[1] * (1 << depth) - 1; |
| @@ -250,7 +303,7 @@ static int config_input(AVFilterLink *inlink) · 3 unmodified lines |
| 250 | 303 | s->thrb[2] = s->fthrb[2] * (1 << depth) - 1; |
| 251 | 304 | |
| 252 | 305 | if (ARCH_X86) |
| 253 | | − ff_atadenoise_init_x86(&s->dsp, depth); |
| 306 | + ff_atadenoise_init_x86(&s->dsp, depth, s->algorithm); |
| 254 | 307 | |
| 255 | 308 | return 0; |
| 256 | 309 | } |