diff options
author | Ronald S. Bultje <rsbultje@gmail.com> | 2015-07-13 02:33:06 +0300 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-07-14 06:07:07 +0300 |
commit | dfc58584b4e5c35d6aebc5d21223bf714024f0ea (patch) | |
tree | 7394cda41bc28fdb073b60f168e508349b4815b8 /libavfilter/vf_ssim.c | |
parent | 39a04ebcaf0410d8c5de1435fd1c4d0ed9752776 (diff) |
vf_ssim: x86 simd for ssim_4x4xN and ssim_endN.
Both are 2-2.5x faster than their C counterpart.
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavfilter/vf_ssim.c')
-rw-r--r-- | libavfilter/vf_ssim.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/libavfilter/vf_ssim.c b/libavfilter/vf_ssim.c index f7a259e2d1..b5a61ee344 100644 --- a/libavfilter/vf_ssim.c +++ b/libavfilter/vf_ssim.c @@ -42,6 +42,7 @@ #include "drawutils.h" #include "formats.h" #include "internal.h" +#include "ssim.h" #include "video.h" typedef struct SSIMContext { @@ -59,6 +60,7 @@ typedef struct SSIMContext { int planeheight[4]; int *temp; int is_rgb; + SSIMDSPContext dsp; } SSIMContext; #define OFFSET(x) offsetof(SSIMContext, x) @@ -85,8 +87,8 @@ static void set_meta(AVDictionary **metadata, const char *key, char comp, float } } -static void ssim_4x4xn(const uint8_t *main, int main_stride, - const uint8_t *ref, int ref_stride, +static void ssim_4x4xn(const uint8_t *main, ptrdiff_t main_stride, + const uint8_t *ref, ptrdiff_t ref_stride, int (*sums)[4], int width) { int x, y, z; @@ -132,7 +134,7 @@ static float ssim_end1(int s1, int s2, int ss, int s12) / ((float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (float)(vars + ssim_c2)); } -static float ssim_endn(int (*sum0)[4], int (*sum1)[4], int width) +static float ssim_endn(const int (*sum0)[4], const int (*sum1)[4], int width) { float ssim = 0.0; int i; @@ -145,7 +147,8 @@ static float ssim_endn(int (*sum0)[4], int (*sum1)[4], int width) return ssim; } -static float ssim_plane(uint8_t *main, int main_stride, +static float ssim_plane(SSIMDSPContext *dsp, + uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp) { @@ -160,12 +163,12 @@ static float ssim_plane(uint8_t *main, int main_stride, for (y = 1; y < height; y++) { for (; z <= y; z++) { FFSWAP(void*, sum0, sum1); - ssim_4x4xn(&main[4 * z * main_stride], main_stride, - &ref[4 * z * ref_stride], ref_stride, - sum0, width); + dsp->ssim_4x4_line(&main[4 * z * main_stride], main_stride, + &ref[4 * z * ref_stride], ref_stride, + sum0, width); } - ssim += ssim_endn(sum0, sum1, width - 1); + ssim += dsp->ssim_end_line(sum0, sum1, width - 1); } return ssim / ((height - 1) * (width - 1)); @@ -187,7 +190,7 @@ static AVFrame *do_ssim(AVFilterContext *ctx, AVFrame *main, s->nb_frames++; for (i = 0; i < s->nb_components; i++) { - c[i] = ssim_plane(main->data[i], main->linesize[i], + c[i] = ssim_plane(&s->dsp, main->data[i], main->linesize[i], ref->data[i], ref->linesize[i], s->planewidth[i], s->planeheight[i], s->temp); ssimv += s->coefs[i] * c[i]; @@ -294,6 +297,11 @@ static int config_input_ref(AVFilterLink *inlink) if (!s->temp) return AVERROR(ENOMEM); + s->dsp.ssim_4x4_line = ssim_4x4xn; + s->dsp.ssim_end_line = ssim_endn; + if (ARCH_X86) + ff_ssim_init_x86(&s->dsp); + return 0; } |