1 |
|
// 30.10.2002 corrected qpel chroma rounding |
2 |
|
// 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 |
5 |
|
|
6 |
|
#include <stdio.h> |
7 |
|
|
8 |
#include "../encoder.h" |
#include "../encoder.h" |
9 |
#include "../utils/mbfunctions.h" |
#include "../utils/mbfunctions.h" |
10 |
#include "../image/interpolate8x8.h" |
#include "../image/interpolate8x8.h" |
11 |
|
#include "../image/reduced.h" |
12 |
#include "../utils/timer.h" |
#include "../utils/timer.h" |
13 |
#include "motion.h" |
#include "motion.h" |
14 |
|
|
15 |
|
#ifndef ABS |
16 |
#define ABS(X) (((X)>0)?(X):-(X)) |
#define ABS(X) (((X)>0)?(X):-(X)) |
17 |
|
#endif |
18 |
|
#ifndef SIGN |
19 |
#define SIGN(X) (((X)>0)?1:-1) |
#define SIGN(X) (((X)>0)?1:-1) |
20 |
|
#endif |
21 |
|
|
22 |
|
|
23 |
|
/* This is borrowed from decoder.c */ |
24 |
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
25 |
|
{ |
26 |
|
int length = 1 << (fcode+4); |
27 |
|
|
28 |
|
if (quarterpel) value *= 2; |
29 |
|
|
30 |
|
if (value < -length) |
31 |
|
return -length; |
32 |
|
else if (value >= length) |
33 |
|
return length-1; |
34 |
|
else return value; |
35 |
|
} |
36 |
|
|
37 |
|
/* And this is borrowed from bitstream.c until we find a common solution */ |
38 |
|
|
39 |
static __inline void compensate8x8_halfpel( |
static uint32_t __inline |
40 |
int16_t * const dct_codes, |
log2bin(uint32_t value) |
41 |
|
{ |
42 |
|
/* Changed by Chenm001 */ |
43 |
|
#if !defined(_MSC_VER) |
44 |
|
int n = 0; |
45 |
|
|
46 |
|
while (value) { |
47 |
|
value >>= 1; |
48 |
|
n++; |
49 |
|
} |
50 |
|
return n; |
51 |
|
#else |
52 |
|
__asm { |
53 |
|
bsr eax, value |
54 |
|
inc eax |
55 |
|
} |
56 |
|
#endif |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
static __inline void |
61 |
|
compensate16x16_interpolate(int16_t * const dct_codes, |
62 |
uint8_t * const cur, |
uint8_t * const cur, |
63 |
const uint8_t * const ref, |
const uint8_t * const ref, |
64 |
const uint8_t * const refh, |
const uint8_t * const refh, |
65 |
const uint8_t * const refv, |
const uint8_t * const refv, |
66 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
67 |
const uint32_t x, const uint32_t y, |
uint8_t * const tmp, |
68 |
const int32_t dx, const int dy, |
uint32_t x, |
69 |
const uint32_t stride) |
uint32_t y, |
70 |
|
const int32_t dx, |
71 |
|
const int32_t dy, |
72 |
|
const int32_t stride, |
73 |
|
const int quarterpel, |
74 |
|
const int reduced_resolution, |
75 |
|
const int32_t rounding) |
76 |
{ |
{ |
77 |
int32_t ddx,ddy; |
const uint8_t * ptr; |
78 |
|
|
79 |
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; |
|
80 |
|
|
81 |
case 1 : |
if(quarterpel) { |
82 |
ddx = dx/2; |
if ((dx&3) | (dy&3)) { |
83 |
ddy = (dy-1)/2; |
interpolate16x16_quarterpel(tmp - y * stride - x, |
84 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
(uint8_t *) ref, tmp + 32, |
85 |
refv + (y+ddy)*stride + x+ddx, stride); |
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
86 |
break; |
ptr = tmp; |
87 |
|
} else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position |
88 |
|
|
89 |
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; |
|
90 |
|
|
|
default : // case 3: |
|
|
ddx = (dx-1)/2; |
|
|
ddy = (dy-1)/2; |
|
91 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
92 |
refhv + (y+ddy)*stride + x+ddx, stride); |
ptr, stride); |
93 |
break; |
transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
94 |
|
ptr + 8, stride); |
95 |
|
transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
96 |
|
ptr + 8*stride, stride); |
97 |
|
transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
98 |
|
ptr + 8*stride + 8, stride); |
99 |
|
|
100 |
|
} else { //reduced_resolution |
101 |
|
|
102 |
|
x *= 2; y *= 2; |
103 |
|
|
104 |
|
ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
105 |
|
|
106 |
|
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
107 |
|
filter_diff_18x18_to_8x8(dct_codes, ptr, stride); |
108 |
|
|
109 |
|
filter_18x18_to_8x8(dct_codes+64, cur+y*stride + x + 16, stride); |
110 |
|
filter_diff_18x18_to_8x8(dct_codes+64, ptr + 16, stride); |
111 |
|
|
112 |
|
filter_18x18_to_8x8(dct_codes+128, cur+(y+16)*stride + x, stride); |
113 |
|
filter_diff_18x18_to_8x8(dct_codes+128, ptr + 16*stride, stride); |
114 |
|
|
115 |
|
filter_18x18_to_8x8(dct_codes+192, cur+(y+16)*stride + x + 16, stride); |
116 |
|
filter_diff_18x18_to_8x8(dct_codes+192, ptr + 16*stride + 16, stride); |
117 |
|
|
118 |
|
transfer32x32_copy(cur + y*stride + x, ptr, stride); |
119 |
} |
} |
120 |
} |
} |
121 |
|
|
122 |
|
static __inline void |
123 |
|
compensate8x8_interpolate( int16_t * const dct_codes, |
124 |
|
uint8_t * const cur, |
125 |
|
const uint8_t * const ref, |
126 |
|
const uint8_t * const refh, |
127 |
|
const uint8_t * const refv, |
128 |
|
const uint8_t * const refhv, |
129 |
|
uint8_t * const tmp, |
130 |
|
uint32_t x, |
131 |
|
uint32_t y, |
132 |
|
const int32_t dx, |
133 |
|
const int32_t dy, |
134 |
|
const int32_t stride, |
135 |
|
const int32_t quarterpel, |
136 |
|
const int reduced_resolution, |
137 |
|
const int32_t rounding) |
138 |
|
{ |
139 |
|
const uint8_t * ptr; |
140 |
|
|
141 |
|
if (!reduced_resolution) { |
142 |
|
|
143 |
void MBMotionCompensation( |
if(quarterpel) { |
144 |
MACROBLOCK * const mb, |
if ((dx&3) | (dy&3)) { |
145 |
|
interpolate8x8_quarterpel(tmp - y*stride - x, |
146 |
|
(uint8_t *) ref, tmp + 32, |
147 |
|
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
148 |
|
ptr = tmp; |
149 |
|
} else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position |
150 |
|
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
151 |
|
|
152 |
|
transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride); |
153 |
|
|
154 |
|
} else { //reduced_resolution |
155 |
|
|
156 |
|
x *= 2; y *= 2; |
157 |
|
|
158 |
|
ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
159 |
|
|
160 |
|
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
161 |
|
filter_diff_18x18_to_8x8(dct_codes, ptr, stride); |
162 |
|
|
163 |
|
transfer16x16_copy(cur + y*stride + x, ptr, stride); |
164 |
|
} |
165 |
|
} |
166 |
|
|
167 |
|
/* XXX: slow, inelegant... */ |
168 |
|
static void |
169 |
|
interpolate18x18_switch(uint8_t * const cur, |
170 |
|
const uint8_t * const refn, |
171 |
|
const uint32_t x, |
172 |
|
const uint32_t y, |
173 |
|
const int32_t dx, |
174 |
|
const int dy, |
175 |
|
const int32_t stride, |
176 |
|
const int32_t rounding) |
177 |
|
{ |
178 |
|
interpolate8x8_switch(cur, refn, x-1, y-1, dx, dy, stride, rounding); |
179 |
|
interpolate8x8_switch(cur, refn, x+7, y-1, dx, dy, stride, rounding); |
180 |
|
interpolate8x8_switch(cur, refn, x+9, y-1, dx, dy, stride, rounding); |
181 |
|
|
182 |
|
interpolate8x8_switch(cur, refn, x-1, y+7, dx, dy, stride, rounding); |
183 |
|
interpolate8x8_switch(cur, refn, x+7, y+7, dx, dy, stride, rounding); |
184 |
|
interpolate8x8_switch(cur, refn, x+9, y+7, dx, dy, stride, rounding); |
185 |
|
|
186 |
|
interpolate8x8_switch(cur, refn, x-1, y+9, dx, dy, stride, rounding); |
187 |
|
interpolate8x8_switch(cur, refn, x+7, y+9, dx, dy, stride, rounding); |
188 |
|
interpolate8x8_switch(cur, refn, x+9, y+9, dx, dy, stride, rounding); |
189 |
|
} |
190 |
|
|
191 |
|
static void |
192 |
|
CompensateChroma( int dx, int dy, |
193 |
|
const int i, const int j, |
194 |
|
IMAGE * const Cur, |
195 |
|
const IMAGE * const Ref, |
196 |
|
uint8_t * const temp, |
197 |
|
int16_t * const coeff, |
198 |
|
const int32_t stride, |
199 |
|
const int rounding, |
200 |
|
const int rrv) |
201 |
|
{ /* uv-block-based compensation */ |
202 |
|
|
203 |
|
if (!rrv) { |
204 |
|
transfer_8to16sub(coeff, Cur->u + 8 * j * stride + 8 * i, |
205 |
|
interpolate8x8_switch2(temp, Ref->u, 8 * i, 8 * j, |
206 |
|
dx, dy, stride, rounding), |
207 |
|
stride); |
208 |
|
transfer_8to16sub(coeff + 64, Cur->v + 8 * j * stride + 8 * i, |
209 |
|
interpolate8x8_switch2(temp, Ref->v, 8 * i, 8 * j, |
210 |
|
dx, dy, stride, rounding), |
211 |
|
stride); |
212 |
|
} else { |
213 |
|
uint8_t * current, * reference; |
214 |
|
|
215 |
|
current = Cur->u + 16*j*stride + 16*i; |
216 |
|
reference = temp - 16*j*stride - 16*i; |
217 |
|
interpolate18x18_switch(reference, Ref->u, 16*i, 16*j, dx, dy, stride, rounding); |
218 |
|
filter_18x18_to_8x8(coeff, current, stride); |
219 |
|
filter_diff_18x18_to_8x8(coeff, temp, stride); |
220 |
|
transfer16x16_copy(current, temp, stride); |
221 |
|
|
222 |
|
current = Cur->v + 16*j*stride + 16*i; |
223 |
|
interpolate18x18_switch(reference, Ref->v, 16*i, 16*j, dx, dy, stride, rounding); |
224 |
|
filter_18x18_to_8x8(coeff + 64, current, stride); |
225 |
|
filter_diff_18x18_to_8x8(coeff + 64, temp, stride); |
226 |
|
transfer16x16_copy(current, temp, stride); |
227 |
|
} |
228 |
|
} |
229 |
|
|
230 |
|
void |
231 |
|
MBMotionCompensation(MACROBLOCK * const mb, |
232 |
const uint32_t i, |
const uint32_t i, |
233 |
const uint32_t j, |
const uint32_t j, |
234 |
const IMAGE * const ref, |
const IMAGE * const ref, |
235 |
const IMAGE * const refh, |
const IMAGE * const refh, |
236 |
const IMAGE * const refv, |
const IMAGE * const refv, |
237 |
const IMAGE * const refhv, |
const IMAGE * const refhv, |
238 |
|
const IMAGE * const refGMC, |
239 |
IMAGE * const cur, |
IMAGE * const cur, |
240 |
int16_t *dct_codes, |
int16_t *dct_codes, |
241 |
const uint32_t width, |
const uint32_t width, |
242 |
const uint32_t height, |
const uint32_t height, |
243 |
const uint32_t edged_width, |
const uint32_t edged_width, |
244 |
const uint32_t rounding) |
const int32_t quarterpel, |
245 |
|
const int reduced_resolution, |
246 |
|
const int32_t rounding) |
247 |
{ |
{ |
248 |
static const uint32_t roundtab[16] = |
int32_t dx; |
249 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
int32_t dy; |
250 |
|
|
251 |
|
|
252 |
|
uint8_t * const tmp = refv->u; |
253 |
|
|
254 |
|
if ( (!reduced_resolution) && (mb->mode == MODE_NOT_CODED) ) { /* quick copy for early SKIP */ |
255 |
|
/* early SKIP is only activated in P-VOPs, not in S-VOPs, so mcsel can never be 1 */ |
256 |
|
|
257 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
/* if (mb->mcsel) { |
258 |
|
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
259 |
|
refGMC->y + 16 * (i + j * edged_width), |
260 |
|
edged_width); |
261 |
|
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
262 |
|
refGMC->u + 8 * (i + j * edged_width/2), |
263 |
|
edged_width / 2); |
264 |
|
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
265 |
|
refGMC->v + 8 * (i + j * edged_width/2), |
266 |
|
edged_width / 2); |
267 |
|
} else |
268 |
|
*/ |
269 |
{ |
{ |
270 |
int32_t dx = mb->mvs[0].x; |
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
271 |
int32_t dy = mb->mvs[0].y; |
ref->y + 16 * (i + j * edged_width), |
272 |
|
edged_width); |
273 |
compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
274 |
16*i, 16*j, dx, dy, edged_width); |
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
275 |
compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
ref->u + 8 * (i + j * edged_width/2), |
276 |
16*i + 8, 16*j, dx, dy, edged_width); |
edged_width / 2); |
277 |
compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
278 |
16*i, 16*j + 8, dx, dy, edged_width); |
ref->v + 8 * (i + j * edged_width/2), |
279 |
compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
edged_width / 2); |
280 |
16*i + 8, 16*j + 8, dx, dy, edged_width); |
} |
281 |
|
return; |
|
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 |
|
282 |
} |
} |
|
else // mode == MODE_INTER4V |
|
|
{ |
|
|
int32_t sum, dx, dy; |
|
283 |
|
|
284 |
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 |
285 |
16*i, 16*j, mb->mvs[0].x, mb->mvs[0].y, edged_width); |
|| mb->mode == MODE_INTER_Q) /*&& !quarterpel*/) { |
286 |
compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
287 |
16*i + 8, 16*j, mb->mvs[1].x, mb->mvs[1].y, edged_width); |
/* reduced resolution + GMC: not possible */ |
288 |
compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
289 |
16*i, 16*j + 8, mb->mvs[2].x, mb->mvs[2].y, edged_width); |
if (mb->mcsel) { |
290 |
compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y, |
|
291 |
16*i + 8, 16*j + 8, mb->mvs[3].x, mb->mvs[3].y, edged_width); |
/* call normal routine once, easier than "if (mcsel)"ing all the time */ |
292 |
|
|
293 |
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
transfer_8to16sub(&dct_codes[0*64], cur->y + 16*j*edged_width + 16*i, |
294 |
dx = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
refGMC->y + 16*j*edged_width + 16*i, edged_width); |
295 |
|
transfer_8to16sub(&dct_codes[1*64], cur->y + 16*j*edged_width + 16*i+8, |
296 |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
refGMC->y + 16*j*edged_width + 16*i+8, edged_width); |
297 |
dy = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
transfer_8to16sub(&dct_codes[2*64], cur->y + (16*j+8)*edged_width + 16*i, |
298 |
|
refGMC->y + (16*j+8)*edged_width + 16*i, edged_width); |
299 |
/* uv-image-based compensation */ |
transfer_8to16sub(&dct_codes[3*64], cur->y + (16*j+8)*edged_width + 16*i+8, |
300 |
#ifdef BFRAMES |
refGMC->y + (16*j+8)*edged_width + 16*i+8, edged_width); |
301 |
compensate8x8_halfpel(&dct_codes[4*64], cur->u, ref->u, refh->u, refv->u, refhv->u, |
|
302 |
8*i, 8*j, dx, dy, edged_width/2); |
/* lumi is needed earlier for mode decision, but chroma should be done block-based, but it isn't, yet. */ |
303 |
compensate8x8_halfpel(&dct_codes[5*64], cur->v, ref->v, refh->v, refv->v, refhv->v, |
|
304 |
8*i, 8*j, dx, dy, edged_width/2); |
transfer_8to16sub(&dct_codes[4 * 64], cur->u + 8 *j*edged_width/2 + 8*i, |
305 |
#else |
refGMC->u + 8 *j*edged_width/2 + 8*i, edged_width/2); |
306 |
/* uv-block-based compensation */ |
|
307 |
interpolate8x8_switch(refv->u, ref->u, 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, |
308 |
transfer_8to16sub(&dct_codes[4*64], |
refGMC->v + 8*j* edged_width/2 + 8*i, edged_width/2); |
309 |
cur->u + 8*j*edged_width/2 + 8*i, |
|
310 |
refv->u + 8*j*edged_width/2 + 8*i, edged_width/2); |
return; |
311 |
|
} |
312 |
interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding); |
|
313 |
transfer_8to16sub(&dct_codes[5*64], |
/* ordinary compensation */ |
314 |
cur->v + 8*j*edged_width/2 + 8*i, |
|
315 |
refv->v + 8*j*edged_width/2 + 8*i, edged_width/2); |
dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x); |
316 |
#endif |
dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y); |
317 |
|
|
318 |
|
if (reduced_resolution) { |
319 |
|
dx = RRV_MV_SCALEUP(dx); |
320 |
|
dy = RRV_MV_SCALEUP(dy); |
321 |
} |
} |
322 |
|
|
323 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
324 |
|
refv->y, refhv->y, tmp, 16 * i, 16 * j, dx, dy, |
325 |
|
edged_width, quarterpel, reduced_resolution, rounding); |
326 |
|
|
327 |
|
dx /= (int)(1 + quarterpel); |
328 |
|
dy /= (int)(1 + quarterpel); |
329 |
|
|
330 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
331 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
332 |
|
|
333 |
|
} else { // mode == MODE_INTER4V |
334 |
|
int k, sumx = 0, sumy = 0; |
335 |
|
const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs); |
336 |
|
|
337 |
|
for (k = 0; k < 4; k++) { |
338 |
|
dx = mvs[k].x; |
339 |
|
dy = mvs[k].y; |
340 |
|
sumx += dx / (1 + quarterpel); |
341 |
|
sumy += dy / (1 + quarterpel); |
342 |
|
|
343 |
|
if (reduced_resolution){ |
344 |
|
dx = RRV_MV_SCALEUP(dx); |
345 |
|
dy = RRV_MV_SCALEUP(dy); |
346 |
} |
} |
347 |
|
|
348 |
|
compensate8x8_interpolate(&dct_codes[k * 64], cur->y, ref->y, refh->y, |
349 |
|
refv->y, refhv->y, tmp, 16 * i + 8*(k&1), 16 * j + 8*(k>>1), dx, |
350 |
|
dy, edged_width, quarterpel, reduced_resolution, rounding); |
351 |
|
} |
352 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
353 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
354 |
|
} |
355 |
|
|
356 |
void MBMotionCompensationBVOP( |
CompensateChroma(dx, dy, i, j, cur, ref, tmp, |
357 |
MBParam * pParam, |
&dct_codes[4 * 64], edged_width / 2, rounding, reduced_resolution); |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
|
void |
362 |
|
MBMotionCompensationBVOP(MBParam * pParam, |
363 |
MACROBLOCK * const mb, |
MACROBLOCK * const mb, |
364 |
const uint32_t i, |
const uint32_t i, |
365 |
const uint32_t j, |
const uint32_t j, |
374 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
375 |
int16_t * dct_codes) |
int16_t * dct_codes) |
376 |
{ |
{ |
377 |
static const uint32_t roundtab[16] = |
const uint32_t edged_width = pParam->edged_width; |
378 |
{ 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; |
379 |
|
int k; |
380 |
|
const int quarterpel = pParam->m_quarterpel; |
381 |
|
const uint8_t * ptr1, * ptr2; |
382 |
|
uint8_t * const tmp = f_refv->u; |
383 |
|
const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs); |
384 |
|
const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs); |
385 |
|
|
386 |
const int32_t edged_width = pParam->edged_width; |
switch (mb->mode) { |
387 |
int32_t dx, dy; |
case MODE_FORWARD: |
388 |
int32_t b_dx, b_dy; |
dx = fmvs->x; dy = fmvs->y; |
|
int x = i; |
|
|
int y = j; |
|
389 |
|
|
390 |
|
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, |
391 |
|
f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx, |
392 |
|
dy, edged_width, quarterpel, 0, 0); |
393 |
|
|
394 |
|
dx /= 1 + quarterpel; |
395 |
|
dy /= 1 + quarterpel; |
396 |
|
CompensateChroma( (dx >> 1) + roundtab_79[dx & 0x3], |
397 |
|
(dy >> 1) + roundtab_79[dy & 0x3], |
398 |
|
i, j, cur, f_ref, tmp, |
399 |
|
&dct_codes[4 * 64], edged_width / 2, 0, 0); |
400 |
|
|
401 |
|
return; |
402 |
|
|
403 |
switch(mb->mode) |
case MODE_BACKWARD: |
404 |
{ |
b_dx = bmvs->x; b_dy = bmvs->y; |
|
case MODE_FORWARD : |
|
|
dx = mb->mvs[0].x; |
|
|
dy = mb->mvs[0].y; |
|
405 |
|
|
406 |
transfer_8to16sub_c( |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
407 |
&dct_codes[0*64], |
b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx, |
408 |
cur->y + (j*16)*edged_width + (i*16), |
b_dy, edged_width, quarterpel, 0, 0); |
409 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
410 |
i*16, j*16, 1, dx, dy, edged_width), |
b_dx /= 1 + quarterpel; |
411 |
edged_width); |
b_dy /= 1 + quarterpel; |
412 |
|
CompensateChroma( (b_dx >> 1) + roundtab_79[b_dx & 0x3], |
413 |
|
(b_dy >> 1) + roundtab_79[b_dy & 0x3], |
414 |
|
i, j, cur, b_ref, tmp, |
415 |
|
&dct_codes[4 * 64], edged_width / 2, 0, 0); |
416 |
|
|
417 |
|
return; |
418 |
|
|
419 |
|
case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */ |
420 |
|
case MODE_DIRECT_NO4V: |
421 |
|
dx = fmvs->x; dy = fmvs->y; |
422 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
423 |
|
|
424 |
|
if (quarterpel) { |
425 |
|
|
426 |
|
if ((dx&3) | (dy&3)) { |
427 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width, |
428 |
|
(uint8_t *) f_ref->y, tmp + 32, |
429 |
|
tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0); |
430 |
|
ptr1 = tmp; |
431 |
|
} else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; // fullpixel position |
432 |
|
|
433 |
|
if ((b_dx&3) | (b_dy&3)) { |
434 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16, |
435 |
|
(uint8_t *) b_ref->y, tmp + 32, |
436 |
|
tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0); |
437 |
|
ptr2 = tmp + 16; |
438 |
|
} else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; // fullpixel position |
439 |
|
|
440 |
|
b_dx /= 2; |
441 |
|
b_dy /= 2; |
442 |
|
dx /= 2; |
443 |
|
dy /= 2; |
444 |
|
|
445 |
|
} else { |
446 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
447 |
|
i, j, 16, dx, dy, edged_width); |
448 |
|
|
449 |
transfer_8to16sub( |
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
450 |
&dct_codes[1*64], |
i, j, 16, b_dx, b_dy, edged_width); |
451 |
cur->y + (j*16)*edged_width + (i*16+8), |
} |
452 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
for (k = 0; k < 4; k++) |
453 |
i*16+8, j*16, 1, dx, dy, edged_width), |
transfer_8to16sub2(&dct_codes[k * 64], |
454 |
edged_width); |
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
455 |
|
ptr1 + (k&1)*8 + (k>>1)*8*edged_width, |
456 |
|
ptr2 + (k&1)*8 + (k>>1)*8*edged_width, edged_width); |
457 |
|
|
|
transfer_8to16sub_c( |
|
|
&dct_codes[2*64], |
|
|
cur->y + (j*16+8)*edged_width + (i*16), |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
i*16, j*16+8, 1, dx, dy, edged_width), |
|
|
edged_width); |
|
458 |
|
|
459 |
transfer_8to16sub( |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
460 |
&dct_codes[3*64], |
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
461 |
cur->y + (j*16+8)*edged_width + (i*16+8), |
|
462 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
463 |
i*16+8, j*16+8, 1, dx, dy, edged_width), |
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
464 |
edged_width); |
|
465 |
|
break; |
466 |
|
|
467 |
|
default: // MODE_DIRECT |
468 |
|
sumx = sumy = b_sumx = b_sumy = 0; |
469 |
|
|
470 |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
for (k = 0; k < 4; k++) { |
471 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
|
472 |
|
dx = fmvs[k].x; dy = fmvs[k].y; |
473 |
|
b_dx = bmvs[k].x; b_dy = bmvs[k].y; |
474 |
|
|
475 |
|
if (quarterpel) { |
476 |
|
sumx += dx/2; sumy += dy/2; |
477 |
|
b_sumx += b_dx/2; b_sumy += b_dy/2; |
478 |
|
|
479 |
|
if ((dx&3) | (dy&3)) { |
480 |
|
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width, |
481 |
|
(uint8_t *) f_ref->y, |
482 |
|
tmp + 32, tmp + 64, tmp + 96, |
483 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
484 |
|
ptr1 = tmp; |
485 |
|
} else ptr1 = f_ref->y + (16*j + (k>>1)*8 + dy/4)*edged_width + 16*i + (k&1)*8 + dx/4; |
486 |
|
|
487 |
|
if ((b_dx&3) | (b_dy&3)) { |
488 |
|
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16, |
489 |
|
(uint8_t *) b_ref->y, |
490 |
|
tmp + 16, tmp + 32, tmp + 48, |
491 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
492 |
|
ptr2 = tmp + 16; |
493 |
|
} else ptr2 = b_ref->y + (16*j + (k>>1)*8 + b_dy/4)*edged_width + 16*i + (k&1)*8 + b_dx/4; |
494 |
|
} else { |
495 |
|
sumx += dx; sumy += dy; |
496 |
|
b_sumx += b_dx; b_sumy += b_dy; |
497 |
|
|
498 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
499 |
|
2*i + (k&1), 2*j + (k>>1), 8, dx, dy, edged_width); |
500 |
|
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
501 |
|
2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, edged_width); |
502 |
|
} |
503 |
|
transfer_8to16sub2(&dct_codes[k * 64], |
504 |
|
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
505 |
|
ptr1, ptr2, edged_width); |
506 |
|
|
507 |
|
} |
508 |
|
|
509 |
/* uv-image-based compensation */ |
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
510 |
compensate8x8_halfpel(&dct_codes[4*64], cur->u, f_ref->u, f_refh->u, f_refv->u, f_refhv->u, |
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
511 |
8*i, 8*j, dx, dy, edged_width/2); |
b_dx = (b_sumx >> 3) + roundtab_76[b_sumx & 0xf]; |
512 |
compensate8x8_halfpel(&dct_codes[5*64], cur->v, f_ref->v, f_refh->v, f_refv->v, f_refhv->v, |
b_dy = (b_sumy >> 3) + roundtab_76[b_sumy & 0xf]; |
|
8*i, 8*j, dx, dy, edged_width/2); |
|
513 |
|
|
514 |
break; |
break; |
515 |
|
} |
516 |
|
|
517 |
case MODE_BACKWARD : |
// uv block-based chroma interpolation for direct and interpolate modes |
518 |
b_dx = mb->b_mvs[0].x; |
transfer_8to16sub2(&dct_codes[4 * 64], |
519 |
b_dy = mb->b_mvs[0].y; |
cur->u + (j * 8) * edged_width / 2 + (i * 8), |
520 |
|
interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j, |
521 |
|
b_dx, b_dy, edged_width / 2, 0), |
522 |
|
interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j, |
523 |
|
dx, dy, edged_width / 2, 0), |
524 |
|
edged_width / 2); |
525 |
|
|
526 |
transfer_8to16sub_c( |
transfer_8to16sub2(&dct_codes[5 * 64], |
527 |
&dct_codes[0*64], |
cur->v + (j * 8) * edged_width / 2 + (i * 8), |
528 |
cur->y + (j*16)*edged_width + (i*16), |
interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j, |
529 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
b_dx, b_dy, edged_width / 2, 0), |
530 |
i*16, j*16, 1, b_dx, b_dy, edged_width), |
interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j, |
531 |
edged_width); |
dx, dy, edged_width / 2, 0), |
532 |
|
edged_width / 2); |
533 |
|
} |
534 |
|
|
|
transfer_8to16sub( |
|
|
&dct_codes[1*64], |
|
|
cur->y + (j*16)*edged_width + (i*16+8), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
i*16+8, j*16, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
535 |
|
|
|
transfer_8to16sub_c( |
|
|
&dct_codes[2*64], |
|
|
cur->y + (j*16+8)*edged_width + (i*16), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
i*16, j*16+8, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
536 |
|
|
537 |
transfer_8to16sub( |
void |
538 |
&dct_codes[3*64], |
generate_GMCparameters( const int num_wp, // [input]: number of warppoints |
539 |
cur->y + (j*16+8)*edged_width + (i*16+8), |
const int res, // [input]: resolution |
540 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
const WARPPOINTS *const warp, // [input]: warp points |
541 |
i*16+8, j*16+8, 1, b_dx, b_dy, edged_width), |
const int width, const int height, |
542 |
edged_width); |
GMC_DATA *const gmc) // [output] precalculated parameters |
543 |
|
{ |
544 |
|
|
545 |
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
/* We follow mainly two sources: The original standard, which is ugly, and the |
546 |
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
thesis from Andreas Dehnhardt, which is much nicer. |
547 |
|
|
548 |
/* uv-image-based compensation */ |
Notation is: indices are written next to the variable, |
549 |
compensate8x8_halfpel(&dct_codes[4*64], cur->u, |
primes in the standard are denoted by a suffix 'p'. |
550 |
b_ref->u, b_refh->u, b_refv->u, b_refhv->u, |
types are "c"=constant, "i"=input parameter, "f"=calculated, then fixed, |
551 |
8*i, 8*j, b_dx, b_dy, edged_width/2); |
"o"=output data, " "=other, "u" = unused, "p"=calc for every pixel |
552 |
compensate8x8_halfpel(&dct_codes[5*64], cur->v, |
|
553 |
b_ref->v, b_refh->v, b_refv->v, b_refhv->v, |
type | variable name | ISO name (TeX-style) | value or range | usage |
554 |
8*i, 8*j, b_dx, b_dy, edged_width/2); |
------------------------------------------------------------------------------------- |
555 |
|
c | H | H | [16 , ?] | image width (w/o edges) |
556 |
|
c | W | W | [16 , ?] | image height (w/o edges) |
557 |
|
|
558 |
|
c | i0 | i_0 | 0 | ref. point #1, X |
559 |
|
c | j0 | j_0 | 0 | ref. point #1, Y |
560 |
|
c | i1 | i_1 | W | ref. point #2, X |
561 |
|
c | j1 | j_1 | 0 | ref. point #2, Y |
562 |
|
cu | i2 | i_2 | 0 | ref. point #3, X |
563 |
|
cu | i2 | j_2 | H | ref. point #3, Y |
564 |
|
|
565 |
|
i | du0 | du[0] | [-16863,16863] | warp vector #1, Y |
566 |
|
i | dv0 | dv[0] | [-16863,16863] | warp vector #1, Y |
567 |
|
i | du1 | du[1] | [-16863,16863] | warp vector #2, Y |
568 |
|
i | dv1 | dv[1] | [-16863,16863] | warp vector #2, Y |
569 |
|
iu | du2 | du[2] | [-16863,16863] | warp vector #3, Y |
570 |
|
iu | dv2 | dv[2] | [-16863,16863] | warp vector #3, Y |
571 |
|
|
572 |
|
i | s | s | {2,4,8,16} | interpol. resolution |
573 |
|
f | sigma | - | log2(s) | X / s == X >> sigma |
574 |
|
f | r | r | =16/s | complementary res. |
575 |
|
f | rho | \rho | log2(r) | X / r == X >> rho |
576 |
|
|
577 |
|
f | i0s | i'_0 | | |
578 |
|
f | j0s | j'_0 | | |
579 |
|
f | i1s | i'_1 | | |
580 |
|
f | j1s | j'_1 | | |
581 |
|
f | i2s | i'_2 | | |
582 |
|
f | j2s | j'_2 | | |
583 |
|
|
584 |
|
f | alpha | \alpha | | 2^{alpha-1} < W <= 2^alpha |
585 |
|
f | beta | \beta | | 2^{beta-1} < H <= 2^beta |
586 |
|
|
587 |
|
f | Ws | W' | W = 2^{alpha} | scaled width |
588 |
|
f | Hs | H' | W = 2^{beta} | scaled height |
589 |
|
|
590 |
|
f | i1ss | i''_1 | "virtual sprite stuff" |
591 |
|
f | j1ss | j''_1 | "virtual sprite stuff" |
592 |
|
f | i2ss | i''_2 | "virtual sprite stuff" |
593 |
|
f | j2ss | j''_2 | "virtual sprite stuff" |
594 |
|
*/ |
595 |
|
|
596 |
|
/* Some calculations are disabled because we only use 2 warppoints at the moment */ |
597 |
|
|
598 |
|
int du0 = warp->duv[0].x; |
599 |
|
int dv0 = warp->duv[0].y; |
600 |
|
int du1 = warp->duv[1].x; |
601 |
|
int dv1 = warp->duv[1].y; |
602 |
|
// int du2 = warp->duv[2].x; |
603 |
|
// int dv2 = warp->duv[2].y; |
604 |
|
|
605 |
|
gmc->num_wp = num_wp; |
606 |
|
|
607 |
|
gmc->s = res; /* scaling parameters 2,4,8 or 16 */ |
608 |
|
gmc->sigma = log2bin(res-1); /* log2bin(15)=4, log2bin(16)=5, log2bin(17)=5 */ |
609 |
|
gmc->r = 16/res; |
610 |
|
gmc->rho = 4 - gmc->sigma; /* = log2bin(r-1) */ |
611 |
|
|
612 |
|
gmc->W = width; |
613 |
|
gmc->H = height; /* fixed reference coordinates */ |
614 |
|
|
615 |
|
gmc->alpha = log2bin(gmc->W-1); |
616 |
|
gmc->Ws= 1<<gmc->alpha; |
617 |
|
|
618 |
|
// gmc->beta = log2bin(gmc->H-1); |
619 |
|
// gmc->Hs= 1<<gmc->beta; |
620 |
|
|
621 |
|
// printf("du0=%d dv0=%d du1=%d dv1=%d s=%d sigma=%d W=%d alpha=%d, Ws=%d, rho=%d\n",du0,dv0,du1,dv1,gmc->s,gmc->sigma,gmc->W,gmc->alpha,gmc->Ws,gmc->rho); |
622 |
|
|
623 |
|
/* i2s is only needed for num_wp >= 3, etc. */ |
624 |
|
/* the 's' values are in 1/s pel resolution */ |
625 |
|
gmc->i0s = res/2 * ( du0 ); |
626 |
|
gmc->j0s = res/2 * ( dv0 ); |
627 |
|
gmc->i1s = res/2 * (2*width + du1 + du0 ); |
628 |
|
gmc->j1s = res/2 * ( dv1 + dv0 ); |
629 |
|
// gmc->i2s = res/2 * ( du2 + du0 ); |
630 |
|
// gmc->j2s = res/2 * (2*height + dv2 + dv0 ); |
631 |
|
|
632 |
|
/* i2s and i2ss are only needed for num_wp == 3, etc. */ |
633 |
|
|
634 |
|
/* the 'ss' values are in 1/16 pel resolution */ |
635 |
|
gmc->i1ss = 16*gmc->Ws + ((gmc->W-gmc->Ws)*(gmc->r*gmc->i0s) + gmc->Ws*(gmc->r*gmc->i1s - 16*gmc->W)) / gmc->W; |
636 |
|
gmc->j1ss = ((gmc->W - gmc->Ws)*(gmc->r*gmc->j0s) + gmc->Ws*gmc->r*gmc->j1s) / gmc->W; |
637 |
|
|
638 |
break; |
// gmc->i2ss = ((gmc->H - gmc->Hs)*(gmc->r*gmc->i0s) + gmc->Hs*(gmc->r*gmc->i2s)) / gmc->H; |
639 |
|
// gmc->j2ss = 16*gmc->Hs + ((gmc->H-gmc->Hs)*(gmc->r*gmc->j0s) + gmc->Ws*(gmc->r*gmc->j2s - 16*gmc->H)) / gmc->H; |
640 |
|
|
641 |
|
return; |
642 |
|
} |
643 |
|
|
|
case MODE_INTERPOLATE : |
|
|
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); |
|
644 |
|
|
|
transfer_8to16sub2_c( |
|
|
&dct_codes[1*64], |
|
|
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); |
|
645 |
|
|
646 |
transfer_8to16sub2_c( |
void |
647 |
&dct_codes[2*64], |
generate_GMCimage( const GMC_DATA *const gmc_data, // [input] precalculated data |
648 |
cur->y + (i*16) + (j*16+8)*edged_width, |
const IMAGE *const pRef, // [input] |
649 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
const int mb_width, |
650 |
16*i, 16*j+8, 1, dx, dy, edged_width), |
const int mb_height, |
651 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
const int stride, |
652 |
16*i, 16*j+8, 1, b_dx, b_dy, edged_width), |
const int stride2, |
653 |
edged_width); |
const int fcode, // [input] some parameters... |
654 |
|
const int32_t quarterpel, // [input] for rounding avgMV |
655 |
|
const int reduced_resolution, // [input] ignored |
656 |
|
const int32_t rounding, // [input] for rounding image data |
657 |
|
MACROBLOCK *const pMBs, // [output] average motion vectors |
658 |
|
IMAGE *const pGMC) // [output] full warped image |
659 |
|
{ |
660 |
|
|
661 |
transfer_8to16sub2_c( |
unsigned int mj,mi; |
662 |
&dct_codes[3*64], |
VECTOR avgMV; |
|
cur->y + (i*16+8) + (j*16+8)*edged_width, |
|
|
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
|
|
16*i + 8, 16*j + 8, 1, dx, dy, edged_width), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
|
|
16*i + 8, 16*j + 8, 1, b_dx, b_dy, edged_width), |
|
|
edged_width); |
|
663 |
|
|
664 |
|
for (mj=0;mj<mb_height;mj++) |
665 |
|
for (mi=0;mi<mb_width; mi++) |
666 |
|
{ |
667 |
|
avgMV = generate_GMCimageMB(gmc_data, pRef, mi, mj, |
668 |
|
stride, stride2, quarterpel, rounding, pGMC); |
669 |
|
|
670 |
dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2; |
pMBs[mj*mb_width+mi].amv.x = gmc_sanitize(avgMV.x, quarterpel, fcode); |
671 |
dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2; |
pMBs[mj*mb_width+mi].amv.y = gmc_sanitize(avgMV.y, quarterpel, fcode); |
672 |
|
pMBs[mj*mb_width+mi].mcsel = 0; /* until mode decision */ |
673 |
|
} |
674 |
|
} |
675 |
|
|
|
b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2; |
|
|
b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2; |
|
676 |
|
|
677 |
transfer_8to16sub2_c( |
VECTOR generate_GMCimageMB( const GMC_DATA *const gmc_data, /* [input] all precalc data */ |
678 |
&dct_codes[4*64], |
const IMAGE *const pRef, /* [input] */ |
679 |
cur->u + (y*8)*edged_width/2 + (x*8), |
const int mi, const int mj, /* [input] MB position */ |
680 |
get_ref(f_ref->u, f_refh->u, f_refv->u, f_refhv->u, |
const int stride, /* [input] Lumi stride */ |
681 |
8*i, 8*j, 1, dx, dy, edged_width/2), |
const int stride2, /* [input] chroma stride */ |
682 |
get_ref(b_ref->u, b_refh->u, b_refv->u, b_refhv->u, |
const int quarterpel, /* [input] for rounding of avgMV */ |
683 |
8*i, 8*j, 1, b_dx, b_dy, edged_width/2), |
const int rounding, /* [input] for rounding of imgae data */ |
684 |
edged_width/2); |
IMAGE *const pGMC) /* [outut] generate image */ |
685 |
|
|
686 |
|
/* |
687 |
|
type | variable name | ISO name (TeX-style) | value or range | usage |
688 |
|
------------------------------------------------------------------------------------- |
689 |
|
p | F | F(i,j) | | pelwise motion vector X in s-th pel |
690 |
|
p | G | G(i,j) | | pelwise motion vector Y in s-th pel |
691 |
|
p | Fc | F_c(i,j) | | |
692 |
|
p | Gc | G_c(i,j) | | same for chroma |
693 |
|
|
694 |
|
p | Y00 | Y_{00} | [0,255*s*s] | first: 4 neighbouring Y-values |
695 |
|
p | Y01 | Y_{01} | [0,255] | at fullpel position, around the |
696 |
|
p | Y10 | Y_{10} | [0,255*s] | position where pelweise MV points to |
697 |
|
p | Y11 | Y_{11} | [0,255] | later: bilinear interpol Y-values in Y00 |
698 |
|
|
699 |
|
p | C00 | C_{00} | [0,255*s*s] | same for chroma Cb and Cr |
700 |
|
p | C01 | C_{01} | [0,255] | |
701 |
|
p | C10 | C_{10} | [0,255*s] | |
702 |
|
p | C11 | C_{11} | [0,255] | |
703 |
|
|
704 |
transfer_8to16sub2_c( |
*/ |
705 |
&dct_codes[5*64], |
{ |
706 |
cur->v + (y*8)*edged_width/2 + (x*8), |
const int W = gmc_data->W; |
707 |
get_ref(f_ref->v, f_refh->v, f_refv->v, f_refhv->v, |
const int H = gmc_data->H; |
|
8*i, 8*j, 1, dx, dy, edged_width/2), |
|
|
get_ref(b_ref->v, b_refh->v, b_refv->v, b_refhv->v, |
|
|
8*i, 8*j, 1, b_dx, b_dy, edged_width/2), |
|
|
edged_width/2); |
|
708 |
|
|
709 |
break; |
const int s = gmc_data->s; |
710 |
|
const int sigma = gmc_data->sigma; |
711 |
|
|
712 |
case MODE_DIRECT : |
const int r = gmc_data->r; |
713 |
// todo |
const int rho = gmc_data->rho; |
714 |
break; |
|
715 |
|
const int i0s = gmc_data->i0s; |
716 |
|
const int j0s = gmc_data->j0s; |
717 |
|
|
718 |
|
const int i1ss = gmc_data->i1ss; |
719 |
|
const int j1ss = gmc_data->j1ss; |
720 |
|
// const int i2ss = gmc_data->i2ss; |
721 |
|
// const int j2ss = gmc_data->j2ss; |
722 |
|
|
723 |
|
const int alpha = gmc_data->alpha; |
724 |
|
const int Ws = gmc_data->Ws; |
725 |
|
|
726 |
|
// const int beta = gmc_data->beta; |
727 |
|
// const int Hs = gmc_data->Hs; |
728 |
|
|
729 |
|
int I,J; |
730 |
|
VECTOR avgMV = {0,0}; |
731 |
|
|
732 |
|
for (J=16*mj;J<16*(mj+1);J++) |
733 |
|
for (I=16*mi;I<16*(mi+1);I++) |
734 |
|
{ |
735 |
|
int F= i0s + ( ((-r*i0s+i1ss)*I + (r*j0s-j1ss)*J + (1<<(alpha+rho-1))) >> (alpha+rho) ); |
736 |
|
int G= j0s + ( ((-r*j0s+j1ss)*I + (-r*i0s+i1ss)*J + (1<<(alpha+rho-1))) >> (alpha+rho) ); |
737 |
|
|
738 |
|
/* this naive implementation (with lots of multiplications) isn't slower (rather faster) than |
739 |
|
working incremental. Don't ask me why... maybe the whole this is memory bound? */ |
740 |
|
|
741 |
|
const int ri= F & (s-1); // fractional part of pelwise MV X |
742 |
|
const int rj= G & (s-1); // fractional part of pelwise MV Y |
743 |
|
|
744 |
|
int Y00,Y01,Y10,Y11; |
745 |
|
|
746 |
|
/* unclipped values are used for avgMV */ |
747 |
|
avgMV.x += F-(I<<sigma); /* shift position to 1/s-pel, as the MV is */ |
748 |
|
avgMV.y += G-(J<<sigma); /* TODO: don't do this (of course) */ |
749 |
|
|
750 |
|
F >>= sigma; |
751 |
|
G >>= sigma; |
752 |
|
|
753 |
|
/* clip values to be in range. Since we have edges, clip to 1 less than lower boundary |
754 |
|
this way positions F+1/G+1 are still right */ |
755 |
|
|
756 |
|
if (F< -1) |
757 |
|
F=-1; |
758 |
|
else if (F>W) |
759 |
|
F=W; /* W or W-1 doesn't matter, so save 1 subtract ;-) */ |
760 |
|
if (G< -1) |
761 |
|
G=-1; |
762 |
|
else if (G>H) |
763 |
|
G=H; /* dito */ |
764 |
|
|
765 |
|
Y00 = pRef->y[ G*stride + F ]; // Lumi values |
766 |
|
Y01 = pRef->y[ G*stride + F+1 ]; |
767 |
|
Y10 = pRef->y[ G*stride + F+stride ]; |
768 |
|
Y11 = pRef->y[ G*stride + F+stride+1 ]; |
769 |
|
|
770 |
|
/* bilinear interpolation */ |
771 |
|
Y00 = ((s-ri)*Y00 + ri*Y01); |
772 |
|
Y10 = ((s-ri)*Y10 + ri*Y11); |
773 |
|
Y00 = ((s-rj)*Y00 + rj*Y10 + s*s/2 - rounding ) >> (sigma+sigma); |
774 |
|
|
775 |
|
pGMC->y[J*stride+I] = (uint8_t)Y00; /* output 1 Y-pixel */ |
776 |
} |
} |
777 |
|
|
778 |
|
|
779 |
|
/* doing chroma _here_ is even more stupid and slow, because won't be used until Compensation and |
780 |
|
most likely not even then (only if the block really _is_ GMC) |
781 |
|
*/ |
782 |
|
|
783 |
|
for (J=8*mj;J<8*(mj+1);J++) /* this plays the role of j_c,i_c in the standard */ |
784 |
|
for (I=8*mi;I<8*(mi+1);I++) /* For I_c we have to use I_c = 4*i_c+1 ! */ |
785 |
|
{ |
786 |
|
/* same positions for both chroma components, U=Cb and V=Cr */ |
787 |
|
int Fc=((-r*i0s+i1ss)*(4*I+1) + (r*j0s-j1ss)*(4*J+1) +2*Ws*r*i0s |
788 |
|
-16*Ws +(1<<(alpha+rho+1)))>>(alpha+rho+2); |
789 |
|
int Gc=((-r*j0s+j1ss)*(4*I+1) +(-r*i0s+i1ss)*(4*J+1) +2*Ws*r*j0s |
790 |
|
-16*Ws +(1<<(alpha+rho+1))) >>(alpha+rho+2); |
791 |
|
|
792 |
|
const int ri= Fc & (s-1); // fractional part of pelwise MV X |
793 |
|
const int rj= Gc & (s-1); // fractional part of pelwise MV Y |
794 |
|
|
795 |
|
int C00,C01,C10,C11; |
796 |
|
|
797 |
|
Fc >>= sigma; |
798 |
|
Gc >>= sigma; |
799 |
|
|
800 |
|
if (Fc< -1) |
801 |
|
Fc=-1; |
802 |
|
else if (Fc>=W/2) |
803 |
|
Fc=W/2; /* W or W-1 doesn't matter, so save 1 subtraction ;-) */ |
804 |
|
if (Gc< -1) |
805 |
|
Gc=-1; |
806 |
|
else if (Gc>=H/2) |
807 |
|
Gc=H/2; /* dito */ |
808 |
|
|
809 |
|
/* now calculate U data */ |
810 |
|
C00 = pRef->u[ Gc*stride2 + Fc ]; // chroma-value Cb |
811 |
|
C01 = pRef->u[ Gc*stride2 + Fc+1 ]; |
812 |
|
C10 = pRef->u[ (Gc+1)*stride2 + Fc ]; |
813 |
|
C11 = pRef->u[ (Gc+1)*stride2 + Fc+1 ]; |
814 |
|
|
815 |
|
/* bilinear interpolation */ |
816 |
|
C00 = ((s-ri)*C00 + ri*C01); |
817 |
|
C10 = ((s-ri)*C10 + ri*C11); |
818 |
|
C00 = ((s-rj)*C00 + rj*C10 + s*s/2 - rounding ) >> (sigma+sigma); |
819 |
|
|
820 |
|
pGMC->u[J*stride2+I] = (uint8_t)C00; /* output 1 U-pixel */ |
821 |
|
|
822 |
|
/* now calculate V data */ |
823 |
|
C00 = pRef->v[ Gc*stride2 + Fc ]; // chroma-value Cr |
824 |
|
C01 = pRef->v[ Gc*stride2 + Fc+1 ]; |
825 |
|
C10 = pRef->v[ (Gc+1)*stride2 + Fc ]; |
826 |
|
C11 = pRef->v[ (Gc+1)*stride2 + Fc+1 ]; |
827 |
|
|
828 |
|
/* bilinear interpolation */ |
829 |
|
C00 = ((s-ri)*C00 + ri*C01); |
830 |
|
C10 = ((s-ri)*C10 + ri*C11); |
831 |
|
C00 = ((s-rj)*C00 + rj*C10 + s*s/2 - rounding ) >> (sigma+sigma); |
832 |
|
|
833 |
|
pGMC->v[J*stride2+I] = (uint8_t)C00; /* output 1 V-pixel */ |
834 |
} |
} |
835 |
|
|
836 |
|
|
837 |
|
|
838 |
|
/* The average vector is rounded from 1/s-pel to 1/2 or 1/4 */ |
839 |
|
if (quarterpel) |
840 |
|
{ /* >>8 because of 256 terms in sum, >>(sigma-2) to obtain 1/4th-pel */ |
841 |
|
avgMV.x = ( (avgMV.x + (1<<(sigma+5)) )>>(sigma+6) ); |
842 |
|
avgMV.y = ( (avgMV.y + (1<<(sigma+5)) )>>(sigma+6) ); |
843 |
|
} |
844 |
|
else |
845 |
|
{ /* >>8 because of 256 terms in sum, >>(sigma-1) to obtain 1/2th-pel */ |
846 |
|
avgMV.x = ( (avgMV.x + (1<<(sigma+6)))>>(sigma+7) ); |
847 |
|
avgMV.y = ( (avgMV.y + (1<<(sigma+6)))>>(sigma+7) ); |
848 |
|
} /* TODO: Check if this is correct way of rounding */ |
849 |
|
|
850 |
|
return avgMV; /* clipping to fcode area is done outside! */ |
851 |
|
} |
852 |
|
|