26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
* |
* |
29 |
* $Id: motion_est.h,v 1.7 2003-05-13 12:48:20 syskin Exp $ |
* $Id: motion_est.h,v 1.10 2003-06-26 10:37:42 syskin Exp $ |
30 |
* |
* |
31 |
***************************************************************************/ |
***************************************************************************/ |
32 |
|
|
50 |
#define NEIGH_TEND_8X8 40.0 |
#define NEIGH_TEND_8X8 40.0 |
51 |
#define NEIGH_8X8_BIAS 30 |
#define NEIGH_8X8_BIAS 30 |
52 |
|
|
53 |
|
#define BITS_MULT 16 |
54 |
|
|
55 |
/* Parameters which control inter/inter4v decision */ |
/* Parameters which control inter/inter4v decision */ |
56 |
#define IMV16X16 2 |
#define IMV16X16 2 |
57 |
|
|
137 |
VECTOR directmvF[4]; |
VECTOR directmvF[4]; |
138 |
VECTOR directmvB[4]; |
VECTOR directmvB[4]; |
139 |
const VECTOR * referencemv; |
const VECTOR * referencemv; |
140 |
// _BITS stuff |
// BITS/R-D stuff |
141 |
int16_t * dctSpace; |
int16_t * dctSpace; |
142 |
uint32_t iQuant; |
uint32_t iQuant; |
143 |
uint32_t quant_type; |
uint32_t quant_type; |
265 |
if (Flags & QUARTERPELREFINE8_BITS) |
if (Flags & QUARTERPELREFINE8_BITS) |
266 |
Flags &= ~PMV_QUARTERPELREFINE8; |
Flags &= ~PMV_QUARTERPELREFINE8; |
267 |
|
|
268 |
|
if (Flags & QUARTERPELREFINE16_BITS) |
269 |
|
Flags &= ~PMV_QUARTERPELREFINE16; |
270 |
|
|
271 |
if (!(GlobalFlags & XVID_QUARTERPEL)) |
if (!(GlobalFlags & XVID_QUARTERPEL)) |
272 |
Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS); |
Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS); |
273 |
|
|
306 |
|
|
307 |
int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); |
int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); |
308 |
int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); |
int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); |
309 |
/* |
|
310 |
static int |
/* one over lambda for R-D mode decision and motion search */ |
311 |
CountDistortionSkip(const SearchData * const Data); |
#define LAMBDA ( (int)(BITS_MULT/1.0) ) |
312 |
*/ |
|
313 |
static __inline unsigned int |
static __inline unsigned int |
314 |
Block_CalcBits(uint16_t * const coeff, |
Block_CalcBits( int16_t * const coeff, |
315 |
uint16_t * const data, |
int16_t * const data, |
316 |
|
int16_t * const dqcoeff, |
317 |
const uint32_t quant, const int quant_type, |
const uint32_t quant, const int quant_type, |
318 |
uint32_t * cbp, |
uint32_t * cbp, |
319 |
const int block, |
const int block) |
|
const int RD) |
|
320 |
{ |
{ |
321 |
int sum; |
int sum; |
322 |
|
int bits; |
323 |
|
int distortion = 0; |
324 |
|
int i; |
325 |
|
|
326 |
fdct(data); |
fdct(data); |
327 |
|
|
330 |
|
|
331 |
if (sum > 0) { |
if (sum > 0) { |
332 |
*cbp |= 1 << (5 - block); |
*cbp |= 1 << (5 - block); |
333 |
return CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
334 |
} else return 0; |
} else bits = 0; |
335 |
|
|
336 |
|
if (quant_type == 0) dequant_inter(dqcoeff, coeff, quant); |
337 |
|
else dequant4_inter(dqcoeff, coeff, quant); |
338 |
|
|
339 |
|
for (i = 0; i < 64; i++) { |
340 |
|
distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]); |
341 |
|
} |
342 |
|
|
343 |
|
bits += (LAMBDA*distortion)/(quant*quant); |
344 |
|
|
345 |
|
return bits; |
346 |
} |
} |
347 |
|
|
|
/* RD experiment. ignore. |
|
348 |
static __inline unsigned int |
static __inline unsigned int |
349 |
Block_CalcBits( int16_t * const coeff, |
Block_CalcBitsIntra(int16_t * const coeff, |
350 |
int16_t * const data, |
int16_t * const data, |
351 |
|
int16_t * const dqcoeff, |
352 |
const uint32_t quant, const int quant_type, |
const uint32_t quant, const int quant_type, |
353 |
uint32_t * cbp, |
uint32_t * cbp, |
354 |
const int block, |
const int block, |
355 |
const int RD) |
int * dcpred) |
356 |
{ |
{ |
357 |
int sum; |
int bits, i; |
|
int bits; |
|
|
const int lambda = quant*quant/2; |
|
358 |
int distortion = 0; |
int distortion = 0; |
359 |
|
uint32_t iDcScaler = get_dc_scaler(quant, block < 4); |
360 |
|
int b_dc; |
361 |
|
|
362 |
fdct(data); |
fdct(data); |
363 |
|
data[0] -= 1024; |
364 |
|
|
365 |
if (quant_type == 0) sum = quant_inter(coeff, data, quant); |
if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler); |
366 |
else sum = quant4_inter(coeff, data, quant); |
else quant4_intra(coeff, data, quant, iDcScaler); |
367 |
|
|
368 |
if (sum > 0) { |
b_dc = coeff[0]; |
369 |
*cbp |= 1 << (5 - block); |
if (block < 4) { |
370 |
bits = CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
coeff[0] -= *dcpred; |
371 |
} else bits = 0; |
*dcpred = b_dc; |
372 |
|
} |
373 |
|
|
374 |
if (RD) { |
bits = BITS_MULT*CodeCoeffIntra_CalcBits(coeff, scan_tables[0]); |
375 |
int i; |
if (bits != 0) *cbp |= 1 << (5 - block); |
376 |
if (quant_type == 0) dequant_inter_c(coeff, coeff, quant); |
|
377 |
else dequant4_inter_c(coeff, coeff, quant); |
if (block < 4) bits += BITS_MULT*dcy_tab[coeff[0] + 255].len; |
378 |
|
else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len; |
379 |
|
|
380 |
|
coeff[0] = b_dc; |
381 |
|
if (quant_type == 0) dequant_intra(dqcoeff, coeff, quant, iDcScaler); |
382 |
|
else dequant4_intra(dqcoeff, coeff, quant, iDcScaler); |
383 |
|
|
384 |
for (i = 0; i < 64; i++) { |
for (i = 0; i < 64; i++) { |
385 |
distortion += (data[i] - coeff[i])*(data[i] - coeff[i]); |
distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]); |
|
} |
|
386 |
} |
} |
387 |
|
|
388 |
bits += distortion/lambda; |
bits += (LAMBDA*distortion)/(quant*quant); |
389 |
|
|
390 |
return bits; |
return bits; |
391 |
} |
} |
|
*/ |
|
392 |
|
|
393 |
#endif /* _MOTION_EST_H_ */ |
#endif /* _MOTION_EST_H_ */ |