H.264的一个重要特色就是采用UVLC(Universal Variable Length coding, 统一可变长编码)编码,提高了编码效率。
UVLC编码中有一种编码方式就是指数哥伦布编码。程序实现该编码时需要计算编码长度len及其value,下面分别对无符号和有符号两种指数哥伦布编码进行分析。
设编码值为code_val。
static const int i_size0_255[256] =
{
1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
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,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,
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,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)
{
int i_size = 0;
{
bs_write( s, 1, 1);
}
else
{
unsigned int tmp = ++code_val;
{
i_size += 16;
tmp >>= 16;
}
if( tmp >= 0x100 )
{
i_size += 8;
tmp >>= 8;
}
i_size += i_size0_255[tmp];
}
}
2. se(v)
{
ue_v( s, code_val <= 0 ? -code_val * 2 : code_val * 2 - 1);
}