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

View file

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