[svn] / branches / dev-api-4 / xvidcore / src / motion / estimation_bvop.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/motion/estimation_bvop.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1273 - (view) (download)

1 : edgomez 1142 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Motion Estimation for B-VOPs -
5 :     *
6 :     * Copyright(C) 2002 Christoph Lampert <gruel@web.de>
7 :     * 2002 Michael Militzer <michael@xvid.org>
8 :     * 2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net>
9 :     *
10 :     * This program is free software ; you can redistribute it and/or modify
11 :     * it under the terms of the GNU General Public License as published by
12 :     * the Free Software Foundation ; either version 2 of the License, or
13 :     * (at your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful,
16 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     * GNU General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program ; if not, write to the Free Software
22 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 : Isibaar 1273 * $Id: estimation_bvop.c,v 1.1.2.8 2003-12-18 02:02:08 Isibaar Exp $
25 : edgomez 1142 *
26 :     ****************************************************************************/
27 :    
28 :    
29 :     #include <assert.h>
30 :     #include <stdio.h>
31 :     #include <stdlib.h>
32 :     #include <string.h> /* memcpy */
33 :    
34 :     #include "../encoder.h"
35 :     #include "../global.h"
36 :     #include "../image/interpolate8x8.h"
37 :     #include "estimation.h"
38 :     #include "motion.h"
39 :     #include "sad.h"
40 :     #include "motion_inlines.h"
41 :    
42 :    
43 :     static int32_t
44 :     ChromaSAD2(const int fx, const int fy, const int bx, const int by,
45 : syskin 1215 SearchData * const data)
46 : edgomez 1142 {
47 :     int sad;
48 :     const uint32_t stride = data->iEdgedWidth/2;
49 :     uint8_t *f_refu, *f_refv, *b_refu, *b_refv;
50 :    
51 :     const INTERPOLATE8X8_PTR interpolate8x8_halfpel[] = {
52 :     NULL,
53 :     interpolate8x8_halfpel_v,
54 :     interpolate8x8_halfpel_h,
55 :     interpolate8x8_halfpel_hv
56 :     };
57 :    
58 :     int offset = (fx>>1) + (fy>>1)*stride;
59 :     int filter = ((fx & 1) << 1) | (fy & 1);
60 :    
61 :     if (filter != 0) {
62 :     f_refu = data->RefQ;
63 :     f_refv = data->RefQ + 8;
64 :     interpolate8x8_halfpel[filter](f_refu, data->RefP[4] + offset, stride, data->rounding);
65 :     interpolate8x8_halfpel[filter](f_refv, data->RefP[5] + offset, stride, data->rounding);
66 :     } else {
67 :     f_refu = (uint8_t*)data->RefP[4] + offset;
68 :     f_refv = (uint8_t*)data->RefP[5] + offset;
69 :     }
70 :    
71 :     offset = (bx>>1) + (by>>1)*stride;
72 :     filter = ((bx & 1) << 1) | (by & 1);
73 :    
74 :     if (filter != 0) {
75 :     b_refu = data->RefQ + 16;
76 :     b_refv = data->RefQ + 24;
77 :     interpolate8x8_halfpel[filter](b_refu, data->b_RefP[4] + offset, stride, data->rounding);
78 :     interpolate8x8_halfpel[filter](b_refv, data->b_RefP[5] + offset, stride, data->rounding);
79 :     } else {
80 :     b_refu = (uint8_t*)data->b_RefP[4] + offset;
81 :     b_refv = (uint8_t*)data->b_RefP[5] + offset;
82 :     }
83 :    
84 :     sad = sad8bi(data->CurU, b_refu, f_refu, stride);
85 :     sad += sad8bi(data->CurV, b_refv, f_refv, stride);
86 :    
87 :     return sad;
88 :     }
89 :    
90 :     static void
91 : syskin 1215 CheckCandidateInt(const int x, const int y, SearchData * const data, const unsigned int Direction)
92 : edgomez 1142 {
93 : syskin 1215 int32_t sad, xf, yf, xb, yb, xcf, ycf, xcb, ycb;
94 : edgomez 1142 uint32_t t;
95 : syskin 1215
96 : edgomez 1142 const uint8_t *ReferenceF, *ReferenceB;
97 :     VECTOR *current;
98 :    
99 : syskin 1215 if ((x > data->max_dx) || (x < data->min_dx) ||
100 :     (y > data->max_dy) || (y < data->min_dy))
101 : edgomez 1142 return;
102 :    
103 : syskin 1215 if (Direction == 1) { /* x and y mean forward vector */
104 :     VECTOR backward = data->qpel_precision ? data->currentQMV[1] : data->currentMV[1];
105 :     xb = backward.x;
106 :     yb = backward.y;
107 :     xf = x; yf = y;
108 :     } else { /* x and y mean backward vector */
109 :     VECTOR forward = data->qpel_precision ? data->currentQMV[0] : data->currentMV[0];
110 :     xf = forward.x;
111 :     yf = forward.y;
112 :     xb = x; yb = y;
113 :     }
114 :    
115 : edgomez 1142 if (!data->qpel_precision) {
116 :     ReferenceF = GetReference(xf, yf, data);
117 :     ReferenceB = GetReferenceB(xb, yb, 1, data);
118 : syskin 1215 current = data->currentMV + Direction - 1;
119 : edgomez 1142 xcf = xf; ycf = yf;
120 :     xcb = xb; ycb = yb;
121 :     } else {
122 :     ReferenceF = xvid_me_interpolate16x16qpel(xf, yf, 0, data);
123 : syskin 1215 current = data->currentQMV + Direction - 1;
124 : edgomez 1142 ReferenceB = xvid_me_interpolate16x16qpel(xb, yb, 1, data);
125 :     xcf = xf/2; ycf = yf/2;
126 :     xcb = xb/2; ycb = yb/2;
127 :     }
128 :    
129 :     t = d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0)
130 :     + d_mv_bits(xb, yb, data->bpredMV, data->iFcode, data->qpel^data->qpel_precision, 0);
131 :    
132 :     sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth);
133 :     sad += (data->lambda16 * t * sad)>>10;
134 :    
135 :     if (data->chroma && sad < *data->iMinSAD)
136 :     sad += ChromaSAD2((xcf >> 1) + roundtab_79[xcf & 0x3],
137 :     (ycf >> 1) + roundtab_79[ycf & 0x3],
138 :     (xcb >> 1) + roundtab_79[xcb & 0x3],
139 :     (ycb >> 1) + roundtab_79[ycb & 0x3], data);
140 :    
141 :     if (sad < *(data->iMinSAD)) {
142 : syskin 1215 *data->iMinSAD = sad;
143 :     current->x = x; current->y = y;
144 :     data->dir = Direction;
145 : edgomez 1142 }
146 :     }
147 :    
148 :     static void
149 : syskin 1215 CheckCandidateDirect(const int x, const int y, SearchData * const data, const unsigned int Direction)
150 : edgomez 1142 {
151 :     int32_t sad = 0, xcf = 0, ycf = 0, xcb = 0, ycb = 0;
152 :     uint32_t k;
153 :     const uint8_t *ReferenceF;
154 :     const uint8_t *ReferenceB;
155 :     VECTOR mvs, b_mvs;
156 :    
157 :     if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return;
158 :    
159 :     for (k = 0; k < 4; k++) {
160 :     mvs.x = data->directmvF[k].x + x;
161 :     b_mvs.x = ((x == 0) ?
162 :     data->directmvB[k].x
163 :     : mvs.x - data->referencemv[k].x);
164 :    
165 :     mvs.y = data->directmvF[k].y + y;
166 :     b_mvs.y = ((y == 0) ?
167 :     data->directmvB[k].y
168 :     : mvs.y - data->referencemv[k].y);
169 :    
170 :     if ((mvs.x > data->max_dx) || (mvs.x < data->min_dx) ||
171 :     (mvs.y > data->max_dy) || (mvs.y < data->min_dy) ||
172 :     (b_mvs.x > data->max_dx) || (b_mvs.x < data->min_dx) ||
173 :     (b_mvs.y > data->max_dy) || (b_mvs.y < data->min_dy) )
174 :     return;
175 :    
176 :     if (data->qpel) {
177 :     xcf += mvs.x/2; ycf += mvs.y/2;
178 :     xcb += b_mvs.x/2; ycb += b_mvs.y/2;
179 :     } else {
180 :     xcf += mvs.x; ycf += mvs.y;
181 :     xcb += b_mvs.x; ycb += b_mvs.y;
182 :     mvs.x *= 2; mvs.y *= 2; /* we move to qpel precision anyway */
183 :     b_mvs.x *= 2; b_mvs.y *= 2;
184 :     }
185 :    
186 :     ReferenceF = xvid_me_interpolate8x8qpel(mvs.x, mvs.y, k, 0, data);
187 :     ReferenceB = xvid_me_interpolate8x8qpel(b_mvs.x, b_mvs.y, k, 1, data);
188 :    
189 :     sad += sad8bi(data->Cur + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth),
190 :     ReferenceF, ReferenceB, data->iEdgedWidth);
191 :     if (sad > *(data->iMinSAD)) return;
192 :     }
193 :    
194 :     sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)>>10;
195 :    
196 :     if (data->chroma && sad < *data->iMinSAD)
197 :     sad += ChromaSAD2((xcf >> 3) + roundtab_76[xcf & 0xf],
198 :     (ycf >> 3) + roundtab_76[ycf & 0xf],
199 :     (xcb >> 3) + roundtab_76[xcb & 0xf],
200 :     (ycb >> 3) + roundtab_76[ycb & 0xf], data);
201 :    
202 :     if (sad < *(data->iMinSAD)) {
203 : syskin 1215 data->iMinSAD[0] = sad;
204 : edgomez 1142 data->currentMV->x = x; data->currentMV->y = y;
205 : syskin 1215 data->dir = Direction;
206 : edgomez 1142 }
207 :     }
208 :    
209 :     static void
210 : syskin 1215 CheckCandidateDirectno4v(const int x, const int y, SearchData * const data, const unsigned int Direction)
211 : edgomez 1142 {
212 :     int32_t sad, xcf, ycf, xcb, ycb;
213 :     const uint8_t *ReferenceF;
214 :     const uint8_t *ReferenceB;
215 :     VECTOR mvs, b_mvs;
216 :    
217 :     if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return;
218 :    
219 :     mvs.x = data->directmvF[0].x + x;
220 :     b_mvs.x = ((x == 0) ?
221 :     data->directmvB[0].x
222 :     : mvs.x - data->referencemv[0].x);
223 :    
224 :     mvs.y = data->directmvF[0].y + y;
225 :     b_mvs.y = ((y == 0) ?
226 :     data->directmvB[0].y
227 :     : mvs.y - data->referencemv[0].y);
228 :    
229 :     if ( (mvs.x > data->max_dx) || (mvs.x < data->min_dx)
230 :     || (mvs.y > data->max_dy) || (mvs.y < data->min_dy)
231 :     || (b_mvs.x > data->max_dx) || (b_mvs.x < data->min_dx)
232 :     || (b_mvs.y > data->max_dy) || (b_mvs.y < data->min_dy) ) return;
233 :    
234 :     if (data->qpel) {
235 :     xcf = 4*(mvs.x/2); ycf = 4*(mvs.y/2);
236 :     xcb = 4*(b_mvs.x/2); ycb = 4*(b_mvs.y/2);
237 :     ReferenceF = xvid_me_interpolate16x16qpel(mvs.x, mvs.y, 0, data);
238 :     ReferenceB = xvid_me_interpolate16x16qpel(b_mvs.x, b_mvs.y, 1, data);
239 :     } else {
240 :     xcf = 4*mvs.x; ycf = 4*mvs.y;
241 :     xcb = 4*b_mvs.x; ycb = 4*b_mvs.y;
242 :     ReferenceF = GetReference(mvs.x, mvs.y, data);
243 :     ReferenceB = GetReferenceB(b_mvs.x, b_mvs.y, 1, data);
244 :     }
245 :    
246 :     sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth);
247 :     sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)>>10;
248 :    
249 :     if (data->chroma && sad < *data->iMinSAD)
250 :     sad += ChromaSAD2((xcf >> 3) + roundtab_76[xcf & 0xf],
251 :     (ycf >> 3) + roundtab_76[ycf & 0xf],
252 :     (xcb >> 3) + roundtab_76[xcb & 0xf],
253 :     (ycb >> 3) + roundtab_76[ycb & 0xf], data);
254 :    
255 :     if (sad < *(data->iMinSAD)) {
256 :     *(data->iMinSAD) = sad;
257 :     data->currentMV->x = x; data->currentMV->y = y;
258 : syskin 1215 data->dir = Direction;
259 : edgomez 1142 }
260 :     }
261 :    
262 :     void
263 : syskin 1215 CheckCandidate16no4v(const int x, const int y, SearchData * const data, const unsigned int Direction)
264 : edgomez 1142 {
265 :     int32_t sad, xc, yc;
266 :     const uint8_t * Reference;
267 :     uint32_t t;
268 :     VECTOR * current;
269 :    
270 :     if ( (x > data->max_dx) || ( x < data->min_dx)
271 :     || (y > data->max_dy) || (y < data->min_dy) ) return;
272 :    
273 :     if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; /* non-zero even value */
274 :    
275 :     if (data->qpel_precision) { /* x and y are in 1/4 precision */
276 :     Reference = xvid_me_interpolate16x16qpel(x, y, 0, data);
277 :     current = data->currentQMV;
278 :     xc = x/2; yc = y/2;
279 :     } else {
280 :     Reference = GetReference(x, y, data);
281 :     current = data->currentMV;
282 :     xc = x; yc = y;
283 :     }
284 :     t = d_mv_bits(x, y, data->predMV, data->iFcode,
285 :     data->qpel^data->qpel_precision, data->rrv);
286 :    
287 :     sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096);
288 :     sad += (data->lambda16 * t * sad)>>10;
289 :    
290 :     if (data->chroma && sad < *data->iMinSAD)
291 :     sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3],
292 :     (yc >> 1) + roundtab_79[yc & 0x3], data);
293 :    
294 :     if (sad < *(data->iMinSAD)) {
295 :     *(data->iMinSAD) = sad;
296 :     current->x = x; current->y = y;
297 : syskin 1215 data->dir = Direction;
298 : edgomez 1142 }
299 :     }
300 :    
301 : Isibaar 1273 void
302 :     CheckCandidate16no4v_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction)
303 :     {
304 :     int32_t sad, xc, yc;
305 :     const uint8_t * Reference;
306 :     uint32_t t;
307 :    
308 :     if ( (x > data->max_dx) || ( x < data->min_dx)
309 :     || (y > data->max_dy) || (y < data->min_dy) ) return;
310 :    
311 :     if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; /* non-zero even value */
312 :    
313 :     Reference = xvid_me_interpolate16x16qpel(x, y, 0, data);
314 :    
315 :     xc = x/2; yc = y/2;
316 :     t = d_mv_bits(x, y, data->predMV, data->iFcode,
317 :     data->qpel^data->qpel_precision, data->rrv);
318 :    
319 :     sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096);
320 :     sad += (data->lambda16 * t * sad)>>10;
321 :    
322 :     if (data->chroma && sad < *data->iMinSAD)
323 :     sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3],
324 :     (yc >> 1) + roundtab_79[yc & 0x3], data);
325 :    
326 :     if (sad < *(data->iMinSAD)) {
327 :     data->iMinSAD2 = *(data->iMinSAD);
328 :     data->currentQMV2.x = data->currentQMV->x;
329 :     data->currentQMV2.y = data->currentQMV->y;
330 :    
331 :     data->iMinSAD[0] = sad;
332 :     data->currentQMV[0].x = x; data->currentQMV[0].y = y;
333 :     } else if (sad < data->iMinSAD2) {
334 :     data->iMinSAD2 = sad;
335 :     data->currentQMV2.x = x; data->currentQMV2.y = y;
336 :     }
337 :     }
338 :    
339 : edgomez 1142 static __inline VECTOR
340 :     ChoosePred(const MACROBLOCK * const pMB, const uint32_t mode)
341 :     {
342 :     /* the stupidiest function ever */
343 : syskin 1215 return (mode == MODE_FORWARD ? pMB->mvs[0] : pMB->b_mvs[0]);
344 : edgomez 1142 }
345 :    
346 :     static void __inline
347 :     PreparePredictionsBF(VECTOR * const pmv, const int x, const int y,
348 :     const uint32_t iWcount,
349 :     const MACROBLOCK * const pMB,
350 :     const uint32_t mode_curr)
351 :     {
352 :    
353 :     /* [0] is prediction */
354 :     pmv[0].x = EVEN(pmv[0].x); pmv[0].y = EVEN(pmv[0].y);
355 :    
356 :     pmv[1].x = pmv[1].y = 0; /* [1] is zero */
357 :    
358 :     pmv[2] = ChoosePred(pMB, mode_curr);
359 :     pmv[2].x = EVEN(pmv[2].x); pmv[2].y = EVEN(pmv[2].y);
360 :    
361 :     if ((y != 0)&&(x != (int)(iWcount+1))) { /* [3] top-right neighbour */
362 :     pmv[3] = ChoosePred(pMB+1-iWcount, mode_curr);
363 :     pmv[3].x = EVEN(pmv[3].x); pmv[3].y = EVEN(pmv[3].y);
364 :     } else pmv[3].x = pmv[3].y = 0;
365 :    
366 :     if (y != 0) {
367 :     pmv[4] = ChoosePred(pMB-iWcount, mode_curr);
368 :     pmv[4].x = EVEN(pmv[4].x); pmv[4].y = EVEN(pmv[4].y);
369 :     } else pmv[4].x = pmv[4].y = 0;
370 :    
371 :     if (x != 0) {
372 :     pmv[5] = ChoosePred(pMB-1, mode_curr);
373 :     pmv[5].x = EVEN(pmv[5].x); pmv[5].y = EVEN(pmv[5].y);
374 :     } else pmv[5].x = pmv[5].y = 0;
375 :    
376 :     if (x != 0 && y != 0) {
377 :     pmv[6] = ChoosePred(pMB-1-iWcount, mode_curr);
378 :     pmv[6].x = EVEN(pmv[6].x); pmv[6].y = EVEN(pmv[6].y);
379 :     } else pmv[6].x = pmv[6].y = 0;
380 :     }
381 :    
382 :    
383 :     /* search backward or forward */
384 :     static void
385 :     SearchBF( const IMAGE * const pRef,
386 :     const uint8_t * const pRefH,
387 :     const uint8_t * const pRefV,
388 :     const uint8_t * const pRefHV,
389 :     const int x, const int y,
390 :     const uint32_t MotionFlags,
391 :     const uint32_t iFcode,
392 :     const MBParam * const pParam,
393 :     MACROBLOCK * const pMB,
394 :     const VECTOR * const predMV,
395 :     int32_t * const best_sad,
396 :     const int32_t mode_current,
397 :     SearchData * const Data)
398 :     {
399 :    
400 :     int i;
401 :     VECTOR pmv[7];
402 :     *Data->iMinSAD = MV_MAX_ERROR;
403 :     Data->iFcode = iFcode;
404 :     Data->qpel_precision = 0;
405 : syskin 1237 Data->chromaX = Data->chromaY = Data->chromaSAD = 256*4096; /* reset chroma-sad cache */
406 : edgomez 1142
407 :     Data->RefP[0] = pRef->y + (x + Data->iEdgedWidth*y) * 16;
408 :     Data->RefP[2] = pRefH + (x + Data->iEdgedWidth*y) * 16;
409 :     Data->RefP[1] = pRefV + (x + Data->iEdgedWidth*y) * 16;
410 :     Data->RefP[3] = pRefHV + (x + Data->iEdgedWidth*y) * 16;
411 :     Data->RefP[4] = pRef->u + (x + y * (Data->iEdgedWidth/2)) * 8;
412 :     Data->RefP[5] = pRef->v + (x + y * (Data->iEdgedWidth/2)) * 8;
413 :    
414 :     Data->predMV = *predMV;
415 :    
416 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
417 :     pParam->width, pParam->height, iFcode - Data->qpel, 1, 0);
418 :    
419 :     pmv[0] = Data->predMV;
420 :     if (Data->qpel) { pmv[0].x /= 2; pmv[0].y /= 2; }
421 :    
422 :     PreparePredictionsBF(pmv, x, y, pParam->mb_width, pMB, mode_current);
423 :    
424 :     Data->currentMV->x = Data->currentMV->y = 0;
425 :    
426 :     /* main loop. checking all predictions */
427 :     for (i = 0; i < 7; i++)
428 :     if (!vector_repeats(pmv, i) )
429 :     CheckCandidate16no4v(pmv[i].x, pmv[i].y, Data, i);
430 :    
431 :     if (*Data->iMinSAD > 512) {
432 : syskin 1215 unsigned int mask = make_mask(pmv, 7, Data->dir);
433 : syskin 1237
434 :     MainSearchFunc *MainSearchPtr;
435 :     if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;
436 :     else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;
437 :     else MainSearchPtr = xvid_me_DiamondSearch;
438 :    
439 : edgomez 1142 MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v);
440 :     }
441 :    
442 :     xvid_me_SubpelRefine(Data, CheckCandidate16no4v);
443 :    
444 :     if (Data->qpel && *Data->iMinSAD < *best_sad + 300) {
445 :     Data->currentQMV->x = 2*Data->currentMV->x;
446 :     Data->currentQMV->y = 2*Data->currentMV->y;
447 :     Data->qpel_precision = 1;
448 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
449 :     pParam->width, pParam->height, iFcode, 2, 0);
450 : Isibaar 1273
451 :     if (MotionFlags & XVID_ME_QUARTERPELREFINE16) {
452 :     if(MotionFlags & XVID_ME_FASTREFINE16)
453 :     SubpelRefine_Fast(Data, CheckCandidate16no4v_qpel);
454 :     else
455 :     xvid_me_SubpelRefine(Data, CheckCandidate16no4v);
456 :     }
457 : edgomez 1142 }
458 :    
459 :     /* three bits are needed to code backward mode. four for forward */
460 :    
461 :     if (mode_current == MODE_FORWARD) *Data->iMinSAD += 4 * Data->lambda16;
462 :     else *Data->iMinSAD += 3 * Data->lambda16;
463 :    
464 :     if (*Data->iMinSAD < *best_sad) {
465 :     *best_sad = *Data->iMinSAD;
466 :     pMB->mode = mode_current;
467 :     if (Data->qpel) {
468 :     pMB->pmvs[0].x = Data->currentQMV->x - predMV->x;
469 :     pMB->pmvs[0].y = Data->currentQMV->y - predMV->y;
470 :     if (mode_current == MODE_FORWARD)
471 :     pMB->qmvs[0] = *Data->currentQMV;
472 :     else
473 :     pMB->b_qmvs[0] = *Data->currentQMV;
474 :     } else {
475 :     pMB->pmvs[0].x = Data->currentMV->x - predMV->x;
476 :     pMB->pmvs[0].y = Data->currentMV->y - predMV->y;
477 :     }
478 :     if (mode_current == MODE_FORWARD) pMB->mvs[0] = *Data->currentMV;
479 :     else pMB->b_mvs[0] = *Data->currentMV;
480 :     }
481 :    
482 :     if (mode_current == MODE_FORWARD) *(Data->currentMV+2) = *Data->currentMV;
483 :     else *(Data->currentMV+1) = *Data->currentMV; /* we store currmv for interpolate search */
484 :     }
485 :    
486 :     static void
487 :     SkipDecisionB(const IMAGE * const pCur,
488 :     const IMAGE * const f_Ref,
489 :     const IMAGE * const b_Ref,
490 :     MACROBLOCK * const pMB,
491 :     const uint32_t x, const uint32_t y,
492 :     const SearchData * const Data)
493 :     {
494 :     int k;
495 :    
496 : syskin 1237 if (!Data->chroma) {
497 :     int dx = 0, dy = 0, b_dx = 0, b_dy = 0;
498 :     int32_t sum;
499 :     const uint32_t stride = Data->iEdgedWidth/2;
500 :     /* this is not full chroma compensation, only it's fullpel approximation. should work though */
501 : edgomez 1142
502 : syskin 1237 for (k = 0; k < 4; k++) {
503 :     dy += Data->directmvF[k].y >> Data->qpel;
504 :     dx += Data->directmvF[k].x >> Data->qpel;
505 :     b_dy += Data->directmvB[k].y >> Data->qpel;
506 :     b_dx += Data->directmvB[k].x >> Data->qpel;
507 :     }
508 : edgomez 1142
509 : syskin 1237 dy = (dy >> 3) + roundtab_76[dy & 0xf];
510 :     dx = (dx >> 3) + roundtab_76[dx & 0xf];
511 :     b_dy = (b_dy >> 3) + roundtab_76[b_dy & 0xf];
512 :     b_dx = (b_dx >> 3) + roundtab_76[b_dx & 0xf];
513 : edgomez 1142
514 : syskin 1237 sum = sad8bi(pCur->u + 8 * x + 8 * y * stride,
515 :     f_Ref->u + (y*8 + dy/2) * stride + x*8 + dx/2,
516 :     b_Ref->u + (y*8 + b_dy/2) * stride + x*8 + b_dx/2,
517 :     stride);
518 : edgomez 1142
519 : syskin 1237 if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */
520 : edgomez 1142
521 : syskin 1237 sum += sad8bi(pCur->v + 8*x + 8 * y * stride,
522 :     f_Ref->v + (y*8 + dy/2) * stride + x*8 + dx/2,
523 :     b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2,
524 :     stride);
525 :    
526 :     if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */
527 : edgomez 1142 }
528 : syskin 1237
529 :     /* skip */
530 :     pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */
531 :     for (k = 0; k < 4; k++) {
532 :     pMB->qmvs[k] = pMB->mvs[k] = Data->directmvF[k];
533 :     pMB->b_qmvs[k] = pMB->b_mvs[k] = Data->directmvB[k];
534 :     }
535 : edgomez 1142 }
536 :    
537 :     static uint32_t
538 :     SearchDirect(const IMAGE * const f_Ref,
539 :     const uint8_t * const f_RefH,
540 :     const uint8_t * const f_RefV,
541 :     const uint8_t * const f_RefHV,
542 :     const IMAGE * const b_Ref,
543 :     const uint8_t * const b_RefH,
544 :     const uint8_t * const b_RefV,
545 :     const uint8_t * const b_RefHV,
546 :     const IMAGE * const pCur,
547 :     const int x, const int y,
548 :     const uint32_t MotionFlags,
549 :     const int32_t TRB, const int32_t TRD,
550 :     const MBParam * const pParam,
551 :     MACROBLOCK * const pMB,
552 :     const MACROBLOCK * const b_mb,
553 :     int32_t * const best_sad,
554 :     SearchData * const Data)
555 :    
556 :     {
557 :     int32_t skip_sad;
558 :     int k = (x + Data->iEdgedWidth*y) * 16;
559 :     MainSearchFunc *MainSearchPtr;
560 :     CheckFunc * CheckCandidate;
561 :    
562 :     *Data->iMinSAD = 256*4096;
563 :     Data->RefP[0] = f_Ref->y + k;
564 :     Data->RefP[2] = f_RefH + k;
565 :     Data->RefP[1] = f_RefV + k;
566 :     Data->RefP[3] = f_RefHV + k;
567 :     Data->b_RefP[0] = b_Ref->y + k;
568 :     Data->b_RefP[2] = b_RefH + k;
569 :     Data->b_RefP[1] = b_RefV + k;
570 :     Data->b_RefP[3] = b_RefHV + k;
571 :     Data->RefP[4] = f_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8;
572 :     Data->RefP[5] = f_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8;
573 :     Data->b_RefP[4] = b_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8;
574 :     Data->b_RefP[5] = b_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8;
575 :    
576 :     k = Data->qpel ? 4 : 2;
577 :     Data->max_dx = k * (pParam->width - x * 16);
578 :     Data->max_dy = k * (pParam->height - y * 16);
579 :     Data->min_dx = -k * (16 + x * 16);
580 :     Data->min_dy = -k * (16 + y * 16);
581 :    
582 :     Data->referencemv = Data->qpel ? b_mb->qmvs : b_mb->mvs;
583 :     Data->qpel_precision = 0;
584 :    
585 :     for (k = 0; k < 4; k++) {
586 :     pMB->mvs[k].x = Data->directmvF[k].x = ((TRB * Data->referencemv[k].x) / TRD);
587 :     pMB->b_mvs[k].x = Data->directmvB[k].x = ((TRB - TRD) * Data->referencemv[k].x) / TRD;
588 :     pMB->mvs[k].y = Data->directmvF[k].y = ((TRB * Data->referencemv[k].y) / TRD);
589 :     pMB->b_mvs[k].y = Data->directmvB[k].y = ((TRB - TRD) * Data->referencemv[k].y) / TRD;
590 :    
591 :     if ( (pMB->b_mvs[k].x > Data->max_dx) | (pMB->b_mvs[k].x < Data->min_dx)
592 :     | (pMB->b_mvs[k].y > Data->max_dy) | (pMB->b_mvs[k].y < Data->min_dy) ) {
593 :    
594 :     *best_sad = 256*4096; /* in that case, we won't use direct mode */
595 :     pMB->mode = MODE_DIRECT; /* just to make sure it doesn't say "MODE_DIRECT_NONE_MV" */
596 :     pMB->b_mvs[0].x = pMB->b_mvs[0].y = 0;
597 :     return 256*4096;
598 :     }
599 :     if (b_mb->mode != MODE_INTER4V) {
600 :     pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mvs[0];
601 :     pMB->b_mvs[1] = pMB->b_mvs[2] = pMB->b_mvs[3] = pMB->b_mvs[0];
602 :     Data->directmvF[1] = Data->directmvF[2] = Data->directmvF[3] = Data->directmvF[0];
603 :     Data->directmvB[1] = Data->directmvB[2] = Data->directmvB[3] = Data->directmvB[0];
604 :     break;
605 :     }
606 :     }
607 :    
608 :     CheckCandidate = b_mb->mode == MODE_INTER4V ? CheckCandidateDirect : CheckCandidateDirectno4v;
609 :    
610 :     CheckCandidate(0, 0, Data, 255);
611 :    
612 :     /* initial (fast) skip decision */
613 : edgomez 1160 if (*Data->iMinSAD < (int)Data->iQuant * INITIAL_SKIP_THRESH * (Data->chroma?3:2)) {
614 : edgomez 1142 /* possible skip */
615 : syskin 1237 SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data);
616 :     if (pMB->mode == MODE_DIRECT_NONE_MV) return *Data->iMinSAD; /* skipped */
617 : edgomez 1142 }
618 :    
619 :     *Data->iMinSAD += Data->lambda16;
620 :     skip_sad = *Data->iMinSAD;
621 :    
622 : Isibaar 1273 if (!(MotionFlags & XVID_ME_SKIP_DELTASEARCH)) {
623 :     if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;
624 :     else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;
625 :     else MainSearchPtr = xvid_me_DiamondSearch;
626 : edgomez 1142
627 : Isibaar 1273 MainSearchPtr(0, 0, Data, 255, CheckCandidate);
628 : edgomez 1142
629 : Isibaar 1273 xvid_me_SubpelRefine(Data, CheckCandidate);
630 :     }
631 : edgomez 1142
632 :     *best_sad = *Data->iMinSAD;
633 :    
634 :     if (Data->qpel || b_mb->mode == MODE_INTER4V) pMB->mode = MODE_DIRECT;
635 :     else pMB->mode = MODE_DIRECT_NO4V; /* for faster compensation */
636 :    
637 :     pMB->pmvs[3] = *Data->currentMV;
638 :    
639 :     for (k = 0; k < 4; k++) {
640 :     pMB->mvs[k].x = Data->directmvF[k].x + Data->currentMV->x;
641 :     pMB->b_mvs[k].x = ( (Data->currentMV->x == 0)
642 :     ? Data->directmvB[k].x
643 :     :pMB->mvs[k].x - Data->referencemv[k].x);
644 :     pMB->mvs[k].y = (Data->directmvF[k].y + Data->currentMV->y);
645 :     pMB->b_mvs[k].y = ((Data->currentMV->y == 0)
646 :     ? Data->directmvB[k].y
647 :     : pMB->mvs[k].y - Data->referencemv[k].y);
648 :     if (Data->qpel) {
649 :     pMB->qmvs[k].x = pMB->mvs[k].x; pMB->mvs[k].x /= 2;
650 :     pMB->b_qmvs[k].x = pMB->b_mvs[k].x; pMB->b_mvs[k].x /= 2;
651 :     pMB->qmvs[k].y = pMB->mvs[k].y; pMB->mvs[k].y /= 2;
652 :     pMB->b_qmvs[k].y = pMB->b_mvs[k].y; pMB->b_mvs[k].y /= 2;
653 :     }
654 :    
655 :     if (b_mb->mode != MODE_INTER4V) {
656 :     pMB->mvs[3] = pMB->mvs[2] = pMB->mvs[1] = pMB->mvs[0];
657 :     pMB->b_mvs[3] = pMB->b_mvs[2] = pMB->b_mvs[1] = pMB->b_mvs[0];
658 :     pMB->qmvs[3] = pMB->qmvs[2] = pMB->qmvs[1] = pMB->qmvs[0];
659 :     pMB->b_qmvs[3] = pMB->b_qmvs[2] = pMB->b_qmvs[1] = pMB->b_qmvs[0];
660 :     break;
661 :     }
662 :     }
663 :     return skip_sad;
664 :     }
665 :    
666 : syskin 1215
667 :     static void set_range(int * range, SearchData * Data)
668 :     {
669 :     Data->min_dx = range[0];
670 :     Data->max_dx = range[1];
671 :     Data->min_dy = range[2];
672 :     Data->max_dy = range[3];
673 :     }
674 :    
675 : edgomez 1142 static void
676 : syskin 1215 SubpelRefine_dir(SearchData * const data, CheckFunc * const CheckCandidate, const int dir)
677 :     {
678 :     /* Do a half-pel or q-pel refinement */
679 :     const VECTOR centerMV = data->qpel_precision ?
680 :     data->currentQMV[dir-1] : data->currentMV[dir-1];
681 :    
682 :     CHECK_CANDIDATE(centerMV.x, centerMV.y - 1, dir);
683 :     CHECK_CANDIDATE(centerMV.x + 1, centerMV.y - 1, dir);
684 :     CHECK_CANDIDATE(centerMV.x + 1, centerMV.y, dir);
685 :     CHECK_CANDIDATE(centerMV.x + 1, centerMV.y + 1, dir);
686 :     CHECK_CANDIDATE(centerMV.x, centerMV.y + 1, dir);
687 :     CHECK_CANDIDATE(centerMV.x - 1, centerMV.y + 1, dir);
688 :     CHECK_CANDIDATE(centerMV.x - 1, centerMV.y, dir);
689 :     CHECK_CANDIDATE(centerMV.x - 1, centerMV.y - 1, dir);
690 :     }
691 :    
692 :     static void
693 : edgomez 1142 SearchInterpolate(const IMAGE * const f_Ref,
694 :     const uint8_t * const f_RefH,
695 :     const uint8_t * const f_RefV,
696 :     const uint8_t * const f_RefHV,
697 :     const IMAGE * const b_Ref,
698 :     const uint8_t * const b_RefH,
699 :     const uint8_t * const b_RefV,
700 :     const uint8_t * const b_RefHV,
701 :     const int x, const int y,
702 :     const uint32_t fcode,
703 :     const uint32_t bcode,
704 :     const uint32_t MotionFlags,
705 :     const MBParam * const pParam,
706 :     const VECTOR * const f_predMV,
707 :     const VECTOR * const b_predMV,
708 :     MACROBLOCK * const pMB,
709 :     int32_t * const best_sad,
710 : syskin 1215 SearchData * const Data)
711 : edgomez 1142
712 :     {
713 :     int i, j;
714 : syskin 1215 int b_range[4], f_range[4];
715 : edgomez 1142
716 : syskin 1215 Data->qpel_precision = 0;
717 :     *Data->iMinSAD = 4096*256;
718 :     Data->iFcode = fcode; Data->bFcode = bcode;
719 : edgomez 1142
720 : syskin 1215 i = (x + y * Data->iEdgedWidth) * 16;
721 : edgomez 1142
722 : syskin 1215 Data->RefP[0] = f_Ref->y + i;
723 :     Data->RefP[2] = f_RefH + i;
724 :     Data->RefP[1] = f_RefV + i;
725 :     Data->RefP[3] = f_RefHV + i;
726 :     Data->b_RefP[0] = b_Ref->y + i;
727 :     Data->b_RefP[2] = b_RefH + i;
728 :     Data->b_RefP[1] = b_RefV + i;
729 :     Data->b_RefP[3] = b_RefHV + i;
730 :     Data->RefP[4] = f_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8;
731 :     Data->RefP[5] = f_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8;
732 :     Data->b_RefP[4] = b_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8;
733 :     Data->b_RefP[5] = b_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8;
734 : edgomez 1142
735 : syskin 1215 Data->predMV = *f_predMV;
736 :     Data->bpredMV = *b_predMV;
737 : edgomez 1142
738 : syskin 1215 Data->currentMV[0] = Data->currentMV[2]; /* forward search left its vector here */
739 : edgomez 1142
740 : syskin 1215 get_range(f_range, f_range+1, f_range+2, f_range+3, x, y, 4, pParam->width, pParam->height, fcode - Data->qpel, 1, 0);
741 :     get_range(b_range, b_range+1, b_range+2, b_range+3, x, y, 4, pParam->width, pParam->height, bcode - Data->qpel, 1, 0);
742 : edgomez 1142
743 : syskin 1215 if (Data->currentMV[0].x > f_range[1]) Data->currentMV[0].x = f_range[1];
744 :     if (Data->currentMV[0].x < f_range[0]) Data->currentMV[0].x = f_range[0];
745 :     if (Data->currentMV[0].y > f_range[3]) Data->currentMV[0].y = f_range[3];
746 :     if (Data->currentMV[0].y < f_range[2]) Data->currentMV[0].y = f_range[2];
747 : edgomez 1142
748 : syskin 1215 if (Data->currentMV[1].x > b_range[1]) Data->currentMV[1].x = b_range[1];
749 :     if (Data->currentMV[1].x < b_range[0]) Data->currentMV[1].x = b_range[0];
750 :     if (Data->currentMV[1].y > b_range[3]) Data->currentMV[1].y = b_range[3];
751 :     if (Data->currentMV[1].y < b_range[2]) Data->currentMV[1].y = b_range[2];
752 : edgomez 1142
753 : syskin 1215 set_range(f_range, Data);
754 :    
755 :     CheckCandidateInt(Data->currentMV[0].x, Data->currentMV[0].y, Data, 1);
756 :    
757 : edgomez 1142 /* diamond */
758 :     do {
759 : syskin 1215 Data->dir = 0;
760 : edgomez 1142 /* forward MV moves */
761 : syskin 1215 i = Data->currentMV[0].x; j = Data->currentMV[0].y;
762 : edgomez 1142
763 : syskin 1215 CheckCandidateInt(i + 1, j, Data, 1);
764 :     CheckCandidateInt(i, j + 1, Data, 1);
765 :     CheckCandidateInt(i - 1, j, Data, 1);
766 :     CheckCandidateInt(i, j - 1, Data, 1);
767 : edgomez 1142
768 :     /* backward MV moves */
769 : syskin 1215 set_range(b_range, Data);
770 :     i = Data->currentMV[1].x; j = Data->currentMV[1].y;
771 : edgomez 1142
772 : syskin 1215 CheckCandidateInt(i + 1, j, Data, 2);
773 :     CheckCandidateInt(i, j + 1, Data, 2);
774 :     CheckCandidateInt(i - 1, j, Data, 2);
775 :     CheckCandidateInt(i, j - 1, Data, 2);
776 : edgomez 1142
777 : syskin 1215 set_range(f_range, Data);
778 :    
779 :     } while (Data->dir != 0);
780 :    
781 : edgomez 1142 /* qpel refinement */
782 : syskin 1215 if (Data->qpel) {
783 :     if (*Data->iMinSAD > *best_sad + 500) return;
784 :     Data->qpel_precision = 1;
785 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, pParam->width, pParam->height, fcode, 2, 0);
786 :    
787 :     Data->currentQMV[0].x = 2 * Data->currentMV[0].x;
788 :     Data->currentQMV[0].y = 2 * Data->currentMV[0].y;
789 :     Data->currentQMV[1].x = 2 * Data->currentMV[1].x;
790 :     Data->currentQMV[1].y = 2 * Data->currentMV[1].y;
791 :     SubpelRefine_dir(Data, CheckCandidateInt, 1);
792 :     if (*Data->iMinSAD > *best_sad + 300) return;
793 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, pParam->width, pParam->height, bcode, 2, 0);
794 :     SubpelRefine_dir(Data, CheckCandidateInt, 2);
795 : edgomez 1142 }
796 :    
797 : syskin 1237 *Data->iMinSAD += 2 * Data->lambda16; /* two bits are needed to code interpolate mode. */
798 : edgomez 1142
799 : syskin 1215 if (*Data->iMinSAD < *best_sad) {
800 :     *best_sad = *Data->iMinSAD;
801 :     pMB->mvs[0] = Data->currentMV[0];
802 :     pMB->b_mvs[0] = Data->currentMV[1];
803 : edgomez 1142 pMB->mode = MODE_INTERPOLATE;
804 : syskin 1215 if (Data->qpel) {
805 :     pMB->qmvs[0] = Data->currentQMV[0];
806 :     pMB->b_qmvs[0] = Data->currentQMV[1];
807 : edgomez 1142 pMB->pmvs[1].x = pMB->qmvs[0].x - f_predMV->x;
808 :     pMB->pmvs[1].y = pMB->qmvs[0].y - f_predMV->y;
809 :     pMB->pmvs[0].x = pMB->b_qmvs[0].x - b_predMV->x;
810 :     pMB->pmvs[0].y = pMB->b_qmvs[0].y - b_predMV->y;
811 :     } else {
812 :     pMB->pmvs[1].x = pMB->mvs[0].x - f_predMV->x;
813 :     pMB->pmvs[1].y = pMB->mvs[0].y - f_predMV->y;
814 :     pMB->pmvs[0].x = pMB->b_mvs[0].x - b_predMV->x;
815 :     pMB->pmvs[0].y = pMB->b_mvs[0].y - b_predMV->y;
816 :     }
817 :     }
818 :     }
819 :    
820 :     void
821 :     MotionEstimationBVOP(MBParam * const pParam,
822 :     FRAMEINFO * const frame,
823 :     const int32_t time_bp,
824 :     const int32_t time_pp,
825 :     /* forward (past) reference */
826 :     const MACROBLOCK * const f_mbs,
827 :     const IMAGE * const f_ref,
828 :     const IMAGE * const f_refH,
829 :     const IMAGE * const f_refV,
830 :     const IMAGE * const f_refHV,
831 :     /* backward (future) reference */
832 :     const FRAMEINFO * const b_reference,
833 :     const IMAGE * const b_ref,
834 :     const IMAGE * const b_refH,
835 :     const IMAGE * const b_refV,
836 :     const IMAGE * const b_refHV)
837 :     {
838 :     uint32_t i, j;
839 :     int32_t best_sad;
840 :     uint32_t skip_sad;
841 :    
842 :     const MACROBLOCK * const b_mbs = b_reference->mbs;
843 :    
844 :     VECTOR f_predMV, b_predMV;
845 :    
846 :     const int32_t TRB = time_pp - time_bp;
847 :     const int32_t TRD = time_pp;
848 :    
849 :     /* some pre-inintialized data for the rest of the search */
850 :    
851 :     SearchData Data;
852 :     memset(&Data, 0, sizeof(SearchData));
853 : syskin 1215
854 : edgomez 1142 Data.iEdgedWidth = pParam->edged_width;
855 :     Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL ? 1 : 0;
856 :     Data.rounding = 0;
857 :     Data.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP;
858 :     Data.iQuant = frame->quant;
859 :    
860 :     Data.RefQ = f_refV->u; /* a good place, also used in MC (for similar purpose) */
861 :    
862 :     /* note: i==horizontal, j==vertical */
863 :     for (j = 0; j < pParam->mb_height; j++) {
864 :    
865 :     f_predMV = b_predMV = zeroMV; /* prediction is reset at left boundary */
866 :    
867 :     for (i = 0; i < pParam->mb_width; i++) {
868 :     MACROBLOCK * const pMB = frame->mbs + i + j * pParam->mb_width;
869 :     const MACROBLOCK * const b_mb = b_mbs + i + j * pParam->mb_width;
870 :    
871 :     /* special case, if collocated block is SKIPed in P-VOP: encoding is forward (0,0), cpb=0 without further ado */
872 :     if (b_reference->coding_type != S_VOP)
873 :     if (b_mb->mode == MODE_NOT_CODED) {
874 :     pMB->mode = MODE_NOT_CODED;
875 : syskin 1215 pMB->mvs[0] = pMB->b_mvs[0] = zeroMV;
876 : edgomez 1142 continue;
877 :     }
878 : syskin 1237
879 :     Data.lambda16 = xvid_me_lambda_vec16[b_mb->quant];
880 : edgomez 1142
881 :     Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16;
882 :     Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8;
883 :     Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8;
884 :    
885 :     /* direct search comes first, because it (1) checks for SKIP-mode
886 :     and (2) sets very good predictions for forward and backward search */
887 :     skip_sad = SearchDirect(f_ref, f_refH->y, f_refV->y, f_refHV->y,
888 :     b_ref, b_refH->y, b_refV->y, b_refHV->y,
889 :     &frame->image,
890 :     i, j,
891 :     frame->motion_flags,
892 :     TRB, TRD,
893 :     pParam,
894 :     pMB, b_mb,
895 :     &best_sad,
896 :     &Data);
897 :    
898 :     if (pMB->mode == MODE_DIRECT_NONE_MV) continue;
899 :    
900 :     /* forward search */
901 :     SearchBF(f_ref, f_refH->y, f_refV->y, f_refHV->y,
902 :     i, j,
903 :     frame->motion_flags,
904 :     frame->fcode, pParam,
905 :     pMB, &f_predMV, &best_sad,
906 :     MODE_FORWARD, &Data);
907 :    
908 :     /* backward search */
909 :     SearchBF(b_ref, b_refH->y, b_refV->y, b_refHV->y,
910 :     i, j,
911 :     frame->motion_flags,
912 :     frame->bcode, pParam,
913 :     pMB, &b_predMV, &best_sad,
914 :     MODE_BACKWARD, &Data);
915 :    
916 :     /* interpolate search comes last, because it uses data from forward and backward as prediction */
917 :     SearchInterpolate(f_ref, f_refH->y, f_refV->y, f_refHV->y,
918 :     b_ref, b_refH->y, b_refV->y, b_refHV->y,
919 :     i, j,
920 :     frame->fcode, frame->bcode,
921 :     frame->motion_flags,
922 :     pParam,
923 :     &f_predMV, &b_predMV,
924 :     pMB, &best_sad,
925 :     &Data);
926 :    
927 :     /* final skip decision */
928 : syskin 1237 if ( (skip_sad < Data.iQuant * MAX_SAD00_FOR_SKIP * (Data.chroma ? 3:2) )
929 :     && ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) )
930 :    
931 : edgomez 1142 SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data);
932 :    
933 :     switch (pMB->mode) {
934 :     case MODE_FORWARD:
935 :     f_predMV = Data.qpel ? pMB->qmvs[0] : pMB->mvs[0];
936 :     break;
937 :     case MODE_BACKWARD:
938 :     b_predMV = Data.qpel ? pMB->b_qmvs[0] : pMB->b_mvs[0];
939 :     break;
940 :     case MODE_INTERPOLATE:
941 :     f_predMV = Data.qpel ? pMB->qmvs[0] : pMB->mvs[0];
942 :     b_predMV = Data.qpel ? pMB->b_qmvs[0] : pMB->b_mvs[0];
943 :     break;
944 :     default:
945 :     break;
946 :     }
947 :     }
948 :     }
949 :     }
950 :    

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4