1 |
|
// 30.10.2002 corrected qpel chroma rounding |
2 |
|
// 04.10.2002 added qpel support to MBMotionCompensation |
3 |
|
// 01.05.2002 updated MBMotionCompensationBVOP |
4 |
|
// 14.04.2002 bframe compensation |
5 |
|
|
6 |
#include "../encoder.h" |
#include "../encoder.h" |
7 |
#include "../utils/mbfunctions.h" |
#include "../utils/mbfunctions.h" |
8 |
#include "../image/interpolate8x8.h" |
#include "../image/interpolate8x8.h" |
9 |
|
#include "../image/reduced.h" |
10 |
#include "../utils/timer.h" |
#include "../utils/timer.h" |
11 |
|
#include "motion.h" |
12 |
|
|
13 |
#define ABS(X) (((X)>0)?(X):-(X)) |
static __inline void |
14 |
#define SIGN(X) (((X)>0)?1:-1) |
compensate16x16_interpolate(int16_t * const dct_codes, |
|
|
|
|
static __inline void compensate8x8_halfpel( |
|
|
int16_t * const dct_codes, |
|
15 |
uint8_t * const cur, |
uint8_t * const cur, |
16 |
const uint8_t * const ref, |
const uint8_t * const ref, |
17 |
const uint8_t * const refh, |
const uint8_t * const refh, |
18 |
const uint8_t * const refv, |
const uint8_t * const refv, |
19 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
20 |
const uint32_t x, const uint32_t y, |
uint8_t * const tmp, |
21 |
const int32_t dx, const int dy, |
uint32_t x, |
22 |
const uint32_t stride) |
uint32_t y, |
23 |
|
const int32_t dx, |
24 |
|
const int32_t dy, |
25 |
|
const uint32_t stride, |
26 |
|
const int quarterpel, |
27 |
|
const int reduced_resolution, |
28 |
|
const uint32_t rounding) |
29 |
{ |
{ |
30 |
int32_t ddx,ddy; |
const uint8_t * ptr; |
31 |
|
|
32 |
switch ( ((dx&1)<<1) + (dy&1) ) // ((dx%2)?2:0)+((dy%2)?1:0) |
if (!reduced_resolution) { |
|
{ |
|
|
case 0 : |
|
|
ddx = dx/2; |
|
|
ddy = dy/2; |
|
|
transfer_8to16sub(dct_codes, cur + y*stride + x, |
|
|
ref + (y+ddy)*stride + x+ddx, stride); |
|
|
break; |
|
33 |
|
|
34 |
case 1 : |
if(quarterpel) { |
35 |
ddx = dx/2; |
if (dx&3 | dy&3) { |
36 |
ddy = (dy-1)/2; |
interpolate16x16_quarterpel(tmp - y * stride - x, |
37 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
(uint8_t *) ref, tmp + 32, |
38 |
refv + (y+ddy)*stride + x+ddx, stride); |
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
39 |
break; |
ptr = tmp; |
40 |
|
} else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position |
41 |
|
|
42 |
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; |
|
43 |
|
|
|
default : // case 3: |
|
|
ddx = (dx-1)/2; |
|
|
ddy = (dy-1)/2; |
|
44 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
45 |
refhv + (y+ddy)*stride + x+ddx, stride); |
ptr, stride); |
46 |
break; |
transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
47 |
|
ptr + 8, stride); |
48 |
|
transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
49 |
|
ptr + 8*stride, stride); |
50 |
|
transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
51 |
|
ptr + 8*stride + 8, stride); |
52 |
|
|
53 |
|
} else { //reduced_resolution |
54 |
|
|
55 |
|
x *= 2; y *= 2; |
56 |
|
|
57 |
|
ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
58 |
|
|
59 |
|
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
60 |
|
filter_diff_18x18_to_8x8(dct_codes, ptr, stride); |
61 |
|
|
62 |
|
filter_18x18_to_8x8(dct_codes+64, cur+y*stride + x + 16, stride); |
63 |
|
filter_diff_18x18_to_8x8(dct_codes+64, ptr + 16, stride); |
64 |
|
|
65 |
|
filter_18x18_to_8x8(dct_codes+128, cur+(y+16)*stride + x, stride); |
66 |
|
filter_diff_18x18_to_8x8(dct_codes+128, ptr + 16*stride, stride); |
67 |
|
|
68 |
|
filter_18x18_to_8x8(dct_codes+192, cur+(y+16)*stride + x + 16, stride); |
69 |
|
filter_diff_18x18_to_8x8(dct_codes+192, ptr + 16*stride + 16, stride); |
70 |
|
|
71 |
|
transfer32x32_copy(cur + y*stride + x, ptr, stride); |
72 |
} |
} |
73 |
} |
} |
74 |
|
|
75 |
|
static __inline void |
76 |
|
compensate8x8_interpolate( int16_t * const dct_codes, |
77 |
|
uint8_t * const cur, |
78 |
|
const uint8_t * const ref, |
79 |
|
const uint8_t * const refh, |
80 |
|
const uint8_t * const refv, |
81 |
|
const uint8_t * const refhv, |
82 |
|
uint8_t * const tmp, |
83 |
|
uint32_t x, |
84 |
|
uint32_t y, |
85 |
|
const int32_t dx, |
86 |
|
const int32_t dy, |
87 |
|
const uint32_t stride, |
88 |
|
const uint32_t quarterpel, |
89 |
|
const int reduced_resolution, |
90 |
|
const uint32_t rounding) |
91 |
|
{ |
92 |
|
const uint8_t * ptr; |
93 |
|
|
94 |
|
if (!reduced_resolution) { |
95 |
|
|
96 |
void MBMotionCompensation( |
if(quarterpel) { |
97 |
MACROBLOCK * const mb, |
if (dx&3 | dy&3) { |
98 |
|
interpolate8x8_quarterpel(tmp - y*stride - x, |
99 |
|
(uint8_t *) ref, tmp + 32, |
100 |
|
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
101 |
|
ptr = tmp; |
102 |
|
} else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position |
103 |
|
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
104 |
|
|
105 |
|
transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride); |
106 |
|
|
107 |
|
} else { //reduced_resolution |
108 |
|
|
109 |
|
x *= 2; y *= 2; |
110 |
|
|
111 |
|
ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
112 |
|
|
113 |
|
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
114 |
|
filter_diff_18x18_to_8x8(dct_codes, ptr, stride); |
115 |
|
|
116 |
|
transfer16x16_copy(cur + y*stride + x, ptr, stride); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
/* XXX: slow, inelegant... */ |
121 |
|
static void |
122 |
|
interpolate18x18_switch(uint8_t * const cur, |
123 |
|
const uint8_t * const refn, |
124 |
|
const uint32_t x, |
125 |
|
const uint32_t y, |
126 |
|
const int32_t dx, |
127 |
|
const int dy, |
128 |
|
const uint32_t stride, |
129 |
|
const uint32_t rounding) |
130 |
|
{ |
131 |
|
interpolate8x8_switch(cur, refn, x-1, y-1, dx, dy, stride, rounding); |
132 |
|
interpolate8x8_switch(cur, refn, x+7, y-1, dx, dy, stride, rounding); |
133 |
|
interpolate8x8_switch(cur, refn, x+9, y-1, dx, dy, stride, rounding); |
134 |
|
|
135 |
|
interpolate8x8_switch(cur, refn, x-1, y+7, dx, dy, stride, rounding); |
136 |
|
interpolate8x8_switch(cur, refn, x+7, y+7, dx, dy, stride, rounding); |
137 |
|
interpolate8x8_switch(cur, refn, x+9, y+7, dx, dy, stride, rounding); |
138 |
|
|
139 |
|
interpolate8x8_switch(cur, refn, x-1, y+9, dx, dy, stride, rounding); |
140 |
|
interpolate8x8_switch(cur, refn, x+7, y+9, dx, dy, stride, rounding); |
141 |
|
interpolate8x8_switch(cur, refn, x+9, y+9, dx, dy, stride, rounding); |
142 |
|
} |
143 |
|
|
144 |
|
static void |
145 |
|
CompensateChroma( int dx, int dy, |
146 |
|
const int i, const int j, |
147 |
|
IMAGE * const Cur, |
148 |
|
const IMAGE * const Ref, |
149 |
|
uint8_t * const temp, |
150 |
|
int16_t * const coeff, |
151 |
|
const uint32_t stride, |
152 |
|
const int rounding, |
153 |
|
const int rrv) |
154 |
|
{ /* uv-block-based compensation */ |
155 |
|
|
156 |
|
if (!rrv) { |
157 |
|
transfer_8to16sub(coeff, Cur->u + 8 * j * stride + 8 * i, |
158 |
|
interpolate8x8_switch2(temp, Ref->u, 8 * i, 8 * j, |
159 |
|
dx, dy, stride, rounding), |
160 |
|
stride); |
161 |
|
|
162 |
|
transfer_8to16sub(coeff + 64, Cur->v + 8 * j * stride + 8 * i, |
163 |
|
interpolate8x8_switch2(temp, Ref->v, 8 * i, 8 * j, |
164 |
|
dx, dy, stride, rounding), |
165 |
|
stride); |
166 |
|
} else { |
167 |
|
uint8_t * current, * reference; |
168 |
|
|
169 |
|
current = Cur->u + 16*j*stride + 16*i; |
170 |
|
reference = temp - 16*j*stride - 16*i; |
171 |
|
interpolate18x18_switch(reference, Ref->u, 16*i, 16*j, dx, dy, stride, rounding); |
172 |
|
filter_18x18_to_8x8(coeff, current, stride); |
173 |
|
filter_diff_18x18_to_8x8(coeff, temp, stride); |
174 |
|
transfer16x16_copy(current, temp, stride); |
175 |
|
|
176 |
|
current = Cur->v + 16*j*stride + 16*i; |
177 |
|
interpolate18x18_switch(reference, Ref->v, 16*i, 16*j, dx, dy, stride, rounding); |
178 |
|
filter_18x18_to_8x8(coeff + 64, current, stride); |
179 |
|
filter_diff_18x18_to_8x8(coeff + 64, temp, stride); |
180 |
|
transfer16x16_copy(current, temp, stride); |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
|
void |
185 |
|
MBMotionCompensation(MACROBLOCK * const mb, |
186 |
const uint32_t i, |
const uint32_t i, |
187 |
const uint32_t j, |
const uint32_t j, |
188 |
const IMAGE * const ref, |
const IMAGE * const ref, |
190 |
const IMAGE * const refv, |
const IMAGE * const refv, |
191 |
const IMAGE * const refhv, |
const IMAGE * const refhv, |
192 |
IMAGE * const cur, |
IMAGE * const cur, |
193 |
int16_t dct_codes[][64], |
int16_t * dct_codes, |
194 |
const uint32_t width, |
const uint32_t width, |
195 |
const uint32_t height, |
const uint32_t height, |
196 |
const uint32_t edged_width, |
const uint32_t edged_width, |
197 |
|
const int quarterpel, |
198 |
|
const int reduced_resolution, |
199 |
const uint32_t rounding) |
const uint32_t rounding) |
200 |
{ |
{ |
201 |
static const uint32_t roundtab[16] = |
int32_t dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x); |
202 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
int32_t dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y); |
203 |
|
uint8_t * const tmp = refv->u; |
204 |
|
|
205 |
|
if ( mb->mode == MODE_NOT_CODED && dx==0 && dy==0 && !reduced_resolution) { /* quick copy */ |
206 |
|
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
207 |
|
ref->y + 16 * (i + j * edged_width), |
208 |
|
edged_width); |
209 |
|
|
210 |
|
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
211 |
|
ref->u + 8 * (i + j * edged_width/2), |
212 |
|
edged_width / 2); |
213 |
|
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
214 |
|
ref->v + 8 * (i + j * edged_width/2), |
215 |
|
edged_width / 2); |
216 |
|
return; |
217 |
|
} |
218 |
|
|
219 |
|
if ((mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) /*&& !quarterpel*/) { |
220 |
|
|
221 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
/* quick MODE_NOT_CODED for GMC with MV!=(0,0) is still needed */ |
|
{ |
|
|
int32_t dx = mb->mvs[0].x; |
|
|
int32_t dy = mb->mvs[0].y; |
|
222 |
|
|
223 |
compensate8x8_halfpel(dct_codes[0], cur->y, ref->y, refh->y, refv->y, refhv->y, |
if (reduced_resolution) { |
224 |
16*i, 16*j, dx, dy, edged_width); |
dx = RRV_MV_SCALEUP(dx); |
225 |
compensate8x8_halfpel(dct_codes[1], cur->y, ref->y, refh->y, refv->y, refhv->y, |
dy = RRV_MV_SCALEUP(dy); |
226 |
16*i + 8, 16*j, dx, dy, edged_width); |
} |
|
compensate8x8_halfpel(dct_codes[2], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
|
16*i, 16*j + 8, dx, dy, edged_width); |
|
|
compensate8x8_halfpel(dct_codes[3], 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 |
|
|
compensate8x8_halfpel(dct_codes[4], cur->u, ref->u, refh->u, refv->u, refhv->u, |
|
|
8*i, 8*j, dx, dy, edged_width/2); |
|
|
compensate8x8_halfpel(dct_codes[5], cur->v, ref->v, refh->v, refv->v, refhv->v, |
|
|
8*i, 8*j, dx, dy, edged_width/2); */ |
|
|
|
|
|
/* 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], |
|
|
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], |
|
|
cur->v + 8*j*edged_width/2 + 8*i, |
|
|
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
|
227 |
|
|
228 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
229 |
|
refv->y, refhv->y, tmp, 16 * i, 16 * j, dx, dy, |
230 |
|
edged_width, quarterpel, reduced_resolution, rounding); |
231 |
|
|
232 |
|
dx /= 1 + quarterpel; |
233 |
|
dy /= 1 + quarterpel; |
234 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
235 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
236 |
|
|
237 |
|
} else { // mode == MODE_INTER4V |
238 |
|
int k, sumx = 0, sumy = 0; |
239 |
|
const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs); |
240 |
|
|
241 |
|
for (k = 0; k < 4; k++) { |
242 |
|
dx = mvs[k].x; |
243 |
|
dy = mvs[k].y; |
244 |
|
sumx += dx / (1 + quarterpel); |
245 |
|
sumy += dy / (1 + quarterpel); |
246 |
|
|
247 |
|
if (reduced_resolution){ |
248 |
|
dx = RRV_MV_SCALEUP(dx); |
249 |
|
dy = RRV_MV_SCALEUP(dy); |
250 |
} |
} |
251 |
else // mode == MODE_INTER4V |
|
252 |
|
compensate8x8_interpolate(&dct_codes[k * 64], cur->y, ref->y, refh->y, |
253 |
|
refv->y, refhv->y, tmp, 16 * i + 8*(k&1), 16 * j + 8*(k>>1), dx, |
254 |
|
dy, edged_width, quarterpel, reduced_resolution, rounding); |
255 |
|
} |
256 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
257 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
258 |
|
} |
259 |
|
|
260 |
|
CompensateChroma(dx, dy, i, j, cur, ref, tmp, |
261 |
|
&dct_codes[4 * 64], edged_width / 2, rounding, reduced_resolution); |
262 |
|
|
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
void |
267 |
|
MBMotionCompensationBVOP(MBParam * pParam, |
268 |
|
MACROBLOCK * const mb, |
269 |
|
const uint32_t i, |
270 |
|
const uint32_t j, |
271 |
|
IMAGE * const cur, |
272 |
|
const IMAGE * const f_ref, |
273 |
|
const IMAGE * const f_refh, |
274 |
|
const IMAGE * const f_refv, |
275 |
|
const IMAGE * const f_refhv, |
276 |
|
const IMAGE * const b_ref, |
277 |
|
const IMAGE * const b_refh, |
278 |
|
const IMAGE * const b_refv, |
279 |
|
const IMAGE * const b_refhv, |
280 |
|
int16_t * dct_codes) |
281 |
{ |
{ |
282 |
int32_t sum, dx, dy; |
const uint32_t edged_width = pParam->edged_width; |
283 |
|
int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy; |
284 |
|
int k; |
285 |
|
const int quarterpel = pParam->m_quarterpel; |
286 |
|
const uint8_t * ptr1, * ptr2; |
287 |
|
uint8_t * const tmp = f_refv->u; |
288 |
|
const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs); |
289 |
|
const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs); |
290 |
|
|
291 |
|
switch (mb->mode) { |
292 |
|
case MODE_FORWARD: |
293 |
|
dx = fmvs->x; dy = fmvs->y; |
294 |
|
|
295 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, |
296 |
|
f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx, |
297 |
|
dy, edged_width, quarterpel, 0, 0); |
298 |
|
|
299 |
|
dx /= 1 + quarterpel; |
300 |
|
dy /= 1 + quarterpel; |
301 |
|
CompensateChroma( (dx >> 1) + roundtab_79[dx & 0x3], |
302 |
|
(dy >> 1) + roundtab_79[dy & 0x3], |
303 |
|
i, j, cur, f_ref, tmp, |
304 |
|
&dct_codes[4 * 64], edged_width / 2, 0, 0); |
305 |
|
|
306 |
|
return; |
307 |
|
|
308 |
|
case MODE_BACKWARD: |
309 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
310 |
|
|
311 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
312 |
|
b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx, |
313 |
|
b_dy, edged_width, quarterpel, 0, 0); |
314 |
|
|
315 |
|
b_dx /= 1 + quarterpel; |
316 |
|
b_dy /= 1 + quarterpel; |
317 |
|
CompensateChroma( (b_dx >> 1) + roundtab_79[b_dx & 0x3], |
318 |
|
(b_dy >> 1) + roundtab_79[b_dy & 0x3], |
319 |
|
i, j, cur, b_ref, tmp, |
320 |
|
&dct_codes[4 * 64], edged_width / 2, 0, 0); |
321 |
|
|
322 |
|
return; |
323 |
|
|
324 |
|
case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */ |
325 |
|
case MODE_DIRECT_NO4V: |
326 |
|
dx = fmvs->x; dy = fmvs->y; |
327 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
328 |
|
|
329 |
|
if (quarterpel) { |
330 |
|
|
331 |
|
if (dx&3 | dy&3) { |
332 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width, |
333 |
|
(uint8_t *) f_ref->y, tmp + 32, |
334 |
|
tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0); |
335 |
|
ptr1 = tmp; |
336 |
|
} else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; // fullpixel position |
337 |
|
|
338 |
|
if (b_dx&3 | b_dy&3) { |
339 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16, |
340 |
|
(uint8_t *) b_ref->y, tmp + 32, |
341 |
|
tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0); |
342 |
|
ptr2 = tmp + 16; |
343 |
|
} else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; // fullpixel position |
344 |
|
|
345 |
|
b_dx /= 2; |
346 |
|
b_dy /= 2; |
347 |
|
dx /= 2; |
348 |
|
dy /= 2; |
349 |
|
|
350 |
|
} else { |
351 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
352 |
|
i, j, 16, dx, dy, edged_width); |
353 |
|
|
354 |
|
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
355 |
|
i, j, 16, b_dx, b_dy, edged_width); |
356 |
|
} |
357 |
|
for (k = 0; k < 4; k++) |
358 |
|
transfer_8to16sub2(&dct_codes[k * 64], |
359 |
|
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
360 |
|
ptr1 + (k&1)*8 + (k>>1)*8*edged_width, |
361 |
|
ptr2 + (k&1)*8 + (k>>1)*8*edged_width, edged_width); |
362 |
|
|
363 |
|
|
364 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
365 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
366 |
|
|
367 |
|
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
368 |
|
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
369 |
|
|
370 |
|
break; |
371 |
|
|
372 |
compensate8x8_halfpel(dct_codes[0], cur->y, ref->y, refh->y, refv->y, refhv->y, |
default: // MODE_DIRECT |
373 |
16*i, 16*j, mb->mvs[0].x, mb->mvs[0].y, edged_width); |
sumx = sumy = b_sumx = b_sumy = 0; |
|
compensate8x8_halfpel(dct_codes[1], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
|
16*i + 8, 16*j, mb->mvs[1].x, mb->mvs[1].y, edged_width); |
|
|
compensate8x8_halfpel(dct_codes[2], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
|
16*i, 16*j + 8, mb->mvs[2].x, mb->mvs[2].y, edged_width); |
|
|
compensate8x8_halfpel(dct_codes[3], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
|
16*i + 8, 16*j + 8, mb->mvs[3].x, mb->mvs[3].y, edged_width); |
|
|
|
|
|
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
|
|
dx = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
|
|
|
|
|
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
|
|
dy = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
|
|
|
|
|
/* uv-image-based compensation |
|
|
compensate8x8_halfpel(dct_codes[4], cur->u, ref->u, refh->u, refv->u, refhv->u, |
|
|
8*i, 8*j, dx, dy, edged_width/2); |
|
|
compensate8x8_halfpel(dct_codes[5], cur->v, ref->v, refh->v, refv->v, refhv->v, |
|
|
8*i, 8*j, dx, dy, edged_width/2); */ |
|
|
|
|
|
/* 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], |
|
|
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], |
|
|
cur->v + 8*j*edged_width/2 + 8*i, |
|
|
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
|
374 |
|
|
375 |
|
for (k = 0; k < 4; k++) { |
376 |
|
|
377 |
|
dx = fmvs[k].x; dy = fmvs[k].y; |
378 |
|
b_dx = bmvs[k].x; b_dy = bmvs[k].y; |
379 |
|
|
380 |
|
if (quarterpel) { |
381 |
|
sumx += dx/2; sumy += dy/2; |
382 |
|
b_sumx += b_dx/2; b_sumy += b_dy/2; |
383 |
|
|
384 |
|
if (dx&3 | dy&3) { |
385 |
|
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width, |
386 |
|
(uint8_t *) f_ref->y, |
387 |
|
tmp + 32, tmp + 64, tmp + 96, |
388 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
389 |
|
ptr1 = tmp; |
390 |
|
} else ptr1 = f_ref->y + (16*j + (k>>1)*8 + dy/4)*edged_width + 16*i + (k&1)*8 + dx/4; |
391 |
|
|
392 |
|
if (b_dx&3 | b_dy&3) { |
393 |
|
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16, |
394 |
|
(uint8_t *) b_ref->y, |
395 |
|
tmp + 16, tmp + 32, tmp + 48, |
396 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
397 |
|
ptr2 = tmp + 16; |
398 |
|
} else ptr2 = b_ref->y + (16*j + (k>>1)*8 + b_dy/4)*edged_width + 16*i + (k&1)*8 + b_dx/4; |
399 |
|
} else { |
400 |
|
sumx += dx; sumy += dy; |
401 |
|
b_sumx += b_dx; b_sumy += b_dy; |
402 |
|
|
403 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
404 |
|
2*i + (k&1), 2*j + (k>>1), 8, dx, dy, edged_width); |
405 |
|
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
406 |
|
2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, edged_width); |
407 |
} |
} |
408 |
|
transfer_8to16sub2(&dct_codes[k * 64], |
409 |
|
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
410 |
|
ptr1, ptr2, edged_width); |
411 |
|
|
412 |
|
} |
413 |
|
|
414 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
415 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
416 |
|
b_dx = (b_sumx >> 3) + roundtab_76[b_sumx & 0xf]; |
417 |
|
b_dy = (b_sumy >> 3) + roundtab_76[b_sumy & 0xf]; |
418 |
|
|
419 |
|
break; |
420 |
|
} |
421 |
|
|
422 |
|
// uv block-based chroma interpolation for direct and interpolate modes |
423 |
|
transfer_8to16sub2(&dct_codes[4 * 64], |
424 |
|
cur->u + (j * 8) * edged_width / 2 + (i * 8), |
425 |
|
interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j, |
426 |
|
b_dx, b_dy, edged_width / 2, 0), |
427 |
|
interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j, |
428 |
|
dx, dy, edged_width / 2, 0), |
429 |
|
edged_width / 2); |
430 |
|
|
431 |
|
transfer_8to16sub2(&dct_codes[5 * 64], |
432 |
|
cur->v + (j * 8) * edged_width / 2 + (i * 8), |
433 |
|
interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j, |
434 |
|
b_dx, b_dy, edged_width / 2, 0), |
435 |
|
interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j, |
436 |
|
dx, dy, edged_width / 2, 0), |
437 |
|
edged_width / 2); |
438 |
} |
} |