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