[svn] / trunk / xvidcore / src / motion / motion_comp.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/motion/motion_comp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (view) (download)

1 : chl 430 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Motion Compensation module -
5 :     *
6 : edgomez 605 * Copyright(C) 2002 Peter Ross <pross@xvid.org>
7 : chl 430 *
8 :     * This program is an implementation of a part of one or more MPEG-4
9 :     * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
10 :     * to use this software module in hardware or software products are
11 :     * advised that its use may infringe existing patents or copyrights, and
12 :     * any such use would be at such party's own risk. The original
13 :     * developer of this software module and his/her company, and subsequent
14 :     * editors and their companies, will have no liability for use of this
15 :     * software or modifications or derivatives thereof.
16 :     *
17 :     * This program is free software; you can redistribute it and/or modify
18 :     * it under the terms of the GNU General Public License as published by
19 :     * the Free Software Foundation; either version 2 of the License, or
20 :     * (at your option) any later version.
21 :     *
22 :     * This program is distributed in the hope that it will be useful,
23 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 :     * GNU General Public License for more details.
26 :     *
27 :     * You should have received a copy of the GNU General Public License
28 :     * along with this program; if not, write to the Free Software
29 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 :     *
31 :     *************************************************************************/
32 : suxen_drol 118
33 : Isibaar 3 #include "../encoder.h"
34 :     #include "../utils/mbfunctions.h"
35 :     #include "../image/interpolate8x8.h"
36 :     #include "../utils/timer.h"
37 : suxen_drol 118 #include "motion.h"
38 : Isibaar 3
39 :     #define ABS(X) (((X)>0)?(X):-(X))
40 :     #define SIGN(X) (((X)>0)?1:-1)
41 :    
42 : edgomez 195 static __inline void
43 :     compensate8x8_halfpel(int16_t * const dct_codes,
44 :     uint8_t * const cur,
45 :     const uint8_t * const ref,
46 :     const uint8_t * const refh,
47 :     const uint8_t * const refv,
48 :     const uint8_t * const refhv,
49 :     const uint32_t x,
50 :     const uint32_t y,
51 :     const int32_t dx,
52 :     const int dy,
53 :     const uint32_t stride)
54 : Isibaar 3 {
55 : edgomez 195 int32_t ddx, ddy;
56 : Isibaar 3
57 : edgomez 195 switch (((dx & 1) << 1) + (dy & 1)) // ((dx%2)?2:0)+((dy%2)?1:0)
58 :     {
59 :     case 0:
60 :     ddx = dx / 2;
61 :     ddy = dy / 2;
62 :     transfer_8to16sub(dct_codes, cur + y * stride + x,
63 : Isibaar 209 ref + (int) ((y + ddy) * stride + x + ddx), stride);
64 : Isibaar 3 break;
65 :    
66 : edgomez 195 case 1:
67 :     ddx = dx / 2;
68 :     ddy = (dy - 1) / 2;
69 :     transfer_8to16sub(dct_codes, cur + y * stride + x,
70 : Isibaar 209 refv + (int) ((y + ddy) * stride + x + ddx), stride);
71 : Isibaar 3 break;
72 :    
73 : edgomez 195 case 2:
74 :     ddx = (dx - 1) / 2;
75 :     ddy = dy / 2;
76 :     transfer_8to16sub(dct_codes, cur + y * stride + x,
77 : Isibaar 209 refh + (int) ((y + ddy) * stride + x + ddx), stride);
78 : Isibaar 3 break;
79 :    
80 : edgomez 195 default: // case 3:
81 :     ddx = (dx - 1) / 2;
82 :     ddy = (dy - 1) / 2;
83 :     transfer_8to16sub(dct_codes, cur + y * stride + x,
84 : Isibaar 209 refhv + (int) ((y + ddy) * stride + x + ddx), stride);
85 : Isibaar 3 break;
86 : edgomez 195 }
87 : Isibaar 3 }
88 :    
89 :    
90 :    
91 : edgomez 195 void
92 :     MBMotionCompensation(MACROBLOCK * const mb,
93 :     const uint32_t i,
94 :     const uint32_t j,
95 :     const IMAGE * const ref,
96 :     const IMAGE * const refh,
97 :     const IMAGE * const refv,
98 :     const IMAGE * const refhv,
99 :     IMAGE * const cur,
100 :     int16_t * dct_codes,
101 :     const uint32_t width,
102 :     const uint32_t height,
103 :     const uint32_t edged_width,
104 :     const uint32_t rounding)
105 : Isibaar 3 {
106 :     static const uint32_t roundtab[16] =
107 :     { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
108 :    
109 :    
110 : edgomez 195 if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
111 : Isibaar 3 int32_t dx = mb->mvs[0].x;
112 :     int32_t dy = mb->mvs[0].y;
113 :    
114 : edgomez 195 compensate8x8_halfpel(&dct_codes[0 * 64], cur->y, ref->y, refh->y,
115 :     refv->y, refhv->y, 16 * i, 16 * j, dx, dy,
116 :     edged_width);
117 :     compensate8x8_halfpel(&dct_codes[1 * 64], cur->y, ref->y, refh->y,
118 :     refv->y, refhv->y, 16 * i + 8, 16 * j, dx, dy,
119 :     edged_width);
120 :     compensate8x8_halfpel(&dct_codes[2 * 64], cur->y, ref->y, refh->y,
121 :     refv->y, refhv->y, 16 * i, 16 * j + 8, dx, dy,
122 :     edged_width);
123 :     compensate8x8_halfpel(&dct_codes[3 * 64], cur->y, ref->y, refh->y,
124 :     refv->y, refhv->y, 16 * i + 8, 16 * j + 8, dx,
125 :     dy, edged_width);
126 : Isibaar 3
127 :     dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2;
128 :     dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2;
129 :    
130 : suxen_drol 152 /* uv-image-based compensation */
131 : chl 437
132 : edgomez 195 interpolate8x8_switch(refv->u, ref->u, 8 * i, 8 * j, dx, dy,
133 :     edged_width / 2, rounding);
134 :     transfer_8to16sub(&dct_codes[4 * 64],
135 :     cur->u + 8 * j * edged_width / 2 + 8 * i,
136 :     refv->u + 8 * j * edged_width / 2 + 8 * i,
137 :     edged_width / 2);
138 : Isibaar 3
139 : edgomez 195 interpolate8x8_switch(refv->v, ref->v, 8 * i, 8 * j, dx, dy,
140 :     edged_width / 2, rounding);
141 :     transfer_8to16sub(&dct_codes[5 * 64],
142 :     cur->v + 8 * j * edged_width / 2 + 8 * i,
143 :     refv->v + 8 * j * edged_width / 2 + 8 * i,
144 :     edged_width / 2);
145 : chl 437
146 : edgomez 195 } else // mode == MODE_INTER4V
147 : Isibaar 3 {
148 :     int32_t sum, dx, dy;
149 :    
150 : edgomez 195 compensate8x8_halfpel(&dct_codes[0 * 64], cur->y, ref->y, refh->y,
151 :     refv->y, refhv->y, 16 * i, 16 * j, mb->mvs[0].x,
152 :     mb->mvs[0].y, edged_width);
153 :     compensate8x8_halfpel(&dct_codes[1 * 64], cur->y, ref->y, refh->y,
154 :     refv->y, refhv->y, 16 * i + 8, 16 * j,
155 :     mb->mvs[1].x, mb->mvs[1].y, edged_width);
156 :     compensate8x8_halfpel(&dct_codes[2 * 64], cur->y, ref->y, refh->y,
157 :     refv->y, refhv->y, 16 * i, 16 * j + 8,
158 :     mb->mvs[2].x, mb->mvs[2].y, edged_width);
159 :     compensate8x8_halfpel(&dct_codes[3 * 64], cur->y, ref->y, refh->y,
160 :     refv->y, refhv->y, 16 * i + 8, 16 * j + 8,
161 :     mb->mvs[3].x, mb->mvs[3].y, edged_width);
162 : Isibaar 3
163 :     sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x;
164 : edgomez 195 dx = (sum ? SIGN(sum) *
165 :     (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);
166 : Isibaar 3
167 :     sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;
168 : edgomez 195 dy = (sum ? SIGN(sum) *
169 :     (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);
170 : Isibaar 3
171 :     /* uv-block-based compensation */
172 : edgomez 195 interpolate8x8_switch(refv->u, ref->u, 8 * i, 8 * j, dx, dy,
173 :     edged_width / 2, rounding);
174 :     transfer_8to16sub(&dct_codes[4 * 64],
175 :     cur->u + 8 * j * edged_width / 2 + 8 * i,
176 :     refv->u + 8 * j * edged_width / 2 + 8 * i,
177 :     edged_width / 2);
178 : Isibaar 3
179 : edgomez 195 interpolate8x8_switch(refv->v, ref->v, 8 * i, 8 * j, dx, dy,
180 :     edged_width / 2, rounding);
181 :     transfer_8to16sub(&dct_codes[5 * 64],
182 :     cur->v + 8 * j * edged_width / 2 + 8 * i,
183 :     refv->v + 8 * j * edged_width / 2 + 8 * i,
184 :     edged_width / 2);
185 : Isibaar 3 }
186 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4