FFmpeg
Loading...
Searching...
No Matches
vf_blend_init.c
Go to the documentation of this file.
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
22#include "libavutil/cpu.h"
23#include "libavutil/x86/cpu.h"
24#include "libavfilter/blend.h"
25
26#define BLEND_FUNC(name, opt) \
27void ff_blend_##name##_##opt(const uint8_t *top, ptrdiff_t top_linesize, \
28 const uint8_t *bottom, ptrdiff_t bottom_linesize, \
29 uint8_t *dst, ptrdiff_t dst_linesize, \
30 ptrdiff_t width, ptrdiff_t height, \
31 FilterParams *param, SliceParams *sliceparam);
32
33BLEND_FUNC(addition, sse2)
34BLEND_FUNC(addition, avx2)
35BLEND_FUNC(grainmerge, sse2)
36BLEND_FUNC(grainmerge, avx2)
37BLEND_FUNC(average, sse2)
38BLEND_FUNC(average, avx2)
39BLEND_FUNC(and, sse2)
40BLEND_FUNC(and, avx2)
41BLEND_FUNC(darken, sse2)
42BLEND_FUNC(darken, avx2)
43BLEND_FUNC(grainextract, sse2)
44BLEND_FUNC(grainextract, avx2)
47BLEND_FUNC(screen, sse2)
48BLEND_FUNC(screen, avx2)
49BLEND_FUNC(hardmix, sse2)
50BLEND_FUNC(hardmix, avx2)
51BLEND_FUNC(divide, sse2)
52BLEND_FUNC(lighten, sse2)
53BLEND_FUNC(lighten, avx2)
54BLEND_FUNC(or, sse2)
55BLEND_FUNC(or, avx2)
56BLEND_FUNC(phoenix, sse2)
57BLEND_FUNC(phoenix, avx2)
58BLEND_FUNC(subtract, sse2)
59BLEND_FUNC(subtract, avx2)
60BLEND_FUNC(xor, sse2)
61BLEND_FUNC(xor, avx2)
65BLEND_FUNC(extremity, sse2)
66BLEND_FUNC(extremity, ssse3)
67BLEND_FUNC(extremity, avx2)
68BLEND_FUNC(negation, sse2)
69BLEND_FUNC(negation, ssse3)
70BLEND_FUNC(negation, avx2)
71
72#if ARCH_X86_64
73BLEND_FUNC(addition_16, sse2)
74BLEND_FUNC(addition_16, avx2)
75BLEND_FUNC(grainmerge_16, sse4)
76BLEND_FUNC(grainmerge_16, avx2)
77BLEND_FUNC(average_16, sse2)
78BLEND_FUNC(average_16, avx2)
79BLEND_FUNC(and_16, sse2)
80BLEND_FUNC(and_16, avx2)
81BLEND_FUNC(darken_16, sse4)
82BLEND_FUNC(darken_16, avx2)
83BLEND_FUNC(grainextract_16, sse4)
84BLEND_FUNC(grainextract_16, avx2)
85BLEND_FUNC(difference_16, sse4)
86BLEND_FUNC(difference_16, avx2)
87BLEND_FUNC(extremity_16, sse4)
88BLEND_FUNC(extremity_16, avx2)
89BLEND_FUNC(negation_16, sse4)
90BLEND_FUNC(negation_16, avx2)
91BLEND_FUNC(lighten_16, sse4)
92BLEND_FUNC(lighten_16, avx2)
93BLEND_FUNC(or_16, sse2)
94BLEND_FUNC(or_16, avx2)
95BLEND_FUNC(phoenix_16, sse4)
96BLEND_FUNC(phoenix_16, avx2)
97BLEND_FUNC(subtract_16, sse2)
98BLEND_FUNC(subtract_16, avx2)
99BLEND_FUNC(xor_16, sse2)
100BLEND_FUNC(xor_16, avx2)
101#endif /* ARCH_X86_64 */
102
104{
106
107 if (depth == 8) {
108 if (EXTERNAL_SSE2(cpu_flags) && param->opacity == 1) {
109 switch (param->mode) {
110 case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
111 case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_sse2; break;
112 case BLEND_AND: param->blend = ff_blend_and_sse2; break;
113 case BLEND_AVERAGE: param->blend = ff_blend_average_sse2; break;
114 case BLEND_DARKEN: param->blend = ff_blend_darken_sse2; break;
115 case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_sse2; break;
116 case BLEND_DIVIDE: param->blend = ff_blend_divide_sse2; break;
117 case BLEND_HARDMIX: param->blend = ff_blend_hardmix_sse2; break;
118 case BLEND_LIGHTEN: param->blend = ff_blend_lighten_sse2; break;
119 case BLEND_MULTIPLY: param->blend = ff_blend_multiply_sse2; break;
120 case BLEND_OR: param->blend = ff_blend_or_sse2; break;
121 case BLEND_PHOENIX: param->blend = ff_blend_phoenix_sse2; break;
122 case BLEND_SCREEN: param->blend = ff_blend_screen_sse2; break;
123 case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
124 case BLEND_XOR: param->blend = ff_blend_xor_sse2; break;
125 case BLEND_DIFFERENCE: param->blend = ff_blend_difference_sse2; break;
126 case BLEND_EXTREMITY: param->blend = ff_blend_extremity_sse2; break;
127 case BLEND_NEGATION: param->blend = ff_blend_negation_sse2; break;
128 }
129 }
130 if (EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1) {
131 switch (param->mode) {
132 case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
133 case BLEND_EXTREMITY: param->blend = ff_blend_extremity_ssse3; break;
134 case BLEND_NEGATION: param->blend = ff_blend_negation_ssse3; break;
135 }
136 }
137
138 if (EXTERNAL_AVX2_FAST(cpu_flags) && param->opacity == 1) {
139 switch (param->mode) {
140 case BLEND_ADDITION: param->blend = ff_blend_addition_avx2; break;
141 case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_avx2; break;
142 case BLEND_AND: param->blend = ff_blend_and_avx2; break;
143 case BLEND_AVERAGE: param->blend = ff_blend_average_avx2; break;
144 case BLEND_DARKEN: param->blend = ff_blend_darken_avx2; break;
145 case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_avx2; break;
146 case BLEND_HARDMIX: param->blend = ff_blend_hardmix_avx2; break;
147 case BLEND_LIGHTEN: param->blend = ff_blend_lighten_avx2; break;
148 case BLEND_MULTIPLY: param->blend = ff_blend_multiply_avx2; break;
149 case BLEND_OR: param->blend = ff_blend_or_avx2; break;
150 case BLEND_PHOENIX: param->blend = ff_blend_phoenix_avx2; break;
151 case BLEND_SCREEN: param->blend = ff_blend_screen_avx2; break;
152 case BLEND_SUBTRACT: param->blend = ff_blend_subtract_avx2; break;
153 case BLEND_XOR: param->blend = ff_blend_xor_avx2; break;
154 case BLEND_DIFFERENCE: param->blend = ff_blend_difference_avx2; break;
155 case BLEND_EXTREMITY: param->blend = ff_blend_extremity_avx2; break;
156 case BLEND_NEGATION: param->blend = ff_blend_negation_avx2; break;
157 }
158 }
159 } else if (depth == 16) {
160#if ARCH_X86_64
161 if (EXTERNAL_SSE2(cpu_flags) && param->opacity == 1) {
162 switch (param->mode) {
163 case BLEND_ADDITION: param->blend = ff_blend_addition_16_sse2; break;
164 case BLEND_AND: param->blend = ff_blend_and_16_sse2; break;
165 case BLEND_AVERAGE: param->blend = ff_blend_average_16_sse2; break;
166 case BLEND_OR: param->blend = ff_blend_or_16_sse2; break;
167 case BLEND_SUBTRACT: param->blend = ff_blend_subtract_16_sse2; break;
168 case BLEND_XOR: param->blend = ff_blend_xor_16_sse2; break;
169 }
170 }
171 if (EXTERNAL_SSE4(cpu_flags) && param->opacity == 1) {
172 switch (param->mode) {
173 case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_16_sse4; break;
174 case BLEND_DARKEN: param->blend = ff_blend_darken_16_sse4; break;
175 case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_16_sse4; break;
176 case BLEND_DIFFERENCE: param->blend = ff_blend_difference_16_sse4; break;
177 case BLEND_EXTREMITY: param->blend = ff_blend_extremity_16_sse4; break;
178 case BLEND_NEGATION: param->blend = ff_blend_negation_16_sse4; break;
179 case BLEND_LIGHTEN: param->blend = ff_blend_lighten_16_sse4; break;
180 case BLEND_PHOENIX: param->blend = ff_blend_phoenix_16_sse4; break;
181 }
182 }
183 if (EXTERNAL_AVX2_FAST(cpu_flags) && param->opacity == 1) {
184 switch (param->mode) {
185 case BLEND_ADDITION: param->blend = ff_blend_addition_16_avx2; break;
186 case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_16_avx2; break;
187 case BLEND_AND: param->blend = ff_blend_and_16_avx2; break;
188 case BLEND_AVERAGE: param->blend = ff_blend_average_16_avx2; break;
189 case BLEND_DARKEN: param->blend = ff_blend_darken_16_avx2; break;
190 case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_16_avx2; break;
191 case BLEND_DIFFERENCE: param->blend = ff_blend_difference_16_avx2; break;
192 case BLEND_EXTREMITY: param->blend = ff_blend_extremity_16_avx2; break;
193 case BLEND_NEGATION: param->blend = ff_blend_negation_16_avx2; break;
194 case BLEND_LIGHTEN: param->blend = ff_blend_lighten_16_avx2; break;
195 case BLEND_OR: param->blend = ff_blend_or_16_avx2; break;
196 case BLEND_PHOENIX: param->blend = ff_blend_phoenix_16_avx2; break;
197 case BLEND_SUBTRACT: param->blend = ff_blend_subtract_16_avx2; break;
198 case BLEND_XOR: param->blend = ff_blend_xor_16_avx2; break;
199 }
200 }
201#endif /* ARCH_X86_64 */
202 }
203}
static SoftFloat_IEEE754 multiply(SoftFloat_IEEE754 a, SoftFloat_IEEE754 b)
multiply two softfloats and handle the rounding off
Definition alsdec.c:1406
@ BLEND_HARDMIX
Definition blend.h:54
@ BLEND_PHOENIX
Definition blend.h:46
@ BLEND_EXTREMITY
Definition blend.h:61
@ BLEND_XOR
Definition blend.h:53
@ BLEND_AVERAGE
Definition blend.h:32
@ BLEND_DIVIDE
Definition blend.h:37
@ BLEND_OR
Definition blend.h:44
@ BLEND_DIFFERENCE
Definition blend.h:35
@ BLEND_DARKEN
Definition blend.h:34
@ BLEND_GRAINEXTRACT
Definition blend.h:36
@ BLEND_AND
Definition blend.h:31
@ BLEND_LIGHTEN
Definition blend.h:41
@ BLEND_GRAINMERGE
Definition blend.h:57
@ BLEND_SCREEN
Definition blend.h:49
@ BLEND_NEGATION
Definition blend.h:43
@ BLEND_ADDITION
Definition blend.h:30
@ BLEND_SUBTRACT
Definition blend.h:51
@ BLEND_MULTIPLY
Definition blend.h:42
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define EXTERNAL_AVX2_FAST(flags)
Definition cpu.h:73
#define EXTERNAL_SSSE3(flags)
Definition cpu.h:59
#define EXTERNAL_SSE4(flags)
Definition cpu.h:62
#define EXTERNAL_SSE2(flags)
Definition cpu.h:53
filter data
Definition mlp.h:86
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, ptrdiff_t width, ptrdiff_t height, struct FilterParams *param, SliceParams *sliceparam)
Definition blend.h:84
enum BlendMode mode
Definition blend.h:79
double opacity
Definition blend.h:80
#define BLEND_FUNC(name, opt)
av_cold void ff_blend_init_x86(FilterParams *param, int depth)
static void difference(IPlane *g, IPlane *f, int y0, int y1)
Definition vf_morpho.c:495