Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-10-21 21:08:24 +0300
committerPaul B Mahol <onemda@gmail.com>2022-10-21 21:11:14 +0300
commitda4ff1d5365a750fe649d0a63ded2052549e33ff (patch)
tree325aa53a8edfde4f52d01047d3ca91a1d9acb023 /libavfilter
parenta1a87b7a24532c87844eb21e20b52d898946d17f (diff)
avfilter/vf_maskedthreshold: implement diff mode
To be useful for adaptive thresholding with threshold filter.
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_maskedthreshold.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/libavfilter/vf_maskedthreshold.c b/libavfilter/vf_maskedthreshold.c
index 4d3745232e..53731eefc9 100644
--- a/libavfilter/vf_maskedthreshold.c
+++ b/libavfilter/vf_maskedthreshold.c
@@ -32,6 +32,7 @@ typedef struct MaskedThresholdContext {
int threshold;
int planes;
+ int mode;
int linesize[4];
int planewidth[4], planeheight[4];
@@ -43,15 +44,19 @@ typedef struct MaskedThresholdContext {
} MaskedThresholdContext;
#define OFFSET(x) offsetof(MaskedThresholdContext, x)
-#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
+#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
typedef struct ThreadData {
AVFrame *src, *ref, *dst;
} ThreadData;
static const AVOption maskedthreshold_options[] = {
- { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_INT, {.i64=1}, 0, UINT16_MAX, FLAGS },
- { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS },
+ { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_INT, {.i64=1}, 0, UINT16_MAX, TFLAGS },
+ { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, TFLAGS },
+ { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "mode" },
+ { "abs", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
+ { "diff", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
{ NULL }
};
@@ -77,13 +82,29 @@ static const enum AVPixelFormat pix_fmts[] = {
AV_PIX_FMT_NONE
};
-static void threshold8(const uint8_t *src, const uint8_t *ref, uint8_t *dst, int threshold, int w)
+static void threshold8_diff(const uint8_t *src, const uint8_t *ref, uint8_t *dst, int threshold, int w)
+{
+ for (int x = 0; x < w; x++)
+ dst[x] = (ref[x] - src[x] <= threshold) ? FFMAX(ref[x] - threshold, 0): src[x];
+}
+
+static void threshold8_abs(const uint8_t *src, const uint8_t *ref, uint8_t *dst, int threshold, int w)
{
for (int x = 0; x < w; x++)
dst[x] = FFABS(src[x] - ref[x]) <= threshold ? src[x] : ref[x];
}
-static void threshold16(const uint8_t *ssrc, const uint8_t *rref, uint8_t *ddst, int threshold, int w)
+static void threshold16_diff(const uint8_t *ssrc, const uint8_t *rref, uint8_t *ddst, int threshold, int w)
+{
+ const uint16_t *src = (const uint16_t *)ssrc;
+ const uint16_t *ref = (const uint16_t *)rref;
+ uint16_t *dst = (uint16_t *)ddst;
+
+ for (int x = 0; x < w; x++)
+ dst[x] = (ref[x] - src[x] <= threshold) ? FFMAX(ref[x] - threshold, 0): src[x];
+}
+
+static void threshold16_abs(const uint8_t *ssrc, const uint8_t *rref, uint8_t *ddst, int threshold, int w)
{
const uint16_t *src = (const uint16_t *)ssrc;
const uint16_t *ref = (const uint16_t *)rref;
@@ -115,9 +136,9 @@ static int config_input(AVFilterLink *inlink)
s->depth = desc->comp[0].depth;
if (desc->comp[0].depth == 8)
- s->maskedthreshold = threshold8;
+ s->maskedthreshold = s->mode ? threshold8_diff : threshold8_abs;
else
- s->maskedthreshold = threshold16;
+ s->maskedthreshold = s->mode ? threshold16_diff : threshold16_abs;
return 0;
}