avfilter/vf_blend: add x86 SIMD for some modes
[ffmpeg.git] / libavfilter / x86 / vf_blend_init.c
1 /*
2  * Copyright (c) 2015 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "libavutil/attributes.h"
22 #include "libavutil/cpu.h"
23 #include "libavutil/x86/cpu.h"
24 #include "libavfilter/blend.h"
25
26 void ff_blend_addition_sse2(const uint8_t *top, ptrdiff_t top_linesize,
27                             const uint8_t *bottom, ptrdiff_t bottom_linesize,
28                             uint8_t *dst, ptrdiff_t dst_linesize,
29                             int width, int start, int end,
30                             struct FilterParams *param, double *values);
31
32 void ff_blend_addition128_sse2(const uint8_t *top, ptrdiff_t top_linesize,
33                                const uint8_t *bottom, ptrdiff_t bottom_linesize,
34                                uint8_t *dst, ptrdiff_t dst_linesize,
35                                int width, int start, int end,
36                                struct FilterParams *param, double *values);
37
38 void ff_blend_average_sse2(const uint8_t *top, ptrdiff_t top_linesize,
39                            const uint8_t *bottom, ptrdiff_t bottom_linesize,
40                            uint8_t *dst, ptrdiff_t dst_linesize,
41                            int width, int start, int end,
42                            struct FilterParams *param, double *values);
43
44 void ff_blend_and_sse2(const uint8_t *top, ptrdiff_t top_linesize,
45                        const uint8_t *bottom, ptrdiff_t bottom_linesize,
46                        uint8_t *dst, ptrdiff_t dst_linesize,
47                        int width, int start, int end,
48                        struct FilterParams *param, double *values);
49
50 void ff_blend_darken_sse2(const uint8_t *top, ptrdiff_t top_linesize,
51                           const uint8_t *bottom, ptrdiff_t bottom_linesize,
52                           uint8_t *dst, ptrdiff_t dst_linesize,
53                           int width, int start, int end,
54                           struct FilterParams *param, double *values);
55
56 void ff_blend_difference128_sse2(const uint8_t *top, ptrdiff_t top_linesize,
57                                  const uint8_t *bottom, ptrdiff_t bottom_linesize,
58                                  uint8_t *dst, ptrdiff_t dst_linesize,
59                                  int width, int start, int end,
60                                  struct FilterParams *param, double *values);
61
62 void ff_blend_lighten_sse2(const uint8_t *top, ptrdiff_t top_linesize,
63                            const uint8_t *bottom, ptrdiff_t bottom_linesize,
64                            uint8_t *dst, ptrdiff_t dst_linesize,
65                            int width, int start, int end,
66                            struct FilterParams *param, double *values);
67
68 void ff_blend_or_sse2(const uint8_t *top, ptrdiff_t top_linesize,
69                       const uint8_t *bottom, ptrdiff_t bottom_linesize,
70                       uint8_t *dst, ptrdiff_t dst_linesize,
71                       int width, int start, int end,
72                       struct FilterParams *param, double *values);
73
74 void ff_blend_subtract_sse2(const uint8_t *top, ptrdiff_t top_linesize,
75                             const uint8_t *bottom, ptrdiff_t bottom_linesize,
76                             uint8_t *dst, ptrdiff_t dst_linesize,
77                             int width, int start, int end,
78                             struct FilterParams *param, double *values);
79
80 void ff_blend_xor_sse2(const uint8_t *top, ptrdiff_t top_linesize,
81                        const uint8_t *bottom, ptrdiff_t bottom_linesize,
82                        uint8_t *dst, ptrdiff_t dst_linesize,
83                        int width, int start, int end,
84                        struct FilterParams *param, double *values);
85
86 void ff_blend_difference_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
87                                const uint8_t *bottom, ptrdiff_t bottom_linesize,
88                                uint8_t *dst, ptrdiff_t dst_linesize,
89                                int width, int start, int end,
90                                struct FilterParams *param, double *values);
91
92 void ff_blend_negation_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
93                              const uint8_t *bottom, ptrdiff_t bottom_linesize,
94                              uint8_t *dst, ptrdiff_t dst_linesize,
95                              int width, int start, int end,
96                              struct FilterParams *param, double *values);
97
98 av_cold void ff_blend_init_x86(FilterParams *param, int is_16bit)
99 {
100     int cpu_flags = av_get_cpu_flags();
101
102     if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags) && param->opacity == 1 && !is_16bit) {
103         switch (param->mode) {
104         case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
105         case BLEND_ADDITION128: param->blend = ff_blend_addition128_sse2; break;
106         case BLEND_AND:      param->blend = ff_blend_and_sse2;      break;
107         case BLEND_AVERAGE:  param->blend = ff_blend_average_sse2;  break;
108         case BLEND_DARKEN:   param->blend = ff_blend_darken_sse2;   break;
109         case BLEND_DIFFERENCE128: param->blend = ff_blend_difference128_sse2; break;
110         case BLEND_LIGHTEN:  param->blend = ff_blend_lighten_sse2;  break;
111         case BLEND_OR:       param->blend = ff_blend_or_sse2;       break;
112         case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
113         case BLEND_XOR:      param->blend = ff_blend_xor_sse2;      break;
114         }
115     }
116     if (ARCH_X86_64 && EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1 && !is_16bit) {
117         switch (param->mode) {
118         case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
119         case BLEND_NEGATION:   param->blend = ff_blend_negation_ssse3;   break;
120         }
121     }
122 }