Remove Exp-Golomb lookup table

This table takes 256kB and isn't used very much. Au revoir!
This commit is contained in:
Ari Koivula 2017-01-31 17:53:47 +02:00
parent e85266efe7
commit ed3bd898fd
4 changed files with 27 additions and 37 deletions

View file

@ -39,8 +39,6 @@ const uint32_t kvz_bit_set_mask[] =
0x10000000,0x20000000,0x40000000,0x80000000
};
bit_table_t kvz_g_exp_table[EXP_GOLOMB_TABLE_SIZE];
//#define VERBOSE
@ -56,29 +54,6 @@ void printf_bitstream(char *msg, ...)
}
#endif
/**
* \brief Initialize the Exp Golomb code table.
*
* Fills kvz_g_exp_table with exponential golomb codes.
*/
void kvz_init_exp_golomb()
{
static int exp_table_initialized = 0;
if (exp_table_initialized) return;
uint32_t code_num;
uint8_t M;
uint32_t info;
for (code_num = 0; code_num < EXP_GOLOMB_TABLE_SIZE; code_num++) {
M = kvz_math_floor_log2(code_num + 1);
info = code_num + 1 - (uint32_t)pow(2, M);
kvz_g_exp_table[code_num].len = M * 2 + 1;
kvz_g_exp_table[code_num].value = (1<<M) | info;
}
exp_table_initialized = 1;
}
/**
* \brief Initialize a new bitstream.
*/
@ -259,6 +234,30 @@ void kvz_bitstream_put(bitstream_t *const stream, const uint32_t data, uint8_t b
}
}
/**
* \brief Write unsigned Exp-Golomb bit string
*/
void bitstream_put_ue(bitstream_t *stream, uint32_t code_num)
{
unsigned code_num_log2 = kvz_math_floor_log2(code_num + 1);
unsigned prefix = 1 << code_num_log2;
unsigned suffix = code_num + 1 - prefix;
unsigned num_bits = code_num_log2 * 2 + 1;
unsigned value = prefix | suffix;
kvz_bitstream_put(stream, value, num_bits);
}
/**
* \brief Write signed Exp-Golomb bit string
*/
void bitstream_put_se(bitstream_t *stream, int32_t data)
{
// Map positive values to even and negative to odd values.
uint32_t code_num = data <= 0 ? (-data) << 1 : (data << 1) - 1;
bitstream_put_ue(stream, code_num);
}
/**
* \brief Add rbsp_trailing_bits syntax element, which aligns the bitstream.
*/

View file

@ -60,10 +60,6 @@ typedef struct
uint32_t value;
} bit_table_t;
extern bit_table_t kvz_g_exp_table[EXP_GOLOMB_TABLE_SIZE];
void kvz_init_exp_golomb();
void kvz_bitstream_init(bitstream_t * stream);
kvz_data_chunk * kvz_bitstream_alloc_chunk();
kvz_data_chunk * kvz_bitstream_take_chunks(bitstream_t *stream);
@ -78,10 +74,9 @@ void kvz_bitstream_clear(bitstream_t *stream);
void kvz_bitstream_put(bitstream_t *stream, uint32_t data, uint8_t bits);
void kvz_bitstream_put_byte(bitstream_t *const stream, const uint32_t data);
/* Use macros to force inlining */
#define bitstream_put_ue(stream, data) { kvz_bitstream_put(stream,kvz_g_exp_table[data].value,kvz_g_exp_table[data].len); }
#define bitstream_put_se(stream, data) { uint32_t index=(uint32_t)(((data)<=0)?(-(data))<<1:((data)<<1)-1); \
kvz_bitstream_put(stream,kvz_g_exp_table[index].value,kvz_g_exp_table[index].len); }
void bitstream_put_ue(bitstream_t *stream, uint32_t data);
void bitstream_put_se(bitstream_t *stream, int32_t data);
void kvz_bitstream_add_rbsp_trailing_bits(bitstream_t *stream);
void kvz_bitstream_align(bitstream_t *stream);

View file

@ -247,8 +247,6 @@ typedef int16_t coeff_t;
#define MAX_TR_DYNAMIC_RANGE 15
#define EXP_GOLOMB_TABLE_SIZE (4096*8)
//Constants
typedef enum { COLOR_Y = 0, COLOR_U, COLOR_V } color_t;

View file

@ -68,8 +68,6 @@ static kvz_encoder * kvazaar_open(const kvz_config *cfg)
goto kvazaar_open_failure;
}
kvz_init_exp_golomb();
encoder = calloc(1, sizeof(kvz_encoder));
if (!encoder) {
goto kvazaar_open_failure;