|
|
|
@ -25,10 +25,8 @@ |
|
|
|
|
* @author Thilo Borgmann <thilo.borgmann _at_ googlemail.com> |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "bgmc.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define FREQ_BITS 14 // bits used by frequency counters
|
|
|
|
|
#define VALUE_BITS 18 // bits used to represent the values
|
|
|
|
|
#define TOP_VALUE ((1 << VALUE_BITS) - 1) // maximum value
|
|
|
|
@ -41,8 +39,7 @@ |
|
|
|
|
#define LUT_BUFF 4 // number of buffered lookup tables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Cumulative frequency tables for block Gilbert-Moore coding.
|
|
|
|
|
*/ |
|
|
|
|
/** Cumulative frequency tables for block Gilbert-Moore coding. */ |
|
|
|
|
static const uint16_t cf_tables_1[3][129] = { |
|
|
|
|
{ |
|
|
|
|
16384, 16066, 15748, 15431, 15114, 14799, 14485, 14173, 13861, 13552, |
|
|
|
@ -416,7 +413,7 @@ static const uint16_t cf_tables_3[5][257] = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const uint16_t * const cf_table[16] = { |
|
|
|
|
static const uint16_t *const cf_table[16] = { |
|
|
|
|
cf_tables_1[0], cf_tables_1[1], cf_tables_1[2], cf_tables_2[0], |
|
|
|
|
cf_tables_2[1], cf_tables_2[2], cf_tables_2[3], cf_tables_2[4], |
|
|
|
|
cf_tables_2[5], cf_tables_2[6], cf_tables_2[7], cf_tables_3[0], |
|
|
|
@ -424,10 +421,8 @@ static const uint16_t * const cf_table[16] = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Initialize a given lookup table using a given delta
|
|
|
|
|
*/ |
|
|
|
|
static void bgmc_lut_fillp(uint8_t *lut, int *lut_status, |
|
|
|
|
int delta) |
|
|
|
|
/** Initialize a given lookup table using a given delta */ |
|
|
|
|
static void bgmc_lut_fillp(uint8_t *lut, int *lut_status, int delta) |
|
|
|
|
{ |
|
|
|
|
unsigned int sx, i; |
|
|
|
|
|
|
|
|
@ -446,10 +441,8 @@ static void bgmc_lut_fillp(uint8_t *lut, int *lut_status, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Retune the index of a suitable lookup table for a given delta
|
|
|
|
|
*/ |
|
|
|
|
static uint8_t* bgmc_lut_getp(uint8_t *lut, int *lut_status, |
|
|
|
|
int delta) |
|
|
|
|
/** Retune the index of a suitable lookup table for a given delta */ |
|
|
|
|
static uint8_t *bgmc_lut_getp(uint8_t *lut, int *lut_status, int delta) |
|
|
|
|
{ |
|
|
|
|
unsigned int i = av_clip(delta, 0, LUT_BUFF - 1); |
|
|
|
|
|
|
|
|
@ -462,11 +455,10 @@ static uint8_t* bgmc_lut_getp(uint8_t *lut, int *lut_status, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Initialize the lookup table arrays
|
|
|
|
|
*/ |
|
|
|
|
/** Initialize the lookup table arrays */ |
|
|
|
|
int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status) |
|
|
|
|
{ |
|
|
|
|
*cf_lut = av_malloc(sizeof(*cf_lut ) * LUT_BUFF * 16 * LUT_SIZE); |
|
|
|
|
*cf_lut = av_malloc(sizeof(*cf_lut) * LUT_BUFF * 16 * LUT_SIZE); |
|
|
|
|
*cf_lut_status = av_malloc(sizeof(*cf_lut_status) * LUT_BUFF); |
|
|
|
|
|
|
|
|
|
if (!cf_lut || !cf_lut_status) { |
|
|
|
@ -474,8 +466,7 @@ int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status) |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); |
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
} else { |
|
|
|
|
// initialize lut_status buffer to a value never used to compare
|
|
|
|
|
// against
|
|
|
|
|
// initialize lut_status buffer to a value never used to compare against
|
|
|
|
|
memset(*cf_lut_status, -1, sizeof(*cf_lut_status) * LUT_BUFF); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -483,8 +474,7 @@ int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Release the lookup table arrays
|
|
|
|
|
*/ |
|
|
|
|
/** Release the lookup table arrays */ |
|
|
|
|
void ff_bgmc_end(uint8_t **cf_lut, int **cf_lut_status) |
|
|
|
|
{ |
|
|
|
|
av_freep(cf_lut); |
|
|
|
@ -492,10 +482,9 @@ void ff_bgmc_end(uint8_t **cf_lut, int **cf_lut_status) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Initialize decoding and reads the first value
|
|
|
|
|
*/ |
|
|
|
|
void ff_bgmc_decode_init(GetBitContext *gb, |
|
|
|
|
unsigned int *h, unsigned int *l, unsigned int *v) |
|
|
|
|
/** Initialize decoding and reads the first value */ |
|
|
|
|
void ff_bgmc_decode_init(GetBitContext *gb, unsigned int *h, unsigned int *l, |
|
|
|
|
unsigned int *v) |
|
|
|
|
{ |
|
|
|
|
*h = TOP_VALUE; |
|
|
|
|
*l = 0; |
|
|
|
@ -503,16 +492,14 @@ void ff_bgmc_decode_init(GetBitContext *gb, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Finish decoding
|
|
|
|
|
*/ |
|
|
|
|
/** Finish decoding */ |
|
|
|
|
void ff_bgmc_decode_end(GetBitContext *gb) |
|
|
|
|
{ |
|
|
|
|
skip_bits_long(gb, -(VALUE_BITS - 2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Read and decode a block Gilbert-Moore coded symbol
|
|
|
|
|
*/ |
|
|
|
|
/** Read and decode a block Gilbert-Moore coded symbol */ |
|
|
|
|
void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, |
|
|
|
|
int delta, unsigned int sx, |
|
|
|
|
unsigned int *h, unsigned int *l, unsigned int *v, |
|
|
|
@ -539,8 +526,8 @@ void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, |
|
|
|
|
|
|
|
|
|
symbol = (symbol >> delta) - 1; |
|
|
|
|
|
|
|
|
|
high = low + ((range * cf_table[sx][(symbol ) << delta] - (1 << FREQ_BITS)) >> FREQ_BITS); |
|
|
|
|
low = low + ((range * cf_table[sx][(symbol + 1) << delta] ) >> FREQ_BITS); |
|
|
|
|
high = low + ((range * cf_table[sx][(symbol) << delta] - (1 << FREQ_BITS)) >> FREQ_BITS); |
|
|
|
|
low = low + ((range * cf_table[sx][(symbol + 1) << delta]) >> FREQ_BITS); |
|
|
|
|
|
|
|
|
|
while (1) { |
|
|
|
|
if (high >= HALF) { |
|
|
|
@ -552,7 +539,8 @@ void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, |
|
|
|
|
value -= FIRST_QTR; |
|
|
|
|
low -= FIRST_QTR; |
|
|
|
|
high -= FIRST_QTR; |
|
|
|
|
} else break; |
|
|
|
|
} else |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
low *= 2; |
|
|
|
|