History

avfilter/vf_maskedthreshold: implement diff mode

To be useful for adaptive thresholding with threshold filter.

Paul B Mahol committed 4 years ago

Commit da4ff1d1 parent a1a87b72 files · +32 −7Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_maskedthreshold.c +28 −7
doc/filters.texi+4−0
@@ -16623,6 +16623,10 @@ video streams. · 16622 unmodified lines
1662316623 Set which planes will be processed as bitmap, unprocessed planes will be
1662416624 copied from second stream.
1662516625 By default value 0xf, all planes will be processed.
16626+
16627+@item mode
16628+Set mode of filter operation. Can be @code{abs} or @code{diff}.
16629+Default is @code{abs}.
1662616630 @end table
1662716631
1662816632 @subsection Commands
libavfilter/vf_maskedthreshold.c+28−7
@@ -32,6 +32,7 @@ typedef struct MaskedThresholdContext { · 31 unmodified lines
3232
3333 int threshold;
3434 int planes;
35+ int mode;
3536
3637 int linesize[4];
3738 int planewidth[4], planeheight[4];
@@ -43,15 +44,19 @@ typedef struct MaskedThresholdContext { · 5 unmodified lines
4344 } MaskedThresholdContext;
4445
4546 #define OFFSET(x) offsetof(MaskedThresholdContext, x)
46−#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
47+#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
48+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
4749
4850 typedef struct ThreadData {
4951 AVFrame *src, *ref, *dst;
5052 } ThreadData;
5153
5254 static const AVOption maskedthreshold_options[] = {
53− { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_INT, {.i64=1}, 0, UINT16_MAX, FLAGS },
54− { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS },
55+ { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_INT, {.i64=1}, 0, UINT16_MAX, TFLAGS },
56+ { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, TFLAGS },
57+ { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "mode" },
58+ { "abs", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
59+ { "diff", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
5560 { NULL }
5661 };
5762
@@ -77,13 +82,29 @@ static const enum AVPixelFormat pix_fmts[] = { · 19 unmodified lines
7782 AV_PIX_FMT_NONE
7883 };
7984
80−static void threshold8(const uint8_t *src, const uint8_t *ref, uint8_t *dst, int threshold, int w)
85+static void threshold8_diff(const uint8_t *src, const uint8_t *ref, uint8_t *dst, int threshold, int w)
86+{
87+ for (int x = 0; x < w; x++)
88+ dst[x] = (ref[x] - src[x] <= threshold) ? FFMAX(ref[x] - threshold, 0): src[x];
89+}
90+
91+static void threshold8_abs(const uint8_t *src, const uint8_t *ref, uint8_t *dst, int threshold, int w)
8192 {
8293 for (int x = 0; x < w; x++)
8394 dst[x] = FFABS(src[x] - ref[x]) <= threshold ? src[x] : ref[x];
8495 }
8596
86−static void threshold16(const uint8_t *ssrc, const uint8_t *rref, uint8_t *ddst, int threshold, int w)
97+static void threshold16_diff(const uint8_t *ssrc, const uint8_t *rref, uint8_t *ddst, int threshold, int w)
98+{
99+ const uint16_t *src = (const uint16_t *)ssrc;
100+ const uint16_t *ref = (const uint16_t *)rref;
101+ uint16_t *dst = (uint16_t *)ddst;
102+
103+ for (int x = 0; x < w; x++)
104+ dst[x] = (ref[x] - src[x] <= threshold) ? FFMAX(ref[x] - threshold, 0): src[x];
105+}
106+
107+static void threshold16_abs(const uint8_t *ssrc, const uint8_t *rref, uint8_t *ddst, int threshold, int w)
87108 {
88109 const uint16_t *src = (const uint16_t *)ssrc;
89110 const uint16_t *ref = (const uint16_t *)rref;
@@ -115,9 +136,9 @@ static int config_input(AVFilterLink *inlink) · 25 unmodified lines
115136 s->depth = desc->comp[0].depth;
116137
117138 if (desc->comp[0].depth == 8)
118− s->maskedthreshold = threshold8;
139+ s->maskedthreshold = s->mode ? threshold8_diff : threshold8_abs;
119140 else
120− s->maskedthreshold = threshold16;
141+ s->maskedthreshold = s->mode ? threshold16_diff : threshold16_abs;
121142
122143 return 0;
123144 }

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