454d03030d465422b738ddf008ab466d097429fa
[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                             ptrdiff_t width, ptrdiff_t start, ptrdiff_t 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                                ptrdiff_t width, ptrdiff_t start, ptrdiff_t 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                            ptrdiff_t width, ptrdiff_t start, ptrdiff_t 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                        ptrdiff_t width, ptrdiff_t start, ptrdiff_t 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                           ptrdiff_t width, ptrdiff_t start, ptrdiff_t 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                                  ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
60                                  struct FilterParams *param, double *values);
61
62 void ff_blend_hardmix_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                            ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
66                            struct FilterParams *param, double *values);
67
68 void ff_blend_lighten_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                            ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
72                            struct FilterParams *param, double *values);
73
74 void ff_blend_or_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                       ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
78                       struct FilterParams *param, double *values);
79
80 void ff_blend_phoenix_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                            ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
84                            struct FilterParams *param, double *values);
85
86 void ff_blend_subtract_sse2(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                             ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
90                             struct FilterParams *param, double *values);
91
92 void ff_blend_xor_sse2(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                        ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
96                        struct FilterParams *param, double *values);
97
98 void ff_blend_difference_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
99                                const uint8_t *bottom, ptrdiff_t bottom_linesize,
100                                uint8_t *dst, ptrdiff_t dst_linesize,
101                                ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
102                                struct FilterParams *param, double *values);
103
104 void ff_blend_negation_ssse3(const uint8_t *top, ptrdiff_t top_linesize,
105                              const uint8_t *bottom, ptrdiff_t bottom_linesize,
106                              uint8_t *dst, ptrdiff_t dst_linesize,
107                              ptrdiff_t width, ptrdiff_t start, ptrdiff_t end,
108                              struct FilterParams *param, double *values);
109
110 av_cold void ff_blend_init_x86(FilterParams *param, int is_16bit)
111 {
112     int cpu_flags = av_get_cpu_flags();
113
114     if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags) && param->opacity == 1 && !is_16bit) {
115         switch (param->mode) {
116         case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
117         case BLEND_ADDITION128: param->blend = ff_blend_addition128_sse2; break;
118         case BLEND_AND:      param->blend = ff_blend_and_sse2;      break;
119         case BLEND_AVERAGE:  param->blend = ff_blend_average_sse2;  break;
120         case BLEND_DARKEN:   param->blend = ff_blend_darken_sse2;   break;
121         case BLEND_DIFFERENCE128: param->blend = ff_blend_difference128_sse2; break;
122         case BLEND_HARDMIX:  param->blend = ff_blend_hardmix_sse2;  break;
123         case BLEND_LIGHTEN:  param->blend = ff_blend_lighten_sse2;  break;
124         case BLEND_OR:       param->blend = ff_blend_or_sse2;       break;
125         case BLEND_PHOENIX:  param->blend = ff_blend_phoenix_sse2;  break;
126         case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
127         case BLEND_XOR:      param->blend = ff_blend_xor_sse2;      break;
128         }
129     }
130     if (ARCH_X86_64 && EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1 && !is_16bit) {
131         switch (param->mode) {
132         case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
133         case BLEND_NEGATION:   param->blend = ff_blend_negation_ssse3;   break;
134         }
135     }
136 }