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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1215 - (view) (download)

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

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