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 |
// 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/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 compensate8x8_halfpel( |
static __inline void |
17 |
int16_t * const dct_codes, |
compensate16x16_interpolate(int16_t * const dct_codes, |
18 |
uint8_t * const cur, |
uint8_t * const cur, |
19 |
const uint8_t * const ref, |
const uint8_t * const ref, |
20 |
const uint8_t * const refh, |
const uint8_t * const refh, |
21 |
const uint8_t * const refv, |
const uint8_t * const refv, |
22 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
23 |
const uint32_t x, const uint32_t y, |
const uint32_t x, |
24 |
const int32_t dx, const int dy, |
const uint32_t y, |
25 |
const uint32_t stride) |
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 |
int32_t ddx,ddy; |
const uint8_t * reference; |
48 |
|
|
49 |
switch ( ((dx&1)<<1) + (dy&1) ) // ((dx%2)?2:0)+((dy%2)?1:0) |
switch ( ((dx&1)<<1) + (dy&1) ) // ((dx%2)?2:0)+((dy%2)?1:0) |
50 |
{ |
{ |
51 |
case 0 : |
case 0: reference = ref + ((y + dy / 2) * stride + x + dx / 2); break; |
52 |
ddx = dx/2; |
case 1: reference = refv + ((y + (dy-1) / 2) * stride + x + dx / 2); break; |
53 |
ddy = dy/2; |
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, |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
58 |
ref + (y+ddy)*stride + x+ddx, stride); |
reference, stride); |
59 |
break; |
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 |
case 1 : |
static __inline void |
69 |
ddx = dx/2; |
compensate8x8_interpolate(int16_t * const dct_codes, |
70 |
ddy = (dy-1)/2; |
uint8_t * const cur, |
71 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
const uint8_t * const ref, |
72 |
refv + (y+ddy)*stride + x+ddx, stride); |
const uint8_t * const refh, |
73 |
break; |
const uint8_t * const refv, |
74 |
|
const uint8_t * const refhv, |
75 |
|
const uint32_t x, |
76 |
|
const uint32_t y, |
77 |
|
const int32_t dx, |
78 |
|
const int32_t dy, |
79 |
|
const uint32_t stride, |
80 |
|
const uint32_t quarterpel, |
81 |
|
const uint32_t rounding) |
82 |
|
{ |
83 |
|
if(quarterpel) { |
84 |
|
interpolate8x8_quarterpel((uint8_t *) refv, (uint8_t *) ref, (uint8_t *) refh, |
85 |
|
(uint8_t *) refh + 64, (uint8_t *) refhv, x, y, dx, dy, stride, rounding); |
86 |
|
|
|
case 2 : |
|
|
ddx = (dx-1)/2; |
|
|
ddy = dy/2; |
|
87 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
88 |
refh + (y+ddy)*stride + x+ddx, stride); |
refv + y*stride + x, stride); |
89 |
break; |
} |
90 |
|
else |
91 |
|
{ |
92 |
|
const uint8_t * reference; |
93 |
|
|
94 |
|
switch (((dx & 1) << 1) + (dy & 1)) // ((dx%2)?2:0)+((dy%2)?1:0) |
95 |
|
{ |
96 |
|
case 0: reference = ref + ((y + dy / 2) * stride + x + dx / 2); break; |
97 |
|
case 1: reference = refv + ((y + (dy-1) / 2) * stride + x + dx / 2); break; |
98 |
|
case 2: reference = refh + ((y + dy / 2) * stride + x + (dx-1) / 2); break; |
99 |
default : // case 3: |
default : // case 3: |
100 |
ddx = (dx-1)/2; |
reference = refhv + ((y + (dy-1) / 2) * stride + x + (dx-1) / 2); break; |
101 |
ddy = (dy-1)/2; |
} |
102 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
103 |
refhv + (y+ddy)*stride + x+ddx, stride); |
reference, stride); |
|
break; |
|
104 |
} |
} |
105 |
} |
} |
106 |
|
|
107 |
|
void |
108 |
|
MBMotionCompensation(MACROBLOCK * const mb, |
|
void MBMotionCompensation( |
|
|
MACROBLOCK * const mb, |
|
109 |
const uint32_t i, |
const uint32_t i, |
110 |
const uint32_t j, |
const uint32_t j, |
111 |
const IMAGE * const ref, |
const IMAGE * const ref, |
117 |
const uint32_t width, |
const uint32_t width, |
118 |
const uint32_t height, |
const uint32_t height, |
119 |
const uint32_t edged_width, |
const uint32_t edged_width, |
120 |
|
const uint32_t quarterpel, |
121 |
const uint32_t rounding) |
const uint32_t rounding) |
122 |
{ |
{ |
123 |
static const uint32_t roundtab[16] = |
if (mb->mode == MODE_NOT_CODED) { |
124 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
transfer8x8_copy(cur->y + 16 * (i + j * edged_width), |
125 |
|
ref->y + 16 * (i + j * edged_width), |
126 |
|
edged_width); |
127 |
|
transfer8x8_copy(cur->y + 16 * (i + j * edged_width) + 8, |
128 |
|
ref->y + 16 * (i + j * edged_width) + 8, |
129 |
|
edged_width); |
130 |
|
transfer8x8_copy(cur->y + 16 * (i + j * edged_width) + 8 * edged_width, |
131 |
|
ref->y + 16 * (i + j * edged_width) + 8 * edged_width, |
132 |
|
edged_width); |
133 |
|
transfer8x8_copy(cur->y + 16 * (i + j * edged_width) + 8 * (edged_width+1), |
134 |
|
ref->y + 16 * (i + j * edged_width) + 8 * (edged_width+1), |
135 |
|
edged_width); |
136 |
|
|
137 |
|
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
138 |
|
ref->u + 8 * (i + j * edged_width/2), |
139 |
|
edged_width / 2); |
140 |
|
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
141 |
|
ref->v + 8 * (i + j * edged_width/2), |
142 |
|
edged_width / 2); |
143 |
|
return; |
144 |
|
} |
145 |
|
|
146 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
|
{ |
|
147 |
int32_t dx = mb->mvs[0].x; |
int32_t dx = mb->mvs[0].x; |
148 |
int32_t dy = mb->mvs[0].y; |
int32_t dy = mb->mvs[0].y; |
149 |
|
|
150 |
compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
if(quarterpel) { |
151 |
16*i, 16*j, dx, dy, edged_width); |
dx = mb->qmvs[0].x; |
152 |
compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
dy = mb->qmvs[0].y; |
153 |
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, 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); |
|
154 |
|
|
155 |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
156 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
refv->y, refhv->y, 16 * i, 16 * j, dx, |
157 |
|
dy, edged_width, quarterpel, rounding); |
158 |
|
|
159 |
/* uv-image-based compensation |
if (quarterpel) |
160 |
compensate8x8_halfpel(dct_codes[4], cur->u, ref->u, refh->u, refv->u, refhv->u, |
{ |
161 |
8*i, 8*j, dx, dy, edged_width/2); |
dx = (dx >> 2) + roundtab_78[dx & 0x7]; |
162 |
compensate8x8_halfpel(dct_codes[5], cur->v, ref->v, refh->v, refv->v, refhv->v, |
dy = (dy >> 2) + roundtab_78[dy & 0x7]; |
163 |
8*i, 8*j, dx, dy, edged_width/2); */ |
} |
164 |
|
else { |
165 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
166 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
167 |
|
} |
168 |
|
|
169 |
/* uv-block-based compensation */ |
/* uv-block-based compensation */ |
|
interpolate8x8_switch(refv->u, ref->u, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
170 |
transfer_8to16sub(&dct_codes[4*64], |
transfer_8to16sub(&dct_codes[4*64], |
171 |
cur->u + 8*j*edged_width/2 + 8*i, |
cur->u + 8*j*edged_width/2 + 8*i, |
172 |
refv->u + 8*j*edged_width/2 + 8*i, edged_width/2); |
interpolate8x8_switch2(refv->u, ref->u, 8 * i, 8 * j, |
173 |
|
dx, dy, edged_width / 2, rounding), |
174 |
|
edged_width / 2); |
175 |
|
|
|
interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
176 |
transfer_8to16sub(&dct_codes[5*64], |
transfer_8to16sub(&dct_codes[5*64], |
177 |
cur->v + 8*j*edged_width/2 + 8*i, |
cur->v + 8*j*edged_width/2 + 8*i, |
178 |
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
interpolate8x8_switch2(refv->u, ref->v, 8 * i, 8 * j, |
179 |
|
dx, dy, edged_width / 2, rounding), |
180 |
|
edged_width / 2); |
181 |
|
|
182 |
} |
} else { // mode == MODE_INTER4V |
|
else // mode == MODE_INTER4V |
|
|
{ |
|
183 |
int32_t sum, dx, dy; |
int32_t sum, dx, dy; |
184 |
|
VECTOR *mvs; |
185 |
|
|
186 |
compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
if(quarterpel) |
187 |
16*i, 16*j, mb->mvs[0].x, mb->mvs[0].y, edged_width); |
mvs = mb->qmvs; |
188 |
compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
else |
189 |
16*i + 8, 16*j, mb->mvs[1].x, mb->mvs[1].y, edged_width); |
mvs = mb->mvs; |
190 |
compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
191 |
16*i, 16*j + 8, mb->mvs[2].x, mb->mvs[2].y, edged_width); |
compensate8x8_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
192 |
compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
refv->y, refhv->y, 16 * i, 16 * j, mvs[0].x, |
193 |
16*i + 8, 16*j + 8, mb->mvs[3].x, mb->mvs[3].y, edged_width); |
mvs[0].y, edged_width, quarterpel, rounding); |
194 |
|
compensate8x8_interpolate(&dct_codes[1 * 64], cur->y, ref->y, refh->y, |
195 |
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
refv->y, refhv->y, 16 * i + 8, 16 * j, |
196 |
dx = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
mvs[1].x, mvs[1].y, edged_width, quarterpel, rounding); |
197 |
|
compensate8x8_interpolate(&dct_codes[2 * 64], cur->y, ref->y, refh->y, |
198 |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
refv->y, refhv->y, 16 * i, 16 * j + 8, |
199 |
dy = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
mvs[2].x, mvs[2].y, edged_width, quarterpel, rounding); |
200 |
|
compensate8x8_interpolate(&dct_codes[3 * 64], cur->y, ref->y, refh->y, |
201 |
|
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, |
202 |
|
mvs[3].x, mvs[3].y, edged_width, quarterpel, rounding); |
203 |
|
|
204 |
|
if(quarterpel) |
205 |
|
sum = (mvs[0].x / 2) + (mvs[1].x / 2) + (mvs[2].x / 2) + (mvs[3].x / 2); |
206 |
|
else |
207 |
|
sum = mvs[0].x + mvs[1].x + mvs[2].x + mvs[3].x; |
208 |
|
|
209 |
|
dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
210 |
|
|
211 |
|
if(quarterpel) |
212 |
|
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 |
/* uv-image-based compensation |
dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
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); */ |
|
217 |
|
|
218 |
/* uv-block-based compensation */ |
/* uv-block-based compensation */ |
|
interpolate8x8_switch(refv->u, ref->u, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
219 |
transfer_8to16sub(&dct_codes[4*64], |
transfer_8to16sub(&dct_codes[4*64], |
220 |
cur->u + 8*j*edged_width/2 + 8*i, |
cur->u + 8*j*edged_width/2 + 8*i, |
221 |
refv->u + 8*j*edged_width/2 + 8*i, edged_width/2); |
interpolate8x8_switch2(refv->u, ref->u, 8 * i, 8 * j, |
222 |
|
dx, dy, edged_width / 2, rounding), |
223 |
|
edged_width / 2); |
224 |
|
|
|
interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
225 |
transfer_8to16sub(&dct_codes[5*64], |
transfer_8to16sub(&dct_codes[5*64], |
226 |
cur->v + 8*j*edged_width/2 + 8*i, |
cur->v + 8*j*edged_width/2 + 8*i, |
227 |
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
interpolate8x8_switch2(refv->u, ref->v, 8 * i, 8 * j, |
228 |
|
dx, dy, edged_width / 2, rounding), |
229 |
|
|
230 |
|
edged_width / 2); |
231 |
} |
} |
232 |
} |
} |
233 |
|
|
234 |
|
|
235 |
|
void |
236 |
void MBMotionCompensationBVOP( |
MBMotionCompensationBVOP(MBParam * pParam, |
|
MBParam * pParam, |
|
237 |
MACROBLOCK * const mb, |
MACROBLOCK * const mb, |
238 |
const uint32_t i, |
const uint32_t i, |
239 |
const uint32_t j, |
const uint32_t j, |
246 |
const IMAGE * const b_refh, |
const IMAGE * const b_refh, |
247 |
const IMAGE * const b_refv, |
const IMAGE * const b_refv, |
248 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
249 |
int16_t dct_codes[][64]) |
int16_t * dct_codes) |
250 |
{ |
{ |
251 |
static const uint32_t roundtab[16] = |
static const uint32_t roundtab[16] = |
252 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
254 |
const int32_t edged_width = pParam->edged_width; |
const int32_t edged_width = pParam->edged_width; |
255 |
int32_t dx, dy; |
int32_t dx, dy; |
256 |
int32_t b_dx, b_dy; |
int32_t b_dx, b_dy; |
257 |
|
int k,sum; |
258 |
int x = i; |
int x = i; |
259 |
int y = j; |
int y = j; |
260 |
|
|
261 |
|
|
262 |
|
switch (mb->mode) { |
|
switch(mb->mode) |
|
|
{ |
|
263 |
case MODE_FORWARD : |
case MODE_FORWARD : |
264 |
dx = mb->mvs[0].x; |
dx = mb->mvs[0].x; |
265 |
dy = mb->mvs[0].y; |
dy = mb->mvs[0].y; |
266 |
|
|
267 |
transfer_8to16sub_c( |
transfer_8to16sub(&dct_codes[0 * 64], |
|
dct_codes[0], |
|
268 |
cur->y + (j*16)*edged_width + (i*16), |
cur->y + (j*16)*edged_width + (i*16), |
269 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
270 |
i*16, j*16, 1, dx, dy, edged_width), |
i*16, j*16, 1, dx, dy, edged_width), |
271 |
edged_width); |
edged_width); |
272 |
|
|
273 |
transfer_8to16sub( |
transfer_8to16sub(&dct_codes[1 * 64], |
|
dct_codes[1], |
|
274 |
cur->y + (j*16)*edged_width + (i*16+8), |
cur->y + (j*16)*edged_width + (i*16+8), |
275 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
276 |
i*16+8, j*16, 1, dx, dy, edged_width), |
i*16+8, j*16, 1, dx, dy, edged_width), |
277 |
edged_width); |
edged_width); |
278 |
|
|
279 |
transfer_8to16sub_c( |
transfer_8to16sub(&dct_codes[2 * 64], |
|
dct_codes[2], |
|
280 |
cur->y + (j*16+8)*edged_width + (i*16), |
cur->y + (j*16+8)*edged_width + (i*16), |
281 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
282 |
i*16, j*16+8, 1, dx, dy, edged_width), |
i*16, j*16+8, 1, dx, dy, edged_width), |
283 |
edged_width); |
edged_width); |
284 |
|
|
285 |
transfer_8to16sub( |
transfer_8to16sub(&dct_codes[3 * 64], |
|
dct_codes[3], |
|
286 |
cur->y + (j*16+8)*edged_width + (i*16+8), |
cur->y + (j*16+8)*edged_width + (i*16+8), |
287 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
288 |
i*16+8, j*16+8, 1, dx, dy, edged_width), |
i*16+8, j*16+8, 1, dx, dy, edged_width), |
292 |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
293 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
294 |
|
|
295 |
/* uv-image-based compensation */ |
/* uv-block-based compensation */ |
296 |
compensate8x8_halfpel(dct_codes[4], cur->u, f_ref->u, f_refh->u, f_refv->u, f_refhv->u, |
transfer_8to16sub(&dct_codes[4 * 64], |
297 |
8*i, 8*j, dx, dy, edged_width/2); |
cur->u + 8 * j * edged_width / 2 + 8 * i, |
298 |
compensate8x8_halfpel(dct_codes[5], cur->v, f_ref->v, f_refh->v, f_refv->v, f_refhv->v, |
interpolate8x8_switch2(f_refv->u, f_ref->u, 8 * i, 8 * j, |
299 |
8*i, 8*j, dx, dy, edged_width/2); |
dx, dy, edged_width / 2, 0), |
300 |
|
|
301 |
|
edged_width / 2); |
302 |
|
|
303 |
|
transfer_8to16sub(&dct_codes[5 * 64], |
304 |
|
cur->v + 8 * j * edged_width / 2 + 8 * i, |
305 |
|
interpolate8x8_switch2(f_refv->u, f_ref->v, 8 * i, 8 * j, |
306 |
|
dx, dy, edged_width / 2, 0), |
307 |
|
|
308 |
|
edged_width / 2); |
309 |
|
|
310 |
break; |
break; |
311 |
|
|
313 |
b_dx = mb->b_mvs[0].x; |
b_dx = mb->b_mvs[0].x; |
314 |
b_dy = mb->b_mvs[0].y; |
b_dy = mb->b_mvs[0].y; |
315 |
|
|
316 |
transfer_8to16sub_c( |
transfer_8to16sub(&dct_codes[0 * 64], |
|
dct_codes[0], |
|
317 |
cur->y + (j*16)*edged_width + (i*16), |
cur->y + (j*16)*edged_width + (i*16), |
318 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
319 |
i*16, j*16, 1, b_dx, b_dy, edged_width), |
i * 16, j * 16, 1, b_dx, b_dy, |
320 |
edged_width); |
edged_width), edged_width); |
321 |
|
|
322 |
transfer_8to16sub( |
transfer_8to16sub(&dct_codes[1 * 64], |
|
dct_codes[1], |
|
323 |
cur->y + (j*16)*edged_width + (i*16+8), |
cur->y + (j*16)*edged_width + (i*16+8), |
324 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
325 |
i*16+8, j*16, 1, b_dx, b_dy, edged_width), |
i * 16 + 8, j * 16, 1, b_dx, b_dy, |
326 |
edged_width); |
edged_width), edged_width); |
327 |
|
|
328 |
transfer_8to16sub_c( |
transfer_8to16sub(&dct_codes[2 * 64], |
|
dct_codes[2], |
|
329 |
cur->y + (j*16+8)*edged_width + (i*16), |
cur->y + (j*16+8)*edged_width + (i*16), |
330 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
331 |
i*16, j*16+8, 1, b_dx, b_dy, edged_width), |
i * 16, j * 16 + 8, 1, b_dx, b_dy, |
332 |
edged_width); |
edged_width), edged_width); |
333 |
|
|
334 |
transfer_8to16sub( |
transfer_8to16sub(&dct_codes[3 * 64], |
|
dct_codes[3], |
|
335 |
cur->y + (j*16+8)*edged_width + (i*16+8), |
cur->y + (j*16+8)*edged_width + (i*16+8), |
336 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
337 |
i*16+8, j*16+8, 1, b_dx, b_dy, edged_width), |
i * 16 + 8, j * 16 + 8, 1, b_dx, b_dy, |
338 |
edged_width); |
edged_width), edged_width); |
339 |
|
|
340 |
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
341 |
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
342 |
|
|
343 |
/* uv-image-based compensation */ |
/* uv-block-based compensation */ |
344 |
compensate8x8_halfpel(dct_codes[4], cur->u, |
transfer_8to16sub(&dct_codes[4 * 64], |
345 |
b_ref->u, b_refh->u, b_refv->u, b_refhv->u, |
cur->u + 8 * j * edged_width / 2 + 8 * i, |
346 |
8*i, 8*j, b_dx, b_dy, edged_width/2); |
interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j, |
347 |
compensate8x8_halfpel(dct_codes[5], cur->v, |
b_dx, b_dy, edged_width / 2, 0), |
348 |
b_ref->v, b_refh->v, b_refv->v, b_refhv->v, |
|
349 |
8*i, 8*j, b_dx, b_dy, edged_width/2); |
edged_width / 2); |
350 |
|
|
351 |
|
transfer_8to16sub(&dct_codes[5 * 64], |
352 |
|
cur->v + 8 * j * edged_width / 2 + 8 * i, |
353 |
|
interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j, |
354 |
|
b_dx, b_dy, edged_width / 2, 0), |
355 |
|
|
356 |
|
edged_width / 2); |
357 |
|
|
358 |
break; |
break; |
359 |
|
|
360 |
|
|
361 |
case MODE_INTERPOLATE : |
case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */ |
362 |
|
case MODE_DIRECT_NO4V: |
363 |
|
|
364 |
dx = mb->mvs[0].x; |
dx = mb->mvs[0].x; |
365 |
dy = mb->mvs[0].y; |
dy = mb->mvs[0].y; |
366 |
|
|
367 |
b_dx = mb->b_mvs[0].x; |
b_dx = mb->b_mvs[0].x; |
368 |
b_dy = mb->b_mvs[0].y; |
b_dy = mb->b_mvs[0].y; |
369 |
|
|
370 |
transfer_8to16sub2_c( |
for (k = 0; k < 4; k++) { |
371 |
dct_codes[0], |
transfer_8to16sub2(&dct_codes[k * 64], |
372 |
cur->y + (i*16) + (j*16)*edged_width, |
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
373 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
get_ref(f_ref->y, f_refh->y, f_refv->y, |
374 |
16*i, 16*j, 1, dx, dy, edged_width), |
f_refhv->y, 2*i + (k&1), 2*j + (k>>1), 8, dx, dy, |
375 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
edged_width), |
376 |
16*i, 16*j, 1, b_dx, b_dy, edged_width), |
get_ref(b_ref->y, b_refh->y, b_refv->y, |
377 |
|
b_refhv->y, 2*i + (k&1), 2 * j+(k>>1), 8, b_dx, b_dy, |
378 |
|
edged_width), |
379 |
edged_width); |
edged_width); |
380 |
|
} |
381 |
|
|
382 |
transfer_8to16sub2_c( |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
383 |
dct_codes[1], |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
|
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); |
|
384 |
|
|
385 |
transfer_8to16sub2_c( |
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
386 |
dct_codes[2], |
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
387 |
cur->y + (i*16) + (j*16+8)*edged_width, |
|
388 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
transfer_8to16sub2(&dct_codes[4 * 64], |
389 |
16*i, 16*j+8, 1, dx, dy, edged_width), |
cur->u + (y * 8) * edged_width / 2 + (x * 8), |
390 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j, |
391 |
16*i, 16*j+8, 1, b_dx, b_dy, edged_width), |
b_dx, b_dy, edged_width / 2, 0), |
392 |
edged_width); |
interpolate8x8_switch2(f_refv->u + 8, f_ref->u, 8 * i, 8 * j, |
393 |
|
dx, dy, edged_width / 2, 0), |
394 |
|
edged_width / 2); |
395 |
|
|
396 |
|
transfer_8to16sub2(&dct_codes[5 * 64], |
397 |
|
cur->v + (y * 8) * edged_width / 2 + (x * 8), |
398 |
|
interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j, |
399 |
|
b_dx, b_dy, edged_width / 2, 0), |
400 |
|
interpolate8x8_switch2(f_refv->u + 8, f_ref->v, 8 * i, 8 * j, |
401 |
|
dx, dy, edged_width / 2, 0), |
402 |
|
edged_width / 2); |
403 |
|
|
404 |
|
break; |
405 |
|
|
406 |
|
case MODE_DIRECT: |
407 |
|
|
408 |
|
for (k=0;k<4;k++) |
409 |
|
{ |
410 |
|
dx = mb->mvs[k].x; |
411 |
|
dy = mb->mvs[k].y; |
412 |
|
|
413 |
|
b_dx = mb->b_mvs[k].x; |
414 |
|
b_dy = mb->b_mvs[k].y; |
415 |
|
|
416 |
transfer_8to16sub2_c( |
// fprintf(stderr,"Direct Vector %d -- %d:%d %d:%d\n",k,dx,dy,b_dx,b_dy); |
417 |
dct_codes[3], |
|
418 |
cur->y + (i*16+8) + (j*16+8)*edged_width, |
transfer_8to16sub2(&dct_codes[k * 64], |
419 |
|
cur->y + (i*16 + (k&1)*8) + (j*16 + (k>>1)*8 ) * edged_width, |
420 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
421 |
16*i + 8, 16*j + 8, 1, dx, dy, edged_width), |
2*i + (k&1), 2*j + (k>>1), 8, dx, dy, |
422 |
|
edged_width), |
423 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
424 |
16*i + 8, 16*j + 8, 1, b_dx, b_dy, edged_width), |
2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, |
425 |
|
edged_width), |
426 |
edged_width); |
edged_width); |
427 |
|
} |
428 |
|
|
429 |
|
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
430 |
|
dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
431 |
|
|
432 |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
433 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
434 |
|
|
|
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
|
|
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
|
435 |
|
|
436 |
transfer_8to16sub2_c( |
sum = mb->b_mvs[0].x + mb->b_mvs[1].x + mb->b_mvs[2].x + mb->b_mvs[3].x; |
437 |
dct_codes[4], |
b_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
438 |
|
|
439 |
|
sum = mb->b_mvs[0].y + mb->b_mvs[1].y + mb->b_mvs[2].y + mb->b_mvs[3].y; |
440 |
|
b_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
441 |
|
|
442 |
|
/* // for QPel don't forget to always do |
443 |
|
|
444 |
|
if (quarterpel) |
445 |
|
sum /= 2; |
446 |
|
*/ |
447 |
|
transfer_8to16sub2(&dct_codes[4 * 64], |
448 |
cur->u + (y*8)*edged_width/2 + (x*8), |
cur->u + (y*8)*edged_width/2 + (x*8), |
449 |
get_ref(f_ref->u, f_refh->u, f_refv->u, f_refhv->u, |
interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j, |
450 |
8*i, 8*j, 1, dx, dy, edged_width/2), |
b_dx, b_dy, edged_width / 2, 0), |
451 |
get_ref(b_ref->u, b_refh->u, b_refv->u, b_refhv->u, |
interpolate8x8_switch2(f_refv->u + 8, f_ref->u, 8 * i, 8 * j, dx, dy, |
452 |
8*i, 8*j, 1, b_dx, b_dy, edged_width/2), |
edged_width / 2, 0), |
453 |
edged_width/2); |
edged_width/2); |
454 |
|
|
455 |
transfer_8to16sub2_c( |
transfer_8to16sub2(&dct_codes[5 * 64], |
|
dct_codes[5], |
|
456 |
cur->v + (y*8)*edged_width/2 + (x*8), |
cur->v + (y*8)*edged_width/2 + (x*8), |
457 |
get_ref(f_ref->v, f_refh->v, f_refv->v, f_refhv->v, |
interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j, |
458 |
8*i, 8*j, 1, dx, dy, edged_width/2), |
b_dx, b_dy, edged_width / 2, 0), |
459 |
get_ref(b_ref->v, b_refh->v, b_refv->v, b_refhv->v, |
interpolate8x8_switch2(f_refv->u + 8, f_ref->v, 8 * i, 8 * j, |
460 |
8*i, 8*j, 1, b_dx, b_dy, edged_width/2), |
dx, dy, edged_width / 2, 0), |
461 |
edged_width/2); |
edged_width/2); |
462 |
|
|
|
break; |
|
463 |
|
|
|
case MODE_DIRECT : |
|
|
// todo |
|
464 |
break; |
break; |
465 |
} |
} |
|
|
|
466 |
} |
} |
|
|
|