avfilter/vf_idet: separate DSP parts

To avoid pulling in the entire libavfilter when using the DSP functions
from checkasm.

The rest of the struct is not needed outside vf_idet.c and was moved there.
This commit is contained in:
Niklas Haas
2025-09-16 14:11:21 +02:00
committed by Niklas Haas
parent 367febc491
commit 5830743363
7 changed files with 129 additions and 99 deletions
+1 -1
View File
@@ -358,7 +358,7 @@ OBJS-$(CONFIG_HYSTERESIS_FILTER) += vf_hysteresis.o framesync.o
OBJS-$(CONFIG_ICCDETECT_FILTER) += vf_iccdetect.o fflcms2.o
OBJS-$(CONFIG_ICCGEN_FILTER) += vf_iccgen.o fflcms2.o
OBJS-$(CONFIG_IDENTITY_FILTER) += vf_identity.o framesync.o
OBJS-$(CONFIG_IDET_FILTER) += vf_idet.o
OBJS-$(CONFIG_IDET_FILTER) += vf_idet.o vf_idetdsp.o
OBJS-$(CONFIG_IL_FILTER) += vf_il.o
OBJS-$(CONFIG_INFLATE_FILTER) += vf_neighbor.o
OBJS-$(CONFIG_INTERLACE_FILTER) += vf_tinterlace.o
+57 -41
View File
@@ -22,8 +22,57 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "filters.h"
#include "vf_idet.h"
#include "vf_idetdsp.h"
typedef enum {
TFF,
BFF,
PROGRESSIVE,
UNDETERMINED,
} Type;
typedef enum {
REPEAT_NONE,
REPEAT_TOP,
REPEAT_BOTTOM,
} RepeatedField;
typedef struct IDETContext {
const AVClass *class;
IDETDSPContext dsp;
float interlace_threshold;
float progressive_threshold;
float repeat_threshold;
float half_life;
uint64_t decay_coefficient;
Type last_type;
uint64_t repeats[3];
uint64_t prestat[4];
uint64_t poststat[4];
uint64_t total_repeats[3];
uint64_t total_prestat[4];
uint64_t total_poststat[4];
#define HIST_SIZE 4
uint8_t history[HIST_SIZE];
AVFrame *cur;
AVFrame *next;
AVFrame *prev;
int interlaced_flag_accuracy;
int analyze_interlaced_flag;
int analyze_interlaced_flag_done;
const AVPixFmtDescriptor *csp;
int eof;
} IDETContext;
#define OFFSET(x) offsetof(IDETContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
@@ -83,32 +132,6 @@ static const char *rep2str(RepeatedField repeated_field)
return NULL;
}
int ff_idet_filter_line_c(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w)
{
int x;
int ret=0;
for(x=0; x<w; x++){
int v = (*a++ + *c++) - 2 * *b++;
ret += FFABS(v);
}
return ret;
}
int ff_idet_filter_line_c_16bit(const uint16_t *a, const uint16_t *b, const uint16_t *c, int w)
{
int x;
int ret=0;
for(x=0; x<w; x++){
int v = (*a++ + *c++) - 2 * *b++;
ret += FFABS(v);
}
return ret;
}
static void filter(AVFilterContext *ctx)
{
IDETContext *idet = ctx->priv;
@@ -120,6 +143,7 @@ static void filter(AVFilterContext *ctx)
RepeatedField repeat;
int match = 0;
AVDictionary **metadata = &idet->cur->metadata;
ff_idet_filter_func filter_line = idet->dsp.filter_line;
for (i = 0; i < idet->csp->nb_components; i++) {
int w = idet->cur->width;
@@ -135,10 +159,10 @@ static void filter(AVFilterContext *ctx)
uint8_t *prev = &idet->prev->data[i][y*refs];
uint8_t *cur = &idet->cur ->data[i][y*refs];
uint8_t *next = &idet->next->data[i][y*refs];
alpha[ y &1] += idet->filter_line(cur-refs, prev, cur+refs, w);
alpha[(y^1)&1] += idet->filter_line(cur-refs, next, cur+refs, w);
delta += idet->filter_line(cur-refs, cur, cur+refs, w);
gamma[(y^1)&1] += idet->filter_line(cur , prev, cur , w);
alpha[ y &1] += filter_line(cur-refs, prev, cur+refs, w);
alpha[(y^1)&1] += filter_line(cur-refs, next, cur+refs, w);
delta += filter_line(cur-refs, cur, cur+refs, w);
gamma[(y^1)&1] += filter_line(cur , prev, cur , w);
}
}
@@ -275,7 +299,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *picref)
if (!idet->csp)
idet->csp = av_pix_fmt_desc_get(link->format);
if (idet->csp->comp[0].depth > 8)
ff_idet_dsp_init(idet, 1);
ff_idet_dsp_init(&idet->dsp, 1);
if (idet->analyze_interlaced_flag) {
if (idet->cur->flags & AV_FRAME_FLAG_INTERLACED) {
@@ -391,14 +415,6 @@ static const enum AVPixelFormat pix_fmts[] = {
AV_PIX_FMT_NONE
};
void ff_idet_dsp_init(IDETContext *idet, int for_16b)
{
idet->filter_line = for_16b ? (ff_idet_filter_func)ff_idet_filter_line_c_16bit : ff_idet_filter_line_c;
#if ARCH_X86
ff_idet_init_x86(idet, for_16b);
#endif
}
static av_cold int init(AVFilterContext *ctx)
{
IDETContext *idet = ctx->priv;
@@ -412,7 +428,7 @@ static av_cold int init(AVFilterContext *ctx)
else
idet->decay_coefficient = PRECISION;
ff_idet_dsp_init(idet, 0);
ff_idet_dsp_init(&idet->dsp, 0);
return 0;
}
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2012 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libavutil/attributes.h>
#include <libavutil/common.h>
#include "vf_idetdsp.h"
int ff_idet_filter_line_c(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w)
{
int x;
int ret=0;
for(x=0; x<w; x++){
int v = (*a++ + *c++) - 2 * *b++;
ret += FFABS(v);
}
return ret;
}
int ff_idet_filter_line_c_16bit(const uint16_t *a, const uint16_t *b, const uint16_t *c, int w)
{
int x;
int ret=0;
for(x=0; x<w; x++){
int v = (*a++ + *c++) - 2 * *b++;
ret += FFABS(v);
}
return ret;
}
void av_cold ff_idet_dsp_init(IDETDSPContext *dsp, int for_16b)
{
dsp->filter_line = for_16b ? (ff_idet_filter_func)ff_idet_filter_line_c_16bit : ff_idet_filter_line_c;
#if ARCH_X86
ff_idet_dsp_init_x86(dsp, for_16b);
#endif
}
@@ -16,67 +16,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFILTER_IDET_H
#define AVFILTER_IDET_H
#ifndef AVFILTER_IDETDSP_H
#define AVFILTER_IDETDSP_H
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#define HIST_SIZE 4
#include <stdint.h>
typedef int (*ff_idet_filter_func)(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w);
typedef enum {
TFF,
BFF,
PROGRESSIVE,
UNDETERMINED,
} Type;
typedef enum {
REPEAT_NONE,
REPEAT_TOP,
REPEAT_BOTTOM,
} RepeatedField;
typedef struct IDETContext {
const AVClass *class;
float interlace_threshold;
float progressive_threshold;
float repeat_threshold;
float half_life;
uint64_t decay_coefficient;
Type last_type;
uint64_t repeats[3];
uint64_t prestat[4];
uint64_t poststat[4];
uint64_t total_repeats[3];
uint64_t total_prestat[4];
uint64_t total_poststat[4];
uint8_t history[HIST_SIZE];
AVFrame *cur;
AVFrame *next;
AVFrame *prev;
typedef struct IDETDSPContext {
ff_idet_filter_func filter_line;
} IDETDSPContext;
int interlaced_flag_accuracy;
int analyze_interlaced_flag;
int analyze_interlaced_flag_done;
void ff_idet_dsp_init(IDETDSPContext *idet, int for_16b);
const AVPixFmtDescriptor *csp;
int eof;
} IDETContext;
void ff_idet_dsp_init(IDETContext *idet, int for_16b);
void ff_idet_init_x86(IDETContext *idet, int for_16b);
void ff_idet_dsp_init_x86(IDETDSPContext *idet, int for_16b);
/* main fall-back for left-over */
int ff_idet_filter_line_c(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w);
int ff_idet_filter_line_c_16bit(const uint16_t *a, const uint16_t *b, const uint16_t *c, int w);
#endif
#endif /* AVFILTER_IDETDSP_H */
+2 -2
View File
@@ -18,7 +18,7 @@ OBJS-$(CONFIG_FRAMERATE_FILTER) += x86/vf_framerate_init.o
OBJS-$(CONFIG_HALDCLUT_FILTER) += x86/vf_lut3d_init.o
OBJS-$(CONFIG_HFLIP_FILTER) += x86/vf_hflip_init.o
OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d_init.o
OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet_init.o
OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idetdsp_init.o
OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_tinterlace_init.o
OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter_init.o
OBJS-$(CONFIG_LUT3D_FILTER) += x86/vf_lut3d_init.o
@@ -66,7 +66,7 @@ X86ASM-OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun.o
X86ASM-OBJS-$(CONFIG_HALDCLUT_FILTER) += x86/vf_lut3d.o
X86ASM-OBJS-$(CONFIG_HFLIP_FILTER) += x86/vf_hflip.o
X86ASM-OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d.o
X86ASM-OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet.o
X86ASM-OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idetdsp.o
X86ASM-OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_interlace.o
X86ASM-OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter.o
X86ASM-OBJS-$(CONFIG_LUT3D_FILTER) += x86/vf_lut3d.o
@@ -20,7 +20,7 @@
#include "libavutil/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/vf_idet.h"
#include "libavfilter/vf_idetdsp.h"
#if HAVE_X86ASM
@@ -60,13 +60,13 @@ FUNC_MAIN_DECL(sse2, 16)
FUNC_MAIN_DECL_16bit(sse2, 8)
#endif
av_cold void ff_idet_init_x86(IDETContext *idet, int for_16b)
av_cold void ff_idet_dsp_init_x86(IDETDSPContext *dsp, int for_16b)
{
#if HAVE_X86ASM
const int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags)) {
idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_sse2 : idet_filter_line_sse2;
dsp->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_sse2 : idet_filter_line_sse2;
}
#endif // HAVE_X86ASM
}