aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2021-02-11 00:40:04 +0100
committerPaul B Mahol <onemda@gmail.com>2021-02-11 00:45:08 +0100
commit16c09b465972b5221811a0f05da8a744966a702a (patch)
tree52a8db57f531c06c104cbf9b61cd4d2aafb8ddcb
parent05b394d5376fe987046b9f52da535301365102ec (diff)
downloadffmpeg-16c09b465972b5221811a0f05da8a744966a702a.tar.gz
avfilter/vf_lagfun: use macro
-rw-r--r--libavfilter/vf_lagfun.c130
1 files changed, 47 insertions, 83 deletions
diff --git a/libavfilter/vf_lagfun.c b/libavfilter/vf_lagfun.c
index 9e2e0726c7..36b19b3f83 100644
--- a/libavfilter/vf_lagfun.c
+++ b/libavfilter/vf_lagfun.c
@@ -77,91 +77,55 @@ typedef struct ThreadData {
AVFrame *in, *out;
} ThreadData;
-static int lagfun_frame8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
-{
- LagfunContext *s = ctx->priv;
- const float decay = s->decay;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
-
- for (int p = 0; p < s->nb_planes; p++) {
- const int slice_start = (s->planeheight[p] * jobnr) / nb_jobs;
- const int slice_end = (s->planeheight[p] * (jobnr+1)) / nb_jobs;
- const uint8_t *src = in->data[p] + slice_start * in->linesize[p];
- float *osrc = s->old[p] + slice_start * s->planewidth[p];
- uint8_t *dst = out->data[p] + slice_start * out->linesize[p];
-
- if (!((1 << p) & s->planes)) {
- av_image_copy_plane(dst, out->linesize[p],
- src, in->linesize[p],
- s->linesize[p], slice_end - slice_start);
- continue;
- }
-
- for (int y = slice_start; y < slice_end; y++) {
- for (int x = 0; x < s->planewidth[p]; x++) {
- float v = FFMAX(src[x], osrc[x] * decay);
-
- osrc[x] = v;
- if (ctx->is_disabled) {
- dst[x] = src[x];
- } else {
- dst[x] = lrintf(v);
- }
- }
-
- src += in->linesize[p];
- osrc += s->planewidth[p];
- dst += out->linesize[p];
- }
- }
-
- return 0;
+#define LAGFUN(name, type) \
+static int lagfun_frame##name(AVFilterContext *ctx, void *arg, \
+ int jobnr, int nb_jobs) \
+{ \
+ LagfunContext *s = ctx->priv; \
+ const float decay = s->decay; \
+ ThreadData *td = arg; \
+ AVFrame *in = td->in; \
+ AVFrame *out = td->out; \
+ \
+ for (int p = 0; p < s->nb_planes; p++) { \
+ const int slice_start = (s->planeheight[p] * jobnr) / nb_jobs; \
+ const int slice_end = (s->planeheight[p] * (jobnr+1)) / nb_jobs; \
+ const type *src = (const type *)in->data[p] + \
+ slice_start * in->linesize[p] / sizeof(type); \
+ float *osrc = s->old[p] + slice_start * s->planewidth[p]; \
+ type *dst = (type *)out->data[p] + \
+ slice_start * out->linesize[p] / sizeof(type); \
+ \
+ if (!((1 << p) & s->planes)) { \
+ av_image_copy_plane((uint8_t *)dst, out->linesize[p], \
+ (const uint8_t *)src, in->linesize[p], \
+ s->linesize[p], slice_end - slice_start); \
+ continue; \
+ } \
+ \
+ for (int y = slice_start; y < slice_end; y++) { \
+ for (int x = 0; x < s->planewidth[p]; x++) { \
+ float v = FFMAX(src[x], osrc[x] * decay); \
+ \
+ osrc[x] = v; \
+ if (ctx->is_disabled) { \
+ dst[x] = src[x]; \
+ } else { \
+ dst[x] = lrintf(v); \
+ } \
+ } \
+ \
+ src += in->linesize[p] / sizeof(type); \
+ osrc += s->planewidth[p]; \
+ dst += out->linesize[p] / sizeof(type); \
+ } \
+ } \
+ \
+ return 0; \
}
-static int lagfun_frame16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
-{
- LagfunContext *s = ctx->priv;
- const float decay = s->decay;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
-
- for (int p = 0; p < s->nb_planes; p++) {
- const int slice_start = (s->planeheight[p] * jobnr) / nb_jobs;
- const int slice_end = (s->planeheight[p] * (jobnr+1)) / nb_jobs;
- const uint16_t *src = (const uint16_t *)in->data[p] + slice_start * in->linesize[p] / 2;
- float *osrc = s->old[p] + slice_start * s->planewidth[p];
- uint16_t *dst = (uint16_t *)out->data[p] + slice_start * out->linesize[p] / 2;
-
- if (!((1 << p) & s->planes)) {
- av_image_copy_plane((uint8_t *)dst, out->linesize[p],
- (uint8_t *)src, in->linesize[p],
- s->linesize[p], slice_end - slice_start);
- continue;
- }
-
- for (int y = slice_start; y < slice_end; y++) {
- for (int x = 0; x < s->planewidth[p]; x++) {
- float v = FFMAX(src[x], osrc[x] * decay);
-
- osrc[x] = v;
- if (ctx->is_disabled) {
- dst[x] = src[x];
- } else {
- dst[x] = lrintf(v);
- }
- }
-
- src += in->linesize[p] / 2;
- osrc += s->planewidth[p];
- dst += out->linesize[p] / 2;
- }
- }
-
- return 0;
-}
+LAGFUN(8, uint8_t)
+LAGFUN(16, uint16_t)
static int config_output(AVFilterLink *outlink)
{