History

avfilter/vf_atadenoise: add option to use additional algorithm

Paul B Mahol committed 7 years ago

Commit 71e33c61 parent 295d99b4 files · +73 −6Browse files

Showing the changes to libavfilter (3 of 4 files). Show all

Unified · Split

3 files
  1. libavfilter/atadenoise.h +7 −1
  2. libavfilter/vf_atadenoise.c +56 −3
  3. libavfilter/x86/vf_atadenoise_init.c +2 −2
libavfilter/atadenoise.h+7−1
@@ -24,6 +24,12 @@ · 23 unmodified lines
2424 #include <stddef.h>
2525 #include <stdint.h>
2626
27+enum ATAAlgorithm {
28+ PARALLEL,
29+ SERIAL,
30+ NB_ATAA
31+};
32+
2733 typedef struct ATADenoiseDSPContext {
2834 void (*filter_row)(const uint8_t *src, uint8_t *dst,
2935 const uint8_t **srcf,
@@ -31,6 +37,6 @@ typedef struct ATADenoiseDSPContext { · 1 unmodified line
3137 int thra, int thrb);
3238 } ATADenoiseDSPContext;
3339
34−void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth);
40+void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth, int algorithm);
3541
3642 #endif /* AVFILTER_ATADENOISE_H */
libavfilter/vf_atadenoise.c+56−3
@@ -45,6 +45,7 @@ typedef struct ATADenoiseContext { · 44 unmodified lines
4545
4646 float fthra[4], fthrb[4];
4747 int thra[4], thrb[4];
48+ int algorithm;
4849
4950 int planes;
5051 int nb_planes;
@@ -74,6 +75,9 @@ static const AVOption atadenoise_options[] = { · 23 unmodified lines
7475 { "2b", "set threshold B for 3rd plane", OFFSET(fthrb[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS },
7576 { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=9}, 5, SIZE, FLAGS },
7677 { "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" },
7781 { NULL }
7882 };
7983
@@ -175,6 +179,55 @@ static void filter_row##name(const uint8_t *ssrc, uint8_t *ddst, \ · 95 unmodified lines
175179 FILTER_ROW(uint8_t, 8)
176180 FILTER_ROW(uint16_t, 16)
177181
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+
178231 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
179232 {
180233 ATADenoiseContext *s = ctx->priv;
@@ -238,9 +291,9 @@ static int config_input(AVFilterLink *inlink) · 57 unmodified lines
238291 depth = desc->comp[0].depth;
239292 s->filter_slice = filter_slice;
240293 if (depth == 8)
241− s->dsp.filter_row = filter_row8;
294+ s->dsp.filter_row = s->algorithm == PARALLEL ? filter_row8 : filter_row8_serial;
242295 else
243− s->dsp.filter_row = filter_row16;
296+ s->dsp.filter_row = s->algorithm == PARALLEL ? filter_row16 : filter_row16_serial;
244297
245298 s->thra[0] = s->fthra[0] * (1 << depth) - 1;
246299 s->thra[1] = s->fthra[1] * (1 << depth) - 1;
@@ -250,7 +303,7 @@ static int config_input(AVFilterLink *inlink) · 3 unmodified lines
250303 s->thrb[2] = s->fthrb[2] * (1 << depth) - 1;
251304
252305 if (ARCH_X86)
253− ff_atadenoise_init_x86(&s->dsp, depth);
306+ ff_atadenoise_init_x86(&s->dsp, depth, s->algorithm);
254307
255308 return 0;
256309 }
libavfilter/x86/vf_atadenoise_init.c+2−2
@@ -30,11 +30,11 @@ void ff_atadenoise_filter_row8_sse4(const uint8_t *src, uint8_t *dst, · 29 unmodified lines
3030 int w, int mid, int size,
3131 int thra, int thrb);
3232
33−av_cold void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth)
33+av_cold void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth, int algorithm)
3434 {
3535 int cpu_flags = av_get_cpu_flags();
3636
37− if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8) {
37+ if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8 && algorithm == PARALLEL) {
3838 dsp->filter_row = ff_atadenoise_filter_row8_sse4;
3939 }
4040 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t