An important feature of H.264 is the use of UVLC (Universal Variable Length Coding, unified Variable Length Encoding) encoding, which improves the coding efficiency.
One of UVLC encoding methods is exponential Columbus encoding. The program needs to calculate the coding length Len and its value when implementing this encoding. The following analyzes the unsigned and signed exponent Columbus encoding respectively.
Set the encoding value to code_val.
Static const int I _size0_255 [1, 256] =
{
,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7,
7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7, 7,7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
};
Void bs_write (bs_t * s, int bit_len, int value );
1. UE (V)
1) value = code_val + 1 2) Len = 2 * I _size0_255 [value] + 1 Programming implementation is as follows:
Void ue_v (bs_t * s, unsigned int code_val)
{
Int I _size = 0;
If (val = 0)
{
Bs_write (s, 1, 1 );
}
Else
{
Unsigned int TMP = ++ code_val; If (TMP> = 0x00010000)
{
I _size + = 16;
TMP> = 16;
}
If (TMP> = 0x100)
{
I _size + = 8;
TMP> = 8;
}
I _size + = I _size0_255 [TMP]; bs_write (S, 2 * I _size-1, code_val );
}
}
2. Se (V)
1) if code_val> 0: value = 2 * code_val-1 if code_val> 0: value =-2 * val 2) Len = 2 * I _size0_255 [value] + 1 Programming implementation is as follows:
Static void se_v (bs_t * s, int code_val)
{
Ue_v (S, code_val <= 0? -Code_val * 2: code_val * 2-1 );
}