1 |
// 01.05.2002 updated MBMotionCompensationBVOP |
/***************************************************************************** |
2 |
// 14.04.2002 bframe compensation |
* |
3 |
|
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Motion Compensation related code - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Peter Ross <pross@xvid.org> |
7 |
|
* 2003 Christoph Lampert <gruel@web.de> |
8 |
|
* |
9 |
|
* 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 |
11 |
|
* the Free Software Foundation ; either version 2 of the License, or |
12 |
|
* (at your option) any later version. |
13 |
|
* |
14 |
|
* This program 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 |
|
* $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 const uint8_t * |
43 |
|
get_ref(const uint8_t * const refn, |
44 |
|
const uint8_t * const refh, |
45 |
|
const uint8_t * const refv, |
46 |
|
const uint8_t * const refhv, |
47 |
|
const uint32_t x, |
48 |
|
const uint32_t y, |
49 |
|
const uint32_t block, |
50 |
|
const int32_t dx, |
51 |
|
const int32_t dy, |
52 |
|
const int32_t stride) |
53 |
|
{ |
54 |
|
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 |
static __inline void compensate8x8_halfpel( |
static __inline void |
67 |
int16_t * const dct_codes, |
compensate16x16_interpolate(int16_t * const dct_codes, |
68 |
uint8_t * const cur, |
uint8_t * const cur, |
69 |
const uint8_t * const ref, |
const uint8_t * const ref, |
70 |
const uint8_t * const refh, |
const uint8_t * const refh, |
71 |
const uint8_t * const refv, |
const uint8_t * const refv, |
72 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
73 |
const uint32_t x, const uint32_t y, |
uint8_t * const tmp, |
74 |
const int32_t dx, const int dy, |
uint32_t x, |
75 |
const uint32_t stride) |
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 |
int32_t ddx,ddy; |
const uint8_t * ptr; |
83 |
|
|
|
switch ( ((dx&1)<<1) + (dy&1) ) // ((dx%2)?2:0)+((dy%2)?1:0) |
|
|
{ |
|
|
case 0 : |
|
|
ddx = dx/2; |
|
|
ddy = dy/2; |
|
|
transfer_8to16sub(dct_codes, cur + y*stride + x, |
|
|
ref + (y+ddy)*stride + x+ddx, stride); |
|
|
break; |
|
84 |
|
|
85 |
case 1 : |
if(quarterpel) { |
86 |
ddx = dx/2; |
if ((dx&3) | (dy&3)) { |
87 |
ddy = (dy-1)/2; |
interpolate16x16_quarterpel(tmp - y * stride - x, |
88 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
(uint8_t *) ref, tmp + 32, |
89 |
refv + (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 |
case 2 : |
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
|
ddx = (dx-1)/2; |
|
|
ddy = dy/2; |
|
|
transfer_8to16sub(dct_codes, cur + y*stride + x, |
|
|
refh + (y+ddy)*stride + x+ddx, stride); |
|
|
break; |
|
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 + (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 MBMotionCompensation( |
void |
159 |
MACROBLOCK * const mb, |
MBMotionCompensation(MACROBLOCK * const mb, |
160 |
const uint32_t i, |
const uint32_t i, |
161 |
const uint32_t j, |
const uint32_t j, |
162 |
const IMAGE * const ref, |
const IMAGE * const ref, |
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 |
{ |
ref->y + 16 * (i + j * edged_width), |
184 |
int32_t dx = mb->mvs[0].x; |
edged_width); |
|
int32_t dy = mb->mvs[0].y; |
|
185 |
|
|
186 |
compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
187 |
16*i, 16*j, dx, dy, edged_width); |
ref->u + 8 * (i + j * edged_width/2), |
188 |
compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
edged_width / 2); |
189 |
16*i + 8, 16*j, dx, dy, edged_width); |
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
190 |
compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
ref->v + 8 * (i + j * edged_width/2), |
191 |
16*i, 16*j + 8, dx, dy, edged_width); |
edged_width / 2); |
192 |
compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
return; |
|
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 */ |
|
|
#ifdef BFRAMES |
|
|
compensate8x8_halfpel(&dct_codes[4*64], cur->u, ref->u, refh->u, refv->u, refhv->u, |
|
|
8*i, 8*j, dx, dy, edged_width/2); |
|
|
compensate8x8_halfpel(&dct_codes[5*64], cur->v, ref->v, refh->v, refv->v, refhv->v, |
|
|
8*i, 8*j, dx, dy, edged_width/2); |
|
|
#else |
|
|
/* uv-block-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); |
|
|
|
|
|
interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
|
transfer_8to16sub(&dct_codes[5*64], |
|
|
cur->v + 8*j*edged_width/2 + 8*i, |
|
|
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
|
|
#endif |
|
193 |
} |
} |
|
else // mode == MODE_INTER4V |
|
|
{ |
|
|
int32_t sum, dx, dy; |
|
194 |
|
|
195 |
compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
if ((mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER |
196 |
16*i, 16*j, mb->mvs[0].x, mb->mvs[0].y, edged_width); |
|| mb->mode == MODE_INTER_Q)) { |
197 |
compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
198 |
16*i + 8, 16*j, mb->mvs[1].x, mb->mvs[1].y, edged_width); |
if (mb->mcsel) { |
199 |
compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
200 |
16*i, 16*j + 8, mb->mvs[2].x, mb->mvs[2].y, edged_width); |
/* call normal routine once, easier than "if (mcsel)"ing all the time */ |
201 |
compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
202 |
16*i + 8, 16*j + 8, mb->mvs[3].x, mb->mvs[3].y, edged_width); |
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 |
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
transfer_8to16sub(&dct_codes[1*64], cur->y + 16*j*edged_width + 16*i+8, |
205 |
dx = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
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 |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
refGMC->y + (16*j+8)*edged_width + 16*i, edged_width); |
208 |
dy = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
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 |
/* uv-image-based compensation */ |
|
211 |
#ifdef BFRAMES |
transfer_8to16sub(&dct_codes[4 * 64], cur->u + 8 *j*edged_width/2 + 8*i, |
212 |
compensate8x8_halfpel(&dct_codes[4*64], cur->u, ref->u, refh->u, refv->u, refhv->u, |
refGMC->u + 8 *j*edged_width/2 + 8*i, edged_width/2); |
213 |
8*i, 8*j, dx, dy, edged_width/2); |
|
214 |
compensate8x8_halfpel(&dct_codes[5*64], cur->v, ref->v, refh->v, refv->v, refhv->v, |
transfer_8to16sub(&dct_codes[5 * 64], cur->v + 8*j* edged_width/2 + 8*i, |
215 |
8*i, 8*j, dx, dy, edged_width/2); |
refGMC->v + 8*j* edged_width/2 + 8*i, edged_width/2); |
216 |
#else |
|
217 |
/* uv-block-based compensation */ |
return; |
|
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); |
|
|
|
|
|
interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
|
transfer_8to16sub(&dct_codes[5*64], |
|
|
cur->v + 8*j*edged_width/2 + 8*i, |
|
|
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
|
|
#endif |
|
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 |
|
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 MBMotionCompensationBVOP( |
void |
258 |
MBParam * pParam, |
MBMotionCompensationBVOP(MBParam * pParam, |
259 |
MACROBLOCK * const mb, |
MACROBLOCK * const mb, |
260 |
const uint32_t i, |
const uint32_t i, |
261 |
const uint32_t j, |
const uint32_t j, |
268 |
const IMAGE * const b_refh, |
const IMAGE * const b_refh, |
269 |
const IMAGE * const b_refv, |
const IMAGE * const b_refv, |
270 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
271 |
int16_t * dct_codes) |
int16_t * dct_codes, |
272 |
|
uint8_t * const tmp) |
273 |
{ |
{ |
274 |
static const uint32_t roundtab[16] = |
const uint32_t edged_width = pParam->edged_width; |
275 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy; |
276 |
|
int k; |
277 |
const int32_t edged_width = pParam->edged_width; |
const int quarterpel = pParam->vol_flags & XVID_VOL_QUARTERPEL; |
278 |
int32_t dx, dy; |
const uint8_t * ptr1, * ptr2; |
279 |
int32_t b_dx, b_dy; |
const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs); |
280 |
int x = i; |
const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs); |
|
int y = j; |
|
281 |
|
|
282 |
|
switch (mb->mode) { |
|
|
|
|
switch(mb->mode) |
|
|
{ |
|
283 |
case MODE_FORWARD : |
case MODE_FORWARD : |
284 |
dx = mb->mvs[0].x; |
dx = fmvs->x; dy = fmvs->y; |
|
dy = mb->mvs[0].y; |
|
285 |
|
|
286 |
transfer_8to16sub_c( |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, |
287 |
&dct_codes[0*64], |
f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx, |
288 |
cur->y + (j*16)*edged_width + (i*16), |
dy, edged_width, quarterpel, 0); |
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
i*16, j*16, 1, dx, dy, edged_width), |
|
|
edged_width); |
|
289 |
|
|
290 |
transfer_8to16sub( |
if (quarterpel) { dx /= 2; dy /= 2; } |
|
&dct_codes[1*64], |
|
|
cur->y + (j*16)*edged_width + (i*16+8), |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
i*16+8, j*16, 1, dx, dy, edged_width), |
|
|
edged_width); |
|
291 |
|
|
292 |
transfer_8to16sub_c( |
CompensateChroma( (dx >> 1) + roundtab_79[dx & 0x3], |
293 |
&dct_codes[2*64], |
(dy >> 1) + roundtab_79[dy & 0x3], |
294 |
cur->y + (j*16+8)*edged_width + (i*16), |
i, j, cur, f_ref, tmp, |
295 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
&dct_codes[4 * 64], edged_width / 2, 0); |
|
i*16, j*16+8, 1, dx, dy, edged_width), |
|
|
edged_width); |
|
296 |
|
|
297 |
transfer_8to16sub( |
return; |
|
&dct_codes[3*64], |
|
|
cur->y + (j*16+8)*edged_width + (i*16+8), |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
i*16+8, j*16+8, 1, dx, dy, edged_width), |
|
|
edged_width); |
|
298 |
|
|
299 |
|
case MODE_BACKWARD: |
300 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
301 |
|
|
302 |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
303 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx, |
304 |
|
b_dy, edged_width, quarterpel, 0); |
305 |
|
|
306 |
/* uv-image-based compensation */ |
if (quarterpel) { b_dx /= 2; b_dy /= 2; } |
|
compensate8x8_halfpel(&dct_codes[4*64], cur->u, f_ref->u, f_refh->u, f_refv->u, f_refhv->u, |
|
|
8*i, 8*j, dx, dy, edged_width/2); |
|
|
compensate8x8_halfpel(&dct_codes[5*64], cur->v, f_ref->v, f_refh->v, f_refv->v, f_refhv->v, |
|
|
8*i, 8*j, dx, dy, edged_width/2); |
|
307 |
|
|
308 |
break; |
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 |
case MODE_BACKWARD : |
return; |
|
b_dx = mb->b_mvs[0].x; |
|
|
b_dy = mb->b_mvs[0].y; |
|
314 |
|
|
315 |
transfer_8to16sub_c( |
case MODE_INTERPOLATE: |
316 |
&dct_codes[0*64], |
case MODE_DIRECT_NO4V: |
317 |
cur->y + (j*16)*edged_width + (i*16), |
dx = fmvs->x; dy = fmvs->y; |
318 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
b_dx = bmvs->x; b_dy = bmvs->y; |
319 |
i*16, j*16, 1, b_dx, b_dy, edged_width), |
|
320 |
edged_width); |
if (quarterpel) { |
321 |
|
|
322 |
transfer_8to16sub( |
if ((dx&3) | (dy&3)) { |
323 |
&dct_codes[1*64], |
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width, |
324 |
cur->y + (j*16)*edged_width + (i*16+8), |
(uint8_t *) f_ref->y, tmp + 32, |
325 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0); |
326 |
i*16+8, j*16, 1, b_dx, b_dy, edged_width), |
ptr1 = tmp; |
327 |
edged_width); |
} 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 |
transfer_8to16sub_c( |
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
346 |
&dct_codes[2*64], |
i, j, 16, b_dx, b_dy, edged_width); |
347 |
cur->y + (j*16+8)*edged_width + (i*16), |
} |
348 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
for (k = 0; k < 4; k++) |
349 |
i*16, j*16+8, 1, b_dx, b_dy, edged_width), |
transfer_8to16sub2(&dct_codes[k * 64], |
350 |
edged_width); |
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 |
|
|
|
transfer_8to16sub( |
|
|
&dct_codes[3*64], |
|
|
cur->y + (j*16+8)*edged_width + (i*16+8), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
i*16+8, j*16+8, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
354 |
|
|
355 |
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
356 |
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
357 |
|
|
358 |
/* uv-image-based compensation */ |
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
359 |
compensate8x8_halfpel(&dct_codes[4*64], cur->u, |
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
|
b_ref->u, b_refh->u, b_refv->u, b_refhv->u, |
|
|
8*i, 8*j, b_dx, b_dy, edged_width/2); |
|
|
compensate8x8_halfpel(&dct_codes[5*64], cur->v, |
|
|
b_ref->v, b_refh->v, b_refv->v, b_refhv->v, |
|
|
8*i, 8*j, b_dx, b_dy, edged_width/2); |
|
360 |
|
|
361 |
break; |
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 |
case MODE_INTERPOLATE : |
for (k = 0; k < 4; k++) { |
|
dx = mb->mvs[0].x; |
|
|
dy = mb->mvs[0].y; |
|
|
b_dx = mb->b_mvs[0].x; |
|
|
b_dy = mb->b_mvs[0].y; |
|
|
|
|
|
transfer_8to16sub2_c( |
|
|
&dct_codes[0*64], |
|
|
cur->y + (i*16) + (j*16)*edged_width, |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
16*i, 16*j, 1, dx, dy, edged_width), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
16*i, 16*j, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
367 |
|
|
368 |
transfer_8to16sub2_c( |
dx = fmvs[k].x; dy = fmvs[k].y; |
369 |
&dct_codes[1*64], |
b_dx = bmvs[k].x; b_dy = bmvs[k].y; |
|
cur->y + (i*16+8) + (j*16)*edged_width, |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
16*i+8, 16*j, 1, dx, dy, edged_width), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
16*i+8, 16*j, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
|
|
|
|
transfer_8to16sub2_c( |
|
|
&dct_codes[2*64], |
|
|
cur->y + (i*16) + (j*16+8)*edged_width, |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
16*i, 16*j+8, 1, dx, dy, edged_width), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
16*i, 16*j+8, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
370 |
|
|
371 |
transfer_8to16sub2_c( |
if (quarterpel) { |
372 |
&dct_codes[3*64], |
sumx += dx/2; sumy += dy/2; |
373 |
cur->y + (i*16+8) + (j*16+8)*edged_width, |
b_sumx += b_dx/2; b_sumy += b_dy/2; |
374 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
375 |
16*i + 8, 16*j + 8, 1, dx, dy, edged_width), |
if ((dx&3) | (dy&3)) { |
376 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width, |
377 |
16*i + 8, 16*j + 8, 1, b_dx, b_dy, edged_width), |
(uint8_t *) f_ref->y, |
378 |
edged_width); |
tmp + 32, tmp + 64, tmp + 96, |
379 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
380 |
|
ptr1 = tmp; |
381 |
|
} 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 |
|
if ((b_dx&3) | (b_dy&3)) { |
384 |
|
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16, |
385 |
|
(uint8_t *) b_ref->y, |
386 |
|
tmp + 16, tmp + 32, tmp + 48, |
387 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
388 |
|
ptr2 = tmp + 16; |
389 |
|
} 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 |
|
} else { |
391 |
|
sumx += dx; sumy += dy; |
392 |
|
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 = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
406 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
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 |
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
break; |
411 |
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
} |
412 |
|
|
413 |
transfer_8to16sub2_c( |
/* block-based chroma interpolation for direct and interpolate modes */ |
414 |
&dct_codes[4*64], |
transfer_8to16sub2(&dct_codes[4 * 64], |
415 |
cur->u + (y*8)*edged_width/2 + (x*8), |
cur->u + (j * 8) * edged_width / 2 + (i * 8), |
416 |
get_ref(f_ref->u, f_refh->u, f_refv->u, f_refhv->u, |
interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j, |
417 |
8*i, 8*j, 1, dx, dy, edged_width/2), |
b_dx, b_dy, edged_width / 2, 0), |
418 |
get_ref(b_ref->u, b_refh->u, b_refv->u, b_refhv->u, |
interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j, |
419 |
8*i, 8*j, 1, b_dx, b_dy, edged_width/2), |
dx, dy, edged_width / 2, 0), |
420 |
edged_width/2); |
edged_width/2); |
421 |
|
|
422 |
transfer_8to16sub2_c( |
transfer_8to16sub2(&dct_codes[5 * 64], |
423 |
&dct_codes[5*64], |
cur->v + (j * 8) * edged_width / 2 + (i * 8), |
424 |
cur->v + (y*8)*edged_width/2 + (x*8), |
interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j, |
425 |
get_ref(f_ref->v, f_refh->v, f_refv->v, f_refhv->v, |
b_dx, b_dy, edged_width / 2, 0), |
426 |
8*i, 8*j, 1, dx, dy, edged_width/2), |
interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j, |
427 |
get_ref(b_ref->v, b_refh->v, b_refv->v, b_refhv->v, |
dx, dy, edged_width / 2, 0), |
|
8*i, 8*j, 1, b_dx, b_dy, edged_width/2), |
|
428 |
edged_width/2); |
edged_width/2); |
|
|
|
|
break; |
|
|
|
|
|
case MODE_DIRECT : |
|
|
// todo |
|
|
break; |
|
|
} |
|
|
|
|
429 |
} |
} |