summaryrefslogtreecommitdiff
path: root/libavfilter/vf_amplify.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-02-17 22:00:59 +0100
committerPaul B Mahol <onemda@gmail.com>2022-02-17 22:19:46 +0100
commitb66afd1caa3e80e144b7fe55277f9eb0e65f9570 (patch)
tree662d6ff5235ad7b833dc81975dd0fff2d09656c6 /libavfilter/vf_amplify.c
parentc644d6605d2373bfb0540b25c56c2279d1dbe86c (diff)
downloadffmpeg-b66afd1caa3e80e144b7fe55277f9eb0e65f9570.tar.gz
avfilter/vf_amplify: add float formats support
Diffstat (limited to 'libavfilter/vf_amplify.c')
-rw-r--r--libavfilter/vf_amplify.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/libavfilter/vf_amplify.c b/libavfilter/vf_amplify.c
index c0a30f88a7..3c393ecfb0 100644
--- a/libavfilter/vf_amplify.c
+++ b/libavfilter/vf_amplify.c
@@ -37,8 +37,8 @@ typedef struct AmplifyContext {
float tolerance;
int planes;
- int llimit;
- int hlimit;
+ float llimit;
+ float hlimit;
int nb_inputs;
int nb_frames;
@@ -53,7 +53,7 @@ typedef struct AmplifyContext {
static const enum AVPixelFormat pixel_fmts[] = {
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9,
AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14,
- AV_PIX_FMT_GRAY16,
+ AV_PIX_FMT_GRAY16, AV_PIX_FMT_GRAYF32,
AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
@@ -74,6 +74,7 @@ static const enum AVPixelFormat pixel_fmts[] = {
AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA422P16,
AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16,
AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
+ AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
AV_PIX_FMT_NONE
};
@@ -95,6 +96,9 @@ typedef struct ThreadData {
} ThreadData;
#define AMPLIFY_SLICE(type, stype, clip) \
+ const stype llimit = s->llimit; \
+ const stype hlimit = s->hlimit; \
+ \
for (int p = 0; p < s->nb_planes; p++) { \
const int slice_start = (s->height[p] * jobnr) / nb_jobs; \
const int slice_end = (s->height[p] * (jobnr+1)) / nb_jobs; \
@@ -123,13 +127,13 @@ typedef struct ThreadData {
diff = src - avg; \
\
if (fabsf(diff) < threshold && fabsf(diff) > tolerance) { \
- int amp; \
+ stype amp; \
if (diff < 0) { \
amp = -FFMIN(FFABS(diff * factor), llimit); \
} else { \
amp = FFMIN(FFABS(diff * factor), hlimit); \
} \
- dst[x] = av_clip_uintp2_c(src + amp, depth); \
+ dst[x] = clip(src + amp, depth); \
} else { \
dst[x] = src; \
} \
@@ -141,6 +145,7 @@ typedef struct ThreadData {
#define CLIP8(x, depth) av_clip_uint8(x)
#define CLIP16(x, depth) av_clip_uintp2_c(x, depth)
+#define NOP(x, depth) (x)
static int amplify_frame(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
@@ -153,14 +158,14 @@ static int amplify_frame(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs
const float threshold = s->threshold;
const float tolerance = s->tolerance;
const float factor = s->factor;
- const int llimit = s->llimit;
- const int hlimit = s->hlimit;
const int depth = s->depth;
if (s->depth <= 8) {
AMPLIFY_SLICE(uint8_t, int, CLIP8)
- } else {
+ } else if (s->depth <= 16) {
AMPLIFY_SLICE(uint16_t, int, CLIP16)
+ } else {
+ AMPLIFY_SLICE(float, float, NOP)
}
return 0;
@@ -247,8 +252,8 @@ static const AVOption amplify_options[] = {
{ "factor", "set factor", OFFSET(factor), AV_OPT_TYPE_FLOAT, {.dbl=2}, 0, UINT16_MAX, .flags = VFT },
{ "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=10}, 0, UINT16_MAX, .flags = VFT },
{ "tolerance", "set tolerance", OFFSET(tolerance), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, UINT16_MAX, .flags = VFT },
- { "low", "set low limit for amplification", OFFSET(llimit), AV_OPT_TYPE_INT, {.i64=UINT16_MAX}, 0, UINT16_MAX, .flags = VFT },
- { "high", "set high limit for amplification", OFFSET(hlimit), AV_OPT_TYPE_INT, {.i64=UINT16_MAX}, 0, UINT16_MAX, .flags = VFT },
+ { "low", "set low limit for amplification", OFFSET(llimit), AV_OPT_TYPE_FLOAT, {.dbl=UINT16_MAX}, 0, UINT16_MAX, .flags = VFT },
+ { "high", "set high limit for amplification", OFFSET(hlimit), AV_OPT_TYPE_FLOAT, {.dbl=UINT16_MAX}, 0, UINT16_MAX, .flags = VFT },
{ "planes", "set what planes to filter", OFFSET(planes), AV_OPT_TYPE_FLAGS, {.i64=7}, 0, 15, VFT },
{ NULL },
};