3 * Original MPlayer filters by Richard Felker.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "libavutil/attributes.h"
23 #include "libavutil/cpu.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/x86/asm.h"
26 #include "libavfilter/vf_eq.h"
28 #if HAVE_MMX_INLINE && HAVE_6REGS
29 static void process_MMX(EQParameters *param, uint8_t *dst, int dst_stride,
30 const uint8_t *src, int src_stride, int w, int h)
34 int dstep = dst_stride - w;
35 int sstep = src_stride - w;
38 int contrast = (int) (param->contrast * 256 * 16);
39 int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
41 brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
42 contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
46 "movq (%5), %%mm3 \n\t"
47 "movq (%6), %%mm4 \n\t"
48 "pxor %%mm0, %%mm0 \n\t"
52 "movq (%0), %%mm1 \n\t"
53 "movq (%0), %%mm2 \n\t"
54 "punpcklbw %%mm0, %%mm1\n\t"
55 "punpckhbw %%mm0, %%mm2\n\t"
56 "psllw $4, %%mm1 \n\t"
57 "psllw $4, %%mm2 \n\t"
58 "pmulhw %%mm4, %%mm1 \n\t"
59 "pmulhw %%mm4, %%mm2 \n\t"
60 "paddw %%mm3, %%mm1 \n\t"
61 "paddw %%mm3, %%mm2 \n\t"
62 "packuswb %%mm2, %%mm1 \n\t"
64 "movq %%mm1, (%1) \n\t"
68 : "=r" (src), "=r" (dst)
69 : "0" (src), "1" (dst), "r" (w>>3), "r" (brvec), "r" (contvec)
73 for (i = w&7; i; i--) {
74 pel = ((*src++ * contrast) >> 12) + brightness;
83 __asm__ volatile ( "emms \n\t" ::: "memory" );
87 av_cold void ff_eq_init_x86(EQContext *eq)
89 #if HAVE_MMX_INLINE && HAVE_6REGS
90 int cpu_flags = av_get_cpu_flags();
92 if (cpu_flags & AV_CPU_FLAG_MMX) {
93 eq->process = process_MMX;