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

Unified · Split

4 files
  1. doc/filters.texi +8 −0
  2. libavfilter/atadenoise.h +7 −1
  3. libavfilter/vf_atadenoise.c +56 −3
  4. libavfilter/x86/vf_atadenoise_init.c +2 −2
doc/filters.texi+8−0
@@ -6271,6 +6271,14 @@ number in range [5, 129]. · 6270 unmodified lines
6271 6271
6272@item p6272@item p
6273Set what planes of frame filter will use for averaging. Default is all.6273Set what planes of frame filter will use for averaging. Default is all.
6274
6275@item a
6276Set what variant of algorithm filter will use for averaging. Default is @code{p} parallel.
6277Alternatively can be set to @code{s} serial.
6278
6279Parallel can be faster then serial, while other way around is never true.
6280Parallel will abort early on first change being greater then thresholds, while serial
6281will continue processing other side of frames if they are equal or bellow thresholds.
6274@end table6282@end table
6275 6283
6276@section avgblur6284@section avgblur
libavfilter/atadenoise.h+7−1
@@ -24,6 +24,12 @@ · 23 unmodified lines
24#include <stddef.h>24#include <stddef.h>
25#include <stdint.h>25#include <stdint.h>
26 26
27enum ATAAlgorithm {
28 PARALLEL,
29 SERIAL,
30 NB_ATAA
31};
32
27typedef struct ATADenoiseDSPContext {33typedef struct ATADenoiseDSPContext {
28 void (*filter_row)(const uint8_t *src, uint8_t *dst,34 void (*filter_row)(const uint8_t *src, uint8_t *dst,
29 const uint8_t **srcf,35 const uint8_t **srcf,
@@ -31,6 +37,6 @@ typedef struct ATADenoiseDSPContext { · 1 unmodified line
31 int thra, int thrb);37 int thra, int thrb);
32} ATADenoiseDSPContext;38} ATADenoiseDSPContext;
33 39
34void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth);40void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth, int algorithm);
35 41
36#endif /* AVFILTER_ATADENOISE_H */42#endif /* AVFILTER_ATADENOISE_H */
libavfilter/vf_atadenoise.c+56−3
@@ -45,6 +45,7 @@ typedef struct ATADenoiseContext { · 44 unmodified lines
45 45
46 float fthra[4], fthrb[4];46 float fthra[4], fthrb[4];
47 int thra[4], thrb[4];47 int thra[4], thrb[4];
48 int algorithm;
48 49
49 int planes;50 int planes;
50 int nb_planes;51 int nb_planes;
@@ -74,6 +75,9 @@ static const AVOption atadenoise_options[] = { · 23 unmodified lines
74 { "2b", "set threshold B for 3rd plane", OFFSET(fthrb[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS },75 { "2b", "set threshold B for 3rd plane", OFFSET(fthrb[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS },
75 { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=9}, 5, SIZE, FLAGS },76 { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=9}, 5, SIZE, FLAGS },
76 { "p", "set what planes to filter", OFFSET(planes), AV_OPT_TYPE_FLAGS, {.i64=7}, 0, 15, FLAGS },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 { NULL }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
175FILTER_ROW(uint8_t, 8)179FILTER_ROW(uint8_t, 8)
176FILTER_ROW(uint16_t, 16)180FILTER_ROW(uint16_t, 16)
177 181
182#define FILTER_ROW_SERIAL(type, name) \
183static 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
228FILTER_ROW_SERIAL(uint8_t, 8)
229FILTER_ROW_SERIAL(uint16_t, 16)
230
178static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)231static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
179{232{
180 ATADenoiseContext *s = ctx->priv;233 ATADenoiseContext *s = ctx->priv;
@@ -238,9 +291,9 @@ static int config_input(AVFilterLink *inlink) · 57 unmodified lines
238 depth = desc->comp[0].depth;291 depth = desc->comp[0].depth;
239 s->filter_slice = filter_slice;292 s->filter_slice = filter_slice;
240 if (depth == 8)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 else295 else
243 s->dsp.filter_row = filter_row16;296 s->dsp.filter_row = s->algorithm == PARALLEL ? filter_row16 : filter_row16_serial;
244 297
245 s->thra[0] = s->fthra[0] * (1 << depth) - 1;298 s->thra[0] = s->fthra[0] * (1 << depth) - 1;
246 s->thra[1] = s->fthra[1] * (1 << depth) - 1;299 s->thra[1] = s->fthra[1] * (1 << depth) - 1;
@@ -250,7 +303,7 @@ static int config_input(AVFilterLink *inlink) · 3 unmodified lines
250 s->thrb[2] = s->fthrb[2] * (1 << depth) - 1;303 s->thrb[2] = s->fthrb[2] * (1 << depth) - 1;
251 304
252 if (ARCH_X86)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 return 0;308 return 0;
256}309}
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
30 int w, int mid, int size,30 int w, int mid, int size,
31 int thra, int thrb);31 int thra, int thrb);
32 32
33av_cold void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth)33av_cold void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth, int algorithm)
34{34{
35 int cpu_flags = av_get_cpu_flags();35 int cpu_flags = av_get_cpu_flags();
36 36
37 if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8) {37 if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8 && algorithm == PARALLEL) {
38 dsp->filter_row = ff_atadenoise_filter_row8_sse4;38 dsp->filter_row = ff_atadenoise_filter_row8_sse4;
39 }39 }
40}40}

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