]> git.sesse.net Git - vlc/blob - modules/codec/xvmc/motion_comp.c
0eef8fbffff638cd3351b4cce98610c20d3420de
[vlc] / modules / codec / xvmc / motion_comp.c
1 /* $Id$
2  * motion_comp.c
3  * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5  *
6  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
7  * See http://libmpeg2.sourceforge.net/ for updates.
8  *
9  * mpeg2dec is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * mpeg2dec is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25
26 #include <inttypes.h>
27
28 #include "mpeg2.h"
29 #include "attributes.h"
30 #include "mpeg2_internal.h"
31
32 mpeg2_mc_t mpeg2_mc;
33
34 void mpeg2_mc_init (uint32_t accel)
35 {
36     if (accel & MPEG2_ACCEL_X86_MMXEXT)
37         mpeg2_mc = mpeg2_mc_mmxext;
38     else if (accel & MPEG2_ACCEL_X86_3DNOW)
39         mpeg2_mc = mpeg2_mc_3dnow;
40     else if (accel & MPEG2_ACCEL_X86_MMX)
41         mpeg2_mc = mpeg2_mc_mmx;
42     else
43         mpeg2_mc = mpeg2_mc_c;
44 }
45
46 #define avg2(a,b) ((a+b+1)>>1)
47 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
48
49 #define predict_o(i) (ref[i])
50 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
51 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
52 #define predict_xy(i) (avg4 (ref[i], ref[i+1], \
53                              (ref+stride)[i], (ref+stride)[i+1]))
54
55 #define put(predictor,i) dest[i] = predictor (i)
56 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
57
58 /* mc function template */
59
60 #define MC_FUNC(op,xy)                                                  \
61 static void MC_##op##_##xy##_16_c (uint8_t * dest, const uint8_t * ref, \
62                                    const int stride, int height)        \
63 {                                                                       \
64     do {                                                                \
65         op (predict_##xy, 0);                                           \
66         op (predict_##xy, 1);                                           \
67         op (predict_##xy, 2);                                           \
68         op (predict_##xy, 3);                                           \
69         op (predict_##xy, 4);                                           \
70         op (predict_##xy, 5);                                           \
71         op (predict_##xy, 6);                                           \
72         op (predict_##xy, 7);                                           \
73         op (predict_##xy, 8);                                           \
74         op (predict_##xy, 9);                                           \
75         op (predict_##xy, 10);                                          \
76         op (predict_##xy, 11);                                          \
77         op (predict_##xy, 12);                                          \
78         op (predict_##xy, 13);                                          \
79         op (predict_##xy, 14);                                          \
80         op (predict_##xy, 15);                                          \
81         ref += stride;                                                  \
82         dest += stride;                                                 \
83     } while (--height);                                                 \
84 }                                                                       \
85 static void MC_##op##_##xy##_8_c (uint8_t * dest, const uint8_t * ref,  \
86                                   const int stride, int height)         \
87 {                                                                       \
88     do {                                                                \
89         op (predict_##xy, 0);                                           \
90         op (predict_##xy, 1);                                           \
91         op (predict_##xy, 2);                                           \
92         op (predict_##xy, 3);                                           \
93         op (predict_##xy, 4);                                           \
94         op (predict_##xy, 5);                                           \
95         op (predict_##xy, 6);                                           \
96         op (predict_##xy, 7);                                           \
97         ref += stride;                                                  \
98         dest += stride;                                                 \
99     } while (--height);                                                 \
100 }
101
102 /* definitions of the actual mc functions */
103
104 MC_FUNC (put,o)
105 MC_FUNC (avg,o)
106 MC_FUNC (put,x)
107 MC_FUNC (avg,x)
108 MC_FUNC (put,y)
109 MC_FUNC (avg,y)
110 MC_FUNC (put,xy)
111 MC_FUNC (avg,xy)
112
113 MPEG2_MC_EXTERN (c)