1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* 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"
#define BLEND_FUNC(name, opt) \
void ff_blend_##name##_##opt(const uint8_t *top, ptrdiff_t top_linesize, \
const uint8_t *bottom, ptrdiff_t bottom_linesize, \
uint8_t *dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
struct FilterParams *param, double *values, int starty);
BLEND_FUNC(addition, sse2)
BLEND_FUNC(addition, avx2)
BLEND_FUNC(grainmerge, sse2)
BLEND_FUNC(grainmerge, avx2)
BLEND_FUNC(average, sse2)
BLEND_FUNC(average, avx2)
BLEND_FUNC(and, sse2)
BLEND_FUNC(and, avx2)
BLEND_FUNC(darken, sse2)
BLEND_FUNC(darken, avx2)
BLEND_FUNC(grainextract, sse2)
BLEND_FUNC(grainextract, avx2)
BLEND_FUNC(multiply, sse2)
BLEND_FUNC(multiply, avx2)
BLEND_FUNC(screen, sse2)
BLEND_FUNC(screen, avx2)
BLEND_FUNC(hardmix, sse2)
BLEND_FUNC(hardmix, avx2)
BLEND_FUNC(divide, sse2)
BLEND_FUNC(lighten, sse2)
BLEND_FUNC(lighten, avx2)
BLEND_FUNC(or, sse2)
BLEND_FUNC(or, avx2)
BLEND_FUNC(phoenix, sse2)
BLEND_FUNC(phoenix, avx2)
BLEND_FUNC(subtract, sse2)
BLEND_FUNC(subtract, avx2)
BLEND_FUNC(xor, sse2)
BLEND_FUNC(xor, avx2)
BLEND_FUNC(difference, sse2)
BLEND_FUNC(difference, ssse3)
BLEND_FUNC(difference, avx2)
BLEND_FUNC(extremity, sse2)
BLEND_FUNC(extremity, ssse3)
BLEND_FUNC(extremity, avx2)
BLEND_FUNC(negation, sse2)
BLEND_FUNC(negation, ssse3)
BLEND_FUNC(negation, avx2)
#if ARCH_X86_64
BLEND_FUNC(addition_16, sse2)
BLEND_FUNC(addition_16, avx2)
BLEND_FUNC(and_16, sse2)
BLEND_FUNC(and_16, avx2)
BLEND_FUNC(darken_16, sse4)
BLEND_FUNC(darken_16, avx2)
BLEND_FUNC(difference_16, sse4)
BLEND_FUNC(difference_16, avx2)
BLEND_FUNC(lighten_16, sse4)
BLEND_FUNC(lighten_16, avx2)
BLEND_FUNC(or_16, sse2)
BLEND_FUNC(or_16, avx2)
BLEND_FUNC(phoenix_16, sse4)
BLEND_FUNC(phoenix_16, avx2)
BLEND_FUNC(subtract_16, sse2)
BLEND_FUNC(subtract_16, avx2)
BLEND_FUNC(xor_16, sse2)
BLEND_FUNC(xor_16, avx2)
#endif /* ARCH_X86_64 */
av_cold void ff_blend_init_x86(FilterParams *param, int is_16bit)
{
int cpu_flags = av_get_cpu_flags();
if (!is_16bit) {
if (EXTERNAL_SSE2(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_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_GRAINEXTRACT: param->blend = ff_blend_grainextract_sse2; break;
case BLEND_DIVIDE: param->blend = ff_blend_divide_sse2; break;
case BLEND_HARDMIX: param->blend = ff_blend_hardmix_sse2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_sse2; break;
case BLEND_MULTIPLY: param->blend = ff_blend_multiply_sse2; break;
case BLEND_OR: param->blend = ff_blend_or_sse2; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_sse2; break;
case BLEND_SCREEN: param->blend = ff_blend_screen_sse2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
case BLEND_XOR: param->blend = ff_blend_xor_sse2; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_sse2; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_sse2; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_sse2; break;
}
}
if (EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_ssse3; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_ssse3; break;
}
}
if (EXTERNAL_AVX2_FAST(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_avx2; break;
case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_avx2; break;
case BLEND_AND: param->blend = ff_blend_and_avx2; break;
case BLEND_AVERAGE: param->blend = ff_blend_average_avx2; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_avx2; break;
case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_avx2; break;
case BLEND_HARDMIX: param->blend = ff_blend_hardmix_avx2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_avx2; break;
case BLEND_MULTIPLY: param->blend = ff_blend_multiply_avx2; break;
case BLEND_OR: param->blend = ff_blend_or_avx2; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_avx2; break;
case BLEND_SCREEN: param->blend = ff_blend_screen_avx2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_avx2; break;
case BLEND_XOR: param->blend = ff_blend_xor_avx2; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_avx2; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_avx2; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_avx2; break;
}
}
} else { /* is_16_bit */
#if ARCH_X86_64
if (EXTERNAL_SSE2(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_16_sse2; break;
case BLEND_AND: param->blend = ff_blend_and_16_sse2; break;
case BLEND_OR: param->blend = ff_blend_or_16_sse2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_16_sse2; break;
case BLEND_XOR: param->blend = ff_blend_xor_16_sse2; break;
}
}
if (EXTERNAL_SSE4(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_DARKEN: param->blend = ff_blend_darken_16_sse4; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_16_sse4; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_16_sse4; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_16_sse4; break;
}
}
if (EXTERNAL_AVX2_FAST(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_16_avx2; break;
case BLEND_AND: param->blend = ff_blend_and_16_avx2; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_16_avx2; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_16_avx2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_16_avx2; break;
case BLEND_OR: param->blend = ff_blend_or_16_avx2; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_16_avx2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_16_avx2; break;
case BLEND_XOR: param->blend = ff_blend_xor_16_avx2; break;
}
}
#endif /* ARCH_X86_64 */
}
}
|