1 |
|
// 30.10.2002 corrected qpel chroma rounding |
2 |
// 04.10.2002 added qpel support to MBMotionCompensation |
// 04.10.2002 added qpel support to MBMotionCompensation |
3 |
// 01.05.2002 updated MBMotionCompensationBVOP |
// 01.05.2002 updated MBMotionCompensationBVOP |
4 |
// 14.04.2002 bframe compensation |
// 14.04.2002 bframe compensation |
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/qpel.h" |
10 |
#include "../utils/timer.h" |
#include "../utils/timer.h" |
11 |
#include "motion.h" |
#include "motion.h" |
12 |
|
|
13 |
#define ABS(X) (((X)>0)?(X):-(X)) |
#define ABS(X) (((X)>0)?(X):-(X)) |
14 |
#define SIGN(X) (((X)>0)?1:-1) |
#define SIGN(X) (((X)>0)?1:-1) |
15 |
|
|
16 |
|
static __inline void |
17 |
|
compensate16x16_interpolate(int16_t * const dct_codes, |
18 |
|
uint8_t * const cur, |
19 |
|
const uint8_t * const ref, |
20 |
|
const uint8_t * const refh, |
21 |
|
const uint8_t * const refv, |
22 |
|
const uint8_t * const refhv, |
23 |
|
const uint32_t x, |
24 |
|
const uint32_t y, |
25 |
|
const int32_t dx, |
26 |
|
const int32_t dy, |
27 |
|
const uint32_t stride, |
28 |
|
const uint32_t quarterpel, |
29 |
|
const uint32_t rounding) |
30 |
|
{ |
31 |
|
if(quarterpel) { |
32 |
|
interpolate16x16_quarterpel((uint8_t *) refv, (uint8_t *) ref, (uint8_t *) refh, |
33 |
|
(uint8_t *) refh + 64, (uint8_t *) refhv, x, y, dx, dy, stride, rounding); |
34 |
|
|
35 |
|
transfer_8to16sub(dct_codes, cur + y*stride + x, |
36 |
|
refv + y*stride + x, stride); |
37 |
|
transfer_8to16sub(dct_codes+64, cur + y*stride + x + 8, |
38 |
|
refv + y*stride + x + 8, stride); |
39 |
|
transfer_8to16sub(dct_codes+128, cur + y*stride + x + 8*stride, |
40 |
|
refv + y*stride + x + 8*stride, stride); |
41 |
|
transfer_8to16sub(dct_codes+192, cur + y*stride + x + 8*stride + 8, |
42 |
|
refv + y*stride + x + 8*stride+8, stride); |
43 |
|
|
44 |
|
} |
45 |
|
else |
46 |
|
{ |
47 |
|
const uint8_t * reference; |
48 |
|
|
49 |
|
switch (((dx & 1) << 1) + (dy & 1)) // ((dx%2)?2:0)+((dy%2)?1:0) |
50 |
|
{ |
51 |
|
case 0: reference = ref + ((y + dy / 2) * stride + x + dx / 2); break; |
52 |
|
case 1: reference = refv + ((y + (dy-1) / 2) * stride + x + dx / 2); break; |
53 |
|
case 2: reference = refh + ((y + dy / 2) * stride + x + (dx-1) / 2); break; |
54 |
|
default: // case 3: |
55 |
|
reference = refhv + ((y + (dy-1) / 2) * stride + x + (dx-1) / 2); break; |
56 |
|
} |
57 |
|
transfer_8to16sub(dct_codes, cur + y * stride + x, |
58 |
|
reference, stride); |
59 |
|
transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
60 |
|
reference + 8, stride); |
61 |
|
transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
62 |
|
reference + 8*stride, stride); |
63 |
|
transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
64 |
|
reference + 8*stride + 8, stride); |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
static __inline void |
static __inline void |
69 |
compensate8x8_interpolate(int16_t * const dct_codes, |
compensate8x8_interpolate(int16_t * const dct_codes, |
152 |
dy = mb->qmvs[0].y; |
dy = mb->qmvs[0].y; |
153 |
} |
} |
154 |
|
|
155 |
compensate8x8_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
156 |
refv->y, refhv->y, 16 * i, 16 * j, dx, dy, |
refv->y, refhv->y, 16 * i, 16 * j, dx, |
|
edged_width, quarterpel, rounding); |
|
|
compensate8x8_interpolate(&dct_codes[1 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i + 8, 16 * j, dx, dy, |
|
|
edged_width, quarterpel, rounding); |
|
|
compensate8x8_interpolate(&dct_codes[2 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i, 16 * j + 8, dx, dy, |
|
|
edged_width, quarterpel, rounding); |
|
|
compensate8x8_interpolate(&dct_codes[3 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, dx, |
|
157 |
dy, edged_width, quarterpel, rounding); |
dy, edged_width, quarterpel, rounding); |
158 |
|
|
159 |
if (quarterpel) |
if (quarterpel) |
160 |
{ |
{ |
161 |
dx = (dx >> 1) | (dx & 1); |
dx = (dx >> 2) + roundtab_78[dx & 0x7]; |
162 |
dy = (dy >> 1) | (dy & 1); |
dy = (dy >> 2) + roundtab_78[dy & 0x7]; |
163 |
|
} |
164 |
|
else { |
165 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
166 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
167 |
} |
} |
|
|
|
|
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
|
|
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
|
168 |
|
|
169 |
/* uv-block-based compensation */ |
/* uv-block-based compensation */ |
170 |
transfer_8to16sub(&dct_codes[4 * 64], |
transfer_8to16sub(&dct_codes[4 * 64], |
201 |
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, |
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, |
202 |
mvs[3].x, mvs[3].y, edged_width, quarterpel, rounding); |
mvs[3].x, mvs[3].y, edged_width, quarterpel, rounding); |
203 |
|
|
|
sum = mvs[0].x + mvs[1].x + mvs[2].x + mvs[3].x; |
|
|
|
|
204 |
if(quarterpel) |
if(quarterpel) |
205 |
sum /= 2; |
sum = (mvs[0].x / 2) + (mvs[1].x / 2) + (mvs[2].x / 2) + (mvs[3].x / 2); |
206 |
|
else |
207 |
dx = (sum ? SIGN(sum) * |
sum = mvs[0].x + mvs[1].x + mvs[2].x + mvs[3].x; |
|
(roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
|
208 |
|
|
209 |
sum = mvs[0].y + mvs[1].y + mvs[2].y + mvs[3].y; |
dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
210 |
|
|
211 |
if(quarterpel) |
if(quarterpel) |
212 |
sum /= 2; |
sum = (mvs[0].y / 2) + (mvs[1].y / 2) + (mvs[2].y / 2) + (mvs[3].y / 2); |
213 |
|
else |
214 |
|
sum = mvs[0].y + mvs[1].y + mvs[2].y + mvs[3].y; |
215 |
|
|
216 |
dy = (sum ? SIGN(sum) * |
dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
(roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
|
217 |
|
|
218 |
/* uv-block-based compensation */ |
/* uv-block-based compensation */ |
219 |
transfer_8to16sub(&dct_codes[4 * 64], |
transfer_8to16sub(&dct_codes[4 * 64], |