Parent Directory | Revision Log
Revision 1142 - (view) (download)
1 : | edgomez | 1054 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - Motion Compensation related code - | ||
5 : | * | ||
6 : | * Copyright(C) 2002 Peter Ross <pross@xvid.org> | ||
7 : | * 2003 Christoph Lampert <gruel@web.de> | ||
8 : | * | ||
9 : | * This program is free software ; you can redistribute it and/or modify | ||
10 : | * it under the terms of the GNU General Public License as published by | ||
11 : | * the Free Software Foundation ; either version 2 of the License, or | ||
12 : | * (at your option) any later version. | ||
13 : | * | ||
14 : | * This program is distributed in the hope that it will be useful, | ||
15 : | * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
16 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 : | * GNU General Public License for more details. | ||
18 : | * | ||
19 : | * You should have received a copy of the GNU General Public License | ||
20 : | * along with this program ; if not, write to the Free Software | ||
21 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 : | * | ||
23 : | edgomez | 1142 | * $Id: motion_comp.c,v 1.18.2.9 2003-09-10 22:19:00 edgomez Exp $ |
24 : | edgomez | 1054 | * |
25 : | ****************************************************************************/ | ||
26 : | suxen_drol | 118 | |
27 : | edgomez | 851 | #include <stdio.h> |
28 : | |||
29 : | Isibaar | 3 | #include "../encoder.h" |
30 : | #include "../utils/mbfunctions.h" | ||
31 : | #include "../image/interpolate8x8.h" | ||
32 : | Isibaar | 1125 | #include "../image/qpel.h" |
33 : | edgomez | 851 | #include "../image/reduced.h" |
34 : | Isibaar | 3 | #include "../utils/timer.h" |
35 : | suxen_drol | 118 | #include "motion.h" |
36 : | Isibaar | 3 | |
37 : | edgomez | 851 | #ifndef RSHIFT |
38 : | #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) | ||
39 : | #endif | ||
40 : | |||
41 : | /* assume b>0 */ | ||
42 : | #ifndef RDIV | ||
43 : | #define RDIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) | ||
44 : | #endif | ||
45 : | |||
46 : | |||
47 : | chl | 1077 | /* This is borrowed from bitstream.c until we find a common solution */ |
48 : | edgomez | 851 | |
49 : | static uint32_t __inline | ||
50 : | log2bin(uint32_t value) | ||
51 : | { | ||
52 : | /* Changed by Chenm001 */ | ||
53 : | #if !defined(_MSC_VER) | ||
54 : | int n = 0; | ||
55 : | |||
56 : | while (value) { | ||
57 : | value >>= 1; | ||
58 : | n++; | ||
59 : | } | ||
60 : | return n; | ||
61 : | #else | ||
62 : | __asm { | ||
63 : | syskin | 935 | bsr eax, value |
64 : | edgomez | 851 | inc eax |
65 : | } | ||
66 : | #endif | ||
67 : | } | ||
68 : | |||
69 : | edgomez | 1142 | /* |
70 : | * getref: calculate reference image pointer | ||
71 : | * the decision to use interpolation h/v/hv or the normal image is | ||
72 : | * based on dx & dy. | ||
73 : | */ | ||
74 : | edgomez | 851 | |
75 : | edgomez | 1142 | static __inline const uint8_t * |
76 : | get_ref(const uint8_t * const refn, | ||
77 : | const uint8_t * const refh, | ||
78 : | const uint8_t * const refv, | ||
79 : | const uint8_t * const refhv, | ||
80 : | const uint32_t x, | ||
81 : | const uint32_t y, | ||
82 : | const uint32_t block, | ||
83 : | const int32_t dx, | ||
84 : | const int32_t dy, | ||
85 : | const int32_t stride) | ||
86 : | { | ||
87 : | switch (((dx & 1) << 1) + (dy & 1)) { | ||
88 : | case 0: | ||
89 : | return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); | ||
90 : | case 1: | ||
91 : | return refv + (int) ((x * block + dx / 2) + (y * block + (dy - 1) / 2) * stride); | ||
92 : | case 2: | ||
93 : | return refh + (int) ((x * block + (dx - 1) / 2) + (y * block + dy / 2) * stride); | ||
94 : | default: | ||
95 : | return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block + (dy - 1) / 2) * stride); | ||
96 : | } | ||
97 : | } | ||
98 : | |||
99 : | edgomez | 195 | static __inline void |
100 : | edgomez | 851 | compensate16x16_interpolate(int16_t * const dct_codes, |
101 : | uint8_t * const cur, | ||
102 : | const uint8_t * const ref, | ||
103 : | const uint8_t * const refh, | ||
104 : | const uint8_t * const refv, | ||
105 : | const uint8_t * const refhv, | ||
106 : | uint8_t * const tmp, | ||
107 : | uint32_t x, | ||
108 : | uint32_t y, | ||
109 : | const int32_t dx, | ||
110 : | const int32_t dy, | ||
111 : | const int32_t stride, | ||
112 : | const int quarterpel, | ||
113 : | const int reduced_resolution, | ||
114 : | const int32_t rounding) | ||
115 : | Isibaar | 3 | { |
116 : | edgomez | 851 | const uint8_t * ptr; |
117 : | Isibaar | 3 | |
118 : | edgomez | 851 | if (!reduced_resolution) { |
119 : | Isibaar | 3 | |
120 : | edgomez | 851 | if(quarterpel) { |
121 : | if ((dx&3) | (dy&3)) { | ||
122 : | Isibaar | 1125 | #if defined(ARCH_IS_IA32) /* new_interpolate is only faster on x86 (MMX) machines */ |
123 : | new_interpolate16x16_quarterpel(tmp - y * stride - x, | ||
124 : | (uint8_t *) ref, tmp + 32, | ||
125 : | tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); | ||
126 : | #else | ||
127 : | edgomez | 851 | interpolate16x16_quarterpel(tmp - y * stride - x, |
128 : | (uint8_t *) ref, tmp + 32, | ||
129 : | tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); | ||
130 : | Isibaar | 1125 | #endif |
131 : | edgomez | 851 | ptr = tmp; |
132 : | edgomez | 1053 | } else ptr = ref + (y + dy/4)*stride + x + dx/4; /* fullpixel position */ |
133 : | Isibaar | 3 | |
134 : | edgomez | 851 | } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
135 : | |||
136 : | edgomez | 195 | transfer_8to16sub(dct_codes, cur + y * stride + x, |
137 : | syskin | 935 | ptr, stride); |
138 : | edgomez | 851 | transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8, |
139 : | syskin | 935 | ptr + 8, stride); |
140 : | edgomez | 851 | transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride, |
141 : | syskin | 935 | ptr + 8*stride, stride); |
142 : | edgomez | 851 | transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8, |
143 : | syskin | 935 | ptr + 8*stride + 8, stride); |
144 : | Isibaar | 3 | |
145 : | edgomez | 1053 | } else { /* reduced_resolution */ |
146 : | syskin | 935 | |
147 : | edgomez | 851 | x *= 2; y *= 2; |
148 : | |||
149 : | ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); | ||
150 : | syskin | 935 | |
151 : | edgomez | 851 | filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); |
152 : | filter_diff_18x18_to_8x8(dct_codes, ptr, stride); | ||
153 : | |||
154 : | filter_18x18_to_8x8(dct_codes+64, cur+y*stride + x + 16, stride); | ||
155 : | filter_diff_18x18_to_8x8(dct_codes+64, ptr + 16, stride); | ||
156 : | |||
157 : | filter_18x18_to_8x8(dct_codes+128, cur+(y+16)*stride + x, stride); | ||
158 : | filter_diff_18x18_to_8x8(dct_codes+128, ptr + 16*stride, stride); | ||
159 : | |||
160 : | filter_18x18_to_8x8(dct_codes+192, cur+(y+16)*stride + x + 16, stride); | ||
161 : | filter_diff_18x18_to_8x8(dct_codes+192, ptr + 16*stride + 16, stride); | ||
162 : | |||
163 : | transfer32x32_copy(cur + y*stride + x, ptr, stride); | ||
164 : | edgomez | 195 | } |
165 : | Isibaar | 3 | } |
166 : | |||
167 : | edgomez | 851 | static __inline void |
168 : | compensate8x8_interpolate( int16_t * const dct_codes, | ||
169 : | uint8_t * const cur, | ||
170 : | const uint8_t * const ref, | ||
171 : | const uint8_t * const refh, | ||
172 : | const uint8_t * const refv, | ||
173 : | const uint8_t * const refhv, | ||
174 : | uint8_t * const tmp, | ||
175 : | uint32_t x, | ||
176 : | uint32_t y, | ||
177 : | const int32_t dx, | ||
178 : | const int32_t dy, | ||
179 : | const int32_t stride, | ||
180 : | const int32_t quarterpel, | ||
181 : | const int reduced_resolution, | ||
182 : | const int32_t rounding) | ||
183 : | { | ||
184 : | const uint8_t * ptr; | ||
185 : | Isibaar | 3 | |
186 : | edgomez | 851 | if (!reduced_resolution) { |
187 : | Isibaar | 3 | |
188 : | edgomez | 851 | if(quarterpel) { |
189 : | if ((dx&3) | (dy&3)) { | ||
190 : | Isibaar | 1125 | #if defined(ARCH_IS_IA32) /* new_interpolate is only faster on x86 (MMX) machines */ |
191 : | new_interpolate8x8_quarterpel(tmp - y*stride - x, | ||
192 : | (uint8_t *) ref, tmp + 32, | ||
193 : | tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); | ||
194 : | #else | ||
195 : | edgomez | 851 | interpolate8x8_quarterpel(tmp - y*stride - x, |
196 : | (uint8_t *) ref, tmp + 32, | ||
197 : | tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding); | ||
198 : | Isibaar | 1125 | #endif |
199 : | edgomez | 851 | ptr = tmp; |
200 : | edgomez | 1053 | } else ptr = ref + (y + dy/4)*stride + x + dx/4; /* fullpixel position */ |
201 : | edgomez | 851 | } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); |
202 : | |||
203 : | transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride); | ||
204 : | |||
205 : | edgomez | 1053 | } else { /* reduced_resolution */ |
206 : | edgomez | 851 | |
207 : | x *= 2; y *= 2; | ||
208 : | |||
209 : | ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride); | ||
210 : | |||
211 : | filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride); | ||
212 : | filter_diff_18x18_to_8x8(dct_codes, ptr, stride); | ||
213 : | syskin | 935 | |
214 : | edgomez | 851 | transfer16x16_copy(cur + y*stride + x, ptr, stride); |
215 : | } | ||
216 : | } | ||
217 : | |||
218 : | /* XXX: slow, inelegant... */ | ||
219 : | static void | ||
220 : | interpolate18x18_switch(uint8_t * const cur, | ||
221 : | const uint8_t * const refn, | ||
222 : | const uint32_t x, | ||
223 : | const uint32_t y, | ||
224 : | const int32_t dx, | ||
225 : | const int dy, | ||
226 : | const int32_t stride, | ||
227 : | const int32_t rounding) | ||
228 : | { | ||
229 : | interpolate8x8_switch(cur, refn, x-1, y-1, dx, dy, stride, rounding); | ||
230 : | interpolate8x8_switch(cur, refn, x+7, y-1, dx, dy, stride, rounding); | ||
231 : | interpolate8x8_switch(cur, refn, x+9, y-1, dx, dy, stride, rounding); | ||
232 : | |||
233 : | interpolate8x8_switch(cur, refn, x-1, y+7, dx, dy, stride, rounding); | ||
234 : | interpolate8x8_switch(cur, refn, x+7, y+7, dx, dy, stride, rounding); | ||
235 : | interpolate8x8_switch(cur, refn, x+9, y+7, dx, dy, stride, rounding); | ||
236 : | |||
237 : | interpolate8x8_switch(cur, refn, x-1, y+9, dx, dy, stride, rounding); | ||
238 : | interpolate8x8_switch(cur, refn, x+7, y+9, dx, dy, stride, rounding); | ||
239 : | interpolate8x8_switch(cur, refn, x+9, y+9, dx, dy, stride, rounding); | ||
240 : | } | ||
241 : | |||
242 : | static void | ||
243 : | CompensateChroma( int dx, int dy, | ||
244 : | const int i, const int j, | ||
245 : | IMAGE * const Cur, | ||
246 : | const IMAGE * const Ref, | ||
247 : | uint8_t * const temp, | ||
248 : | int16_t * const coeff, | ||
249 : | const int32_t stride, | ||
250 : | const int rounding, | ||
251 : | const int rrv) | ||
252 : | { /* uv-block-based compensation */ | ||
253 : | |||
254 : | if (!rrv) { | ||
255 : | transfer_8to16sub(coeff, Cur->u + 8 * j * stride + 8 * i, | ||
256 : | syskin | 935 | interpolate8x8_switch2(temp, Ref->u, 8 * i, 8 * j, |
257 : | edgomez | 851 | dx, dy, stride, rounding), |
258 : | stride); | ||
259 : | transfer_8to16sub(coeff + 64, Cur->v + 8 * j * stride + 8 * i, | ||
260 : | syskin | 935 | interpolate8x8_switch2(temp, Ref->v, 8 * i, 8 * j, |
261 : | edgomez | 851 | dx, dy, stride, rounding), |
262 : | stride); | ||
263 : | } else { | ||
264 : | uint8_t * current, * reference; | ||
265 : | |||
266 : | current = Cur->u + 16*j*stride + 16*i; | ||
267 : | reference = temp - 16*j*stride - 16*i; | ||
268 : | interpolate18x18_switch(reference, Ref->u, 16*i, 16*j, dx, dy, stride, rounding); | ||
269 : | filter_18x18_to_8x8(coeff, current, stride); | ||
270 : | filter_diff_18x18_to_8x8(coeff, temp, stride); | ||
271 : | transfer16x16_copy(current, temp, stride); | ||
272 : | |||
273 : | current = Cur->v + 16*j*stride + 16*i; | ||
274 : | interpolate18x18_switch(reference, Ref->v, 16*i, 16*j, dx, dy, stride, rounding); | ||
275 : | filter_18x18_to_8x8(coeff + 64, current, stride); | ||
276 : | filter_diff_18x18_to_8x8(coeff + 64, temp, stride); | ||
277 : | transfer16x16_copy(current, temp, stride); | ||
278 : | } | ||
279 : | } | ||
280 : | |||
281 : | edgomez | 195 | void |
282 : | MBMotionCompensation(MACROBLOCK * const mb, | ||
283 : | syskin | 935 | const uint32_t i, |
284 : | const uint32_t j, | ||
285 : | const IMAGE * const ref, | ||
286 : | const IMAGE * const refh, | ||
287 : | const IMAGE * const refv, | ||
288 : | const IMAGE * const refhv, | ||
289 : | const IMAGE * const refGMC, | ||
290 : | IMAGE * const cur, | ||
291 : | int16_t * dct_codes, | ||
292 : | const uint32_t width, | ||
293 : | const uint32_t height, | ||
294 : | const uint32_t edged_width, | ||
295 : | const int32_t quarterpel, | ||
296 : | const int reduced_resolution, | ||
297 : | const int32_t rounding) | ||
298 : | Isibaar | 3 | { |
299 : | edgomez | 851 | int32_t dx; |
300 : | int32_t dy; | ||
301 : | Isibaar | 3 | |
302 : | edgomez | 851 | uint8_t * const tmp = refv->u; |
303 : | Isibaar | 3 | |
304 : | edgomez | 851 | if ( (!reduced_resolution) && (mb->mode == MODE_NOT_CODED) ) { /* quick copy for early SKIP */ |
305 : | /* early SKIP is only activated in P-VOPs, not in S-VOPs, so mcsel can never be 1 */ | ||
306 : | Isibaar | 3 | |
307 : | edgomez | 851 | transfer16x16_copy(cur->y + 16 * (i + j * edged_width), |
308 : | syskin | 935 | ref->y + 16 * (i + j * edged_width), |
309 : | edged_width); | ||
310 : | |||
311 : | edgomez | 851 | transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2), |
312 : | ref->u + 8 * (i + j * edged_width/2), | ||
313 : | edged_width / 2); | ||
314 : | transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2), | ||
315 : | ref->v + 8 * (i + j * edged_width/2), | ||
316 : | edged_width / 2); | ||
317 : | return; | ||
318 : | } | ||
319 : | Isibaar | 3 | |
320 : | syskin | 935 | if ((mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER |
321 : | edgomez | 851 | || mb->mode == MODE_INTER_Q)) { |
322 : | chl | 437 | |
323 : | edgomez | 851 | /* reduced resolution + GMC: not possible */ |
324 : | Isibaar | 3 | |
325 : | edgomez | 851 | if (mb->mcsel) { |
326 : | syskin | 935 | |
327 : | edgomez | 851 | /* call normal routine once, easier than "if (mcsel)"ing all the time */ |
328 : | syskin | 935 | |
329 : | edgomez | 851 | transfer_8to16sub(&dct_codes[0*64], cur->y + 16*j*edged_width + 16*i, |
330 : | syskin | 935 | refGMC->y + 16*j*edged_width + 16*i, edged_width); |
331 : | edgomez | 851 | transfer_8to16sub(&dct_codes[1*64], cur->y + 16*j*edged_width + 16*i+8, |
332 : | syskin | 935 | refGMC->y + 16*j*edged_width + 16*i+8, edged_width); |
333 : | edgomez | 851 | transfer_8to16sub(&dct_codes[2*64], cur->y + (16*j+8)*edged_width + 16*i, |
334 : | syskin | 935 | refGMC->y + (16*j+8)*edged_width + 16*i, edged_width); |
335 : | edgomez | 851 | transfer_8to16sub(&dct_codes[3*64], cur->y + (16*j+8)*edged_width + 16*i+8, |
336 : | syskin | 935 | refGMC->y + (16*j+8)*edged_width + 16*i+8, edged_width); |
337 : | chl | 437 | |
338 : | edgomez | 851 | /* lumi is needed earlier for mode decision, but chroma should be done block-based, but it isn't, yet. */ |
339 : | |||
340 : | transfer_8to16sub(&dct_codes[4 * 64], cur->u + 8 *j*edged_width/2 + 8*i, | ||
341 : | refGMC->u + 8 *j*edged_width/2 + 8*i, edged_width/2); | ||
342 : | |||
343 : | transfer_8to16sub(&dct_codes[5 * 64], cur->v + 8*j* edged_width/2 + 8*i, | ||
344 : | refGMC->v + 8*j* edged_width/2 + 8*i, edged_width/2); | ||
345 : | |||
346 : | return; | ||
347 : | } | ||
348 : | |||
349 : | /* ordinary compensation */ | ||
350 : | syskin | 935 | |
351 : | edgomez | 851 | dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x); |
352 : | dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y); | ||
353 : | |||
354 : | if (reduced_resolution) { | ||
355 : | dx = RRV_MV_SCALEUP(dx); | ||
356 : | dy = RRV_MV_SCALEUP(dy); | ||
357 : | } | ||
358 : | |||
359 : | compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y, | ||
360 : | refv->y, refhv->y, tmp, 16 * i, 16 * j, dx, dy, | ||
361 : | edged_width, quarterpel, reduced_resolution, rounding); | ||
362 : | |||
363 : | syskin | 935 | if (quarterpel) { dx /= 2; dy /= 2; } |
364 : | |||
365 : | edgomez | 851 | dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
366 : | dy = (dy >> 1) + roundtab_79[dy & 0x3]; | ||
367 : | |||
368 : | edgomez | 1053 | } else { /* mode == MODE_INTER4V */ |
369 : | edgomez | 851 | int k, sumx = 0, sumy = 0; |
370 : | const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs); | ||
371 : | |||
372 : | for (k = 0; k < 4; k++) { | ||
373 : | dx = mvs[k].x; | ||
374 : | dy = mvs[k].y; | ||
375 : | syskin | 935 | sumx += quarterpel ? dx/2 : dx; |
376 : | sumy += quarterpel ? dy/2 : dy; | ||
377 : | edgomez | 851 | |
378 : | if (reduced_resolution){ | ||
379 : | dx = RRV_MV_SCALEUP(dx); | ||
380 : | dy = RRV_MV_SCALEUP(dy); | ||
381 : | } | ||
382 : | |||
383 : | compensate8x8_interpolate(&dct_codes[k * 64], cur->y, ref->y, refh->y, | ||
384 : | refv->y, refhv->y, tmp, 16 * i + 8*(k&1), 16 * j + 8*(k>>1), dx, | ||
385 : | dy, edged_width, quarterpel, reduced_resolution, rounding); | ||
386 : | } | ||
387 : | dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; | ||
388 : | dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; | ||
389 : | } | ||
390 : | |||
391 : | CompensateChroma(dx, dy, i, j, cur, ref, tmp, | ||
392 : | &dct_codes[4 * 64], edged_width / 2, rounding, reduced_resolution); | ||
393 : | } | ||
394 : | |||
395 : | |||
396 : | void | ||
397 : | MBMotionCompensationBVOP(MBParam * pParam, | ||
398 : | MACROBLOCK * const mb, | ||
399 : | const uint32_t i, | ||
400 : | const uint32_t j, | ||
401 : | IMAGE * const cur, | ||
402 : | const IMAGE * const f_ref, | ||
403 : | const IMAGE * const f_refh, | ||
404 : | const IMAGE * const f_refv, | ||
405 : | const IMAGE * const f_refhv, | ||
406 : | const IMAGE * const b_ref, | ||
407 : | const IMAGE * const b_refh, | ||
408 : | const IMAGE * const b_refv, | ||
409 : | const IMAGE * const b_refhv, | ||
410 : | int16_t * dct_codes) | ||
411 : | { | ||
412 : | const uint32_t edged_width = pParam->edged_width; | ||
413 : | int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy; | ||
414 : | int k; | ||
415 : | edgomez | 949 | const int quarterpel = pParam->vol_flags & XVID_VOL_QUARTERPEL; |
416 : | edgomez | 851 | const uint8_t * ptr1, * ptr2; |
417 : | uint8_t * const tmp = f_refv->u; | ||
418 : | const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs); | ||
419 : | const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs); | ||
420 : | |||
421 : | switch (mb->mode) { | ||
422 : | case MODE_FORWARD: | ||
423 : | dx = fmvs->x; dy = fmvs->y; | ||
424 : | |||
425 : | compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y, | ||
426 : | f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx, | ||
427 : | dy, edged_width, quarterpel, 0, 0); | ||
428 : | |||
429 : | if (quarterpel) { dx /= 2; dy /= 2; } | ||
430 : | |||
431 : | CompensateChroma( (dx >> 1) + roundtab_79[dx & 0x3], | ||
432 : | (dy >> 1) + roundtab_79[dy & 0x3], | ||
433 : | i, j, cur, f_ref, tmp, | ||
434 : | &dct_codes[4 * 64], edged_width / 2, 0, 0); | ||
435 : | |||
436 : | return; | ||
437 : | |||
438 : | case MODE_BACKWARD: | ||
439 : | b_dx = bmvs->x; b_dy = bmvs->y; | ||
440 : | |||
441 : | syskin | 935 | compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y, |
442 : | edgomez | 851 | b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx, |
443 : | syskin | 935 | b_dy, edged_width, quarterpel, 0, 0); |
444 : | edgomez | 851 | |
445 : | if (quarterpel) { b_dx /= 2; b_dy /= 2; } | ||
446 : | |||
447 : | CompensateChroma( (b_dx >> 1) + roundtab_79[b_dx & 0x3], | ||
448 : | (b_dy >> 1) + roundtab_79[b_dy & 0x3], | ||
449 : | i, j, cur, b_ref, tmp, | ||
450 : | &dct_codes[4 * 64], edged_width / 2, 0, 0); | ||
451 : | |||
452 : | return; | ||
453 : | |||
454 : | case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */ | ||
455 : | case MODE_DIRECT_NO4V: | ||
456 : | dx = fmvs->x; dy = fmvs->y; | ||
457 : | b_dx = bmvs->x; b_dy = bmvs->y; | ||
458 : | |||
459 : | if (quarterpel) { | ||
460 : | syskin | 935 | |
461 : | edgomez | 851 | if ((dx&3) | (dy&3)) { |
462 : | interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width, | ||
463 : | (uint8_t *) f_ref->y, tmp + 32, | ||
464 : | tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0); | ||
465 : | ptr1 = tmp; | ||
466 : | edgomez | 1053 | } else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; /* fullpixel position */ |
467 : | edgomez | 851 | |
468 : | if ((b_dx&3) | (b_dy&3)) { | ||
469 : | interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16, | ||
470 : | (uint8_t *) b_ref->y, tmp + 32, | ||
471 : | tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0); | ||
472 : | ptr2 = tmp + 16; | ||
473 : | edgomez | 1053 | } else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; /* fullpixel position */ |
474 : | edgomez | 851 | |
475 : | b_dx /= 2; | ||
476 : | b_dy /= 2; | ||
477 : | dx /= 2; | ||
478 : | dy /= 2; | ||
479 : | |||
480 : | } else { | ||
481 : | ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, | ||
482 : | i, j, 16, dx, dy, edged_width); | ||
483 : | |||
484 : | ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, | ||
485 : | i, j, 16, b_dx, b_dy, edged_width); | ||
486 : | } | ||
487 : | for (k = 0; k < 4; k++) | ||
488 : | transfer_8to16sub2(&dct_codes[k * 64], | ||
489 : | cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, | ||
490 : | ptr1 + (k&1)*8 + (k>>1)*8*edged_width, | ||
491 : | ptr2 + (k&1)*8 + (k>>1)*8*edged_width, edged_width); | ||
492 : | |||
493 : | |||
494 : | dx = (dx >> 1) + roundtab_79[dx & 0x3]; | ||
495 : | dy = (dy >> 1) + roundtab_79[dy & 0x3]; | ||
496 : | |||
497 : | b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3]; | ||
498 : | b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3]; | ||
499 : | |||
500 : | break; | ||
501 : | syskin | 935 | |
502 : | edgomez | 1053 | default: /* MODE_DIRECT (or MODE_DIRECT_NONE_MV in case of bframes decoding) */ |
503 : | edgomez | 851 | sumx = sumy = b_sumx = b_sumy = 0; |
504 : | |||
505 : | for (k = 0; k < 4; k++) { | ||
506 : | syskin | 935 | |
507 : | edgomez | 851 | dx = fmvs[k].x; dy = fmvs[k].y; |
508 : | b_dx = bmvs[k].x; b_dy = bmvs[k].y; | ||
509 : | |||
510 : | if (quarterpel) { | ||
511 : | sumx += dx/2; sumy += dy/2; | ||
512 : | b_sumx += b_dx/2; b_sumy += b_dy/2; | ||
513 : | |||
514 : | if ((dx&3) | (dy&3)) { | ||
515 : | interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width, | ||
516 : | syskin | 935 | (uint8_t *) f_ref->y, |
517 : | tmp + 32, tmp + 64, tmp + 96, | ||
518 : | edgomez | 851 | 16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0); |
519 : | ptr1 = tmp; | ||
520 : | } else ptr1 = f_ref->y + (16*j + (k>>1)*8 + dy/4)*edged_width + 16*i + (k&1)*8 + dx/4; | ||
521 : | |||
522 : | if ((b_dx&3) | (b_dy&3)) { | ||
523 : | interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16, | ||
524 : | (uint8_t *) b_ref->y, | ||
525 : | syskin | 935 | tmp + 16, tmp + 32, tmp + 48, |
526 : | edgomez | 851 | 16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0); |
527 : | ptr2 = tmp + 16; | ||
528 : | } else ptr2 = b_ref->y + (16*j + (k>>1)*8 + b_dy/4)*edged_width + 16*i + (k&1)*8 + b_dx/4; | ||
529 : | } else { | ||
530 : | sumx += dx; sumy += dy; | ||
531 : | b_sumx += b_dx; b_sumy += b_dy; | ||
532 : | |||
533 : | syskin | 935 | ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y, |
534 : | edgomez | 851 | 2*i + (k&1), 2*j + (k>>1), 8, dx, dy, edged_width); |
535 : | syskin | 935 | ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y, |
536 : | edgomez | 851 | 2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy, edged_width); |
537 : | } | ||
538 : | transfer_8to16sub2(&dct_codes[k * 64], | ||
539 : | cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width, | ||
540 : | ptr1, ptr2, edged_width); | ||
541 : | syskin | 935 | |
542 : | edgomez | 851 | } |
543 : | |||
544 : | dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; | ||
545 : | dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; | ||
546 : | b_dx = (b_sumx >> 3) + roundtab_76[b_sumx & 0xf]; | ||
547 : | b_dy = (b_sumy >> 3) + roundtab_76[b_sumy & 0xf]; | ||
548 : | |||
549 : | break; | ||
550 : | } | ||
551 : | |||
552 : | edgomez | 1053 | /* v block-based chroma interpolation for direct and interpolate modes */ |
553 : | edgomez | 851 | transfer_8to16sub2(&dct_codes[4 * 64], |
554 : | cur->u + (j * 8) * edged_width / 2 + (i * 8), | ||
555 : | interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j, | ||
556 : | b_dx, b_dy, edged_width / 2, 0), | ||
557 : | interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j, | ||
558 : | dx, dy, edged_width / 2, 0), | ||
559 : | edged_width / 2); | ||
560 : | |||
561 : | transfer_8to16sub2(&dct_codes[5 * 64], | ||
562 : | cur->v + (j * 8) * edged_width / 2 + (i * 8), | ||
563 : | interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j, | ||
564 : | b_dx, b_dy, edged_width / 2, 0), | ||
565 : | interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j, | ||
566 : | dx, dy, edged_width / 2, 0), | ||
567 : | edged_width / 2); | ||
568 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |