const bit_table for exp_golomb

This commit is contained in:
Laurent Fasnacht 2014-04-15 14:37:16 +02:00
parent 763b775d3e
commit 288a4537ba
2 changed files with 9 additions and 6 deletions

View file

@ -63,7 +63,7 @@ void printf_bitstream(char *msg, ...)
}
#endif
bit_table *g_exp_table;
const bit_table *g_exp_table;
//From wikipedia
//http://en.wikipedia.org/wiki/Binary_logarithm#Algorithm
@ -89,16 +89,19 @@ int init_exp_golomb(uint32_t len)
uint32_t code_num;
uint8_t M;
uint32_t info;
g_exp_table = (bit_table*)malloc(len*sizeof(bit_table));
if(!g_exp_table)
bit_table* exp_table;
exp_table = (bit_table*)malloc(len*sizeof(bit_table));
if(!exp_table)
return 0;
for (code_num = 0; code_num < len; code_num++) {
M = (uint8_t)floor_log2(code_num + 1);
info = code_num + 1 - (uint32_t)pow(2, M);
g_exp_table[code_num].len = M * 2 + 1;
g_exp_table[code_num].value = (1<<M) | info;
exp_table[code_num].len = M * 2 + 1;
exp_table[code_num].value = (1<<M) | info;
}
g_exp_table = exp_table;
return 1;
}

View file

@ -58,7 +58,7 @@ typedef struct
uint32_t value;
} bit_table;
extern bit_table *g_exp_table;
extern const bit_table *g_exp_table;
int floor_log2(unsigned int n);