Commit 9762554d authored by Paul B Mahol's avatar Paul B Mahol

avfilter/vf_blend: add x86 SIMD for some modes

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 061b67fb
/*
* Copyright (c) 2013 Paul B Mahol
*
* 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/eval.h"
#include "avfilter.h"
enum BlendMode {
BLEND_UNSET = -1,
BLEND_NORMAL,
BLEND_ADDITION,
BLEND_AND,
BLEND_AVERAGE,
BLEND_BURN,
BLEND_DARKEN,
BLEND_DIFFERENCE,
BLEND_DIFFERENCE128,
BLEND_DIVIDE,
BLEND_DODGE,
BLEND_EXCLUSION,
BLEND_HARDLIGHT,
BLEND_LIGHTEN,
BLEND_MULTIPLY,
BLEND_NEGATION,
BLEND_OR,
BLEND_OVERLAY,
BLEND_PHOENIX,
BLEND_PINLIGHT,
BLEND_REFLECT,
BLEND_SCREEN,
BLEND_SOFTLIGHT,
BLEND_SUBTRACT,
BLEND_VIVIDLIGHT,
BLEND_XOR,
BLEND_HARDMIX,
BLEND_LINEARLIGHT,
BLEND_GLOW,
BLEND_ADDITION128,
BLEND_NB
};
typedef struct FilterParams {
enum BlendMode mode;
double opacity;
AVExpr *e;
char *expr_str;
void (*blend)(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
} FilterParams;
void ff_blend_init_x86(FilterParams *param, int is_16bit);
......@@ -28,69 +28,12 @@
#include "internal.h"
#include "dualinput.h"
#include "video.h"
#include "blend.h"
#define TOP 0
#define BOTTOM 1
enum BlendMode {
BLEND_UNSET = -1,
BLEND_NORMAL,
BLEND_ADDITION,
BLEND_AND,
BLEND_AVERAGE,
BLEND_BURN,
BLEND_DARKEN,
BLEND_DIFFERENCE,
BLEND_DIFFERENCE128,
BLEND_DIVIDE,
BLEND_DODGE,
BLEND_EXCLUSION,
BLEND_HARDLIGHT,
BLEND_LIGHTEN,
BLEND_MULTIPLY,
BLEND_NEGATION,
BLEND_OR,
BLEND_OVERLAY,
BLEND_PHOENIX,
BLEND_PINLIGHT,
BLEND_REFLECT,
BLEND_SCREEN,
BLEND_SOFTLIGHT,
BLEND_SUBTRACT,
BLEND_VIVIDLIGHT,
BLEND_XOR,
BLEND_HARDMIX,
BLEND_LINEARLIGHT,
BLEND_GLOW,
BLEND_ADDITION128,
BLEND_NB
};
static const char *const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL };
enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_SW, VAR_SH, VAR_T, VAR_N, VAR_A, VAR_B, VAR_TOP, VAR_BOTTOM, VAR_VARS_NB };
typedef struct FilterParams {
enum BlendMode mode;
double opacity;
AVExpr *e;
char *expr_str;
void (*blend)(const uint8_t *top, int top_linesize,
const uint8_t *bottom, int bottom_linesize,
uint8_t *dst, int dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
} FilterParams;
typedef struct ThreadData {
const AVFrame *top, *bottom;
AVFrame *dst;
AVFilterLink *inlink;
int plane;
int w, h;
FilterParams *param;
} ThreadData;
typedef struct {
typedef struct BlendContext {
const AVClass *class;
FFDualInputContext dinput;
int hsub, vsub; ///< chroma subsampling values
......@@ -104,6 +47,18 @@ typedef struct {
AVFrame *prev_frame; /* only used with tblend */
} BlendContext;
static const char *const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL };
enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_SW, VAR_SH, VAR_T, VAR_N, VAR_A, VAR_B, VAR_TOP, VAR_BOTTOM, VAR_VARS_NB };
typedef struct ThreadData {
const AVFrame *top, *bottom;
AVFrame *dst;
AVFilterLink *inlink;
int plane;
int w, h;
FilterParams *param;
} ThreadData;
#define COMMON_OPTIONS \
{ "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},\
{ "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},\
......@@ -162,9 +117,9 @@ static const AVOption blend_options[] = {
AVFILTER_DEFINE_CLASS(blend);
static void blend_normal(const uint8_t *top, int top_linesize,
const uint8_t *bottom, int bottom_linesize,
uint8_t *dst, int dst_linesize,
static void blend_normal(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
FilterParams *param, double *values)
{
......@@ -172,9 +127,9 @@ static void blend_normal(const uint8_t *top, int top_linesize,
}
#define DEFINE_BLEND8(name, expr) \
static void blend_## name##_8bit(const uint8_t *top, int top_linesize, \
const uint8_t *bottom, int bottom_linesize, \
uint8_t *dst, int dst_linesize, \
static void blend_## name##_8bit(const uint8_t *top, ptrdiff_t top_linesize, \
const uint8_t *bottom, ptrdiff_t bottom_linesize, \
uint8_t *dst, ptrdiff_t dst_linesize, \
int width, int start, int end, \
FilterParams *param, double *values) \
{ \
......@@ -192,9 +147,9 @@ static void blend_## name##_8bit(const uint8_t *top, int top_linesize, \
}
#define DEFINE_BLEND16(name, expr) \
static void blend_## name##_16bit(const uint8_t *_top, int top_linesize, \
const uint8_t *_bottom, int bottom_linesize, \
uint8_t *_dst, int dst_linesize, \
static void blend_## name##_16bit(const uint8_t *_top, ptrdiff_t top_linesize, \
const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
uint8_t *_dst, ptrdiff_t dst_linesize, \
int width, int start, int end, \
FilterParams *param, double *values) \
{ \
......@@ -294,9 +249,9 @@ DEFINE_BLEND16(vividlight, (A < 32768) ? BURN(2 * A, B) : DODGE(2 * (A - 32768),
DEFINE_BLEND16(linearlight,av_clip_uint16((B < 32768) ? B + 2 * A - 65535 : B + 2 * (A - 32768)))
#define DEFINE_BLEND_EXPR(type, name, div) \
static void blend_expr_## name(const uint8_t *_top, int top_linesize, \
const uint8_t *_bottom, int bottom_linesize, \
uint8_t *_dst, int dst_linesize, \
static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \
const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
uint8_t *_dst, ptrdiff_t dst_linesize, \
int width, int start, int end, \
FilterParams *param, double *values) \
{ \
......@@ -515,6 +470,9 @@ static int config_output(AVFilterLink *outlink)
case BLEND_XOR: param->blend = is_16bit ? blend_xor_16bit : blend_xor_8bit; break;
}
if (ARCH_X86)
ff_blend_init_x86(param, is_16bit);
if (s->all_expr && !param->expr_str) {
param->expr_str = av_strdup(s->all_expr);
if (!param->expr_str)
......
OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend_init.o
OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o
OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp_init.o
OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o
......@@ -12,10 +13,12 @@ OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup_init.o
OBJS-$(CONFIG_REMOVEGRAIN_FILTER) += x86/vf_removegrain_init.o
OBJS-$(CONFIG_SPP_FILTER) += x86/vf_spp.o
OBJS-$(CONFIG_SSIM_FILTER) += x86/vf_ssim_init.o
OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend_init.o
OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_tinterlace_init.o
OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume_init.o
OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif_init.o
YASM-OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend.o
YASM-OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o
YASM-OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun.o
YASM-OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d.o
......@@ -29,6 +32,7 @@ ifdef CONFIG_GPL
YASM-OBJS-$(CONFIG_REMOVEGRAIN_FILTER) += x86/vf_removegrain.o
endif
YASM-OBJS-$(CONFIG_SSIM_FILTER) += x86/vf_ssim.o
YASM-OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend.o
YASM-OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_interlace.o
YASM-OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume.o
YASM-OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif.o x86/yadif-16.o x86/yadif-10.o
This diff is collapsed.
/*
* Copyright (c) 2015 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/blend.h"
void ff_blend_addition_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_addition128_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_average_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_and_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_darken_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_difference128_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_lighten_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_or_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_subtract_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_xor_sse2(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_difference_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
void ff_blend_negation_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
const uint8_t *bottom, ptrdiff_t bottom_linesize,
uint8_t *dst, ptrdiff_t dst_linesize,
int width, int start, int end,
struct FilterParams *param, double *values);
av_cold void ff_blend_init_x86(FilterParams *param, int is_16bit)
{
int cpu_flags = av_get_cpu_flags();
if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags) && param->opacity == 1 && !is_16bit) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
case BLEND_ADDITION128: param->blend = ff_blend_addition128_sse2; break;
case BLEND_AND: param->blend = ff_blend_and_sse2; break;
case BLEND_AVERAGE: param->blend = ff_blend_average_sse2; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_sse2; break;
case BLEND_DIFFERENCE128: param->blend = ff_blend_difference128_sse2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_sse2; break;
case BLEND_OR: param->blend = ff_blend_or_sse2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
case BLEND_XOR: param->blend = ff_blend_xor_sse2; break;
}
}
if (ARCH_X86_64 && EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1 && !is_16bit) {
switch (param->mode) {
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_ssse3; break;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment