[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 1205 - (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 : edgomez 1205 * $Id: estimation_rd_based.c,v 1.1.2.9 2003-11-13 23:11:24 edgomez 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 :     CheckCandidateRD16(const int x, const int y, const SearchData * const data, const unsigned int Direction)
176 :     {
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 :     int i, cbp = 0, t, xc, yc;
183 :    
184 :     if ( (x > data->max_dx) || (x < data->min_dx)
185 :     || (y > data->max_dy) || (y < data->min_dy) ) return;
186 :    
187 :     if (!data->qpel_precision) {
188 :     ptr = GetReference(x, y, data);
189 :     current = data->currentMV;
190 :     xc = x; yc = y;
191 :     } else { /* x and y are in 1/4 precision */
192 :     ptr = xvid_me_interpolate16x16qpel(x, y, 0, data);
193 :     current = data->currentQMV;
194 :     xc = x/2; yc = y/2;
195 :     }
196 :    
197 :     for(i = 0; i < 4; i++) {
198 :     int s = 8*((i&1) + (i>>1)*data->iEdgedWidth);
199 :     transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth);
200 : edgomez 1169 rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i, data->scan_table);
201 : edgomez 1142 }
202 :    
203 :     rd += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
204 :    
205 :     if (data->temp[0] + t < data->iMinSAD[1]) {
206 :     data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; data->cbp[1] = (data->cbp[1]&~32) | (cbp&32); }
207 :     if (data->temp[1] < data->iMinSAD[2]) {
208 :     data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; data->cbp[1] = (data->cbp[1]&~16) | (cbp&16); }
209 :     if (data->temp[2] < data->iMinSAD[3]) {
210 :     data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; data->cbp[1] = (data->cbp[1]&~8) | (cbp&8); }
211 :     if (data->temp[3] < data->iMinSAD[4]) {
212 :     data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; data->cbp[1] = (data->cbp[1]&~4) | (cbp&4); }
213 :    
214 :     rd += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
215 :    
216 :     if (rd >= data->iMinSAD[0]) return;
217 :    
218 :     /* chroma */
219 :     xc = (xc >> 1) + roundtab_79[xc & 0x3];
220 :     yc = (yc >> 1) + roundtab_79[yc & 0x3];
221 :    
222 :     /* chroma U */
223 :     ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding);
224 :     transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2);
225 : edgomez 1169 rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table);
226 : edgomez 1142 if (rd >= data->iMinSAD[0]) return;
227 :    
228 :     /* chroma V */
229 :     ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding);
230 :     transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2);
231 : edgomez 1169 rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table);
232 : edgomez 1142
233 :     rd += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
234 :    
235 :     if (rd < data->iMinSAD[0]) {
236 :     data->iMinSAD[0] = rd;
237 :     current[0].x = x; current[0].y = y;
238 :     *data->dir = Direction;
239 :     *data->cbp = cbp;
240 :     }
241 :     }
242 :    
243 :     static void
244 :     CheckCandidateRD8(const int x, const int y, const SearchData * const data, const unsigned int Direction)
245 :     {
246 :    
247 :     int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64;
248 :     int32_t rd;
249 :     VECTOR * current;
250 :     const uint8_t * ptr;
251 :     int cbp = 0;
252 :    
253 :     if ( (x > data->max_dx) || (x < data->min_dx)
254 :     || (y > data->max_dy) || (y < data->min_dy) ) return;
255 :    
256 :     if (!data->qpel_precision) {
257 :     ptr = GetReference(x, y, data);
258 :     current = data->currentMV;
259 :     } else { /* x and y are in 1/4 precision */
260 :     ptr = xvid_me_interpolate8x8qpel(x, y, 0, 0, data);
261 :     current = data->currentQMV;
262 :     }
263 :    
264 :     transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth);
265 : edgomez 1169 rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table);
266 : edgomez 1142 rd += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
267 :    
268 :     if (rd < data->iMinSAD[0]) {
269 :     *data->cbp = cbp;
270 :     data->iMinSAD[0] = rd;
271 :     current[0].x = x; current[0].y = y;
272 :     *data->dir = Direction;
273 :     }
274 :     }
275 :    
276 :    
277 :     static int
278 :     findRD_inter(SearchData * const Data,
279 :     const int x, const int y,
280 :     const MBParam * const pParam,
281 :     const uint32_t MotionFlags)
282 :     {
283 :     int i;
284 :     int32_t bsad[5];
285 :    
286 :     if (Data->qpel) {
287 :     for(i = 0; i < 5; i++) {
288 :     Data->currentMV[i].x = Data->currentQMV[i].x/2;
289 :     Data->currentMV[i].y = Data->currentQMV[i].y/2;
290 :     }
291 :     Data->qpel_precision = 1;
292 :     CheckCandidateRD16(Data->currentQMV[0].x, Data->currentQMV[0].y, Data, 255);
293 :    
294 :     if (MotionFlags & (XVID_ME_HALFPELREFINE16_RD | XVID_ME_EXTSEARCH_RD)) { /* we have to prepare for halfpixel-precision search */
295 :     for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i];
296 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
297 :     pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv);
298 :     Data->qpel_precision = 0;
299 :     if (Data->currentQMV->x & 1 || Data->currentQMV->y & 1)
300 :     CheckCandidateRD16(Data->currentMV[0].x, Data->currentMV[0].y, Data, 255);
301 :     }
302 :    
303 :     } else { /* not qpel */
304 :    
305 :     CheckCandidateRD16(Data->currentMV[0].x, Data->currentMV[0].y, Data, 255);
306 :     }
307 :    
308 :     if (MotionFlags&XVID_ME_EXTSEARCH_RD)
309 :     xvid_me_SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidateRD16);
310 :    
311 :     if (MotionFlags&XVID_ME_HALFPELREFINE16_RD)
312 :     xvid_me_SubpelRefine(Data, CheckCandidateRD16);
313 :    
314 :     if (Data->qpel) {
315 :     if (MotionFlags&(XVID_ME_EXTSEARCH_RD | XVID_ME_HALFPELREFINE16_RD)) { /* there was halfpel-precision search */
316 :     for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) {
317 :     Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* we have found a better match */
318 :     Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
319 :     }
320 :    
321 :     /* preparing for qpel-precision search */
322 :     Data->qpel_precision = 1;
323 :     get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
324 :     pParam->width, pParam->height, Data->iFcode, 2, 0);
325 :     }
326 :     if (MotionFlags&XVID_ME_QUARTERPELREFINE16_RD)
327 :     xvid_me_SubpelRefine(Data, CheckCandidateRD16);
328 :     }
329 :    
330 :     if (MotionFlags&XVID_ME_CHECKPREDICTION_RD) { /* let's check vector equal to prediction */
331 :     VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV;
332 :     if (!MVequal(Data->predMV, *v))
333 :     CheckCandidateRD16(Data->predMV.x, Data->predMV.y, Data, 255);
334 :     }
335 :     return Data->iMinSAD[0];
336 :     }
337 :    
338 :     static int
339 :     findRD_inter4v(const SearchData * const Data,
340 :     MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
341 :     const int x, const int y,
342 :     const MBParam * const pParam, const uint32_t MotionFlags,
343 :     const VECTOR * const backup)
344 :     {
345 :    
346 :     int cbp = 0, bits = 0, t = 0, i;
347 :     SearchData Data2, *Data8 = &Data2;
348 :     int sumx = 0, sumy = 0;
349 :     int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64;
350 :     uint8_t * ptr;
351 :    
352 :     memcpy(Data8, Data, sizeof(SearchData));
353 :    
354 :     for (i = 0; i < 4; i++) { /* for all luma blocks */
355 :    
356 :     Data8->iMinSAD = Data->iMinSAD + i + 1;
357 :     Data8->currentMV = Data->currentMV + i + 1;
358 :     Data8->currentQMV = Data->currentQMV + i + 1;
359 :     Data8->Cur = Data->Cur + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
360 :     Data8->RefP[0] = Data->RefP[0] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
361 :     Data8->RefP[2] = Data->RefP[2] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
362 :     Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
363 :     Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth);
364 : edgomez 1160 *Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; /* copy corresponding cbp bit */
365 : edgomez 1142
366 :     if(Data->qpel) {
367 :     Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i);
368 :     if (i != 0) t = d_mv_bits( Data8->currentQMV->x, Data8->currentQMV->y,
369 :     Data8->predMV, Data8->iFcode, 0, 0);
370 :     } else {
371 :     Data8->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, i);
372 :     if (i != 0) t = d_mv_bits( Data8->currentMV->x, Data8->currentMV->y,
373 :     Data8->predMV, Data8->iFcode, 0, 0);
374 :     }
375 :    
376 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
377 :     pParam->width, pParam->height, Data8->iFcode, Data8->qpel+1, 0);
378 :    
379 :     *Data8->iMinSAD += BITS_MULT*t;
380 :    
381 :     Data8->qpel_precision = Data8->qpel;
382 :     /* checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far) */
383 :     {
384 :     VECTOR *v = Data8->qpel ? Data8->currentQMV : Data8->currentMV;
385 :     if (!MVequal (*v, backup[i+1]) )
386 :     CheckCandidateRD8(backup[i+1].x, backup[i+1].y, Data8, 255);
387 :     }
388 :    
389 :     if (Data8->qpel) {
390 :     if (MotionFlags&XVID_ME_HALFPELREFINE8_RD || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_RD)) { /* halfpixel motion search follows */
391 :     int32_t s = *Data8->iMinSAD;
392 :     Data8->currentMV->x = Data8->currentQMV->x/2;
393 :     Data8->currentMV->y = Data8->currentQMV->y/2;
394 :     Data8->qpel_precision = 0;
395 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
396 :     pParam->width, pParam->height, Data8->iFcode - 1, 1, 0);
397 :    
398 :     if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1)
399 :     CheckCandidateRD8(Data8->currentMV->x, Data8->currentMV->y, Data8, 255);
400 :    
401 :     if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD)
402 :     xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8);
403 :    
404 :     if (MotionFlags & XVID_ME_HALFPELREFINE8_RD)
405 :     xvid_me_SubpelRefine(Data8, CheckCandidateRD8);
406 :    
407 :     if(s > *Data8->iMinSAD) { /* we have found a better match */
408 :     Data8->currentQMV->x = 2*Data8->currentMV->x;
409 :     Data8->currentQMV->y = 2*Data8->currentMV->y;
410 :     }
411 :    
412 :     Data8->qpel_precision = 1;
413 :     get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3,
414 :     pParam->width, pParam->height, Data8->iFcode, 2, 0);
415 :    
416 :     }
417 :     if (MotionFlags & XVID_ME_QUARTERPELREFINE8_RD)
418 :     xvid_me_SubpelRefine(Data8, CheckCandidateRD8);
419 :    
420 :     } else { /* not qpel */
421 :    
422 :     if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD) /* extsearch */
423 :     xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8);
424 :    
425 :     if (MotionFlags & XVID_ME_HALFPELREFINE8_RD)
426 :     xvid_me_SubpelRefine(Data8, CheckCandidateRD8); /* halfpel refinement */
427 :     }
428 :    
429 :     /* checking vector equal to predicion */
430 :     if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_RD) {
431 :     const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV;
432 :     if (!MVequal(*v, Data8->predMV))
433 :     CheckCandidateRD8(Data8->predMV.x, Data8->predMV.y, Data8, 255);
434 :     }
435 :    
436 :     bits += *Data8->iMinSAD;
437 :     if (bits >= Data->iMinSAD[0]) return bits; /* no chances for INTER4V */
438 :    
439 :     /* MB structures for INTER4V mode; we have to set them here, we don't have predictor anywhere else */
440 :     if(Data->qpel) {
441 :     pMB->pmvs[i].x = Data8->currentQMV->x - Data8->predMV.x;
442 :     pMB->pmvs[i].y = Data8->currentQMV->y - Data8->predMV.y;
443 :     pMB->qmvs[i] = *Data8->currentQMV;
444 :     sumx += Data8->currentQMV->x/2;
445 :     sumy += Data8->currentQMV->y/2;
446 :     } else {
447 :     pMB->pmvs[i].x = Data8->currentMV->x - Data8->predMV.x;
448 :     pMB->pmvs[i].y = Data8->currentMV->y - Data8->predMV.y;
449 :     sumx += Data8->currentMV->x;
450 :     sumy += Data8->currentMV->y;
451 :     }
452 :     pMB->mvs[i] = *Data8->currentMV;
453 :     pMB->sad8[i] = 4 * *Data8->iMinSAD;
454 :     if (Data8->cbp[0]) cbp |= 1 << (5 - i);
455 :    
456 :     } /* end - for all luma blocks */
457 :    
458 :     bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
459 :    
460 :     /* let's check chroma */
461 :     sumx = (sumx >> 3) + roundtab_76[sumx & 0xf];
462 :     sumy = (sumy >> 3) + roundtab_76[sumy & 0xf];
463 :    
464 :     /* chroma U */
465 :     ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
466 :     transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);
467 : edgomez 1169 bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table);
468 : edgomez 1142
469 :     if (bits >= *Data->iMinSAD) return bits;
470 :    
471 :     /* chroma V */
472 :     ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
473 :     transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);
474 : edgomez 1169 bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table);
475 : edgomez 1142
476 :     bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;
477 :    
478 :     *Data->cbp = cbp;
479 :     return bits;
480 :     }
481 :    
482 :     static int
483 : syskin 1177 findRD_intra(const SearchData * const Data, MACROBLOCK * pMB,
484 :     const int x, const int y, const int mb_width)
485 : edgomez 1142 {
486 : syskin 1177 int cbp[2] = {0, 0}, bits[2], i;
487 :     int bits1 = BITS_MULT*1, bits2 = BITS_MULT*1; /* this one is ac/dc prediction flag bit */
488 :     int distortion = 0;
489 : edgomez 1142
490 : syskin 1177 int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64, * dqcoeff = Data->dctSpace + 128;
491 :     const uint32_t iQuant = Data->iQuant;
492 :     int16_t predictors[6][8];
493 :    
494 : edgomez 1142 for(i = 0; i < 4; i++) {
495 :     int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
496 :     transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);
497 : syskin 1177
498 : edgomez 1142
499 : syskin 1177 distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff,
500 :     predictors[i], iQuant, Data->quant_type, bits, cbp);
501 :     bits1 += distortion + BITS_MULT * bits[0];
502 :     bits2 += distortion + BITS_MULT * bits[1];
503 :    
504 :     if (bits1 >= Data->iMinSAD[0] && bits2 >= Data->iMinSAD[0])
505 :     return bits1;
506 : edgomez 1142 }
507 :    
508 : syskin 1177 bits1 += BITS_MULT*xvid_cbpy_tab[cbp[0]>>2].len;
509 :     bits2 += BITS_MULT*xvid_cbpy_tab[cbp[1]>>2].len;
510 : edgomez 1142
511 :     /*chroma U */
512 :     transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);
513 : syskin 1177 distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff,
514 :     predictors[4], iQuant, Data->quant_type, bits, cbp);
515 :     bits1 += distortion + BITS_MULT * bits[0];
516 :     bits2 += distortion + BITS_MULT * bits[1];
517 : edgomez 1142
518 : syskin 1177 if (bits1 >= Data->iMinSAD[0] && bits2 >= Data->iMinSAD[0])
519 :     return bits1;
520 : edgomez 1142
521 :     /* chroma V */
522 :     transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);
523 : syskin 1177 distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff,
524 :     predictors[5], iQuant, Data->quant_type, bits, cbp);
525 : edgomez 1142
526 : syskin 1177 bits1 += distortion + BITS_MULT * bits[0];
527 :     bits2 += distortion + BITS_MULT * bits[1];
528 : edgomez 1142
529 : syskin 1177 bits1 += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp[0] & 3) << 3)].len;
530 :     bits2 += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp[1] & 3) << 3)].len;
531 :    
532 :     *Data->cbp = bits1 <= bits2 ? cbp[0] : cbp[1];
533 :    
534 :     return MIN(bits1, bits2);
535 : edgomez 1142 }
536 :    
537 : syskin 1177
538 : edgomez 1142 static int
539 :     findRD_gmc(const SearchData * const Data, const IMAGE * const vGMC, const int x, const int y)
540 :     {
541 :     int bits = BITS_MULT*1; /* this one is mcsel */
542 :     int cbp = 0, i;
543 :     int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64;
544 :    
545 :     for(i = 0; i < 4; i++) {
546 :     int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
547 :     transfer_8to16subro(in, Data->Cur + s, vGMC->y + s + 16*(x+y*Data->iEdgedWidth), Data->iEdgedWidth);
548 : edgomez 1169 bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, Data->scan_table);
549 : edgomez 1142 if (bits >= Data->iMinSAD[0]) return bits;
550 :     }
551 :    
552 :     bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
553 :    
554 :     /*chroma U */
555 :     transfer_8to16subro(in, Data->CurU, vGMC->u + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2);
556 : edgomez 1169 bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table);
557 : edgomez 1142
558 :     if (bits >= Data->iMinSAD[0]) return bits;
559 :    
560 :     /* chroma V */
561 :     transfer_8to16subro(in, Data->CurV , vGMC->v + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2);
562 : edgomez 1169 bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table);
563 : edgomez 1142
564 :     bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
565 :    
566 :     *Data->cbp = cbp;
567 :    
568 :     return bits;
569 :     }
570 :    
571 :     void
572 :     xvid_me_ModeDecision_RD(SearchData * const Data,
573 :     MACROBLOCK * const pMB,
574 :     const MACROBLOCK * const pMBs,
575 :     const int x, const int y,
576 :     const MBParam * const pParam,
577 :     const uint32_t MotionFlags,
578 :     const uint32_t VopFlags,
579 :     const uint32_t VolFlags,
580 :     const IMAGE * const pCurrent,
581 :     const IMAGE * const pRef,
582 :     const IMAGE * const vGMC,
583 :     const int coding_type)
584 :     {
585 :     int mode = MODE_INTER;
586 :     int mcsel = 0;
587 :     int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0);
588 :     const uint32_t iQuant = pMB->quant;
589 :    
590 :     int min_rd, intra_rd, i, cbp, c[2] = {0, 0};
591 :     VECTOR backup[5], *v;
592 :     Data->iQuant = iQuant;
593 :     Data->cbp = c;
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 : edgomez 1142 int min_rd = -1, intra_rd, i, cbp = 63, c[2] = {0, 0};
698 :     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 :     Data->cbp = c;
752 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
753 :    
754 :     /* final skip decision, a.k.a. "the vector you found, really that good?" */
755 :     if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))
756 :     if ( (100*Data->iMinSAD[0])/(pMB->sad16+1) > FINAL_SKIP_THRESH)
757 :     if (Data->chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {
758 :     mode = MODE_NOT_CODED;
759 :     sad = 0; /* Compiler warning */
760 :     goto early_out;
761 :     }
762 :    
763 :     for (i = 0; i < 5; i++) {
764 :     sad_backup[i] = Data->iMinSAD[i];
765 :     Data->iMinSAD[i] = 256*4096;
766 :     backup[i] = v[i];
767 :     }
768 :    
769 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
770 :     cbp = *Data->cbp;
771 :     sad = sad_backup[0];
772 :    
773 :     if (coding_type == S_VOP) {
774 :     int gmc_rd;
775 :    
776 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
777 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
778 :     if (gmc_rd < min_rd) {
779 :     mcsel = 1;
780 :     *Data->iMinSAD = min_rd = gmc_rd;
781 :     mode = MODE_INTER;
782 :     cbp = *Data->cbp;
783 :     sad = sad16(Data->Cur,
784 :     vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536);
785 :     if (Data->chroma) {
786 :     sad += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
787 :     sad += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2);
788 :     }
789 :     }
790 :     }
791 :    
792 :     if (inter4v) {
793 :     int v4_rd;
794 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
795 :     if (v4_rd < min_rd) {
796 :     Data->iMinSAD[0] = min_rd = v4_rd;
797 :     mode = MODE_INTER4V;
798 :     cbp = *Data->cbp;
799 :     sad = sad_backup[1] + sad_backup[2] +
800 :     sad_backup[3] + sad_backup[4] + IMV16X16 * (int32_t)iQuant;
801 :     }
802 :     }
803 :     }
804 :    
805 :     left = top = top_right = -1;
806 :     thresh = 0;
807 :    
808 :     if((x > 0) && (y > 0) && (x < (int32_t) pParam->mb_width)) {
809 : edgomez 1160 left = (&pMBs[(x-1) + y * pParam->mb_width])->sad16; /* left */
810 :     top = (&pMBs[x + (y-1) * pParam->mb_width])->sad16; /* top */
811 :     top_right = (&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16; /* top right */
812 : edgomez 1142
813 :     if(((&pMBs[(x-1) + y * pParam->mb_width])->mode != MODE_INTRA) &&
814 :     ((&pMBs[x + (y-1) * pParam->mb_width])->mode != MODE_INTRA) &&
815 :     ((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mode != MODE_INTRA)) {
816 :     thresh = MAX(MAX(top, left), top_right);
817 :     }
818 :     else
819 :     thresh = MIN(MIN(top, left), top_right);
820 :     }
821 :    
822 :     /* INTRA <-> INTER decision */
823 :     if (sad < thresh) { /* normal, fast, SAD-based mode decision */
824 :     /* intra decision */
825 :    
826 :     if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */
827 :     if (y != 0)
828 :     if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80;
829 :     if (x != 0)
830 :     if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80;
831 :    
832 :     if (Data->chroma) InterBias += 50; /* dev8(chroma) ??? <-- yes, we need dev8 (no big difference though) */
833 :     if (Data->rrv) InterBias *= 4;
834 :    
835 :     if (InterBias < sad) {
836 :     int32_t deviation;
837 :     if (!Data->rrv)
838 :     deviation = dev16(Data->Cur, Data->iEdgedWidth);
839 :     else
840 :     deviation = dev16(Data->Cur, Data->iEdgedWidth) + /* dev32() */
841 :     dev16(Data->Cur+16, Data->iEdgedWidth) +
842 :     dev16(Data->Cur + 16*Data->iEdgedWidth, Data->iEdgedWidth) +
843 :     dev16(Data->Cur+16+16*Data->iEdgedWidth, Data->iEdgedWidth);
844 :    
845 :     if (deviation < (sad - InterBias)) mode = MODE_INTRA;
846 :     }
847 :    
848 :     pMB->cbp = 63;
849 :     } else { /* Rate-Distortion INTRA<->INTER */
850 :     if(min_rd < 0) {
851 :     Data->iQuant = iQuant;
852 :     Data->cbp = c;
853 :     v = Data->qpel ? Data->currentQMV : Data->currentMV;
854 :    
855 :     for (i = 0; i < 5; i++) {
856 :     Data->iMinSAD[i] = 256*4096;
857 :     backup[i] = v[i];
858 :     }
859 :    
860 :     if(mode == MODE_INTER) {
861 :     min_rd = findRD_inter(Data, x, y, pParam, MotionFlags);
862 :     cbp = *Data->cbp;
863 :    
864 :     if (coding_type == S_VOP) {
865 :     int gmc_rd;
866 :    
867 :     *Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */
868 :     gmc_rd = findRD_gmc(Data, vGMC, x, y);
869 :     if (gmc_rd < min_rd) {
870 :     mcsel = 1;
871 :     *Data->iMinSAD = min_rd = gmc_rd;
872 :     mode = MODE_INTER;
873 :     cbp = *Data->cbp;
874 :     }
875 :     }
876 :     }
877 :    
878 :     if(mode == MODE_INTER4V) {
879 :     int v4_rd;
880 :     v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
881 :     if (v4_rd < min_rd) {
882 :     Data->iMinSAD[0] = min_rd = v4_rd;
883 :     mode = MODE_INTER4V;
884 :     cbp = *Data->cbp;
885 :     }
886 :     }
887 :     }
888 :    
889 : syskin 1177 intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width);
890 : edgomez 1142 if (intra_rd < min_rd) {
891 :     *Data->iMinSAD = min_rd = intra_rd;
892 :     mode = MODE_INTRA;
893 :     }
894 :    
895 :     pMB->cbp = cbp;
896 :     }
897 :    
898 :     early_out:
899 :     pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;
900 :    
901 :     if (Data->rrv) {
902 :     Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
903 :     Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y);
904 :     }
905 :    
906 :     if (mode == MODE_INTER && mcsel == 0) {
907 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
908 :    
909 :     if(Data->qpel) {
910 :     pMB->qmvs[0] = pMB->qmvs[1]
911 :     = pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];
912 :     pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x;
913 :     pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y;
914 :     } else {
915 :     pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
916 :     pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
917 :     }
918 :    
919 : edgomez 1160 } else if (mode == MODE_INTER ) { /* but mcsel == 1 */
920 : edgomez 1142
921 :     pMB->mcsel = 1;
922 :     if (Data->qpel) {
923 :     pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
924 :     pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2;
925 :     pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2;
926 :     } else
927 :     pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
928 :    
929 :     } else
930 :     if (mode == MODE_INTER4V) ; /* anything here? */
931 :     else /* INTRA, NOT_CODED */
932 :     ZeroMacroblockP(pMB, 0);
933 :    
934 :     pMB->mode = mode;
935 :     }

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