[svn] / branches / release-1_0-branch / xvidcore / src / motion / estimation_rd_based.c Repository:
ViewVC logotype

Annotation of /branches/release-1_0-branch/xvidcore/src/motion/estimation_rd_based.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1467 - (view) (download)

1 : edgomez 1382 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Rate-Distortion Based Motion Estimation for P- and S- VOPs -
5 :     *
6 :     * Copyright(C) 2003 Radoslaw Czyz <xvid@syskin.cjb.net>
7 :     * 2003 Michael Militzer <michael@xvid.org>
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 1467 * $Id: estimation_rd_based.c,v 1.2.2.2 2004-06-04 11:54:42 edgomez Exp $
24 : edgomez 1382 *
25 :     ****************************************************************************/
26 :    
27 :     /* RD mode decision and search */
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 "../bitstream/mbcoding.h"
36 :     #include "../prediction/mbprediction.h"
37 :     #include "../global.h"
38 :     #include "../image/interpolate8x8.h"
39 :     #include "estimation.h"
40 :     #include "motion.h"
41 :     #include "sad.h"
42 :     #include "../bitstream/zigzag.h"
43 :     #include "../quant/quant.h"
44 :     #include "../bitstream/vlc_codes.h"
45 :     #include "../dct/fdct.h"
46 :     #include "motion_inlines.h"
47 :    
48 :     /* rd = BITS_MULT*bits + LAMBDA*distortion */
49 :     #define LAMBDA ( (int)(BITS_MULT*1.0) )
50 :    
51 :     static __inline unsigned int
52 :     Block_CalcBits( int16_t * const coeff,
53 :     int16_t * const data,
54 :     int16_t * const dqcoeff,
55 :     const uint32_t quant, const int quant_type,
56 :     uint32_t * cbp,
57 :     const int block,
58 :     const uint16_t * scan_table,
59 :     const uint16_t * mpeg_quant_matrices)
60 :     {
61 :     int sum;
62 :     int bits;
63 :     int distortion = 0;
64 :    
65 :     fdct(data);
66 :    
67 :     if (quant_type) sum = quant_h263_inter(coeff, data, quant, mpeg_quant_matrices);
68 :     else sum = quant_mpeg_inter(coeff, data, quant, mpeg_quant_matrices);
69 :    
70 :     if (sum > 0) {
71 :     *cbp |= 1 << (5 - block);
72 :     bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_table);
73 :    
74 :     if (quant_type) dequant_h263_inter(dqcoeff, coeff, quant, mpeg_quant_matrices);
75 :     else dequant_mpeg_inter(dqcoeff, coeff, quant, mpeg_quant_matrices);
76 :    
77 :     distortion = sse8_16bit(data, dqcoeff, 8*sizeof(int16_t));
78 :     } else {
79 :     const static int16_t zero_block[64] =
80 :     {
81 :     0, 0, 0, 0, 0, 0, 0, 0,
82 :     0, 0, 0, 0, 0, 0, 0, 0,
83 :     0, 0, 0, 0, 0, 0, 0, 0,
84 :     0, 0, 0, 0, 0, 0, 0, 0,
85 :     0, 0, 0, 0, 0, 0, 0, 0,
86 :     0, 0, 0, 0, 0, 0, 0, 0,
87 :     0, 0, 0, 0, 0, 0, 0, 0,
88 :     0, 0, 0, 0, 0, 0, 0, 0,
89 :     };
90 :     bits = 0;
91 :     distortion = sse8_16bit(data, zero_block, 8*sizeof(int16_t));
92 :     }
93 :    
94 :    
95 :     return bits + (LAMBDA*distortion)/(quant*quant);
96 :     }
97 :    
98 :     static __inline unsigned int
99 :     Block_CalcBitsIntra(MACROBLOCK * pMB,
100 :     const unsigned int x,
101 :     const unsigned int y,
102 :     const unsigned int mb_width,
103 :     const uint32_t block,
104 :     int16_t coeff[64],
105 :     int16_t qcoeff[64],
106 :     int16_t dqcoeff[64],
107 :     int16_t predictors[8],
108 :     const uint32_t quant,
109 :     const int quant_type,
110 :     unsigned int bits[2],
111 :     unsigned int cbp[2],
112 :     const uint16_t * mpeg_quant_matrices)
113 :     {
114 :     int direction;
115 :     int16_t *pCurrent;
116 :     unsigned int i, coded;
117 :     unsigned int distortion = 0;
118 :     const uint32_t iDcScaler = get_dc_scaler(quant, block < 4);
119 :    
120 :     fdct(coeff);
121 :    
122 :     if (quant_type) {
123 :     quant_h263_intra(qcoeff, coeff, quant, iDcScaler, mpeg_quant_matrices);
124 :     dequant_h263_intra(dqcoeff, qcoeff, quant, iDcScaler, mpeg_quant_matrices);
125 :     } else {
126 :     quant_mpeg_intra(qcoeff, coeff, quant, iDcScaler, mpeg_quant_matrices);
127 :     dequant_mpeg_intra(dqcoeff, qcoeff, quant, iDcScaler, mpeg_quant_matrices);
128 :     }
129 :    
130 :     predict_acdc(pMB-(x+mb_width*y), x, y, mb_width, block, qcoeff,
131 : edgomez 1467 quant, iDcScaler, predictors, 0);
132 : edgomez 1382
133 :     direction = pMB->acpred_directions[block];
134 :     pCurrent = pMB->pred_values[block];
135 :    
136 :     /* store current coeffs to pred_values[] for future prediction */
137 :     pCurrent[0] = qcoeff[0] * iDcScaler;
138 : edgomez 1467 pCurrent[0] = CLIP(pCurrent[0], -2048, 2047);
139 : edgomez 1382 for (i = 1; i < 8; i++) {
140 :     pCurrent[i] = qcoeff[i];
141 :     pCurrent[i + 7] = qcoeff[i * 8];
142 :     }
143 :    
144 :     /* dc prediction */
145 :     qcoeff[0] = qcoeff[0] - predictors[0];
146 :    
147 :     if (block < 4) bits[1] = bits[0] = dcy_tab[qcoeff[0] + 255].len;
148 :     else bits[1] = bits[0] = dcc_tab[qcoeff[0] + 255].len;
149 :    
150 :     /* calc cost before ac prediction */
151 :     bits[0] += coded = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[0]);
152 :     if (coded > 0) cbp[0] |= 1 << (5 - block);
153 :    
154 :     /* apply ac prediction & calc cost*/
155 :     if (direction == 1) {
156 :     for (i = 1; i < 8; i++) {
157 :     qcoeff[i] -= predictors[i];
158 :     predictors[i] = qcoeff[i];
159 :     }
160 :     } else { /* acpred_direction == 2 */
161 :     for (i = 1; i < 8; i++) {
162 :     qcoeff[i*8] -= predictors[i];
163 :     predictors[i] = qcoeff[i*8];
164 :     }
165 :     }
166 :    
167 :     bits[1] += coded = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]);
168 :     if (coded > 0) cbp[1] |= 1 << (5 - block);
169 :    
170 :     distortion = sse8_16bit(coeff, dqcoeff, 8*sizeof(int16_t));
171 :    
172 :     return (LAMBDA*distortion)/(quant*quant);
173 :     }
174 :    
175 :    
176 :    
177 :     static void
178 :     CheckCandidateRD16(const int x, const int y, SearchData * const data, const unsigned int Direction)
179 :     {
180 :    
181 :     int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64;
182 :     int32_t rd = 0;
183 :     VECTOR * current;
184 :     const uint8_t * ptr;
185 :     int i, t, xc, yc;
186 :     unsigned cbp = 0;
187 :    
188 :     if ( (x > data->max_dx) || (x < data->min_dx)
189 :     || (y > data->max_dy) || (y < data->min_dy) ) return;
190 :    
191 :     if (!data->qpel_precision) {
192 :     ptr = GetReference(x, y, data);
193 :     current = data->currentMV;
194 :     xc = x; yc = y;
195 :     } else { /* x and y are in 1/4 precision */
196 :     ptr = xvid_me_interpolate16x16qpel(x, y, 0, data);
197 :     current = data->currentQMV;
198 :     xc = x/2; yc = y/2;
199 :     }
200 :    
201 :     for(i = 0; i < 4; i++) {
202 :     int s = 8*((i&1) + (i>>1)*data->iEdgedWidth);
203 :     transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth);
204 :     rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i, data->scan_table, data->mpeg_quant_matrices);
205 :     }
206 :    
207 :     rd += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
208 :    
209 :     if (data->temp[0] + t < data->iMinSAD[1]) {
210 :     data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; data->cbp[1] = (data->cbp[1]&~32) | (cbp&32); }
211 :     if (data->temp[1] < data->iMinSAD[2]) {
212 :     data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; data->cbp[1] = (data->cbp[1]&~16) | (cbp&16); }
213 :     if (data->temp[2] < data->iMinSAD[3]) {
214 :     data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; data->cbp[1] = (data->cbp[1]&~8) | (cbp&8); }
215 :     if (data->temp[3] < data->iMinSAD[4]) {
216 :     data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; data->cbp[1] = (data->cbp[1]&~4) | (cbp&4); }
217 :    
218 :     rd += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
219 :    
220 :     if (rd >= data->iMinSAD[0]) return;
221 :    
222 :     /* chroma */
223 :     xc = (xc >> 1) + roundtab_79[xc & 0x3];
224 :     yc = (yc >> 1) + roundtab_79[yc & 0x3];
225 :    
226 :     /* chroma U */
227 :     ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding);
228 :     transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2);
229 :     rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table, data->mpeg_quant_matrices);
230 :     if (rd >= data->iMinSAD[0]) return;
231 :    
232 :     /* chroma V */
233 :     ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding);
234 :     transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2);
235 :     rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->mpeg_quant_matrices);
236 :    
237 :     rd += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
238 :    
239 :     if (rd < data->iMinSAD[0]) {
240 :     data->iMinSAD[0] = rd;
241 :     current[0].x = x; current[0].y = y;
242 :     data->dir = Direction;
243 :     *data->cbp = cbp;
244 :     }
245 :     }
246 :    
247 :     static void
248 :     CheckCandidateRD8(const int x, const int y, SearchData * const data, const unsigned int Direction)
249 :     {
250 :    
251 :     int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64;
252 :     int32_t rd;
253 :     VECTOR * current;
254 :     const uint8_t * ptr;
255 :     unsigned int cbp = 0;
256 :    
257 :     if ( (x > data->max_dx) || (x < data->min_dx)
258 :     || (y > data->max_dy) || (y < data->min_dy) ) return;
259 :    
260 :     if (!data->qpel_precision) {
261 :     ptr = GetReference(x, y, data);
262 :     current = data->currentMV;
263 :     } else { /* x and y are in 1/4 precision */
264 :     ptr = xvid_me_interpolate8x8qpel(x, y, 0, 0, data);
265 :     current = data->currentQMV;
266 :     }
267 :    
268 :     transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth);
269 :     rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->mpeg_quant_matrices);
270 :     rd += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
271 :    
272 :     if (rd < data->iMinSAD[0]) {
273 :     *data->cbp = cbp;
274 :     data->iMinSAD[0] = rd;
275 :     current[0].x = x; current[0].y = y;
276 :     data->dir = Direction;
277 :     }
278 :     }
279 :    
280 :    
281 :     static int
282 :     findRD_inter(SearchData * const Data,
283 :     const int x, const int y,
284 :     const MBParam * const pParam,
285 :     const uint32_t MotionFlags)
286 :     {
287 :     int i;
288 :     int32_t bsad[5];
289 :    
290 :     if (Data->qpel) {
291 :     for(i = 0; i < 5; i++) {
292 :     Data->currentMV[i].x = Data->currentQMV[i].x/2;
293 :     Data->currentMV[i].y = Data->currentQMV[i].y/2;
294 :     }
295 :     Data->qpel_precision = 1;
296 :     CheckCandidateRD16(Data->currentQMV[0].x, Data->currentQMV[0].y, Data, 255);
297 :    
298 :     if (MotionFlags & (XVID_ME_HALFPELREFINE16_RD | XVID_ME_EXTSEARCH_RD)) { /* we have to prepare for halfpixel-precision search */
299 :     for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i];
300 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
301 :     pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv);
302 :     Data->qpel_precision = 0;
303 :     if (Data->currentQMV->x & 1 || Data->currentQMV->y & 1)
304 :     CheckCandidateRD16(Data->currentMV[0].x, Data->currentMV[0].y, Data, 255);
305 :     }
306 :    
307 :     } else { /* not qpel */
308 :    
309 :     CheckCandidateRD16(Data->currentMV[0].x, Data->currentMV[0].y, Data, 255);
310 :     }
311 :    
312 :     if (MotionFlags&XVID_ME_EXTSEARCH_RD)
313 :     xvid_me_SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidateRD16);
314 :    
315 :     if (MotionFlags&XVID_ME_HALFPELREFINE16_RD)
316 :     xvid_me_SubpelRefine(Data, CheckCandidateRD16);
317 :    
318 :     if (Data->qpel) {
319 :     if (MotionFlags&(XVID_ME_EXTSEARCH_RD | XVID_ME_HALFPELREFINE16_RD)) { /* there was halfpel-precision search */
320 :     for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) {
321 :     Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* we have found a better match */
322 :     Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
323 :     }
324 :    
325 :     /* preparing for qpel-precision search */
326 :     Data->qpel_precision = 1;
327 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
328 :     pParam->width, pParam->height, Data->iFcode, 2, 0);
329 :     }
330 :     if (MotionFlags&XVID_ME_QUARTERPELREFINE16_RD)
331 :     xvid_me_SubpelRefine(Data, CheckCandidateRD16);
332 :     }
333 :    
334 :     if (MotionFlags&XVID_ME_CHECKPREDICTION_RD) { /* let's check vector equal to prediction */
335 :     VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV;
336 :     if (!MVequal(Data->predMV, *v))
337 :     CheckCandidateRD16(Data->predMV.x, Data->predMV.y, Data, 255);
338 :     }
339 :     return Data->iMinSAD[0];
340 :     }
341 :    
342 :     static int
343 :     findRD_inter4v(SearchData * const Data,
344 :     MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
345 :     const int x, const int y,
346 :     const MBParam * const pParam, const uint32_t MotionFlags,
347 :     const VECTOR * const backup)
348 :     {
349 :    
350 :     unsigned int cbp = 0, bits = 0, t = 0, i;
351 :     SearchData Data2, *Data8 = &Data2;
352 :     int sumx = 0, sumy = 0;
353 :     int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64;
354 :     uint8_t * ptr;
355 :    
356 :     memcpy(Data8, Data, sizeof(SearchData));
357 :    
358 :     for (i = 0; i < 4; i++) { /* for all luma blocks */
359 :    
360 :     *Data8->iMinSAD = *(Data->iMinSAD + i + 1);
361 :     *Data8->currentMV = *(Data->currentMV + i + 1);
362 :     *Data8->currentQMV = *(Data->currentQMV + i + 1);
363 :     Data8->Cur = Data->Cur + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
364 :     Data8->RefP[0] = Data->RefP[0] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
365 :     Data8->RefP[2] = Data->RefP[2] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
366 :     Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
367 :     Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
368 :     *Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; /* copy corresponding cbp bit */
369 :    
370 :     if(Data->qpel) {
371 :     Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i);
372 :     if (i != 0) t = d_mv_bits( Data8->currentQMV->x, Data8->currentQMV->y,
373 :     Data8->predMV, Data8->iFcode, 0, 0);
374 :     } else {
375 :     Data8->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, i);
376 :     if (i != 0) t = d_mv_bits( Data8->currentMV->x, Data8->currentMV->y,
377 :     Data8->predMV, Data8->iFcode, 0, 0);
378 :     }
379 :    
380 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
381 :     pParam->width, pParam->height, Data8->iFcode, Data8->qpel+1, 0);
382 :    
383 :     *Data8->iMinSAD += BITS_MULT*t;
384 :    
385 :     Data8->qpel_precision = Data8->qpel;
386 :     /* checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far) */
387 :     {
388 :     VECTOR *v = Data8->qpel ? Data8->currentQMV : Data8->currentMV;
389 :     if (!MVequal (*v, backup[i+1]) )
390 :     CheckCandidateRD8(backup[i+1].x, backup[i+1].y, Data8, 255);
391 :     }
392 :    
393 :     if (Data8->qpel) {
394 :     if (MotionFlags&XVID_ME_HALFPELREFINE8_RD || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_RD)) { /* halfpixel motion search follows */
395 :     int32_t s = *Data8->iMinSAD;
396 :     Data8->currentMV->x = Data8->currentQMV->x/2;
397 :     Data8->currentMV->y = Data8->currentQMV->y/2;
398 :     Data8->qpel_precision = 0;
399 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
400 :     pParam->width, pParam->height, Data8->iFcode - 1, 1, 0);
401 :    
402 :     if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1)
403 :     CheckCandidateRD8(Data8->currentMV->x, Data8->currentMV->y, Data8, 255);
404 :    
405 :     if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD)
406 :     xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8);
407 :    
408 :     if (MotionFlags & XVID_ME_HALFPELREFINE8_RD)
409 :     xvid_me_SubpelRefine(Data8, CheckCandidateRD8);
410 :    
411 :     if(s > *Data8->iMinSAD) { /* we have found a better match */
412 :     Data8->currentQMV->x = 2*Data8->currentMV->x;
413 :     Data8->currentQMV->y = 2*Data8->currentMV->y;
414 :     }
415 :    
416 :     Data8->qpel_precision = 1;
417 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
418 :     pParam->width, pParam->height, Data8->iFcode, 2, 0);
419 :    
420 :     }
421 :     if (MotionFlags & XVID_ME_QUARTERPELREFINE8_RD)
422 :     xvid_me_SubpelRefine(Data8, CheckCandidateRD8);
423 :    
424 :     } else { /* not qpel */
425 :    
426 :     if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD) /* extsearch */
427 :     xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8);
428 :    
429 :     if (MotionFlags & XVID_ME_HALFPELREFINE8_RD)
430 :     xvid_me_SubpelRefine(Data8, CheckCandidateRD8); /* halfpel refinement */
431 :     }
432 :    
433 :     /* checking vector equal to predicion */
434 :     if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_RD) {
435 :     const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV;
436 :     if (!MVequal(*v, Data8->predMV))
437 :     CheckCandidateRD8(Data8->predMV.x, Data8->predMV.y, Data8, 255);
438 :     }
439 :    
440 :     bits += *Data8->iMinSAD;
441 :     if (bits >= Data->iMinSAD[0]) return bits; /* no chances for INTER4V */
442 :    
443 :     /* MB structures for INTER4V mode; we have to set them here, we don't have predictor anywhere else */
444 :     if(Data->qpel) {
445 :     pMB->pmvs[i].x = Data8->currentQMV->x - Data8->predMV.x;
446 :     pMB->pmvs[i].y = Data8->currentQMV->y - Data8->predMV.y;
447 :     pMB->qmvs[i] = *Data8->currentQMV;
448 :     sumx += Data8->currentQMV->x/2;
449 :     sumy += Data8->currentQMV->y/2;
450 :     } else {
451 :     pMB->pmvs[i].x = Data8->currentMV->x - Data8->predMV.x;
452 :     pMB->pmvs[i].y = Data8->currentMV->y - Data8->predMV.y;
453 :     sumx += Data8->currentMV->x;
454 :     sumy += Data8->currentMV->y;
455 :     }
456 :     pMB->mvs[i] = *Data8->currentMV;
457 :     pMB->sad8[i] = 4 * *Data8->iMinSAD;
458 :     if (Data8->cbp[0]) cbp |= 1 << (5 - i);
459 :    
460 :     } /* end - for all luma blocks */
461 :    
462 :     bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
463 :    
464 :     /* let's check chroma */
465 :     sumx = (sumx >> 3) + roundtab_76[sumx & 0xf];
466 :     sumy = (sumy >> 3) + roundtab_76[sumy & 0xf];
467 :    
468 :     /* chroma U */
469 :     ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
470 :     transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);
471 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->mpeg_quant_matrices);
472 :    
473 :     if (bits >= *Data->iMinSAD) return bits;
474 :    
475 :     /* chroma V */
476 :     ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
477 :     transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);
478 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->mpeg_quant_matrices);
479 :    
480 :     bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;
481 :    
482 :     *Data->cbp = cbp;
483 :     return bits;
484 :     }
485 :    
486 :     static int
487 :     findRD_intra(SearchData * const Data, MACROBLOCK * pMB,
488 :     const int x, const int y, const int mb_width)
489 :     {
490 :     unsigned int cbp[2] = {0, 0}, bits[2], i;
491 :     unsigned int bits1 = BITS_MULT*1, bits2 = BITS_MULT*1; /* this one is ac/dc prediction flag bit */
492 :     unsigned int distortion = 0;
493 :    
494 :     int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64, * dqcoeff = Data->dctSpace + 128;
495 :     const uint32_t iQuant = Data->iQuant;
496 :     int16_t predictors[6][8];
497 :    
498 :     for(i = 0; i < 4; i++) {
499 :     int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
500 :     transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);
501 :    
502 :    
503 :     distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff,
504 :     predictors[i], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices);
505 :     bits1 += distortion + BITS_MULT * bits[0];
506 :     bits2 += distortion + BITS_MULT * bits[1];
507 :    
508 :     if (bits1 >= Data->iMinSAD[0] && bits2 >= Data->iMinSAD[0])
509 :     return bits1;
510 :     }
511 :    
512 :     bits1 += BITS_MULT*xvid_cbpy_tab[cbp[0]>>2].len;
513 :     bits2 += BITS_MULT*xvid_cbpy_tab[cbp[1]>>2].len;
514 :    
515 :     /*chroma U */
516 :     transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);
517 :     distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff,
518 :     predictors[4], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices);
519 :     bits1 += distortion + BITS_MULT * bits[0];
520 :     bits2 += distortion + BITS_MULT * bits[1];
521 :    
522 :     if (bits1 >= Data->iMinSAD[0] && bits2 >= Data->iMinSAD[0])
523 :     return bits1;
524 :    
525 :     /* chroma V */
526 :     transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);
527 :     distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff,
528 :     predictors[5], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices);
529 :    
530 :     bits1 += distortion + BITS_MULT * bits[0];
531 :     bits2 += distortion + BITS_MULT * bits[1];
532 :    
533 :     bits1 += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp[0] & 3) << 3)].len;
534 :     bits2 += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp[1] & 3) << 3)].len;
535 :    
536 :     *Data->cbp = bits1 <= bits2 ? cbp[0] : cbp[1];
537 :    
538 :     return MIN(bits1, bits2);
539 :     }
540 :    
541 :    
542 :     static int
543 :     findRD_gmc(SearchData * const Data, const IMAGE * const vGMC, const int x, const int y)
544 :     {
545 :     int bits = BITS_MULT*1; /* this one is mcsel */
546 :     unsigned int cbp = 0, i;
547 :     int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64;
548 :    
549 :     for(i = 0; i < 4; i++) {
550 :     int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
551 :     transfer_8to16subro(in, Data->Cur + s, vGMC->y + s + 16*(x+y*Data->iEdgedWidth), Data->iEdgedWidth);
552 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, Data->scan_table, Data->mpeg_quant_matrices);
553 :     if (bits >= Data->iMinSAD[0]) return bits;
554 :     }
555 :    
556 :     bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
557 :    
558 :     /*chroma U */
559 :     transfer_8to16subro(in, Data->CurU, vGMC->u + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2);
560 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->mpeg_quant_matrices);
561 :    
562 :     if (bits >= Data->iMinSAD[0]) return bits;
563 :    
564 :     /* chroma V */
565 :     transfer_8to16subro(in, Data->CurV , vGMC->v + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2);
566 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->mpeg_quant_matrices);
567 :    
568 :     bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
569 :    
570 :     *Data->cbp = cbp;
571 :    
572 :     return bits;
573 :     }
574 :    
575 :     void
576 :     xvid_me_ModeDecision_RD(SearchData * const Data,
577 :     MACROBLOCK * const pMB,
578 :     const MACROBLOCK * const pMBs,
579 :     const int x, const int y,
580 :     const MBParam * const pParam,
581 :     const uint32_t MotionFlags,
582 :     const uint32_t VopFlags,
583 :     const uint32_t VolFlags,
584 :     const IMAGE * const pCurrent,
585 :     const IMAGE * const pRef,
586 :     const IMAGE * const vGMC,
587 :     const int coding_type)
588 :     {
589 :     int mode = MODE_INTER;
590 :     int mcsel = 0;
591 :     int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0);
592 :     const uint32_t iQuant = pMB->quant;
593 :    
594 :     int min_rd, intra_rd, i, cbp;
595 :     VECTOR backup[5], *v;
596 :     Data->iQuant = iQuant;
597 :     Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ?
598 :     scan_tables[2] : scan_tables[0];
599 :    
600 :     pMB->mcsel = 0;
601 :    
602 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
603 :     for (i = 0; i < 5; i++) {
604 :     Data->iMinSAD[i] = 256*4096;
605 :     backup[i] = v[i];
606 :     }
607 :    
608 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
609 :     cbp = *Data->cbp;
610 :    
611 :     if (coding_type == S_VOP) {
612 :     int gmc_rd;
613 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
614 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
615 :     if (gmc_rd < min_rd) {
616 :     mcsel = 1;
617 :     *Data->iMinSAD = min_rd = gmc_rd;
618 :     mode = MODE_INTER;
619 :     cbp = *Data->cbp;
620 :     }
621 :     }
622 :    
623 :     if (inter4v) {
624 :     int v4_rd;
625 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
626 :     if (v4_rd < min_rd) {
627 :     Data->iMinSAD[0] = min_rd = v4_rd;
628 :     mode = MODE_INTER4V;
629 :     cbp = *Data->cbp;
630 :     }
631 :     }
632 :    
633 :     intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width);
634 :     if (intra_rd < min_rd) {
635 :     *Data->iMinSAD = min_rd = intra_rd;
636 :     mode = MODE_INTRA;
637 :     cbp = *Data->cbp;
638 :     }
639 :    
640 :     pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = 0;
641 :     pMB->cbp = cbp;
642 :    
643 :    
644 :     if (Data->rrv) {
645 :     Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
646 :     Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y);
647 :     }
648 :    
649 :     if (mode == MODE_INTER && mcsel == 0) {
650 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
651 :    
652 :     if(Data->qpel) {
653 :     pMB->qmvs[0] = pMB->qmvs[1]
654 :     = pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];
655 :     pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x;
656 :     pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y;
657 :     } else {
658 :     pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
659 :     pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
660 :     }
661 :    
662 :     } else if (mode == MODE_INTER ) { /* but mcsel == 1 */
663 :    
664 :     pMB->mcsel = 1;
665 :     if (Data->qpel) {
666 :     pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
667 :     pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2;
668 :     pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2;
669 :     } else
670 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
671 :    
672 :     } else
673 :     if (mode == MODE_INTER4V) ; /* anything here? */
674 :     else /* INTRA, NOT_CODED */
675 :     ZeroMacroblockP(pMB, 0);
676 :    
677 :     pMB->mode = mode;
678 :     }
679 :    
680 :     void
681 :     xvid_me_ModeDecision_Fast(SearchData * const Data,
682 :     MACROBLOCK * const pMB,
683 :     const MACROBLOCK * const pMBs,
684 :     const int x, const int y,
685 :     const MBParam * const pParam,
686 :     const uint32_t MotionFlags,
687 :     const uint32_t VopFlags,
688 :     const uint32_t VolFlags,
689 :     const IMAGE * const pCurrent,
690 :     const IMAGE * const pRef,
691 :     const IMAGE * const vGMC,
692 :     const int coding_type)
693 :     {
694 :     int mode = MODE_INTER;
695 :     int mcsel = 0;
696 :     int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0);
697 :     const uint32_t iQuant = pMB->quant;
698 :     const int skip_possible = (coding_type == P_VOP) && (pMB->dquant == 0);
699 :     int sad;
700 :     int min_rd = -1, intra_rd, i, cbp = 63;
701 :     VECTOR backup[5], *v;
702 :     int sad_backup[5];
703 :     int InterBias = MV16_INTER_BIAS;
704 :     int thresh = 0;
705 :     int top = 0, top_right = 0, left = 0;
706 :     Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ?
707 :     scan_tables[2] : scan_tables[0];
708 :    
709 :     pMB->mcsel = 0;
710 :    
711 :     /* INTER <-> INTER4V decision */
712 :     if ((Data->iMinSAD[0] + 75 < Data->iMinSAD[1] +
713 :     Data->iMinSAD[2] + Data->iMinSAD[3] + Data->iMinSAD[4])) { /* normal, fast, SAD-based mode decision */
714 :     if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] +
715 :     Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) {
716 :     mode = MODE_INTER;
717 :     sad = Data->iMinSAD[0];
718 :     } else {
719 :     mode = MODE_INTER4V;
720 :     sad = Data->iMinSAD[1] + Data->iMinSAD[2] +
721 :     Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant;
722 :     Data->iMinSAD[0] = sad;
723 :     }
724 :    
725 :     /* final skip decision, a.k.a. "the vector you found, really that good?" */
726 :     if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))
727 :     if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH)
728 :     if (Data->chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {
729 :     mode = MODE_NOT_CODED;
730 :     sad = 0; /* Compiler warning */
731 :     goto early_out;
732 :     }
733 :    
734 :     /* mcsel */
735 :     if (coding_type == S_VOP) {
736 :    
737 :     int32_t iSAD = sad16(Data->Cur,
738 :     vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536);
739 :    
740 :     if (Data->chroma) {
741 :     iSAD += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
742 :     iSAD += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
743 :     }
744 :    
745 :     if (iSAD <= sad) { /* mode decision GMC */
746 :     mode = MODE_INTER;
747 :     mcsel = 1;
748 :     sad = iSAD;
749 :     }
750 :    
751 :     }
752 :     } else { /* Rate-Distortion INTER<->INTER4V */
753 :     Data->iQuant = iQuant;
754 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
755 :    
756 :     /* final skip decision, a.k.a. "the vector you found, really that good?" */
757 :     if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))
758 :     if ( (100*Data->iMinSAD[0])/(pMB->sad16+1) > FINAL_SKIP_THRESH)
759 :     if (Data->chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {
760 :     mode = MODE_NOT_CODED;
761 :     sad = 0; /* Compiler warning */
762 :     goto early_out;
763 :     }
764 :    
765 :     for (i = 0; i < 5; i++) {
766 :     sad_backup[i] = Data->iMinSAD[i];
767 :     Data->iMinSAD[i] = 256*4096;
768 :     backup[i] = v[i];
769 :     }
770 :    
771 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
772 :     cbp = *Data->cbp;
773 :     sad = sad_backup[0];
774 :    
775 :     if (coding_type == S_VOP) {
776 :     int gmc_rd;
777 :    
778 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
779 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
780 :     if (gmc_rd < min_rd) {
781 :     mcsel = 1;
782 :     *Data->iMinSAD = min_rd = gmc_rd;
783 :     mode = MODE_INTER;
784 :     cbp = *Data->cbp;
785 :     sad = sad16(Data->Cur,
786 :     vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536);
787 :     if (Data->chroma) {
788 :     sad += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
789 :     sad += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
790 :     }
791 :     }
792 :     }
793 :    
794 :     if (inter4v) {
795 :     int v4_rd;
796 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
797 :     if (v4_rd < min_rd) {
798 :     Data->iMinSAD[0] = min_rd = v4_rd;
799 :     mode = MODE_INTER4V;
800 :     cbp = *Data->cbp;
801 :     sad = sad_backup[1] + sad_backup[2] +
802 :     sad_backup[3] + sad_backup[4] + IMV16X16 * (int32_t)iQuant;
803 :     }
804 :     }
805 :     }
806 :    
807 :     left = top = top_right = -1;
808 :     thresh = 0;
809 :    
810 :     if((x > 0) && (y > 0) && (x < (int32_t) pParam->mb_width)) {
811 :     left = (&pMBs[(x-1) + y * pParam->mb_width])->sad16; /* left */
812 :     top = (&pMBs[x + (y-1) * pParam->mb_width])->sad16; /* top */
813 :     top_right = (&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16; /* top right */
814 :    
815 :     if(((&pMBs[(x-1) + y * pParam->mb_width])->mode != MODE_INTRA) &&
816 :     ((&pMBs[x + (y-1) * pParam->mb_width])->mode != MODE_INTRA) &&
817 :     ((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mode != MODE_INTRA)) {
818 :     thresh = MAX(MAX(top, left), top_right);
819 :     }
820 :     else
821 :     thresh = MIN(MIN(top, left), top_right);
822 :     }
823 :    
824 :     /* INTRA <-> INTER decision */
825 :     if (sad < thresh) { /* normal, fast, SAD-based mode decision */
826 :     /* intra decision */
827 :    
828 :     if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */
829 :     if (y != 0)
830 :     if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80;
831 :     if (x != 0)
832 :     if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80;
833 :    
834 :     if (Data->chroma) InterBias += 50; /* dev8(chroma) ??? <-- yes, we need dev8 (no big difference though) */
835 :     if (Data->rrv) InterBias *= 4;
836 :    
837 :     if (InterBias < sad) {
838 :     int32_t deviation;
839 :     if (!Data->rrv)
840 :     deviation = dev16(Data->Cur, Data->iEdgedWidth);
841 :     else
842 :     deviation = dev16(Data->Cur, Data->iEdgedWidth) + /* dev32() */
843 :     dev16(Data->Cur+16, Data->iEdgedWidth) +
844 :     dev16(Data->Cur + 16*Data->iEdgedWidth, Data->iEdgedWidth) +
845 :     dev16(Data->Cur+16+16*Data->iEdgedWidth, Data->iEdgedWidth);
846 :    
847 :     if (deviation < (sad - InterBias)) mode = MODE_INTRA;
848 :     }
849 :    
850 :     pMB->cbp = 63;
851 :     } else { /* Rate-Distortion INTRA<->INTER */
852 :     if(min_rd < 0) {
853 :     Data->iQuant = iQuant;
854 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
855 :    
856 :     for (i = 0; i < 5; i++) {
857 :     Data->iMinSAD[i] = 256*4096;
858 :     backup[i] = v[i];
859 :     }
860 :    
861 :     if(mode == MODE_INTER) {
862 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
863 :     cbp = *Data->cbp;
864 :    
865 :     if (coding_type == S_VOP) {
866 :     int gmc_rd;
867 :    
868 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
869 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
870 :     if (gmc_rd < min_rd) {
871 :     mcsel = 1;
872 :     *Data->iMinSAD = min_rd = gmc_rd;
873 :     mode = MODE_INTER;
874 :     cbp = *Data->cbp;
875 :     }
876 :     }
877 :     }
878 :    
879 :     if(mode == MODE_INTER4V) {
880 :     int v4_rd;
881 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
882 :     if (v4_rd < min_rd) {
883 :     Data->iMinSAD[0] = min_rd = v4_rd;
884 :     mode = MODE_INTER4V;
885 :     cbp = *Data->cbp;
886 :     }
887 :     }
888 :     }
889 :    
890 :     intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width);
891 :     if (intra_rd < min_rd) {
892 :     *Data->iMinSAD = min_rd = intra_rd;
893 :     mode = MODE_INTRA;
894 :     }
895 :    
896 :     pMB->cbp = cbp;
897 :     }
898 :    
899 :     early_out:
900 :     pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;
901 :    
902 :     if (Data->rrv) {
903 :     Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
904 :     Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y);
905 :     }
906 :    
907 :     if (mode == MODE_INTER && mcsel == 0) {
908 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
909 :    
910 :     if(Data->qpel) {
911 :     pMB->qmvs[0] = pMB->qmvs[1]
912 :     = pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];
913 :     pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x;
914 :     pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y;
915 :     } else {
916 :     pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
917 :     pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
918 :     }
919 :    
920 :     } else if (mode == MODE_INTER ) { /* but mcsel == 1 */
921 :    
922 :     pMB->mcsel = 1;
923 :     if (Data->qpel) {
924 :     pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
925 :     pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2;
926 :     pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2;
927 :     } else
928 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
929 :    
930 :     } else
931 :     if (mode == MODE_INTER4V) ; /* anything here? */
932 :     else /* INTRA, NOT_CODED */
933 :     ZeroMacroblockP(pMB, 0);
934 :    
935 :     pMB->mode = mode;
936 :     }

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