[svn] / trunk / xvidcore / src / motion / estimation_rd_based.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/motion/estimation_rd_based.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1478 - (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 : syskin 1478 * $Id: estimation_rd_based.c,v 1.6 2004-07-08 07:12:54 syskin 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 1472 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 1472 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 : syskin 1478 xvid_me_SubpelRefine(Data->currentMV[0], Data, CheckCandidateRD16, 0);
317 : edgomez 1382
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 : syskin 1441 if (MotionFlags & XVID_ME_QUARTERPELREFINE16_RD) {
331 :     if (MotionFlags & XVID_ME_FASTREFINE16)
332 :     FullRefine_Fast(Data, CheckCandidateRD16, 0);
333 :     else
334 : syskin 1478 xvid_me_SubpelRefine(Data->currentQMV[0], Data, CheckCandidateRD16, 0);
335 : syskin 1441 }
336 : edgomez 1382 }
337 :    
338 :     if (MotionFlags&XVID_ME_CHECKPREDICTION_RD) { /* let's check vector equal to prediction */
339 :     VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV;
340 :     if (!MVequal(Data->predMV, *v))
341 :     CheckCandidateRD16(Data->predMV.x, Data->predMV.y, Data, 255);
342 :     }
343 :     return Data->iMinSAD[0];
344 :     }
345 :    
346 :     static int
347 :     findRD_inter4v(SearchData * const Data,
348 :     MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
349 :     const int x, const int y,
350 :     const MBParam * const pParam, const uint32_t MotionFlags,
351 :     const VECTOR * const backup)
352 :     {
353 :    
354 :     unsigned int cbp = 0, bits = 0, t = 0, i;
355 :     SearchData Data2, *Data8 = &Data2;
356 :     int sumx = 0, sumy = 0;
357 :     int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64;
358 :     uint8_t * ptr;
359 :    
360 :     memcpy(Data8, Data, sizeof(SearchData));
361 :    
362 :     for (i = 0; i < 4; i++) { /* for all luma blocks */
363 :    
364 :     *Data8->iMinSAD = *(Data->iMinSAD + i + 1);
365 :     *Data8->currentMV = *(Data->currentMV + i + 1);
366 :     *Data8->currentQMV = *(Data->currentQMV + i + 1);
367 :     Data8->Cur = Data->Cur + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
368 :     Data8->RefP[0] = Data->RefP[0] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
369 :     Data8->RefP[2] = Data->RefP[2] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
370 :     Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
371 :     Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
372 :     *Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; /* copy corresponding cbp bit */
373 :    
374 :     if(Data->qpel) {
375 :     Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i);
376 :     if (i != 0) t = d_mv_bits( Data8->currentQMV->x, Data8->currentQMV->y,
377 :     Data8->predMV, Data8->iFcode, 0, 0);
378 :     } else {
379 :     Data8->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, i);
380 :     if (i != 0) t = d_mv_bits( Data8->currentMV->x, Data8->currentMV->y,
381 :     Data8->predMV, Data8->iFcode, 0, 0);
382 :     }
383 :    
384 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
385 :     pParam->width, pParam->height, Data8->iFcode, Data8->qpel+1, 0);
386 :    
387 :     *Data8->iMinSAD += BITS_MULT*t;
388 :    
389 :     Data8->qpel_precision = Data8->qpel;
390 :     /* checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far) */
391 :     {
392 :     VECTOR *v = Data8->qpel ? Data8->currentQMV : Data8->currentMV;
393 :     if (!MVequal (*v, backup[i+1]) )
394 :     CheckCandidateRD8(backup[i+1].x, backup[i+1].y, Data8, 255);
395 :     }
396 :    
397 :     if (Data8->qpel) {
398 : syskin 1441 int bsad = Data8->iMinSAD[0];
399 :     int bx = Data8->currentQMV->x;
400 :     int by = Data8->currentQMV->y;
401 :    
402 :     Data8->currentMV->x = Data8->currentQMV->x/2;
403 :     Data8->currentMV->y = Data8->currentQMV->y/2;
404 :    
405 : edgomez 1382 if (MotionFlags&XVID_ME_HALFPELREFINE8_RD || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_RD)) { /* halfpixel motion search follows */
406 :     Data8->qpel_precision = 0;
407 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
408 :     pParam->width, pParam->height, Data8->iFcode - 1, 1, 0);
409 :    
410 :     if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1)
411 :     CheckCandidateRD8(Data8->currentMV->x, Data8->currentMV->y, Data8, 255);
412 :    
413 :     if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD)
414 :     xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8);
415 :    
416 :     if (MotionFlags & XVID_ME_HALFPELREFINE8_RD)
417 : syskin 1478 xvid_me_SubpelRefine(Data->currentMV[0], Data8, CheckCandidateRD8, 0);
418 : edgomez 1382
419 : syskin 1441 if(bsad > *Data8->iMinSAD) { /* we have found a better match */
420 :     bx = Data8->currentQMV->x = 2*Data8->currentMV->x;
421 :     by = Data8->currentQMV->y = 2*Data8->currentMV->y;
422 :     bsad = Data8->iMinSAD[0];
423 : edgomez 1382 }
424 :    
425 :     Data8->qpel_precision = 1;
426 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
427 :     pParam->width, pParam->height, Data8->iFcode, 2, 0);
428 :    
429 :     }
430 :    
431 : syskin 1441 if (MotionFlags & XVID_ME_QUARTERPELREFINE8_RD) {
432 :     if (MotionFlags & XVID_ME_FASTREFINE8)
433 :     FullRefine_Fast(Data8, CheckCandidateRD8, 0);
434 : syskin 1478 else xvid_me_SubpelRefine(Data->currentQMV[0], Data8, CheckCandidateRD8, 0);
435 : syskin 1441 }
436 :    
437 :     if (bsad <= Data->iMinSAD[0]) {
438 :     /* we have not found a better match */
439 :     Data8->iMinSAD[0] = bsad;
440 :     Data8->currentQMV->x = bx;
441 :     Data8->currentQMV->y = by;
442 :     }
443 :    
444 : edgomez 1382 } else { /* not qpel */
445 :    
446 :     if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD) /* extsearch */
447 :     xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8);
448 :    
449 :     if (MotionFlags & XVID_ME_HALFPELREFINE8_RD)
450 : syskin 1478 xvid_me_SubpelRefine(Data->currentMV[0], Data8, CheckCandidateRD8, 0); /* halfpel refinement */
451 : edgomez 1382 }
452 :    
453 :     /* checking vector equal to predicion */
454 :     if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_RD) {
455 :     const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV;
456 :     if (!MVequal(*v, Data8->predMV))
457 :     CheckCandidateRD8(Data8->predMV.x, Data8->predMV.y, Data8, 255);
458 :     }
459 :    
460 :     bits += *Data8->iMinSAD;
461 :     if (bits >= Data->iMinSAD[0]) return bits; /* no chances for INTER4V */
462 :    
463 :     /* MB structures for INTER4V mode; we have to set them here, we don't have predictor anywhere else */
464 :     if(Data->qpel) {
465 :     pMB->pmvs[i].x = Data8->currentQMV->x - Data8->predMV.x;
466 :     pMB->pmvs[i].y = Data8->currentQMV->y - Data8->predMV.y;
467 :     pMB->qmvs[i] = *Data8->currentQMV;
468 :     sumx += Data8->currentQMV->x/2;
469 :     sumy += Data8->currentQMV->y/2;
470 :     } else {
471 :     pMB->pmvs[i].x = Data8->currentMV->x - Data8->predMV.x;
472 :     pMB->pmvs[i].y = Data8->currentMV->y - Data8->predMV.y;
473 :     sumx += Data8->currentMV->x;
474 :     sumy += Data8->currentMV->y;
475 :     }
476 :     pMB->mvs[i] = *Data8->currentMV;
477 :     pMB->sad8[i] = 4 * *Data8->iMinSAD;
478 :     if (Data8->cbp[0]) cbp |= 1 << (5 - i);
479 :    
480 :     } /* end - for all luma blocks */
481 :    
482 :     bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
483 :    
484 :     /* let's check chroma */
485 :     sumx = (sumx >> 3) + roundtab_76[sumx & 0xf];
486 :     sumy = (sumy >> 3) + roundtab_76[sumy & 0xf];
487 :    
488 :     /* chroma U */
489 :     ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
490 :     transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);
491 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->mpeg_quant_matrices);
492 :    
493 :     if (bits >= *Data->iMinSAD) return bits;
494 :    
495 :     /* chroma V */
496 :     ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
497 :     transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);
498 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->mpeg_quant_matrices);
499 :    
500 :     bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;
501 :    
502 :     *Data->cbp = cbp;
503 :     return bits;
504 :     }
505 :    
506 :     static int
507 :     findRD_intra(SearchData * const Data, MACROBLOCK * pMB,
508 :     const int x, const int y, const int mb_width)
509 :     {
510 :     unsigned int cbp[2] = {0, 0}, bits[2], i;
511 :     unsigned int bits1 = BITS_MULT*1, bits2 = BITS_MULT*1; /* this one is ac/dc prediction flag bit */
512 :     unsigned int distortion = 0;
513 :    
514 :     int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64, * dqcoeff = Data->dctSpace + 128;
515 :     const uint32_t iQuant = Data->iQuant;
516 :     int16_t predictors[6][8];
517 :    
518 :     for(i = 0; i < 4; i++) {
519 :     int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
520 :     transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);
521 :    
522 :    
523 :     distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff,
524 :     predictors[i], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices);
525 :     bits1 += distortion + BITS_MULT * bits[0];
526 :     bits2 += distortion + BITS_MULT * bits[1];
527 :    
528 :     if (bits1 >= Data->iMinSAD[0] && bits2 >= Data->iMinSAD[0])
529 :     return bits1;
530 :     }
531 :    
532 :     bits1 += BITS_MULT*xvid_cbpy_tab[cbp[0]>>2].len;
533 :     bits2 += BITS_MULT*xvid_cbpy_tab[cbp[1]>>2].len;
534 :    
535 :     /*chroma U */
536 :     transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);
537 :     distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff,
538 :     predictors[4], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices);
539 :     bits1 += distortion + BITS_MULT * bits[0];
540 :     bits2 += distortion + BITS_MULT * bits[1];
541 :    
542 :     if (bits1 >= Data->iMinSAD[0] && bits2 >= Data->iMinSAD[0])
543 :     return bits1;
544 :    
545 :     /* chroma V */
546 :     transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);
547 :     distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff,
548 :     predictors[5], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices);
549 :    
550 :     bits1 += distortion + BITS_MULT * bits[0];
551 :     bits2 += distortion + BITS_MULT * bits[1];
552 :    
553 :     bits1 += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp[0] & 3) << 3)].len;
554 :     bits2 += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp[1] & 3) << 3)].len;
555 :    
556 :     *Data->cbp = bits1 <= bits2 ? cbp[0] : cbp[1];
557 :    
558 :     return MIN(bits1, bits2);
559 :     }
560 :    
561 :    
562 :     static int
563 :     findRD_gmc(SearchData * const Data, const IMAGE * const vGMC, const int x, const int y)
564 :     {
565 :     int bits = BITS_MULT*1; /* this one is mcsel */
566 :     unsigned int cbp = 0, i;
567 :     int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64;
568 :    
569 :     for(i = 0; i < 4; i++) {
570 :     int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
571 :     transfer_8to16subro(in, Data->Cur + s, vGMC->y + s + 16*(x+y*Data->iEdgedWidth), Data->iEdgedWidth);
572 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, Data->scan_table, Data->mpeg_quant_matrices);
573 :     if (bits >= Data->iMinSAD[0]) return bits;
574 :     }
575 :    
576 :     bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
577 :    
578 :     /*chroma U */
579 :     transfer_8to16subro(in, Data->CurU, vGMC->u + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2);
580 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->mpeg_quant_matrices);
581 :    
582 :     if (bits >= Data->iMinSAD[0]) return bits;
583 :    
584 :     /* chroma V */
585 :     transfer_8to16subro(in, Data->CurV , vGMC->v + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2);
586 :     bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->mpeg_quant_matrices);
587 :    
588 :     bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
589 :    
590 :     *Data->cbp = cbp;
591 :    
592 :     return bits;
593 :     }
594 :    
595 :     void
596 :     xvid_me_ModeDecision_RD(SearchData * const Data,
597 :     MACROBLOCK * const pMB,
598 :     const MACROBLOCK * const pMBs,
599 :     const int x, const int y,
600 :     const MBParam * const pParam,
601 :     const uint32_t MotionFlags,
602 :     const uint32_t VopFlags,
603 :     const uint32_t VolFlags,
604 :     const IMAGE * const pCurrent,
605 :     const IMAGE * const pRef,
606 :     const IMAGE * const vGMC,
607 :     const int coding_type)
608 :     {
609 :     int mode = MODE_INTER;
610 :     int mcsel = 0;
611 :     int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0);
612 :     const uint32_t iQuant = pMB->quant;
613 :    
614 :     int min_rd, intra_rd, i, cbp;
615 :     VECTOR backup[5], *v;
616 :     Data->iQuant = iQuant;
617 :     Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ?
618 :     scan_tables[2] : scan_tables[0];
619 :    
620 :     pMB->mcsel = 0;
621 :    
622 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
623 :     for (i = 0; i < 5; i++) {
624 :     Data->iMinSAD[i] = 256*4096;
625 :     backup[i] = v[i];
626 :     }
627 :    
628 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
629 :     cbp = *Data->cbp;
630 :    
631 :     if (coding_type == S_VOP) {
632 :     int gmc_rd;
633 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
634 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
635 :     if (gmc_rd < min_rd) {
636 :     mcsel = 1;
637 :     *Data->iMinSAD = min_rd = gmc_rd;
638 :     mode = MODE_INTER;
639 :     cbp = *Data->cbp;
640 :     }
641 :     }
642 :    
643 :     if (inter4v) {
644 :     int v4_rd;
645 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
646 :     if (v4_rd < min_rd) {
647 :     Data->iMinSAD[0] = min_rd = v4_rd;
648 :     mode = MODE_INTER4V;
649 :     cbp = *Data->cbp;
650 :     }
651 :     }
652 :    
653 :     intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width);
654 :     if (intra_rd < min_rd) {
655 :     *Data->iMinSAD = min_rd = intra_rd;
656 :     mode = MODE_INTRA;
657 :     cbp = *Data->cbp;
658 :     }
659 :    
660 :     pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = 0;
661 :     pMB->cbp = cbp;
662 :    
663 :    
664 :     if (Data->rrv) {
665 :     Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
666 :     Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y);
667 :     }
668 :    
669 :     if (mode == MODE_INTER && mcsel == 0) {
670 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
671 :    
672 :     if(Data->qpel) {
673 :     pMB->qmvs[0] = pMB->qmvs[1]
674 :     = pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];
675 :     pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x;
676 :     pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y;
677 :     } else {
678 :     pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
679 :     pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
680 :     }
681 :    
682 :     } else if (mode == MODE_INTER ) { /* but mcsel == 1 */
683 :    
684 :     pMB->mcsel = 1;
685 :     if (Data->qpel) {
686 :     pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
687 :     pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2;
688 :     pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2;
689 :     } else
690 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
691 :    
692 :     } else
693 :     if (mode == MODE_INTER4V) ; /* anything here? */
694 :     else /* INTRA, NOT_CODED */
695 :     ZeroMacroblockP(pMB, 0);
696 :    
697 :     pMB->mode = mode;
698 :     }
699 :    
700 :     void
701 :     xvid_me_ModeDecision_Fast(SearchData * const Data,
702 :     MACROBLOCK * const pMB,
703 :     const MACROBLOCK * const pMBs,
704 :     const int x, const int y,
705 :     const MBParam * const pParam,
706 :     const uint32_t MotionFlags,
707 :     const uint32_t VopFlags,
708 :     const uint32_t VolFlags,
709 :     const IMAGE * const pCurrent,
710 :     const IMAGE * const pRef,
711 :     const IMAGE * const vGMC,
712 :     const int coding_type)
713 :     {
714 :     int mode = MODE_INTER;
715 :     int mcsel = 0;
716 :     int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0);
717 :     const uint32_t iQuant = pMB->quant;
718 :     const int skip_possible = (coding_type == P_VOP) && (pMB->dquant == 0);
719 :     int sad;
720 :     int min_rd = -1, intra_rd, i, cbp = 63;
721 :     VECTOR backup[5], *v;
722 :     int sad_backup[5];
723 :     int InterBias = MV16_INTER_BIAS;
724 :     int thresh = 0;
725 :     int top = 0, top_right = 0, left = 0;
726 :     Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ?
727 :     scan_tables[2] : scan_tables[0];
728 :    
729 :     pMB->mcsel = 0;
730 :    
731 :     /* INTER <-> INTER4V decision */
732 :     if ((Data->iMinSAD[0] + 75 < Data->iMinSAD[1] +
733 :     Data->iMinSAD[2] + Data->iMinSAD[3] + Data->iMinSAD[4])) { /* normal, fast, SAD-based mode decision */
734 :     if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] +
735 :     Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) {
736 :     mode = MODE_INTER;
737 :     sad = Data->iMinSAD[0];
738 :     } else {
739 :     mode = MODE_INTER4V;
740 :     sad = Data->iMinSAD[1] + Data->iMinSAD[2] +
741 :     Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant;
742 :     Data->iMinSAD[0] = sad;
743 :     }
744 :    
745 :     /* final skip decision, a.k.a. "the vector you found, really that good?" */
746 :     if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))
747 :     if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH)
748 :     if (Data->chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {
749 :     mode = MODE_NOT_CODED;
750 :     sad = 0; /* Compiler warning */
751 :     goto early_out;
752 :     }
753 :    
754 :     /* mcsel */
755 :     if (coding_type == S_VOP) {
756 :    
757 :     int32_t iSAD = sad16(Data->Cur,
758 :     vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536);
759 :    
760 :     if (Data->chroma) {
761 :     iSAD += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
762 :     iSAD += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
763 :     }
764 :    
765 :     if (iSAD <= sad) { /* mode decision GMC */
766 :     mode = MODE_INTER;
767 :     mcsel = 1;
768 :     sad = iSAD;
769 :     }
770 :    
771 :     }
772 :     } else { /* Rate-Distortion INTER<->INTER4V */
773 :     Data->iQuant = iQuant;
774 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
775 :    
776 :     /* final skip decision, a.k.a. "the vector you found, really that good?" */
777 :     if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))
778 :     if ( (100*Data->iMinSAD[0])/(pMB->sad16+1) > FINAL_SKIP_THRESH)
779 :     if (Data->chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {
780 :     mode = MODE_NOT_CODED;
781 :     sad = 0; /* Compiler warning */
782 :     goto early_out;
783 :     }
784 :    
785 :     for (i = 0; i < 5; i++) {
786 :     sad_backup[i] = Data->iMinSAD[i];
787 :     Data->iMinSAD[i] = 256*4096;
788 :     backup[i] = v[i];
789 :     }
790 :    
791 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
792 :     cbp = *Data->cbp;
793 :     sad = sad_backup[0];
794 :    
795 :     if (coding_type == S_VOP) {
796 :     int gmc_rd;
797 :    
798 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
799 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
800 :     if (gmc_rd < min_rd) {
801 :     mcsel = 1;
802 :     *Data->iMinSAD = min_rd = gmc_rd;
803 :     mode = MODE_INTER;
804 :     cbp = *Data->cbp;
805 :     sad = sad16(Data->Cur,
806 :     vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536);
807 :     if (Data->chroma) {
808 :     sad += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
809 :     sad += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
810 :     }
811 :     }
812 :     }
813 :    
814 :     if (inter4v) {
815 :     int v4_rd;
816 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
817 :     if (v4_rd < min_rd) {
818 :     Data->iMinSAD[0] = min_rd = v4_rd;
819 :     mode = MODE_INTER4V;
820 :     cbp = *Data->cbp;
821 :     sad = sad_backup[1] + sad_backup[2] +
822 :     sad_backup[3] + sad_backup[4] + IMV16X16 * (int32_t)iQuant;
823 :     }
824 :     }
825 :     }
826 :    
827 :     left = top = top_right = -1;
828 :     thresh = 0;
829 :    
830 :     if((x > 0) && (y > 0) && (x < (int32_t) pParam->mb_width)) {
831 :     left = (&pMBs[(x-1) + y * pParam->mb_width])->sad16; /* left */
832 :     top = (&pMBs[x + (y-1) * pParam->mb_width])->sad16; /* top */
833 :     top_right = (&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16; /* top right */
834 :    
835 :     if(((&pMBs[(x-1) + y * pParam->mb_width])->mode != MODE_INTRA) &&
836 :     ((&pMBs[x + (y-1) * pParam->mb_width])->mode != MODE_INTRA) &&
837 :     ((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mode != MODE_INTRA)) {
838 :     thresh = MAX(MAX(top, left), top_right);
839 :     }
840 :     else
841 :     thresh = MIN(MIN(top, left), top_right);
842 :     }
843 :    
844 :     /* INTRA <-> INTER decision */
845 :     if (sad < thresh) { /* normal, fast, SAD-based mode decision */
846 :     /* intra decision */
847 :    
848 :     if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */
849 :     if (y != 0)
850 :     if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80;
851 :     if (x != 0)
852 :     if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80;
853 :    
854 :     if (Data->chroma) InterBias += 50; /* dev8(chroma) ??? <-- yes, we need dev8 (no big difference though) */
855 :     if (Data->rrv) InterBias *= 4;
856 :    
857 :     if (InterBias < sad) {
858 :     int32_t deviation;
859 :     if (!Data->rrv)
860 :     deviation = dev16(Data->Cur, Data->iEdgedWidth);
861 :     else
862 :     deviation = dev16(Data->Cur, Data->iEdgedWidth) + /* dev32() */
863 :     dev16(Data->Cur+16, Data->iEdgedWidth) +
864 :     dev16(Data->Cur + 16*Data->iEdgedWidth, Data->iEdgedWidth) +
865 :     dev16(Data->Cur+16+16*Data->iEdgedWidth, Data->iEdgedWidth);
866 :    
867 :     if (deviation < (sad - InterBias)) mode = MODE_INTRA;
868 :     }
869 :    
870 :     pMB->cbp = 63;
871 :     } else { /* Rate-Distortion INTRA<->INTER */
872 :     if(min_rd < 0) {
873 :     Data->iQuant = iQuant;
874 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
875 :    
876 :     for (i = 0; i < 5; i++) {
877 :     Data->iMinSAD[i] = 256*4096;
878 :     backup[i] = v[i];
879 :     }
880 :    
881 :     if(mode == MODE_INTER) {
882 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
883 :     cbp = *Data->cbp;
884 :    
885 :     if (coding_type == S_VOP) {
886 :     int gmc_rd;
887 :    
888 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
889 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
890 :     if (gmc_rd < min_rd) {
891 :     mcsel = 1;
892 :     *Data->iMinSAD = min_rd = gmc_rd;
893 :     mode = MODE_INTER;
894 :     cbp = *Data->cbp;
895 :     }
896 :     }
897 :     }
898 :    
899 :     if(mode == MODE_INTER4V) {
900 :     int v4_rd;
901 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
902 :     if (v4_rd < min_rd) {
903 :     Data->iMinSAD[0] = min_rd = v4_rd;
904 :     mode = MODE_INTER4V;
905 :     cbp = *Data->cbp;
906 :     }
907 :     }
908 :     }
909 :    
910 :     intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width);
911 :     if (intra_rd < min_rd) {
912 :     *Data->iMinSAD = min_rd = intra_rd;
913 :     mode = MODE_INTRA;
914 :     }
915 :    
916 :     pMB->cbp = cbp;
917 :     }
918 :    
919 :     early_out:
920 :     pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;
921 :    
922 :     if (Data->rrv) {
923 :     Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
924 :     Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y);
925 :     }
926 :    
927 :     if (mode == MODE_INTER && mcsel == 0) {
928 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
929 :    
930 :     if(Data->qpel) {
931 :     pMB->qmvs[0] = pMB->qmvs[1]
932 :     = pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];
933 :     pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x;
934 :     pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y;
935 :     } else {
936 :     pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
937 :     pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
938 :     }
939 :    
940 :     } else if (mode == MODE_INTER ) { /* but mcsel == 1 */
941 :    
942 :     pMB->mcsel = 1;
943 :     if (Data->qpel) {
944 :     pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
945 :     pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2;
946 :     pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2;
947 :     } else
948 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
949 :    
950 :     } else
951 :     if (mode == MODE_INTER4V) ; /* anything here? */
952 :     else /* INTRA, NOT_CODED */
953 :     ZeroMacroblockP(pMB, 0);
954 :    
955 :     pMB->mode = mode;
956 :     }

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