[XviD-devel] [In progress] devapi4 -- mpeg matrices

skal skal at planet-d.net
Fri Nov 28 14:10:25 CET 2003


	Re,

On Fri, 2003-11-28 at 13:48, Edouard Gomez wrote:

> Does this code looks right to you skal ?
> 
> void
> quant_mpeg_init_context_c(quant_context_t *q,
>                           const uint8_t *matrix,
>                           const int32_t intra)
> {
>     int qp;
> 
>     for (qp=1; qp<32; qp++) {
>         int i;
>         for(i=0; i<64; i++) {
>             const int S = qp*matrix[i];
>             const int shift = mpeg_shifts[qp-1];
>             q[0][qp-1][0][i] = FIX(S<<1, shift, 1);  /* quant */
>             q[0][qp-1][1][i] = intra ? ((3*S+2)>>2) : 0;
>             q[1][qp-1][0][i] = S<<1;                 /* dequant */
>             q[1][qp-1][1][i] = intra ?      0       : (S>>1);
>         }
>     }
> }

	Assuming the actual quant/dequant code (not just the init above)
	is the same, i think it's ok. Anyway, running your automatic
	testing scripts should quickly spot problems if any: file size
	and PSNR should not differ sensibly.
	Just a remark: don't forget to test veeeery high quant (Q=31)
	and veeeery low ones (Q=1). It's where rounder errors usually
	rear their ugly heads...

	@Michael: the small difference come from variable fixed point
	precision (from 15bits up to 20bits) of the divide-by-multiply
	quantization. Increasing the precision, for high quant is sometime
	helpful (note: 14bits could be enough, but at the price of
	heavier code => http://skal.planet-d.net/coding/divide.html)

	bye!
Skal


Note: the 3*Q/8 bias is not a magic constant, just a trade-off
yielding good overall sensitivity. Some prefer Q/3, e.g... Holy
Belief isn't far :)



More information about the XviD-devel mailing list