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" |
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 |
|
#ifndef RSHIFT |
23 |
|
#define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) |
24 |
|
#endif |
25 |
|
|
26 |
|
/* assume b>0 */ |
27 |
|
#ifndef RDIV |
28 |
|
#define RDIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
29 |
|
#endif |
30 |
|
|
31 |
|
|
32 |
|
/* This is borrowed from decoder.c */ |
33 |
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
34 |
|
{ |
35 |
|
int length = 1 << (fcode+4); |
36 |
|
|
37 |
|
// if (quarterpel) value *= 2; |
38 |
|
|
39 |
|
if (value < -length) |
40 |
|
return -length; |
41 |
|
else if (value >= length) |
42 |
|
return length-1; |
43 |
|
else return value; |
44 |
|
} |
45 |
|
|
46 |
|
/* And this is borrowed from bitstream.c until we find a common solution */ |
47 |
|
|
48 |
|
static uint32_t __inline |
49 |
|
log2bin(uint32_t value) |
50 |
|
{ |
51 |
|
/* Changed by Chenm001 */ |
52 |
|
#if !defined(_MSC_VER) |
53 |
|
int n = 0; |
54 |
|
|
55 |
|
while (value) { |
56 |
|
value >>= 1; |
57 |
|
n++; |
58 |
|
} |
59 |
|
return n; |
60 |
|
#else |
61 |
|
__asm { |
62 |
|
bsr eax, value |
63 |
|
inc eax |
64 |
|
} |
65 |
|
#endif |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
static __inline void |
static __inline void |
71 |
uint8_t * const cur, |
uint8_t * const cur, |
72 |
const uint8_t * const ref, |
const uint8_t * const ref, |
73 |
const uint8_t * const refh, |
const uint8_t * const refh, |
74 |
uint8_t * const refv, |
const uint8_t * const refv, |
75 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
76 |
|
uint8_t * const tmp, |
77 |
uint32_t x, |
uint32_t x, |
78 |
uint32_t y, |
uint32_t y, |
79 |
const int32_t dx, |
const int32_t dx, |
80 |
const int32_t dy, |
const int32_t dy, |
81 |
const uint32_t stride, |
const int32_t stride, |
82 |
const uint32_t quarterpel, |
const int quarterpel, |
83 |
const int reduced_resolution, |
const int reduced_resolution, |
84 |
const uint32_t rounding) |
const int32_t rounding) |
85 |
{ |
{ |
86 |
|
const uint8_t * ptr; |
87 |
|
|
88 |
|
if (!reduced_resolution) { |
89 |
|
|
90 |
|
if(quarterpel) { |
91 |
|
if ((dx&3) | (dy&3)) { |
92 |
|
interpolate16x16_quarterpel(tmp - y * stride - x, |
93 |
|
(uint8_t *) ref, tmp + 32, |
94 |
|
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
95 |
|
ptr = tmp; |
96 |
|
} else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position |
97 |
|
|
98 |
|
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
99 |
|
|
100 |
|
transfer_8to16sub(dct_codes, cur + y * stride + x, |
101 |
|
ptr, stride); |
102 |
|
transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
103 |
|
ptr + 8, stride); |
104 |
|
transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
105 |
|
ptr + 8*stride, stride); |
106 |
|
transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
107 |
|
ptr + 8*stride + 8, stride); |
108 |
|
|
109 |
|
} else { //reduced_resolution |
110 |
|
|
|
if (reduced_resolution) |
|
|
{ |
|
|
const uint8_t * reference; |
|
111 |
x*=2; y*=2; |
x*=2; y*=2; |
112 |
|
|
113 |
reference = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
114 |
|
|
115 |
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
116 |
filter_diff_18x18_to_8x8(dct_codes, reference, stride); |
filter_diff_18x18_to_8x8(dct_codes, ptr, stride); |
117 |
|
|
118 |
filter_18x18_to_8x8(dct_codes+64, cur+y*stride + x + 16, stride); |
filter_18x18_to_8x8(dct_codes+64, cur+y*stride + x + 16, stride); |
119 |
filter_diff_18x18_to_8x8(dct_codes+64, reference + 16, stride); |
filter_diff_18x18_to_8x8(dct_codes+64, ptr + 16, stride); |
120 |
|
|
121 |
filter_18x18_to_8x8(dct_codes+128, cur+(y+16)*stride + x, stride); |
filter_18x18_to_8x8(dct_codes+128, cur+(y+16)*stride + x, stride); |
122 |
filter_diff_18x18_to_8x8(dct_codes+128, reference + 16*stride, stride); |
filter_diff_18x18_to_8x8(dct_codes+128, ptr + 16*stride, stride); |
123 |
|
|
124 |
filter_18x18_to_8x8(dct_codes+192, cur+(y+16)*stride + x + 16, stride); |
filter_18x18_to_8x8(dct_codes+192, cur+(y+16)*stride + x + 16, stride); |
125 |
filter_diff_18x18_to_8x8(dct_codes+192, reference + 16*stride + 16, stride); |
filter_diff_18x18_to_8x8(dct_codes+192, ptr + 16*stride + 16, stride); |
|
|
|
|
transfer32x32_copy(cur + y*stride + x, reference, stride); |
|
|
|
|
|
}else{ |
|
|
if(quarterpel) { |
|
|
interpolate16x16_quarterpel((uint8_t *) refv, (uint8_t *) ref, (uint8_t *) refh, |
|
|
(uint8_t *) refh + 64, (uint8_t *) refhv, x, y, dx, dy, stride, rounding); |
|
|
|
|
|
transfer_8to16sub(dct_codes, cur + y*stride + x, |
|
|
refv + y*stride + x, stride); |
|
|
transfer_8to16sub(dct_codes+64, cur + y*stride + x + 8, |
|
|
refv + y*stride + x + 8, stride); |
|
|
transfer_8to16sub(dct_codes+128, cur + y*stride + x + 8*stride, |
|
|
refv + y*stride + x + 8*stride, stride); |
|
|
transfer_8to16sub(dct_codes+192, cur + y*stride + x + 8*stride + 8, |
|
|
refv + y*stride + x + 8*stride+8, stride); |
|
|
|
|
|
} |
|
|
else |
|
|
{ |
|
|
const uint8_t * reference = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
|
126 |
|
|
127 |
transfer_8to16sub(dct_codes, cur + y * stride + x, |
transfer32x32_copy(cur + y*stride + x, ptr, stride); |
|
reference, stride); |
|
|
transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
|
|
reference + 8, stride); |
|
|
transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
|
|
reference + 8*stride, stride); |
|
|
transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
|
|
reference + 8*stride + 8, stride); |
|
|
} |
|
128 |
} |
} |
129 |
} |
} |
130 |
|
|
135 |
const uint8_t * const refh, |
const uint8_t * const refh, |
136 |
const uint8_t * const refv, |
const uint8_t * const refv, |
137 |
const uint8_t * const refhv, |
const uint8_t * const refhv, |
138 |
|
uint8_t * const tmp, |
139 |
uint32_t x, |
uint32_t x, |
140 |
uint32_t y, |
uint32_t y, |
141 |
const int32_t dx, |
const int32_t dx, |
142 |
const int32_t dy, |
const int32_t dy, |
143 |
const uint32_t stride, |
const int32_t stride, |
144 |
const uint32_t quarterpel, |
const int32_t quarterpel, |
145 |
const int reduced_resolution, |
const int reduced_resolution, |
146 |
const uint32_t rounding) |
const int32_t rounding) |
|
{ |
|
|
if (reduced_resolution) |
|
147 |
{ |
{ |
148 |
const uint8_t * reference; |
const uint8_t * ptr; |
|
x*=2; y*=2; |
|
149 |
|
|
150 |
reference = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
if (!reduced_resolution) { |
151 |
|
|
152 |
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
if(quarterpel) { |
153 |
filter_diff_18x18_to_8x8(dct_codes, reference, stride); |
if ((dx&3) | (dy&3)) { |
154 |
|
interpolate8x8_quarterpel(tmp - y*stride - x, |
155 |
|
(uint8_t *) ref, tmp + 32, |
156 |
|
tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); |
157 |
|
ptr = tmp; |
158 |
|
} else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position |
159 |
|
} else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
160 |
|
|
161 |
transfer16x16_copy(cur + y*stride + x, reference, stride); |
transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride); |
162 |
|
|
163 |
} else { |
} else { //reduced_resolution |
164 |
|
|
165 |
if(quarterpel) { |
x *= 2; y *= 2; |
|
interpolate8x8_quarterpel((uint8_t *) refv, (uint8_t *) ref, (uint8_t *) refh, |
|
|
(uint8_t *) refh + 64, (uint8_t *) refhv, x, y, dx, dy, stride, rounding); |
|
166 |
|
|
167 |
transfer_8to16sub(dct_codes, cur + y*stride + x, |
ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
|
refv + y*stride + x, stride); |
|
|
} |
|
|
else |
|
|
{ |
|
|
const uint8_t * reference = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
|
168 |
|
|
169 |
transfer_8to16sub(dct_codes, cur + y * stride + x, |
filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
170 |
reference, stride); |
filter_diff_18x18_to_8x8(dct_codes, ptr, stride); |
171 |
} |
|
172 |
|
transfer16x16_copy(cur + y*stride + x, ptr, stride); |
173 |
} |
} |
174 |
} |
} |
175 |
|
|
|
|
|
|
|
|
176 |
/* XXX: slow, inelegant... */ |
/* XXX: slow, inelegant... */ |
177 |
static void |
static void |
178 |
interpolate18x18_switch(uint8_t * const cur, |
interpolate18x18_switch(uint8_t * const cur, |
181 |
const uint32_t y, |
const uint32_t y, |
182 |
const int32_t dx, |
const int32_t dx, |
183 |
const int dy, |
const int dy, |
184 |
const uint32_t stride, |
const int32_t stride, |
185 |
const uint32_t rounding) |
const int32_t rounding) |
186 |
{ |
{ |
187 |
interpolate8x8_switch(cur, refn, x-1, y-1, dx, dy, stride, rounding); |
interpolate8x8_switch(cur, refn, x-1, y-1, dx, dy, stride, rounding); |
188 |
interpolate8x8_switch(cur, refn, x+7, y-1, dx, dy, stride, rounding); |
interpolate8x8_switch(cur, refn, x+7, y-1, dx, dy, stride, rounding); |
197 |
interpolate8x8_switch(cur, refn, x+9, y+9, dx, dy, stride, rounding); |
interpolate8x8_switch(cur, refn, x+9, y+9, dx, dy, stride, rounding); |
198 |
} |
} |
199 |
|
|
200 |
|
static void |
201 |
|
CompensateChroma( int dx, int dy, |
202 |
|
const int i, const int j, |
203 |
|
IMAGE * const Cur, |
204 |
|
const IMAGE * const Ref, |
205 |
|
uint8_t * const temp, |
206 |
|
int16_t * const coeff, |
207 |
|
const int32_t stride, |
208 |
|
const int rounding, |
209 |
|
const int rrv) |
210 |
|
{ /* uv-block-based compensation */ |
211 |
|
|
212 |
|
if (!rrv) { |
213 |
|
transfer_8to16sub(coeff, Cur->u + 8 * j * stride + 8 * i, |
214 |
|
interpolate8x8_switch2(temp, Ref->u, 8 * i, 8 * j, |
215 |
|
dx, dy, stride, rounding), |
216 |
|
stride); |
217 |
|
transfer_8to16sub(coeff + 64, Cur->v + 8 * j * stride + 8 * i, |
218 |
|
interpolate8x8_switch2(temp, Ref->v, 8 * i, 8 * j, |
219 |
|
dx, dy, stride, rounding), |
220 |
|
stride); |
221 |
|
} else { |
222 |
|
uint8_t * current, * reference; |
223 |
|
|
224 |
|
current = Cur->u + 16*j*stride + 16*i; |
225 |
|
reference = temp - 16*j*stride - 16*i; |
226 |
|
interpolate18x18_switch(reference, Ref->u, 16*i, 16*j, dx, dy, stride, rounding); |
227 |
|
filter_18x18_to_8x8(coeff, current, stride); |
228 |
|
filter_diff_18x18_to_8x8(coeff, temp, stride); |
229 |
|
transfer16x16_copy(current, temp, stride); |
230 |
|
|
231 |
|
current = Cur->v + 16*j*stride + 16*i; |
232 |
|
interpolate18x18_switch(reference, Ref->v, 16*i, 16*j, dx, dy, stride, rounding); |
233 |
|
filter_18x18_to_8x8(coeff + 64, current, stride); |
234 |
|
filter_diff_18x18_to_8x8(coeff + 64, temp, stride); |
235 |
|
transfer16x16_copy(current, temp, stride); |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
void |
void |
240 |
MBMotionCompensation(MACROBLOCK * const mb, |
MBMotionCompensation(MACROBLOCK * const mb, |
244 |
const IMAGE * const refh, |
const IMAGE * const refh, |
245 |
const IMAGE * const refv, |
const IMAGE * const refv, |
246 |
const IMAGE * const refhv, |
const IMAGE * const refhv, |
247 |
|
const IMAGE * const refGMC, |
248 |
IMAGE * const cur, |
IMAGE * const cur, |
249 |
int16_t * dct_codes, |
int16_t * dct_codes, |
250 |
const uint32_t width, |
const uint32_t width, |
251 |
const uint32_t height, |
const uint32_t height, |
252 |
const uint32_t edged_width, |
const uint32_t edged_width, |
253 |
const uint32_t quarterpel, |
const int32_t quarterpel, |
254 |
const int reduced_resolution, |
const int reduced_resolution, |
255 |
const uint32_t rounding) |
const int32_t rounding) |
256 |
{ |
{ |
257 |
|
int32_t dx; |
258 |
|
int32_t dy; |
259 |
|
|
|
if (mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
|
260 |
|
|
261 |
int32_t dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x); |
uint8_t * const tmp = refv->u; |
|
int32_t dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y); |
|
262 |
|
|
263 |
if ( (!reduced_resolution) && (mb->mode == MODE_NOT_CODED) && (dx==0) && (dy==0) ) { /* quick copy */ |
if ( (!reduced_resolution) && (mb->mode == MODE_NOT_CODED) ) { /* quick copy for early SKIP */ |
264 |
|
/* early SKIP is only activated in P-VOPs, not in S-VOPs, so mcsel can never be 1 */ |
265 |
|
|
266 |
|
/* if (mb->mcsel) { |
267 |
|
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
268 |
|
refGMC->y + 16 * (i + j * edged_width), |
269 |
|
edged_width); |
270 |
|
transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
271 |
|
refGMC->u + 8 * (i + j * edged_width/2), |
272 |
|
edged_width / 2); |
273 |
|
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
274 |
|
refGMC->v + 8 * (i + j * edged_width/2), |
275 |
|
edged_width / 2); |
276 |
|
} else |
277 |
|
*/ |
278 |
|
{ |
279 |
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
280 |
ref->y + 16 * (i + j * edged_width), |
ref->y + 16 * (i + j * edged_width), |
281 |
edged_width); |
edged_width); |
286 |
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), |
287 |
ref->v + 8 * (i + j * edged_width/2), |
ref->v + 8 * (i + j * edged_width/2), |
288 |
edged_width / 2); |
edged_width / 2); |
289 |
|
} |
290 |
return; |
return; |
291 |
} |
} |
|
/* quick MODE_NOT_CODED for GMC with MV!=(0,0) is still needed */ |
|
292 |
|
|
293 |
if (reduced_resolution) |
if ((mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER |
294 |
{ |
|| mb->mode == MODE_INTER_Q) /*&& !quarterpel*/) { |
|
dx = RRV_MV_SCALEUP(dx); |
|
|
dy = RRV_MV_SCALEUP(dy); |
|
|
} |
|
295 |
|
|
296 |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
/* reduced resolution + GMC: not possible */ |
|
refv->y, refhv->y, 16 * i, 16 * j, dx, dy, |
|
|
edged_width, quarterpel, reduced_resolution, rounding); |
|
297 |
|
|
298 |
if (quarterpel) |
if (mb->mcsel) { |
|
{ |
|
|
dx /= 2; |
|
|
dy /= 2; |
|
|
} |
|
299 |
|
|
300 |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
/* call normal routine once, easier than "if (mcsel)"ing all the time */ |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
|
301 |
|
|
302 |
/* uv-block-based compensation |
transfer_8to16sub(&dct_codes[0*64], cur->y + 16*j*edged_width + 16*i, |
303 |
XXX: rrv doesnt work with 16x16 block-based intepolation. |
refGMC->y + 16*j*edged_width + 16*i, edged_width); |
304 |
we need to use 18x18-block interpolation */ |
transfer_8to16sub(&dct_codes[1*64], cur->y + 16*j*edged_width + 16*i+8, |
305 |
if (reduced_resolution) |
refGMC->y + 16*j*edged_width + 16*i+8, edged_width); |
306 |
{ |
transfer_8to16sub(&dct_codes[2*64], cur->y + (16*j+8)*edged_width + 16*i, |
307 |
const stride = edged_width/2; |
refGMC->y + (16*j+8)*edged_width + 16*i, edged_width); |
308 |
uint8_t * current, * reference; |
transfer_8to16sub(&dct_codes[3*64], cur->y + (16*j+8)*edged_width + 16*i+8, |
309 |
|
refGMC->y + (16*j+8)*edged_width + 16*i+8, edged_width); |
310 |
|
|
311 |
current = cur->u + 16*j*stride + 16*i; |
/* lumi is needed earlier for mode decision, but chroma should be done block-based, but it isn't, yet. */ |
|
reference = refv->u + 16*j*stride + 16*i; |
|
|
//interpolate16x16_switch(refv->u, ref->u, 16*i, 16*j, dx, dy, stride, rounding); |
|
|
interpolate18x18_switch(refv->u, ref->u, 16*i, 16*j, dx, dy, stride, rounding); |
|
|
filter_18x18_to_8x8(dct_codes + 4*64, current, stride); |
|
|
filter_diff_18x18_to_8x8(dct_codes + 4*64, reference, stride); |
|
|
transfer16x16_copy(current, reference, stride); |
|
|
|
|
|
current = cur->v + 16*j*stride + 16*i; |
|
|
reference = refv->v + 16*j*stride + 16*i; |
|
|
//interpolate16x16_switch(refv->v, ref->v, 16*i, 16*j, dx, dy, stride, rounding); |
|
|
interpolate18x18_switch(refv->v, ref->v, 16*i, 16*j, dx, dy, stride, rounding); |
|
|
filter_18x18_to_8x8(dct_codes + 5*64, current, stride); |
|
|
filter_diff_18x18_to_8x8(dct_codes + 5*64, reference, stride); |
|
|
transfer16x16_copy(current, reference, stride); |
|
|
}else{ |
|
|
transfer_8to16sub(&dct_codes[4 * 64], |
|
|
cur->u + 8 * j * edged_width / 2 + 8 * i, |
|
|
interpolate8x8_switch2(refv->u, ref->u, 8 * i, 8 * j, |
|
|
dx, dy, edged_width / 2, rounding), |
|
|
edged_width / 2); |
|
312 |
|
|
313 |
transfer_8to16sub(&dct_codes[5 * 64], |
transfer_8to16sub(&dct_codes[4 * 64], cur->u + 8 *j*edged_width/2 + 8*i, |
314 |
cur->v + 8 * j * edged_width / 2 + 8 * i, |
refGMC->u + 8 *j*edged_width/2 + 8*i, edged_width/2); |
|
interpolate8x8_switch2(refv->u, ref->v, 8 * i, 8 * j, |
|
|
dx, dy, edged_width / 2, rounding), |
|
|
edged_width / 2); |
|
|
} |
|
315 |
|
|
316 |
} else { // mode == MODE_INTER4V |
transfer_8to16sub(&dct_codes[5 * 64], cur->v + 8*j* edged_width/2 + 8*i, |
317 |
int i; |
refGMC->v + 8*j* edged_width/2 + 8*i, edged_width/2); |
|
int32_t sum, dx, dy; |
|
|
VECTOR mvs[4]; |
|
318 |
|
|
319 |
if(quarterpel) |
return; |
|
for (i = 0; i < 4; i++) mvs[i] = mb->qmvs[i]; |
|
|
else |
|
|
for (i = 0; i < 4; i++) mvs[i] = mb->mvs[i]; |
|
|
|
|
|
if (reduced_resolution) |
|
|
{ |
|
|
for (i = 0; i < 4; i++) |
|
|
{ |
|
|
mvs[i].x = RRV_MV_SCALEUP(mvs[i].x); |
|
|
mvs[i].y = RRV_MV_SCALEUP(mvs[i].y); |
|
|
} |
|
320 |
} |
} |
321 |
|
|
322 |
compensate8x8_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
/* ordinary compensation */ |
|
refv->y, refhv->y, 16 * i, 16 * j, mvs[0].x, |
|
|
mvs[0].y, edged_width, quarterpel, reduced_resolution, rounding); |
|
|
compensate8x8_interpolate(&dct_codes[1 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i + 8, 16 * j, |
|
|
mvs[1].x, mvs[1].y, edged_width, quarterpel, reduced_resolution, rounding); |
|
|
compensate8x8_interpolate(&dct_codes[2 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i, 16 * j + 8, |
|
|
mvs[2].x, mvs[2].y, edged_width, quarterpel, reduced_resolution, rounding); |
|
|
compensate8x8_interpolate(&dct_codes[3 * 64], cur->y, ref->y, refh->y, |
|
|
refv->y, refhv->y, 16 * i + 8, 16 * j + 8, |
|
|
mvs[3].x, mvs[3].y, edged_width, quarterpel, reduced_resolution, rounding); |
|
323 |
|
|
324 |
if(quarterpel) |
dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x); |
325 |
sum = (mvs[0].x / 2) + (mvs[1].x / 2) + (mvs[2].x / 2) + (mvs[3].x / 2); |
dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y); |
|
else |
|
|
sum = mvs[0].x + mvs[1].x + mvs[2].x + mvs[3].x; |
|
326 |
|
|
327 |
dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
if (reduced_resolution) { |
328 |
|
dx = RRV_MV_SCALEUP(dx); |
329 |
|
dy = RRV_MV_SCALEUP(dy); |
330 |
|
} |
331 |
|
|
332 |
if(quarterpel) |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, |
333 |
sum = (mvs[0].y / 2) + (mvs[1].y / 2) + (mvs[2].y / 2) + (mvs[3].y / 2); |
refv->y, refhv->y, tmp, 16 * i, 16 * j, dx, dy, |
334 |
else |
edged_width, quarterpel, reduced_resolution, rounding); |
|
sum = mvs[0].y + mvs[1].y + mvs[2].y + mvs[3].y; |
|
335 |
|
|
336 |
dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
dx /= (int)(1 + quarterpel); |
337 |
|
dy /= (int)(1 + quarterpel); |
338 |
|
|
339 |
|
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
340 |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
341 |
|
|
342 |
/* uv-block-based compensation |
} else { // mode == MODE_INTER4V |
343 |
XXX: rrv doesnt work with 16x16 block-based intepolation. |
int k, sumx = 0, sumy = 0; |
344 |
we need to use 18x18-block interpolation */ |
const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs); |
|
if (reduced_resolution) |
|
|
{ |
|
|
const stride = edged_width/2; |
|
|
uint8_t * current, * reference; |
|
345 |
|
|
346 |
current = cur->u + 16*j*stride + 16*i; |
for (k = 0; k < 4; k++) { |
347 |
reference = refv->u + 16*j*stride + 16*i; |
dx = mvs[k].x; |
348 |
interpolate16x16_switch(refv->u, ref->u, 16*i, 16*j, dx, dy, stride, rounding); |
dy = mvs[k].y; |
349 |
filter_18x18_to_8x8(dct_codes + 4*64, current, stride); |
sumx += dx / (1 + quarterpel); |
350 |
filter_diff_18x18_to_8x8(dct_codes + 4*64, reference, stride); |
sumy += dy / (1 + quarterpel); |
|
transfer16x16_copy(current, reference, stride); |
|
|
|
|
|
current = cur->v + 16*j*stride + 16*i; |
|
|
reference = refv->v + 16*j*stride + 16*i; |
|
|
interpolate16x16_switch(refv->v, ref->v, 16*i, 16*j, dx, dy, stride, rounding); |
|
|
filter_18x18_to_8x8(dct_codes + 5*64, current, stride); |
|
|
filter_diff_18x18_to_8x8(dct_codes + 5*64, reference, stride); |
|
|
transfer16x16_copy(current, reference, stride); |
|
351 |
|
|
352 |
}else{ |
if (reduced_resolution){ |
353 |
transfer_8to16sub(&dct_codes[4 * 64], |
dx = RRV_MV_SCALEUP(dx); |
354 |
cur->u + 8 * j * edged_width / 2 + 8 * i, |
dy = RRV_MV_SCALEUP(dy); |
355 |
interpolate8x8_switch2(refv->u, ref->u, 8 * i, 8 * j, |
} |
|
dx, dy, edged_width / 2, rounding), |
|
|
edged_width / 2); |
|
356 |
|
|
357 |
transfer_8to16sub(&dct_codes[5 * 64], |
compensate8x8_interpolate(&dct_codes[k * 64], cur->y, ref->y, refh->y, |
358 |
cur->v + 8 * j * edged_width / 2 + 8 * i, |
refv->y, refhv->y, tmp, 16 * i + 8*(k&1), 16 * j + 8*(k>>1), dx, |
359 |
interpolate8x8_switch2(refv->u, ref->v, 8 * i, 8 * j, |
dy, edged_width, quarterpel, reduced_resolution, rounding); |
|
dx, dy, edged_width / 2, rounding), |
|
|
edged_width / 2); |
|
360 |
} |
} |
361 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
362 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
363 |
} |
} |
364 |
|
|
365 |
|
CompensateChroma(dx, dy, i, j, cur, ref, tmp, |
366 |
|
&dct_codes[4 * 64], edged_width / 2, rounding, reduced_resolution); |
367 |
} |
} |
368 |
|
|
369 |
|
|
383 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
384 |
int16_t * dct_codes) |
int16_t * dct_codes) |
385 |
{ |
{ |
386 |
static const uint32_t roundtab[16] = |
const uint32_t edged_width = pParam->edged_width; |
387 |
{ 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; |
388 |
|
int k; |
389 |
const int32_t edged_width = pParam->edged_width; |
const int quarterpel = pParam->m_quarterpel; |
390 |
int32_t dx, dy; |
const uint8_t * ptr1, * ptr2; |
391 |
int32_t b_dx, b_dy; |
uint8_t * const tmp = f_refv->u; |
392 |
int k,sum; |
const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs); |
393 |
int x = i; |
const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs); |
|
int y = j; |
|
|
uint32_t quarterpel = pParam->m_quarterpel; |
|
394 |
|
|
395 |
switch (mb->mode) { |
switch (mb->mode) { |
396 |
case MODE_FORWARD: |
case MODE_FORWARD: |
397 |
|
dx = fmvs->x; dy = fmvs->y; |
|
if (quarterpel) { |
|
|
dx = mb->qmvs[0].x; |
|
|
dy = mb->qmvs[0].y; |
|
|
} else { |
|
|
dx = mb->mvs[0].x; |
|
|
dy = mb->mvs[0].y; |
|
|
} |
|
398 |
|
|
399 |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, |
400 |
f_refv->y, f_refhv->y, 16 * i, 16 * j, dx, |
f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx, |
401 |
dy, edged_width, quarterpel, 0 /*reduced_resolution*/, 0); |
dy, edged_width, quarterpel, 0, 0); |
402 |
|
|
403 |
if (quarterpel) { |
dx /= 1 + quarterpel; |
404 |
dx /= 2; |
dy /= 1 + quarterpel; |
405 |
dy /= 2; |
CompensateChroma( (dx >> 1) + roundtab_79[dx & 0x3], |
406 |
} |
(dy >> 1) + roundtab_79[dy & 0x3], |
407 |
|
i, j, cur, f_ref, tmp, |
408 |
|
&dct_codes[4 * 64], edged_width / 2, 0, 0); |
409 |
|
|
410 |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
return; |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
|
411 |
|
|
412 |
/* uv-block-based compensation */ |
case MODE_BACKWARD: |
413 |
transfer_8to16sub(&dct_codes[4 * 64], |
b_dx = bmvs->x; b_dy = bmvs->y; |
|
cur->u + 8 * j * edged_width / 2 + 8 * i, |
|
|
interpolate8x8_switch2(f_refv->u, f_ref->u, 8 * i, 8 * j, |
|
|
dx, dy, edged_width / 2, 0), |
|
414 |
|
|
415 |
edged_width / 2); |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
416 |
|
b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx, |
417 |
|
b_dy, edged_width, quarterpel, 0, 0); |
418 |
|
|
419 |
transfer_8to16sub(&dct_codes[5 * 64], |
b_dx /= 1 + quarterpel; |
420 |
cur->v + 8 * j * edged_width / 2 + 8 * i, |
b_dy /= 1 + quarterpel; |
421 |
interpolate8x8_switch2(f_refv->u, f_ref->v, 8 * i, 8 * j, |
CompensateChroma( (b_dx >> 1) + roundtab_79[b_dx & 0x3], |
422 |
dx, dy, edged_width / 2, 0), |
(b_dy >> 1) + roundtab_79[b_dy & 0x3], |
423 |
|
i, j, cur, b_ref, tmp, |
424 |
|
&dct_codes[4 * 64], edged_width / 2, 0, 0); |
425 |
|
|
426 |
edged_width / 2); |
return; |
427 |
|
|
428 |
break; |
case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */ |
429 |
|
case MODE_DIRECT_NO4V: |
430 |
|
dx = fmvs->x; dy = fmvs->y; |
431 |
|
b_dx = bmvs->x; b_dy = bmvs->y; |
432 |
|
|
|
case MODE_BACKWARD: |
|
433 |
if (quarterpel) { |
if (quarterpel) { |
|
b_dx = mb->b_qmvs[0].x; |
|
|
b_dy = mb->b_qmvs[0].y; |
|
|
} else { |
|
|
b_dx = mb->b_mvs[0].x; |
|
|
b_dy = mb->b_mvs[0].y; |
|
|
} |
|
434 |
|
|
435 |
compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
if ((dx&3) | (dy&3)) { |
436 |
b_refv->y, b_refhv->y, 16 * i, 16 * j, b_dx, |
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width, |
437 |
b_dy, edged_width, quarterpel, 0 /*reduced_resolution*/, 0); |
(uint8_t *) f_ref->y, tmp + 32, |
438 |
|
tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0); |
439 |
|
ptr1 = tmp; |
440 |
|
} else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; // fullpixel position |
441 |
|
|
442 |
|
if ((b_dx&3) | (b_dy&3)) { |
443 |
|
interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16, |
444 |
|
(uint8_t *) b_ref->y, tmp + 32, |
445 |
|
tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0); |
446 |
|
ptr2 = tmp + 16; |
447 |
|
} else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; // fullpixel position |
448 |
|
|
|
if (quarterpel) { |
|
449 |
b_dx /= 2; |
b_dx /= 2; |
450 |
b_dy /= 2; |
b_dy /= 2; |
451 |
} |
dx /= 2; |
452 |
|
dy /= 2; |
|
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
|
|
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
|
453 |
|
|
454 |
|
} else { |
455 |
|
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
456 |
|
i, j, 16, dx, dy, edged_width); |
457 |
|
|
458 |
/* uv-block-based compensation */ |
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
459 |
transfer_8to16sub(&dct_codes[4 * 64], |
i, j, 16, b_dx, b_dy, edged_width); |
460 |
cur->u + 8 * j * edged_width / 2 + 8 * i, |
} |
461 |
interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j, |
for (k = 0; k < 4; k++) |
462 |
b_dx, b_dy, edged_width / 2, 0), |
transfer_8to16sub2(&dct_codes[k * 64], |
463 |
|
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
464 |
|
ptr1 + (k&1)*8 + (k>>1)*8*edged_width, |
465 |
|
ptr2 + (k&1)*8 + (k>>1)*8*edged_width, edged_width); |
466 |
|
|
|
edged_width / 2); |
|
467 |
|
|
468 |
transfer_8to16sub(&dct_codes[5 * 64], |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
469 |
cur->v + 8 * j * edged_width / 2 + 8 * i, |
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
|
interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j, |
|
|
b_dx, b_dy, edged_width / 2, 0), |
|
470 |
|
|
471 |
edged_width / 2); |
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
472 |
|
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
473 |
|
|
474 |
break; |
break; |
475 |
|
|
476 |
case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */ |
default: // MODE_DIRECT |
477 |
case MODE_DIRECT_NO4V: |
sumx = sumy = b_sumx = b_sumy = 0; |
478 |
|
|
479 |
|
for (k = 0; k < 4; k++) { |
480 |
|
|
481 |
|
dx = fmvs[k].x; dy = fmvs[k].y; |
482 |
|
b_dx = bmvs[k].x; b_dy = bmvs[k].y; |
483 |
|
|
484 |
if (quarterpel) { |
if (quarterpel) { |
485 |
dx = mb->qmvs[0].x; |
sumx += dx/2; sumy += dy/2; |
486 |
dy = mb->qmvs[0].y; |
b_sumx += b_dx/2; b_sumy += b_dy/2; |
|
b_dx = mb->b_qmvs[0].x; |
|
|
b_dy = mb->b_qmvs[0].y; |
|
|
|
|
|
interpolate16x16_quarterpel((uint8_t *) f_refv->y, (uint8_t *) f_ref->y, (uint8_t *) f_refh->y, |
|
|
(uint8_t *) f_refh->y + 64, (uint8_t *) f_refhv->y, 16*i, 16*j, dx, dy, edged_width, 0); |
|
|
interpolate16x16_quarterpel((uint8_t *) b_refv->y, (uint8_t *) b_ref->y, (uint8_t *) b_refh->y, |
|
|
(uint8_t *) b_refh->y + 64, (uint8_t *) b_refhv->y, 16*i, 16*j, b_dx, b_dy, edged_width, 0); |
|
487 |
|
|
488 |
for (k = 0; k < 4; k++) { |
if ((dx&3) | (dy&3)) { |
489 |
transfer_8to16sub2(&dct_codes[k * 64], |
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width, |
490 |
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
(uint8_t *) f_ref->y, |
491 |
f_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
tmp + 32, tmp + 64, tmp + 96, |
492 |
b_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
493 |
edged_width); |
ptr1 = tmp; |
494 |
} |
} else ptr1 = f_ref->y + (16*j + (k>>1)*8 + dy/4)*edged_width + 16*i + (k&1)*8 + dx/4; |
|
b_dx /= 2; |
|
|
b_dy /= 2; |
|
|
dx /= 2; |
|
|
dy /= 2; |
|
495 |
|
|
496 |
|
if ((b_dx&3) | (b_dy&3)) { |
497 |
|
interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16, |
498 |
|
(uint8_t *) b_ref->y, |
499 |
|
tmp + 16, tmp + 32, tmp + 48, |
500 |
|
16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
501 |
|
ptr2 = tmp + 16; |
502 |
|
} else ptr2 = b_ref->y + (16*j + (k>>1)*8 + b_dy/4)*edged_width + 16*i + (k&1)*8 + b_dx/4; |
503 |
} else { |
} else { |
504 |
dx = mb->mvs[0].x; |
sumx += dx; sumy += dy; |
505 |
dy = mb->mvs[0].y; |
b_sumx += b_dx; b_sumy += b_dy; |
|
b_dx = mb->b_mvs[0].x; |
|
|
b_dy = mb->b_mvs[0].y; |
|
506 |
|
|
507 |
for (k = 0; k < 4; k++) { |
ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
508 |
|
2*i + (k&1), 2*j + (k>>1), 8, dx, dy, edged_width); |
509 |
|
ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
510 |
|
2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, edged_width); |
511 |
|
} |
512 |
transfer_8to16sub2(&dct_codes[k * 64], |
transfer_8to16sub2(&dct_codes[k * 64], |
513 |
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
514 |
get_ref(f_ref->y, f_refh->y, f_refv->y, |
ptr1, ptr2, edged_width); |
|
f_refhv->y, 2*i + (k&1), 2*j + (k>>1), 8, dx, dy, |
|
|
edged_width), |
|
|
get_ref(b_ref->y, b_refh->y, b_refv->y, |
|
|
b_refhv->y, 2*i + (k&1), 2 * j+(k>>1), 8, b_dx, b_dy, |
|
|
edged_width), |
|
|
edged_width); |
|
|
} |
|
515 |
|
|
516 |
} |
} |
517 |
|
|
518 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
519 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
520 |
|
b_dx = (b_sumx >> 3) + roundtab_76[b_sumx & 0xf]; |
521 |
|
b_dy = (b_sumy >> 3) + roundtab_76[b_sumy & 0xf]; |
522 |
|
|
523 |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
break; |
524 |
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
} |
|
|
|
|
b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; |
|
|
b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; |
|
525 |
|
|
526 |
|
// uv block-based chroma interpolation for direct and interpolate modes |
527 |
transfer_8to16sub2(&dct_codes[4 * 64], |
transfer_8to16sub2(&dct_codes[4 * 64], |
528 |
cur->u + (y * 8) * edged_width / 2 + (x * 8), |
cur->u + (j * 8) * edged_width / 2 + (i * 8), |
529 |
interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j, |
interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j, |
530 |
b_dx, b_dy, edged_width / 2, 0), |
b_dx, b_dy, edged_width / 2, 0), |
531 |
interpolate8x8_switch2(f_refv->u + 8, f_ref->u, 8 * i, 8 * j, |
interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j, |
532 |
dx, dy, edged_width / 2, 0), |
dx, dy, edged_width / 2, 0), |
533 |
edged_width / 2); |
edged_width / 2); |
534 |
|
|
535 |
transfer_8to16sub2(&dct_codes[5 * 64], |
transfer_8to16sub2(&dct_codes[5 * 64], |
536 |
cur->v + (y * 8) * edged_width / 2 + (x * 8), |
cur->v + (j * 8) * edged_width / 2 + (i * 8), |
537 |
interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j, |
interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j, |
538 |
b_dx, b_dy, edged_width / 2, 0), |
b_dx, b_dy, edged_width / 2, 0), |
539 |
interpolate8x8_switch2(f_refv->u + 8, f_ref->v, 8 * i, 8 * j, |
interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j, |
540 |
dx, dy, edged_width / 2, 0), |
dx, dy, edged_width / 2, 0), |
541 |
edged_width / 2); |
edged_width / 2); |
542 |
|
} |
543 |
|
|
|
break; |
|
544 |
|
|
|
case MODE_DIRECT: |
|
|
if (quarterpel) { |
|
|
for (k=0;k<4;k++) { |
|
545 |
|
|
546 |
dx = mb->qmvs[k].x; |
void generate_GMCparameters( const int num_wp, const int res, |
547 |
dy = mb->qmvs[k].y; |
const WARPPOINTS *const warp, |
548 |
b_dx = mb->b_qmvs[k].x; |
const int width, const int height, |
549 |
b_dy = mb->b_qmvs[k].y; |
GMC_DATA *const gmc) |
550 |
|
{ |
551 |
|
const int du0 = warp->duv[0].x; |
552 |
|
const int dv0 = warp->duv[0].y; |
553 |
|
const int du1 = warp->duv[1].x; |
554 |
|
const int dv1 = warp->duv[1].y; |
555 |
|
const int du2 = warp->duv[2].x; |
556 |
|
const int dv2 = warp->duv[2].y; |
557 |
|
|
558 |
|
gmc->W = width; |
559 |
|
gmc->H = height; |
560 |
|
|
561 |
|
gmc->rho = 4 - log2bin(res-1); // = {3,2,1,0} for res={2,4,8,16} |
562 |
|
|
563 |
|
gmc->alpha = log2bin(gmc->W-1); |
564 |
|
gmc->Ws = (1 << gmc->alpha); |
565 |
|
|
566 |
|
gmc->dxF = 16*gmc->Ws + RDIV( 8*gmc->Ws*du1, gmc->W ); |
567 |
|
gmc->dxG = RDIV( 8*gmc->Ws*dv1, gmc->W ); |
568 |
|
gmc->Fo = (res*du0 + 1) << (gmc->alpha+gmc->rho-1); |
569 |
|
gmc->Go = (res*dv0 + 1) << (gmc->alpha+gmc->rho-1); |
570 |
|
|
571 |
|
if (num_wp==2) { |
572 |
|
gmc->dyF = -gmc->dxG; |
573 |
|
gmc->dyG = gmc->dxF; |
574 |
|
} |
575 |
|
else if (num_wp==3) { |
576 |
|
gmc->beta = log2bin(gmc->H-1); |
577 |
|
gmc->Hs = (1 << gmc->beta); |
578 |
|
gmc->dyF = RDIV( 8*gmc->Hs*du2, gmc->H ); |
579 |
|
gmc->dyG = 16*gmc->Hs + RDIV( 8*gmc->Hs*dv2, gmc->H ); |
580 |
|
if (gmc->beta > gmc->alpha) { |
581 |
|
gmc->dxF <<= (gmc->beta - gmc->alpha); |
582 |
|
gmc->dxG <<= (gmc->beta - gmc->alpha); |
583 |
|
gmc->alpha = gmc->beta; |
584 |
|
gmc->Ws = 1<< gmc->beta; |
585 |
|
} |
586 |
|
else { |
587 |
|
gmc->dyF <<= gmc->alpha - gmc->beta; |
588 |
|
gmc->dyG <<= gmc->alpha - gmc->beta; |
589 |
|
} |
590 |
|
} |
591 |
|
|
592 |
interpolate8x8_quarterpel((uint8_t *) f_refv->y, |
gmc->cFo = gmc->dxF + gmc->dyF + (1 << (gmc->alpha+gmc->rho+1)); |
593 |
(uint8_t *) f_ref->y, |
gmc->cFo += 16*gmc->Ws*(du0-1); |
|
(uint8_t *) f_refh->y, |
|
|
(uint8_t *) f_refh->y + 64, |
|
|
(uint8_t *) f_refhv->y, |
|
|
16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
|
|
interpolate8x8_quarterpel((uint8_t *) b_refv->y, |
|
|
(uint8_t *) b_ref->y, |
|
|
(uint8_t *) b_refh->y, |
|
|
(uint8_t *) b_refh->y + 64, |
|
|
(uint8_t *) b_refhv->y, |
|
|
16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
|
594 |
|
|
595 |
|
gmc->cGo = gmc->dxG + gmc->dyG + (1 << (gmc->alpha+gmc->rho+1)); |
596 |
|
gmc->cGo += 16*gmc->Ws*(dv0-1); |
597 |
|
} |
598 |
|
|
599 |
transfer_8to16sub2(&dct_codes[k * 64], |
void |
600 |
cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
generate_GMCimage( const GMC_DATA *const gmc_data, // [input] precalculated data |
601 |
f_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
const IMAGE *const pRef, // [input] |
602 |
b_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, |
const int mb_width, |
603 |
edged_width); |
const int mb_height, |
604 |
|
const int stride, |
605 |
|
const int stride2, |
606 |
|
const int fcode, // [input] some parameters... |
607 |
|
const int32_t quarterpel, // [input] for rounding avgMV |
608 |
|
const int reduced_resolution, // [input] ignored |
609 |
|
const int32_t rounding, // [input] for rounding image data |
610 |
|
MACROBLOCK *const pMBs, // [output] average motion vectors |
611 |
|
IMAGE *const pGMC) // [output] full warped image |
612 |
|
{ |
613 |
|
|
614 |
|
unsigned int mj,mi; |
615 |
|
VECTOR avgMV; |
616 |
|
|
617 |
|
for (mj=0;mj<mb_height;mj++) |
618 |
|
for (mi=0;mi<mb_width; mi++) |
619 |
|
{ |
620 |
|
avgMV = generate_GMCimageMB(gmc_data, pRef, mi, mj, |
621 |
|
stride, stride2, quarterpel, rounding, pGMC); |
622 |
|
|
623 |
|
pMBs[mj*mb_width+mi].amv.x = gmc_sanitize(avgMV.x, quarterpel, fcode); |
624 |
|
pMBs[mj*mb_width+mi].amv.y = gmc_sanitize(avgMV.y, quarterpel, fcode); |
625 |
|
pMBs[mj*mb_width+mi].mcsel = 0; /* until mode decision */ |
626 |
|
} |
627 |
} |
} |
|
sum = mb->qmvs[0].y/2 + mb->qmvs[1].y/2 + mb->qmvs[2].y/2 + mb->qmvs[3].y/2; |
|
|
dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
|
sum = mb->qmvs[0].x/2 + mb->qmvs[1].x/2 + mb->qmvs[2].x/2 + mb->qmvs[3].x/2; |
|
|
dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
|
|
|
|
sum = mb->b_qmvs[0].y/2 + mb->b_qmvs[1].y/2 + mb->b_qmvs[2].y/2 + mb->b_qmvs[3].y/2; |
|
|
b_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
|
sum = mb->b_qmvs[0].x/2 + mb->b_qmvs[1].x/2 + mb->b_qmvs[2].x/2 + mb->b_qmvs[3].x/2; |
|
|
b_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
628 |
|
|
|
} else { |
|
|
for (k=0;k<4;k++) { |
|
|
dx = mb->mvs[k].x; |
|
|
dy = mb->mvs[k].y; |
|
629 |
|
|
|
b_dx = mb->b_mvs[k].x; |
|
|
b_dy = mb->b_mvs[k].y; |
|
630 |
|
|
631 |
transfer_8to16sub2(&dct_codes[k * 64], |
#define MLT(i) (((16-(i))<<16) + (i)) |
632 |
cur->y + (i*16 + (k&1)*8) + (j*16 + (k>>1)*8 ) * edged_width, |
static const uint32_t MTab[16] = { |
633 |
get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
MLT( 0), MLT( 1), MLT( 2), MLT( 3), MLT( 4), MLT( 5), MLT( 6), MLT(7), |
634 |
2*i + (k&1), 2*j + (k>>1), 8, dx, dy, |
MLT( 8), MLT( 9), MLT(10), MLT(11), MLT(12), MLT(13), MLT(14), MLT(15) |
635 |
edged_width), |
}; |
636 |
get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
#undef MLT |
637 |
2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, |
|
638 |
edged_width), |
VECTOR generate_GMCimageMB( const GMC_DATA *const gmc_data, |
639 |
edged_width); |
const IMAGE *const pRef, |
640 |
|
const int mi, const int mj, |
641 |
|
const int stride, |
642 |
|
const int stride2, |
643 |
|
const int quarterpel, |
644 |
|
const int rounding, |
645 |
|
IMAGE *const pGMC) |
646 |
|
{ |
647 |
|
const int W = gmc_data->W; |
648 |
|
const int H = gmc_data->H; |
649 |
|
|
650 |
|
const int rho = gmc_data->rho; |
651 |
|
const int alpha = gmc_data->alpha; |
652 |
|
|
653 |
|
const int rounder = ( 128 - (rounding<<(rho+rho)) ) << 16; |
654 |
|
|
655 |
|
const int dxF = gmc_data->dxF; |
656 |
|
const int dyF = gmc_data->dyF; |
657 |
|
const int dxG = gmc_data->dxG; |
658 |
|
const int dyG = gmc_data->dyG; |
659 |
|
|
660 |
|
uint8_t *dstY, *dstU, *dstV; |
661 |
|
|
662 |
|
int I,J; |
663 |
|
VECTOR avgMV = {0,0}; |
664 |
|
|
665 |
|
int32_t Fj, Gj; |
666 |
|
|
667 |
|
dstY = &pGMC->y[(mj*16)*stride+mi*16] + 16; |
668 |
|
|
669 |
|
Fj = gmc_data->Fo + dyF*mj*16 + dxF*mi*16; |
670 |
|
Gj = gmc_data->Go + dyG*mj*16 + dxG*mi*16; |
671 |
|
for (J=16; J>0; --J) |
672 |
|
{ |
673 |
|
int32_t Fi, Gi; |
674 |
|
|
675 |
|
Fi = Fj; Fj += dyF; |
676 |
|
Gi = Gj; Gj += dyG; |
677 |
|
for (I=-16; I<0; ++I) |
678 |
|
{ |
679 |
|
int32_t F, G; |
680 |
|
uint32_t ri, rj; |
681 |
|
|
682 |
|
F = ( Fi >> (alpha+rho) ) << rho; Fi += dxF; |
683 |
|
G = ( Gi >> (alpha+rho) ) << rho; Gi += dxG; |
684 |
|
|
685 |
|
avgMV.x += F; |
686 |
|
avgMV.y += G; |
687 |
|
|
688 |
|
ri = MTab[F&15]; |
689 |
|
rj = MTab[G&15]; |
690 |
|
|
691 |
|
F >>= 4; |
692 |
|
G >>= 4; |
693 |
|
|
694 |
|
if (F< -1) F=-1; |
695 |
|
else if (F>W) F=W; |
696 |
|
if (G< -1) G=-1; |
697 |
|
else if (G>H) G=H; |
698 |
|
|
699 |
|
{ // MMX-like bilinear... |
700 |
|
const int offset = G*stride + F; |
701 |
|
uint32_t f0, f1; |
702 |
|
f0 = pRef->y[ offset +0 ]; |
703 |
|
f0 |= pRef->y[ offset +1 ] << 16; |
704 |
|
f1 = pRef->y[ offset+stride +0 ]; |
705 |
|
f1 |= pRef->y[ offset+stride +1 ] << 16; |
706 |
|
f0 = (ri*f0)>>16; |
707 |
|
f1 = (ri*f1) & 0x0fff0000; |
708 |
|
f0 |= f1; |
709 |
|
f0 = ( rj*f0 + rounder ) >> 24; |
710 |
|
|
711 |
|
dstY[I] = (uint8_t)f0; |
712 |
|
} |
713 |
|
} |
714 |
|
dstY += stride; |
715 |
|
} |
716 |
|
|
717 |
|
dstU = &pGMC->u[(mj*8)*stride2+mi*8] + 8; |
718 |
|
dstV = &pGMC->v[(mj*8)*stride2+mi*8] + 8; |
719 |
|
|
720 |
|
Fj = gmc_data->cFo + dyF*4 *mj*8 + dxF*4 *mi*8; |
721 |
|
Gj = gmc_data->cGo + dyG*4 *mj*8 + dxG*4 *mi*8; |
722 |
|
for (J=8; J>0; --J) |
723 |
|
{ |
724 |
|
int32_t Fi, Gi; |
725 |
|
Fi = Fj; Fj += 4*dyF; |
726 |
|
Gi = Gj; Gj += 4*dyG; |
727 |
|
|
728 |
|
for (I=-8; I<0; ++I) |
729 |
|
{ |
730 |
|
int32_t F, G; |
731 |
|
uint32_t ri, rj; |
732 |
|
|
733 |
|
F = ( Fi >> (alpha+rho+2) ) << rho; Fi += 4*dxF; |
734 |
|
G = ( Gi >> (alpha+rho+2) ) << rho; Gi += 4*dxG; |
735 |
|
|
736 |
|
ri = MTab[F&15]; |
737 |
|
rj = MTab[G&15]; |
738 |
|
|
739 |
|
F >>= 4; |
740 |
|
G >>= 4; |
741 |
|
|
742 |
|
if (F< -1) F=-1; |
743 |
|
else if (F>=W/2) F=W/2; |
744 |
|
if (G< -1) G=-1; |
745 |
|
else if (G>=H/2) G=H/2; |
746 |
|
|
747 |
|
{ |
748 |
|
const int offset = G*stride2 + F; |
749 |
|
uint32_t f0, f1; |
750 |
|
|
751 |
|
f0 = pRef->u[ offset +0 ]; |
752 |
|
f0 |= pRef->u[ offset +1 ] << 16; |
753 |
|
f1 = pRef->u[ offset+stride2 +0 ]; |
754 |
|
f1 |= pRef->u[ offset+stride2 +1 ] << 16; |
755 |
|
f0 = (ri*f0)>>16; |
756 |
|
f1 = (ri*f1) & 0x0fff0000; |
757 |
|
f0 |= f1; |
758 |
|
f0 = ( rj*f0 + rounder ) >> 24; |
759 |
|
|
760 |
|
dstU[I] = (uint8_t)f0; |
761 |
|
|
762 |
|
|
763 |
|
f0 = pRef->v[ offset +0 ]; |
764 |
|
f0 |= pRef->v[ offset +1 ] << 16; |
765 |
|
f1 = pRef->v[ offset+stride2 +0 ]; |
766 |
|
f1 |= pRef->v[ offset+stride2 +1 ] << 16; |
767 |
|
f0 = (ri*f0)>>16; |
768 |
|
f1 = (ri*f1) & 0x0fff0000; |
769 |
|
f0 |= f1; |
770 |
|
f0 = ( rj*f0 + rounder ) >> 24; |
771 |
|
|
772 |
|
dstV[I] = (uint8_t)f0; |
773 |
|
} |
774 |
} |
} |
775 |
|
dstU += stride2; |
776 |
|
dstV += stride2; |
777 |
|
} |
778 |
|
|
779 |
|
|
780 |
|
avgMV.x -= 16*((256*mi+120)<<4); // 120 = 15*16/2 |
781 |
|
avgMV.y -= 16*((256*mj+120)<<4); |
782 |
|
|
783 |
|
avgMV.x = RSHIFT( avgMV.x, (4+7-quarterpel) ); |
784 |
|
avgMV.y = RSHIFT( avgMV.y, (4+7-quarterpel) ); |
785 |
|
|
786 |
|
return avgMV; |
787 |
|
} |
788 |
|
|
789 |
|
|
790 |
|
|
791 |
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
#ifdef OLD_GRUEL_GMC |
792 |
dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
void |
793 |
|
generate_GMCparameters( const int num_wp, // [input]: number of warppoints |
794 |
|
const int res, // [input]: resolution |
795 |
|
const WARPPOINTS *const warp, // [input]: warp points |
796 |
|
const int width, const int height, |
797 |
|
GMC_DATA *const gmc) // [output] precalculated parameters |
798 |
|
{ |
799 |
|
|
800 |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
/* We follow mainly two sources: The original standard, which is ugly, and the |
801 |
dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
thesis from Andreas Dehnhardt, which is much nicer. |
802 |
|
|
803 |
sum = mb->b_mvs[0].x + mb->b_mvs[1].x + mb->b_mvs[2].x + mb->b_mvs[3].x; |
Notation is: indices are written next to the variable, |
804 |
b_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
primes in the standard are denoted by a suffix 'p'. |
805 |
|
types are "c"=constant, "i"=input parameter, "f"=calculated, then fixed, |
806 |
|
"o"=output data, " "=other, "u" = unused, "p"=calc for every pixel |
807 |
|
|
808 |
|
type | variable name | ISO name (TeX-style) | value or range | usage |
809 |
|
------------------------------------------------------------------------------------- |
810 |
|
c | H | H | [16 , ?] | image width (w/o edges) |
811 |
|
c | W | W | [16 , ?] | image height (w/o edges) |
812 |
|
|
813 |
|
c | i0 | i_0 | 0 | ref. point #1, X |
814 |
|
c | j0 | j_0 | 0 | ref. point #1, Y |
815 |
|
c | i1 | i_1 | W | ref. point #2, X |
816 |
|
c | j1 | j_1 | 0 | ref. point #2, Y |
817 |
|
cu | i2 | i_2 | 0 | ref. point #3, X |
818 |
|
cu | i2 | j_2 | H | ref. point #3, Y |
819 |
|
|
820 |
|
i | du0 | du[0] | [-16863,16863] | warp vector #1, Y |
821 |
|
i | dv0 | dv[0] | [-16863,16863] | warp vector #1, Y |
822 |
|
i | du1 | du[1] | [-16863,16863] | warp vector #2, Y |
823 |
|
i | dv1 | dv[1] | [-16863,16863] | warp vector #2, Y |
824 |
|
iu | du2 | du[2] | [-16863,16863] | warp vector #3, Y |
825 |
|
iu | dv2 | dv[2] | [-16863,16863] | warp vector #3, Y |
826 |
|
|
827 |
|
i | s | s | {2,4,8,16} | interpol. resolution |
828 |
|
f | sigma | - | log2(s) | X / s == X >> sigma |
829 |
|
f | r | r | =16/s | complementary res. |
830 |
|
f | rho | \rho | log2(r) | X / r == X >> rho |
831 |
|
|
832 |
|
f | i0s | i'_0 | | |
833 |
|
f | j0s | j'_0 | | |
834 |
|
f | i1s | i'_1 | | |
835 |
|
f | j1s | j'_1 | | |
836 |
|
f | i2s | i'_2 | | |
837 |
|
f | j2s | j'_2 | | |
838 |
|
|
839 |
|
f | alpha | \alpha | | 2^{alpha-1} < W <= 2^alpha |
840 |
|
f | beta | \beta | | 2^{beta-1} < H <= 2^beta |
841 |
|
|
842 |
|
f | Ws | W' | W = 2^{alpha} | scaled width |
843 |
|
f | Hs | H' | W = 2^{beta} | scaled height |
844 |
|
|
845 |
|
f | i1ss | i''_1 | "virtual sprite stuff" |
846 |
|
f | j1ss | j''_1 | "virtual sprite stuff" |
847 |
|
f | i2ss | i''_2 | "virtual sprite stuff" |
848 |
|
f | j2ss | j''_2 | "virtual sprite stuff" |
849 |
|
*/ |
850 |
|
|
851 |
|
/* Some calculations are disabled because we only use 2 warppoints at the moment */ |
852 |
|
|
853 |
|
int du0 = warp->duv[0].x; |
854 |
|
int dv0 = warp->duv[0].y; |
855 |
|
int du1 = warp->duv[1].x; |
856 |
|
int dv1 = warp->duv[1].y; |
857 |
|
// int du2 = warp->duv[2].x; |
858 |
|
// int dv2 = warp->duv[2].y; |
859 |
|
|
860 |
|
gmc->num_wp = num_wp; |
861 |
|
|
862 |
|
gmc->s = res; /* scaling parameters 2,4,8 or 16 */ |
863 |
|
gmc->sigma = log2bin(res-1); /* log2bin(15)=4, log2bin(16)=5, log2bin(17)=5 */ |
864 |
|
gmc->r = 16/res; |
865 |
|
gmc->rho = 4 - gmc->sigma; /* = log2bin(r-1) */ |
866 |
|
|
867 |
|
gmc->W = width; |
868 |
|
gmc->H = height; /* fixed reference coordinates */ |
869 |
|
|
870 |
|
gmc->alpha = log2bin(gmc->W-1); |
871 |
|
gmc->Ws= 1<<gmc->alpha; |
872 |
|
|
873 |
|
// gmc->beta = log2bin(gmc->H-1); |
874 |
|
// gmc->Hs= 1<<gmc->beta; |
875 |
|
|
876 |
|
// 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); |
877 |
|
|
878 |
|
/* i2s is only needed for num_wp >= 3, etc. */ |
879 |
|
/* the 's' values are in 1/s pel resolution */ |
880 |
|
gmc->i0s = res/2 * ( du0 ); |
881 |
|
gmc->j0s = res/2 * ( dv0 ); |
882 |
|
gmc->i1s = res/2 * (2*width + du1 + du0 ); |
883 |
|
gmc->j1s = res/2 * ( dv1 + dv0 ); |
884 |
|
// gmc->i2s = res/2 * ( du2 + du0 ); |
885 |
|
// gmc->j2s = res/2 * (2*height + dv2 + dv0 ); |
886 |
|
|
887 |
|
/* i2s and i2ss are only needed for num_wp == 3, etc. */ |
888 |
|
|
889 |
|
/* the 'ss' values are in 1/16 pel resolution */ |
890 |
|
gmc->i1ss = 16*gmc->Ws + ROUNDED_DIV(((gmc->W-gmc->Ws)*(gmc->r*gmc->i0s) + gmc->Ws*(gmc->r*gmc->i1s - 16*gmc->W)),gmc->W); |
891 |
|
gmc->j1ss = ROUNDED_DIV( ((gmc->W - gmc->Ws)*(gmc->r*gmc->j0s) + gmc->Ws*gmc->r*gmc->j1s) ,gmc->W ); |
892 |
|
|
893 |
sum = mb->b_mvs[0].y + mb->b_mvs[1].y + mb->b_mvs[2].y + mb->b_mvs[3].y; |
// gmc->i2ss = ROUNDED_DIV( ((gmc->H - gmc->Hs)*(gmc->r*gmc->i0s) + gmc->Hs*(gmc->r*gmc->i2s)), gmc->H); |
894 |
b_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
// gmc->j2ss = 16*gmc->Hs + ROUNDED_DIV( ((gmc->H-gmc->Hs)*(gmc->r*gmc->j0s) + gmc->Ws*(gmc->r*gmc->j2s - 16*gmc->H)), gmc->H); |
895 |
|
|
896 |
|
return; |
897 |
} |
} |
|
transfer_8to16sub2(&dct_codes[4 * 64], |
|
|
cur->u + (y * 8) * edged_width / 2 + (x * 8), |
|
|
interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j, |
|
|
b_dx, b_dy, edged_width / 2, 0), |
|
|
interpolate8x8_switch2(f_refv->u + 8, f_ref->u, 8 * i, 8 * j, dx, dy, |
|
|
edged_width / 2, 0), |
|
|
edged_width / 2); |
|
898 |
|
|
|
transfer_8to16sub2(&dct_codes[5 * 64], |
|
|
cur->v + (y * 8) * edged_width / 2 + (x * 8), |
|
|
interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j, |
|
|
b_dx, b_dy, edged_width / 2, 0), |
|
|
interpolate8x8_switch2(f_refv->u + 8, f_ref->v, 8 * i, 8 * j, |
|
|
dx, dy, edged_width / 2, 0), |
|
|
edged_width / 2); |
|
899 |
|
|
900 |
|
|
901 |
break; |
void |
902 |
|
generate_GMCimage( const GMC_DATA *const gmc_data, // [input] precalculated data |
903 |
|
const IMAGE *const pRef, // [input] |
904 |
|
const int mb_width, |
905 |
|
const int mb_height, |
906 |
|
const int stride, |
907 |
|
const int stride2, |
908 |
|
const int fcode, // [input] some parameters... |
909 |
|
const int32_t quarterpel, // [input] for rounding avgMV |
910 |
|
const int reduced_resolution, // [input] ignored |
911 |
|
const int32_t rounding, // [input] for rounding image data |
912 |
|
MACROBLOCK *const pMBs, // [output] average motion vectors |
913 |
|
IMAGE *const pGMC) // [output] full warped image |
914 |
|
{ |
915 |
|
|
916 |
|
unsigned int mj,mi; |
917 |
|
VECTOR avgMV; |
918 |
|
|
919 |
|
for (mj=0;mj<mb_height;mj++) |
920 |
|
for (mi=0;mi<mb_width; mi++) |
921 |
|
{ |
922 |
|
avgMV = generate_GMCimageMB(gmc_data, pRef, mi, mj, |
923 |
|
stride, stride2, quarterpel, rounding, pGMC); |
924 |
|
|
925 |
|
pMBs[mj*mb_width+mi].amv.x = gmc_sanitize(avgMV.x, quarterpel, fcode); |
926 |
|
pMBs[mj*mb_width+mi].amv.y = gmc_sanitize(avgMV.y, quarterpel, fcode); |
927 |
|
pMBs[mj*mb_width+mi].mcsel = 0; /* until mode decision */ |
928 |
} |
} |
929 |
} |
} |
930 |
|
|
931 |
|
|
932 |
|
VECTOR generate_GMCimageMB( const GMC_DATA *const gmc_data, /* [input] all precalc data */ |
933 |
|
const IMAGE *const pRef, /* [input] */ |
934 |
|
const int mi, const int mj, /* [input] MB position */ |
935 |
|
const int stride, /* [input] Lumi stride */ |
936 |
|
const int stride2, /* [input] chroma stride */ |
937 |
|
const int quarterpel, /* [input] for rounding of avgMV */ |
938 |
|
const int rounding, /* [input] for rounding of imgae data */ |
939 |
|
IMAGE *const pGMC) /* [outut] generate image */ |
940 |
|
|
941 |
|
/* |
942 |
|
type | variable name | ISO name (TeX-style) | value or range | usage |
943 |
|
------------------------------------------------------------------------------------- |
944 |
|
p | F | F(i,j) | | pelwise motion vector X in s-th pel |
945 |
|
p | G | G(i,j) | | pelwise motion vector Y in s-th pel |
946 |
|
p | Fc | F_c(i,j) | | |
947 |
|
p | Gc | G_c(i,j) | | same for chroma |
948 |
|
|
949 |
|
p | Y00 | Y_{00} | [0,255*s*s] | first: 4 neighbouring Y-values |
950 |
|
p | Y01 | Y_{01} | [0,255] | at fullpel position, around the |
951 |
|
p | Y10 | Y_{10} | [0,255*s] | position where pelweise MV points to |
952 |
|
p | Y11 | Y_{11} | [0,255] | later: bilinear interpol Y-values in Y00 |
953 |
|
|
954 |
|
p | C00 | C_{00} | [0,255*s*s] | same for chroma Cb and Cr |
955 |
|
p | C01 | C_{01} | [0,255] | |
956 |
|
p | C10 | C_{10} | [0,255*s] | |
957 |
|
p | C11 | C_{11} | [0,255] | |
958 |
|
|
959 |
|
*/ |
960 |
|
{ |
961 |
|
const int W = gmc_data->W; |
962 |
|
const int H = gmc_data->H; |
963 |
|
|
964 |
|
const int s = gmc_data->s; |
965 |
|
const int sigma = gmc_data->sigma; |
966 |
|
|
967 |
|
const int r = gmc_data->r; |
968 |
|
const int rho = gmc_data->rho; |
969 |
|
|
970 |
|
const int i0s = gmc_data->i0s; |
971 |
|
const int j0s = gmc_data->j0s; |
972 |
|
|
973 |
|
const int i1ss = gmc_data->i1ss; |
974 |
|
const int j1ss = gmc_data->j1ss; |
975 |
|
// const int i2ss = gmc_data->i2ss; |
976 |
|
// const int j2ss = gmc_data->j2ss; |
977 |
|
|
978 |
|
const int alpha = gmc_data->alpha; |
979 |
|
const int Ws = gmc_data->Ws; |
980 |
|
|
981 |
|
// const int beta = gmc_data->beta; |
982 |
|
// const int Hs = gmc_data->Hs; |
983 |
|
|
984 |
|
int I,J; |
985 |
|
VECTOR avgMV = {0,0}; |
986 |
|
|
987 |
|
for (J=16*mj;J<16*(mj+1);J++) |
988 |
|
for (I=16*mi;I<16*(mi+1);I++) |
989 |
|
{ |
990 |
|
int F= i0s + ( ((-r*i0s+i1ss)*I + (r*j0s-j1ss)*J + (1<<(alpha+rho-1))) >> (alpha+rho) ); |
991 |
|
int G= j0s + ( ((-r*j0s+j1ss)*I + (-r*i0s+i1ss)*J + (1<<(alpha+rho-1))) >> (alpha+rho) ); |
992 |
|
|
993 |
|
/* this naive implementation (with lots of multiplications) isn't slower (rather faster) than |
994 |
|
working incremental. Don't ask me why... maybe the whole this is memory bound? */ |
995 |
|
|
996 |
|
const int ri= F & (s-1); // fractional part of pelwise MV X |
997 |
|
const int rj= G & (s-1); // fractional part of pelwise MV Y |
998 |
|
|
999 |
|
int Y00,Y01,Y10,Y11; |
1000 |
|
|
1001 |
|
/* unclipped values are used for avgMV */ |
1002 |
|
avgMV.x += F-(I<<sigma); /* shift position to 1/s-pel, as the MV is */ |
1003 |
|
avgMV.y += G-(J<<sigma); /* TODO: don't do this (of course) */ |
1004 |
|
|
1005 |
|
F >>= sigma; |
1006 |
|
G >>= sigma; |
1007 |
|
|
1008 |
|
/* clip values to be in range. Since we have edges, clip to 1 less than lower boundary |
1009 |
|
this way positions F+1/G+1 are still right */ |
1010 |
|
|
1011 |
|
if (F< -1) |
1012 |
|
F=-1; |
1013 |
|
else if (F>W) |
1014 |
|
F=W; /* W or W-1 doesn't matter, so save 1 subtract ;-) */ |
1015 |
|
if (G< -1) |
1016 |
|
G=-1; |
1017 |
|
else if (G>H) |
1018 |
|
G=H; /* dito */ |
1019 |
|
|
1020 |
|
Y00 = pRef->y[ G*stride + F ]; // Lumi values |
1021 |
|
Y01 = pRef->y[ G*stride + F+1 ]; |
1022 |
|
Y10 = pRef->y[ G*stride + F+stride ]; |
1023 |
|
Y11 = pRef->y[ G*stride + F+stride+1 ]; |
1024 |
|
|
1025 |
|
/* bilinear interpolation */ |
1026 |
|
Y00 = ((s-ri)*Y00 + ri*Y01); |
1027 |
|
Y10 = ((s-ri)*Y10 + ri*Y11); |
1028 |
|
Y00 = ((s-rj)*Y00 + rj*Y10 + s*s/2 - rounding ) >> (sigma+sigma); |
1029 |
|
|
1030 |
|
pGMC->y[J*stride+I] = (uint8_t)Y00; /* output 1 Y-pixel */ |
1031 |
|
} |
1032 |
|
|
1033 |
|
|
1034 |
|
/* doing chroma _here_ is even more stupid and slow, because won't be used until Compensation and |
1035 |
|
most likely not even then (only if the block really _is_ GMC) |
1036 |
|
*/ |
1037 |
|
|
1038 |
|
for (J=8*mj;J<8*(mj+1);J++) /* this plays the role of j_c,i_c in the standard */ |
1039 |
|
for (I=8*mi;I<8*(mi+1);I++) /* For I_c we have to use I_c = 4*i_c+1 ! */ |
1040 |
|
{ |
1041 |
|
/* same positions for both chroma components, U=Cb and V=Cr */ |
1042 |
|
int Fc=((-r*i0s+i1ss)*(4*I+1) + (r*j0s-j1ss)*(4*J+1) +2*Ws*r*i0s |
1043 |
|
-16*Ws +(1<<(alpha+rho+1)))>>(alpha+rho+2); |
1044 |
|
int Gc=((-r*j0s+j1ss)*(4*I+1) +(-r*i0s+i1ss)*(4*J+1) +2*Ws*r*j0s |
1045 |
|
-16*Ws +(1<<(alpha+rho+1))) >>(alpha+rho+2); |
1046 |
|
|
1047 |
|
const int ri= Fc & (s-1); // fractional part of pelwise MV X |
1048 |
|
const int rj= Gc & (s-1); // fractional part of pelwise MV Y |
1049 |
|
|
1050 |
|
int C00,C01,C10,C11; |
1051 |
|
|
1052 |
|
Fc >>= sigma; |
1053 |
|
Gc >>= sigma; |
1054 |
|
|
1055 |
|
if (Fc< -1) |
1056 |
|
Fc=-1; |
1057 |
|
else if (Fc>=W/2) |
1058 |
|
Fc=W/2; /* W or W-1 doesn't matter, so save 1 subtraction ;-) */ |
1059 |
|
if (Gc< -1) |
1060 |
|
Gc=-1; |
1061 |
|
else if (Gc>=H/2) |
1062 |
|
Gc=H/2; /* dito */ |
1063 |
|
|
1064 |
|
/* now calculate U data */ |
1065 |
|
C00 = pRef->u[ Gc*stride2 + Fc ]; // chroma-value Cb |
1066 |
|
C01 = pRef->u[ Gc*stride2 + Fc+1 ]; |
1067 |
|
C10 = pRef->u[ (Gc+1)*stride2 + Fc ]; |
1068 |
|
C11 = pRef->u[ (Gc+1)*stride2 + Fc+1 ]; |
1069 |
|
|
1070 |
|
/* bilinear interpolation */ |
1071 |
|
C00 = ((s-ri)*C00 + ri*C01); |
1072 |
|
C10 = ((s-ri)*C10 + ri*C11); |
1073 |
|
C00 = ((s-rj)*C00 + rj*C10 + s*s/2 - rounding ) >> (sigma+sigma); |
1074 |
|
|
1075 |
|
pGMC->u[J*stride2+I] = (uint8_t)C00; /* output 1 U-pixel */ |
1076 |
|
|
1077 |
|
/* now calculate V data */ |
1078 |
|
C00 = pRef->v[ Gc*stride2 + Fc ]; // chroma-value Cr |
1079 |
|
C01 = pRef->v[ Gc*stride2 + Fc+1 ]; |
1080 |
|
C10 = pRef->v[ (Gc+1)*stride2 + Fc ]; |
1081 |
|
C11 = pRef->v[ (Gc+1)*stride2 + Fc+1 ]; |
1082 |
|
|
1083 |
|
/* bilinear interpolation */ |
1084 |
|
C00 = ((s-ri)*C00 + ri*C01); |
1085 |
|
C10 = ((s-ri)*C10 + ri*C11); |
1086 |
|
C00 = ((s-rj)*C00 + rj*C10 + s*s/2 - rounding ) >> (sigma+sigma); |
1087 |
|
|
1088 |
|
pGMC->v[J*stride2+I] = (uint8_t)C00; /* output 1 V-pixel */ |
1089 |
|
} |
1090 |
|
|
1091 |
|
/* The average vector is rounded from 1/s-pel to 1/2 or 1/4 using the '//' operator*/ |
1092 |
|
|
1093 |
|
avgMV.x = RSHIFT( avgMV.x, (sigma+7-quarterpel) ); |
1094 |
|
avgMV.y = RSHIFT( avgMV.y, (sigma+7-quarterpel) ); |
1095 |
|
|
1096 |
|
/* ^^^^ this is the way MS Reference Software does it */ |
1097 |
|
|
1098 |
|
return avgMV; /* clipping to fcode area is done outside! */ |
1099 |
|
} |
1100 |
|
|
1101 |
|
#endif |