[XviD-devel] _real_ adaptive quantization

skal xvid-devel@xvid.org
01 Oct 2002 18:11:50 +0200


On Tue, 2002-10-01 at 16:13, Christoph Lampert wrote:
 
> Btw. since you seem to be online: 

	Somehow. But I shouldn't ;)

> 
> Is there a quantizer value where calculating the error/distorsion is 
> equivalent to a very fast (MMX) operation, like ANDing with a constant? 
> 
> Like quant 6 means calculating modulus 15 which is almost ANDing with 0x0F 
> Or is it 16? That would be perfect... Same holds for quant 3 -> modulus
> 7 or 8. 

	Well, let's see: quantizing coeff C with quant q gives
	 (forgetting biases for now): C' = C/2q. Dequantizing
	C' is H263-normalized as: C'' = (C'*2q)+ q if q is odd, 
	C'*2q + q-1 if q is even. Hence, coeffs of the form
	2kq+q or 2kq+ q-1 undergoes no distortion. Apart these
	middle values, error raise from 0 to q-1. So, error
	is a sawtooth function with period 2q, and amplitude
	q-1. Something like: Err(C) = Abs( C%2q - q ). Doing
	it fast with MMX bit-soup seems achievable, thanks
	to the Abs(x) = x^(x<0) - (x<0) mask trick, but only
	when 2q is a power of 2... Does it makes sense??

	bye,
		Skal