1 |
/***************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Motion Compensation module - |
* - Motion Compensation related code - |
5 |
* |
* |
6 |
* Copyright(C) 2002 Peter Ross <pross@xvid.org> |
* Copyright(C) 2002 Peter Ross <pross@xvid.org> |
7 |
|
* 2003 Christoph Lampert <gruel@web.de> |
8 |
* |
* |
9 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
* This program is free software ; you can redistribute it and/or modify |
10 |
* |
* it under the terms of the GNU General Public License as published by |
|
* XviD is free software; you can redistribute it and/or modify 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 |
* the Free Software Foundation; either version 2 of the License, or |
12 |
* (at your option) any later version. |
* (at your option) any later version. |
13 |
* |
* |
20 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
|
* Under section 8 of the GNU General Public License, the copyright |
|
|
* holders of XVID explicitly forbid distribution in the following |
|
|
* countries: |
|
|
* |
|
|
* - Japan |
|
|
* - United States of America |
|
|
* |
|
|
* Linking XviD statically or dynamically with other modules is making a |
|
|
* combined work based on XviD. Thus, the terms and conditions of the |
|
|
* GNU General Public License cover the whole combination. |
|
|
* |
|
|
* As a special exception, the copyright holders of XviD give you |
|
|
* permission to link XviD with independent modules that communicate with |
|
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
* license terms of these independent modules, and to copy and distribute |
|
|
* the resulting combined work under terms of your choice, provided that |
|
|
* every copy of the combined work is accompanied by a complete copy of |
|
|
* the source code of XviD (the version of XviD used to produce the |
|
|
* combined work), being distributed under the terms of the GNU General |
|
|
* Public License plus this exception. An independent module is a module |
|
|
* which is not derived from or based on XviD. |
|
|
* |
|
|
* Note that people who make modified versions of XviD are not obligated |
|
|
* to grant this special exception for their modified versions; it is |
|
|
* their choice whether to do so. The GNU General Public License gives |
|
|
* permission to release a modified version without this exception; this |
|
|
* exception also makes it possible to release a modified version which |
|
|
* carries forward this exception. |
|
|
* |
|
23 |
* $Id$ |
* $Id$ |
24 |
* |
* |
25 |
*************************************************************************/ |
****************************************************************************/ |
26 |
|
|
27 |
|
#include <stdio.h> |
28 |
|
|
29 |
#include "../encoder.h" |
#include "../encoder.h" |
30 |
#include "../utils/mbfunctions.h" |
#include "../utils/mbfunctions.h" |
31 |
#include "../image/interpolate8x8.h" |
#include "../image/interpolate8x8.h" |
32 |
|
#include "../image/qpel.h" |
33 |
#include "../utils/timer.h" |
#include "../utils/timer.h" |
34 |
#include "motion.h" |
#include "motion.h" |
35 |
|
|
36 |
#define ABS(X) (((X)>0)?(X):-(X)) |
/* |
37 |
#define SIGN(X) (((X)>0)?1:-1) |
* getref: calculate reference image pointer |
38 |
|
* the decision to use interpolation h/v/hv or the normal image is |
39 |
|
* based on dx & dy. |
40 |
|
*/ |
41 |
|
|
42 |
static __inline void |
static __inline const uint8_t * |
43 |
compensate8x8_halfpel(int16_t * const dct_codes, |
get_ref(const uint8_t * const refn, |
|
uint8_t * const cur, |
|
|
const uint8_t * const ref, |
|
44 |
const uint8_t * const refh, |
const uint8_t * const refh, |
45 |
const uint8_t * const refv, |
const uint8_t * const refv, |
46 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
47 |
const uint32_t x, |
const uint32_t x, |
48 |
const uint32_t y, |
const uint32_t y, |
49 |
|
const uint32_t block, |
50 |
const int32_t dx, |
const int32_t dx, |
51 |
const int dy, |
const int32_t dy, |
52 |
const uint32_t stride) |
const int32_t stride) |
53 |
{ |
{ |
54 |
int32_t ddx, ddy; |
switch (((dx & 1) << 1) + (dy & 1)) { |
55 |
|
case 0: |
56 |
|
return refn + (int) (((int)x * (int)block + dx / 2) + ((int)y * (int)block + dy / 2) * (int)stride); |
57 |
|
case 1: |
58 |
|
return refv + (int) (((int)x * (int)block + dx / 2) + ((int)y * (int)block + (dy - 1) / 2) * (int)stride); |
59 |
|
case 2: |
60 |
|
return refh + (int) (((int)x * (int)block + (dx - 1) / 2) + ((int)y * (int)block + dy / 2) * (int)stride); |
61 |
|
default: |
62 |
|
return refhv + (int) (((int)x * (int)block + (dx - 1) / 2) + ((int)y * (int)block + (dy - 1) / 2) * (int)stride); |
63 |
|
} |
64 |
|
} |
65 |
|
|
66 |
switch (((dx & 1) << 1) + (dy & 1)) // ((dx%2)?2:0)+((dy%2)?1:0) |
static __inline void |
67 |
|
compensate16x16_interpolate(int16_t * const dct_codes, |
68 |
|
uint8_t * const cur, |
69 |
|
const uint8_t * const ref, |
70 |
|
const uint8_t * const refh, |
71 |
|
const uint8_t * const refv, |
72 |
|
const uint8_t * const refhv, |
73 |
|
uint8_t * const tmp, |
74 |
|
uint32_t x, |
75 |
|
uint32_t y, |
76 |
|
const int32_t dx, |
77 |
|
const int32_t dy, |
78 |
|
const int32_t stride, |
79 |
|
const int quarterpel, |
80 |
|
const int32_t rounding) |
81 |
{ |
{ |
82 |
case 0: |
const uint8_t * ptr; |
|
ddx = dx / 2; |
|
|
ddy = dy / 2; |
|
|
transfer_8to16sub(dct_codes, cur + y * stride + x, |
|
|
ref + (int) ((y + ddy) * stride + x + ddx), stride); |
|
|
break; |
|
83 |
|
|
|
case 1: |
|
|
ddx = dx / 2; |
|
|
ddy = (dy - 1) / 2; |
|
|
transfer_8to16sub(dct_codes, cur + y * stride + x, |
|
|
refv + (int) ((y + ddy) * stride + x + ddx), stride); |
|
|
break; |
|
84 |
|
|
85 |
case 2: |
if(quarterpel) { |
86 |
ddx = (dx - 1) / 2; |
if ((dx&3) | (dy&3)) { |
87 |
ddy = dy / 2; |
interpolate16x16_quarterpel(tmp - y * stride - x, |
88 |
transfer_8to16sub(dct_codes, cur + y * stride + x, |
(uint8_t *) ref, tmp + 32, |
89 |
refh + (int) ((y + ddy) * stride + x + ddx), stride); |
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
90 |
break; |
ptr = tmp; |
91 |
|
} else ptr = ref + ((int)y + dy/4)*(int)stride + (int)x + dx/4; /* fullpixel position */ |
92 |
|
|
93 |
|
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
94 |
|
|
|
default: // case 3: |
|
|
ddx = (dx - 1) / 2; |
|
|
ddy = (dy - 1) / 2; |
|
95 |
transfer_8to16sub(dct_codes, cur + y * stride + x, |
transfer_8to16sub(dct_codes, cur + y * stride + x, |
96 |
refhv + (int) ((y + ddy) * stride + x + ddx), stride); |
ptr, stride); |
97 |
break; |
transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
98 |
|
ptr + 8, stride); |
99 |
|
transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
100 |
|
ptr + 8*stride, stride); |
101 |
|
transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
102 |
|
ptr + 8*stride + 8, stride); |
103 |
|
|
104 |
} |
} |
105 |
|
|
106 |
|
static __inline void |
107 |
|
compensate8x8_interpolate( int16_t * const dct_codes, |
108 |
|
uint8_t * const cur, |
109 |
|
const uint8_t * const ref, |
110 |
|
const uint8_t * const refh, |
111 |
|
const uint8_t * const refv, |
112 |
|
const uint8_t * const refhv, |
113 |
|
uint8_t * const tmp, |
114 |
|
uint32_t x, |
115 |
|
uint32_t y, |
116 |
|
const int32_t dx, |
117 |
|
const int32_t dy, |
118 |
|
const int32_t stride, |
119 |
|
const int32_t quarterpel, |
120 |
|
const int32_t rounding) |
121 |
|
{ |
122 |
|
const uint8_t * ptr; |
123 |
|
|
124 |
|
if(quarterpel) { |
125 |
|
if ((dx&3) | (dy&3)) { |
126 |
|
interpolate8x8_quarterpel(tmp - y*stride - x, |
127 |
|
(uint8_t *) ref, tmp + 32, |
128 |
|
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
129 |
|
ptr = tmp; |
130 |
|
} else ptr = ref + ((int)y + dy/4)*(int)stride + (int)x + dx/4; /* fullpixel position */ |
131 |
|
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
132 |
|
|
133 |
|
transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride); |
134 |
} |
} |
135 |
|
|
136 |
|
|
137 |
|
static void |
138 |
|
CompensateChroma( int dx, int dy, |
139 |
|
const int i, const int j, |
140 |
|
IMAGE * const Cur, |
141 |
|
const IMAGE * const Ref, |
142 |
|
uint8_t * const temp, |
143 |
|
int16_t * const coeff, |
144 |
|
const int32_t stride, |
145 |
|
const int rounding) |
146 |
|
{ /* uv-block-based compensation */ |
147 |
|
|
148 |
|
transfer_8to16sub(coeff, Cur->u + 8 * j * stride + 8 * i, |
149 |
|
interpolate8x8_switch2(temp, Ref->u, 8 * i, 8 * j, |
150 |
|
dx, dy, stride, rounding), |
151 |
|
stride); |
152 |
|
transfer_8to16sub(coeff + 64, Cur->v + 8 * j * stride + 8 * i, |
153 |
|
interpolate8x8_switch2(temp, Ref->v, 8 * i, 8 * j, |
154 |
|
dx, dy, stride, rounding), |
155 |
|
stride); |
156 |
|
} |
157 |
|
|
158 |
void |
void |
159 |
MBMotionCompensation(MACROBLOCK * const mb, |
MBMotionCompensation(MACROBLOCK * const mb, |
163 |
const IMAGE * const refh, |
const IMAGE * const refh, |
164 |
const IMAGE * const refv, |
const IMAGE * const refv, |
165 |
const IMAGE * const refhv, |
const IMAGE * const refhv, |
166 |
|
const IMAGE * const refGMC, |
167 |
IMAGE * const cur, |
IMAGE * const cur, |
168 |
int16_t * dct_codes, |
int16_t * dct_codes, |
169 |
const uint32_t width, |
const uint32_t width, |
170 |
const uint32_t height, |
const uint32_t height, |
171 |
const uint32_t edged_width, |
const uint32_t edged_width, |
172 |
const uint32_t rounding) |
const int32_t quarterpel, |
173 |
|
const int32_t rounding, |
174 |
|
uint8_t * const tmp) |
175 |
{ |
{ |
176 |
static const uint32_t roundtab[16] = |
int32_t dx; |
177 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
int32_t dy; |
178 |
|
|
179 |
|
if (mb->mode == MODE_NOT_CODED) { /* quick copy for early SKIP */ |
180 |
|
/* early SKIP is only activated in P-VOPs, not in S-VOPs, so mcsel can never be 1 */ |
181 |
|
|
182 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
183 |
int32_t dx = mb->mvs[0].x; |
ref->y + 16 * (i + j * edged_width), |
|
int32_t dy = mb->mvs[0].y; |
|
|
|
|
|
compensate8x8_halfpel(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i, 16 * j, dx, dy, |
|
|
edged_width); |
|
|
compensate8x8_halfpel(&dct_codes[1 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i + 8, 16 * j, dx, dy, |
|
|
edged_width); |
|
|
compensate8x8_halfpel(&dct_codes[2 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i, 16 * j + 8, dx, dy, |
|
184 |
edged_width); |
edged_width); |
|
compensate8x8_halfpel(&dct_codes[3 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, dx, |
|
|
dy, edged_width); |
|
|
|
|
|
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
|
|
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
|
|
|
|
|
/* uv-image-based compensation */ |
|
|
|
|
|
interpolate8x8_switch(refv->u, ref->u, 8 * i, 8 * j, dx, dy, |
|
|
edged_width / 2, rounding); |
|
|
transfer_8to16sub(&dct_codes[4 * 64], |
|
|
cur->u + 8 * j * edged_width / 2 + 8 * i, |
|
|
refv->u + 8 * j * edged_width / 2 + 8 * i, |
|
|
edged_width / 2); |
|
185 |
|
|
186 |
interpolate8x8_switch(refv->v, ref->v, 8 * i, 8 * j, dx, dy, |
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
187 |
edged_width / 2, rounding); |
ref->u + 8 * (i + j * edged_width/2), |
188 |
transfer_8to16sub(&dct_codes[5 * 64], |
edged_width / 2); |
189 |
cur->v + 8 * j * edged_width / 2 + 8 * i, |
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
190 |
refv->v + 8 * j * edged_width / 2 + 8 * i, |
ref->v + 8 * (i + j * edged_width/2), |
191 |
edged_width / 2); |
edged_width / 2); |
192 |
|
return; |
193 |
|
} |
194 |
|
|
195 |
|
if ((mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER |
196 |
|
|| mb->mode == MODE_INTER_Q)) { |
197 |
|
|
198 |
|
if (mb->mcsel) { |
199 |
|
|
200 |
|
/* call normal routine once, easier than "if (mcsel)"ing all the time */ |
201 |
|
|
202 |
|
transfer_8to16sub(&dct_codes[0*64], cur->y + 16*j*edged_width + 16*i, |
203 |
|
refGMC->y + 16*j*edged_width + 16*i, edged_width); |
204 |
|
transfer_8to16sub(&dct_codes[1*64], cur->y + 16*j*edged_width + 16*i+8, |
205 |
|
refGMC->y + 16*j*edged_width + 16*i+8, edged_width); |
206 |
|
transfer_8to16sub(&dct_codes[2*64], cur->y + (16*j+8)*edged_width + 16*i, |
207 |
|
refGMC->y + (16*j+8)*edged_width + 16*i, edged_width); |
208 |
|
transfer_8to16sub(&dct_codes[3*64], cur->y + (16*j+8)*edged_width + 16*i+8, |
209 |
|
refGMC->y + (16*j+8)*edged_width + 16*i+8, edged_width); |
210 |
|
|
211 |
|
transfer_8to16sub(&dct_codes[4 * 64], cur->u + 8 *j*edged_width/2 + 8*i, |
212 |
|
refGMC->u + 8 *j*edged_width/2 + 8*i, edged_width/2); |
213 |
|
|
214 |
|
transfer_8to16sub(&dct_codes[5 * 64], cur->v + 8*j* edged_width/2 + 8*i, |
215 |
|
refGMC->v + 8*j* edged_width/2 + 8*i, edged_width/2); |
216 |
|
|
217 |
|
return; |
218 |
|
} |
219 |
|
|
220 |
|
/* ordinary compensation */ |
221 |
|
|
222 |
|
dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x); |
223 |
|
dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y); |
224 |
|
|
225 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
226 |
|
refv->y, refhv->y, tmp, 16 * i, 16 * j, dx, dy, |
227 |
|
edged_width, quarterpel, rounding); |
228 |
|
|
229 |
} else // mode == MODE_INTER4V |
if (quarterpel) { dx /= 2; dy /= 2; } |
230 |
|
|
231 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
232 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
233 |
|
|
234 |
|
} else { /* mode == MODE_INTER4V */ |
235 |
|
int k, sumx = 0, sumy = 0; |
236 |
|
const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs); |
237 |
|
|
238 |
|
for (k = 0; k < 4; k++) { |
239 |
|
dx = mvs[k].x; |
240 |
|
dy = mvs[k].y; |
241 |
|
sumx += quarterpel ? dx/2 : dx; |
242 |
|
sumy += quarterpel ? dy/2 : dy; |
243 |
|
|
244 |
|
compensate8x8_interpolate(&dct_codes[k * 64], cur->y, ref->y, refh->y, |
245 |
|
refv->y, refhv->y, tmp, 16 * i + 8*(k&1), 16 * j + 8*(k>>1), dx, |
246 |
|
dy, edged_width, quarterpel, rounding); |
247 |
|
} |
248 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
249 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
250 |
|
} |
251 |
|
|
252 |
|
CompensateChroma(dx, dy, i, j, cur, ref, tmp, |
253 |
|
&dct_codes[4 * 64], edged_width / 2, rounding); |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
|
void |
258 |
|
MBMotionCompensationBVOP(MBParam * pParam, |
259 |
|
MACROBLOCK * const mb, |
260 |
|
const uint32_t i, |
261 |
|
const uint32_t j, |
262 |
|
IMAGE * const cur, |
263 |
|
const IMAGE * const f_ref, |
264 |
|
const IMAGE * const f_refh, |
265 |
|
const IMAGE * const f_refv, |
266 |
|
const IMAGE * const f_refhv, |
267 |
|
const IMAGE * const b_ref, |
268 |
|
const IMAGE * const b_refh, |
269 |
|
const IMAGE * const b_refv, |
270 |
|
const IMAGE * const b_refhv, |
271 |
|
int16_t * dct_codes, |
272 |
|
uint8_t * const tmp) |
273 |
{ |
{ |
274 |
int32_t sum, dx, dy; |
const uint32_t edged_width = pParam->edged_width; |
275 |
|
int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy; |
276 |
|
int k; |
277 |
|
const int quarterpel = pParam->vol_flags & XVID_VOL_QUARTERPEL; |
278 |
|
const uint8_t * ptr1, * ptr2; |
279 |
|
const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs); |
280 |
|
const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs); |
281 |
|
|
282 |
|
switch (mb->mode) { |
283 |
|
case MODE_FORWARD: |
284 |
|
dx = fmvs->x; dy = fmvs->y; |
285 |
|
|
286 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, |
287 |
|
f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx, |
288 |
|
dy, edged_width, quarterpel, 0); |
289 |
|
|
290 |
|
if (quarterpel) { dx /= 2; dy /= 2; } |
291 |
|
|
292 |
|
CompensateChroma( (dx >> 1) + roundtab_79[dx & 0x3], |
293 |
|
(dy >> 1) + roundtab_79[dy & 0x3], |
294 |
|
i, j, cur, f_ref, tmp, |
295 |
|
&dct_codes[4 * 64], edged_width / 2, 0); |
296 |
|
|
297 |
|
return; |
298 |
|
|
299 |
|
case MODE_BACKWARD: |
300 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
301 |
|
|
302 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
303 |
|
b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx, |
304 |
|
b_dy, edged_width, quarterpel, 0); |
305 |
|
|
306 |
|
if (quarterpel) { b_dx /= 2; b_dy /= 2; } |
307 |
|
|
308 |
|
CompensateChroma( (b_dx >> 1) + roundtab_79[b_dx & 0x3], |
309 |
|
(b_dy >> 1) + roundtab_79[b_dy & 0x3], |
310 |
|
i, j, cur, b_ref, tmp, |
311 |
|
&dct_codes[4 * 64], edged_width / 2, 0); |
312 |
|
|
313 |
|
return; |
314 |
|
|
315 |
|
case MODE_INTERPOLATE: |
316 |
|
case MODE_DIRECT_NO4V: |
317 |
|
dx = fmvs->x; dy = fmvs->y; |
318 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
319 |
|
|
320 |
|
if (quarterpel) { |
321 |
|
|
322 |
|
if ((dx&3) | (dy&3)) { |
323 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width, |
324 |
|
(uint8_t *) f_ref->y, tmp + 32, |
325 |
|
tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0); |
326 |
|
ptr1 = tmp; |
327 |
|
} else ptr1 = f_ref->y + (16*(int)j + dy/4)*(int)edged_width + 16*(int)i + dx/4; /* fullpixel position */ |
328 |
|
|
329 |
|
if ((b_dx&3) | (b_dy&3)) { |
330 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16, |
331 |
|
(uint8_t *) b_ref->y, tmp + 32, |
332 |
|
tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0); |
333 |
|
ptr2 = tmp + 16; |
334 |
|
} else ptr2 = b_ref->y + (16*(int)j + b_dy/4)*(int)edged_width + 16*(int)i + b_dx/4; /* fullpixel position */ |
335 |
|
|
336 |
|
b_dx /= 2; |
337 |
|
b_dy /= 2; |
338 |
|
dx /= 2; |
339 |
|
dy /= 2; |
340 |
|
|
341 |
|
} else { |
342 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
343 |
|
i, j, 16, dx, dy, edged_width); |
344 |
|
|
345 |
|
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
346 |
|
i, j, 16, b_dx, b_dy, edged_width); |
347 |
|
} |
348 |
|
for (k = 0; k < 4; k++) |
349 |
|
transfer_8to16sub2(&dct_codes[k * 64], |
350 |
|
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
351 |
|
ptr1 + (k&1)*8 + (k>>1)*8*edged_width, |
352 |
|
ptr2 + (k&1)*8 + (k>>1)*8*edged_width, edged_width); |
353 |
|
|
354 |
|
|
355 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
356 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
357 |
|
|
358 |
|
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
359 |
|
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
360 |
|
|
361 |
|
break; |
362 |
|
|
363 |
|
default: /* MODE_DIRECT (or MODE_DIRECT_NONE_MV in case of bframes decoding) */ |
364 |
|
sumx = sumy = b_sumx = b_sumy = 0; |
365 |
|
|
366 |
compensate8x8_halfpel(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
for (k = 0; k < 4; k++) { |
367 |
refv->y, refhv->y, 16 * i, 16 * j, mb->mvs[0].x, |
|
368 |
mb->mvs[0].y, edged_width); |
dx = fmvs[k].x; dy = fmvs[k].y; |
369 |
compensate8x8_halfpel(&dct_codes[1 * 64], cur->y, ref->y, refh->y, |
b_dx = bmvs[k].x; b_dy = bmvs[k].y; |
370 |
refv->y, refhv->y, 16 * i + 8, 16 * j, |
|
371 |
mb->mvs[1].x, mb->mvs[1].y, edged_width); |
if (quarterpel) { |
372 |
compensate8x8_halfpel(&dct_codes[2 * 64], cur->y, ref->y, refh->y, |
sumx += dx/2; sumy += dy/2; |
373 |
refv->y, refhv->y, 16 * i, 16 * j + 8, |
b_sumx += b_dx/2; b_sumy += b_dy/2; |
374 |
mb->mvs[2].x, mb->mvs[2].y, edged_width); |
|
375 |
compensate8x8_halfpel(&dct_codes[3 * 64], cur->y, ref->y, refh->y, |
if ((dx&3) | (dy&3)) { |
376 |
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, |
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width, |
377 |
mb->mvs[3].x, mb->mvs[3].y, edged_width); |
(uint8_t *) f_ref->y, |
378 |
|
tmp + 32, tmp + 64, tmp + 96, |
379 |
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
380 |
dx = (sum ? SIGN(sum) * |
ptr1 = tmp; |
381 |
(roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
} else ptr1 = f_ref->y + (16*(int)j + (k>>1)*8 + dy/4)*(int)edged_width + 16*(int)i + (k&1)*8 + dx/4; |
382 |
|
|
383 |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
if ((b_dx&3) | (b_dy&3)) { |
384 |
dy = (sum ? SIGN(sum) * |
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16, |
385 |
(roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
(uint8_t *) b_ref->y, |
386 |
|
tmp + 16, tmp + 32, tmp + 48, |
387 |
/* uv-block-based compensation */ |
16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
388 |
interpolate8x8_switch(refv->u, ref->u, 8 * i, 8 * j, dx, dy, |
ptr2 = tmp + 16; |
389 |
edged_width / 2, rounding); |
} else ptr2 = b_ref->y + (16*(int)j + (k>>1)*8 + b_dy/4)*(int)edged_width + 16*(int)i + (k&1)*8 + b_dx/4; |
390 |
transfer_8to16sub(&dct_codes[4 * 64], |
} else { |
391 |
cur->u + 8 * j * edged_width / 2 + 8 * i, |
sumx += dx; sumy += dy; |
392 |
refv->u + 8 * j * edged_width / 2 + 8 * i, |
b_sumx += b_dx; b_sumy += b_dy; |
393 |
|
|
394 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
395 |
|
2*i + (k&1), 2*j + (k>>1), 8, dx, dy, edged_width); |
396 |
|
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
397 |
|
2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, edged_width); |
398 |
|
} |
399 |
|
transfer_8to16sub2(&dct_codes[k * 64], |
400 |
|
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
401 |
|
ptr1, ptr2, edged_width); |
402 |
|
|
403 |
|
} |
404 |
|
|
405 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
406 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
407 |
|
b_dx = (b_sumx >> 3) + roundtab_76[b_sumx & 0xf]; |
408 |
|
b_dy = (b_sumy >> 3) + roundtab_76[b_sumy & 0xf]; |
409 |
|
|
410 |
|
break; |
411 |
|
} |
412 |
|
|
413 |
|
/* block-based chroma interpolation for direct and interpolate modes */ |
414 |
|
transfer_8to16sub2(&dct_codes[4 * 64], |
415 |
|
cur->u + (j * 8) * edged_width / 2 + (i * 8), |
416 |
|
interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j, |
417 |
|
b_dx, b_dy, edged_width / 2, 0), |
418 |
|
interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j, |
419 |
|
dx, dy, edged_width / 2, 0), |
420 |
edged_width / 2); |
edged_width / 2); |
421 |
|
|
422 |
interpolate8x8_switch(refv->v, ref->v, 8 * i, 8 * j, dx, dy, |
transfer_8to16sub2(&dct_codes[5 * 64], |
423 |
edged_width / 2, rounding); |
cur->v + (j * 8) * edged_width / 2 + (i * 8), |
424 |
transfer_8to16sub(&dct_codes[5 * 64], |
interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j, |
425 |
cur->v + 8 * j * edged_width / 2 + 8 * i, |
b_dx, b_dy, edged_width / 2, 0), |
426 |
refv->v + 8 * j * edged_width / 2 + 8 * i, |
interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j, |
427 |
|
dx, dy, edged_width / 2, 0), |
428 |
edged_width / 2); |
edged_width / 2); |
429 |
} |
} |
|
} |
|