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.9 2003-06-19 10:06:40 syskin Exp $ |
* $Id: motion_est.h,v 1.10 2003-06-26 10:37:42 syskin Exp $ |
30 |
* |
* |
31 |
***************************************************************************/ |
***************************************************************************/ |
32 |
|
|
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 |
#define LAMBDA ( (int)(1.0*BITS_MULT) ) |
/* one over lambda for R-D mode decision and motion search */ |
311 |
|
#define LAMBDA ( (int)(BITS_MULT/1.0) ) |
312 |
|
|
313 |
static __inline unsigned int |
static __inline unsigned int |
314 |
Block_CalcBits( int16_t * const coeff, |
Block_CalcBits( int16_t * const coeff, |
315 |
int16_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) |
320 |
{ |
{ |
321 |
int sum; |
int sum; |
322 |
int bits; |
int bits; |
|
const int lambda = LAMBDA*quant*quant; |
|
323 |
int distortion = 0; |
int distortion = 0; |
324 |
int i; |
int i; |
325 |
|
|
333 |
bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
334 |
} else bits = 0; |
} else bits = 0; |
335 |
|
|
336 |
if (quant_type == 0) dequant_inter(coeff, coeff, quant); |
if (quant_type == 0) dequant_inter(dqcoeff, coeff, quant); |
337 |
else dequant4_inter(coeff, coeff, quant); |
else dequant4_inter(dqcoeff, coeff, quant); |
338 |
|
|
339 |
for (i = 0; i < 64; i++) { |
for (i = 0; i < 64; i++) { |
340 |
distortion += (data[i] - coeff[i])*(data[i] - coeff[i]); |
distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]); |
341 |
} |
} |
342 |
bits += (BITS_MULT*BITS_MULT*distortion)/lambda; |
|
343 |
|
bits += (LAMBDA*distortion)/(quant*quant); |
344 |
|
|
345 |
return bits; |
return bits; |
346 |
} |
} |
348 |
static __inline unsigned int |
static __inline unsigned int |
349 |
Block_CalcBitsIntra(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 |
int * dcpred) |
int * dcpred) |
356 |
{ |
{ |
357 |
int bits, i; |
int bits, i; |
|
const int lambda = LAMBDA*quant*quant; |
|
358 |
int distortion = 0; |
int distortion = 0; |
359 |
uint32_t iDcScaler = get_dc_scaler(quant, block < 4); |
uint32_t iDcScaler = get_dc_scaler(quant, block < 4); |
360 |
int b_dc; |
int b_dc; |
362 |
fdct(data); |
fdct(data); |
363 |
data[0] -= 1024; |
data[0] -= 1024; |
364 |
|
|
365 |
if (quant_type == 0) quant_intra_c(coeff, data, quant, iDcScaler); // MUST BE _C |
if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler); |
366 |
else quant4_intra_c(coeff, data, quant, iDcScaler); // MUST BE _C |
else quant4_intra(coeff, data, quant, iDcScaler); |
367 |
|
|
368 |
b_dc = coeff[0]; |
b_dc = coeff[0]; |
369 |
if (block < 4) { |
if (block < 4) { |
378 |
else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len; |
else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len; |
379 |
|
|
380 |
coeff[0] = b_dc; |
coeff[0] = b_dc; |
381 |
if (quant_type == 0) dequant_intra(coeff, coeff, quant, iDcScaler); |
if (quant_type == 0) dequant_intra(dqcoeff, coeff, quant, iDcScaler); |
382 |
else dequant4_intra(coeff, coeff, quant, iDcScaler); |
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 += (BITS_MULT*BITS_MULT*distortion)/lambda; |
bits += (LAMBDA*distortion)/(quant*quant); |
389 |
|
|
390 |
return bits; |
return bits; |
391 |
} |
} |