diff --git a/src/cabac.c b/src/cabac.c index f68b98fc..fcbdb241 100644 --- a/src/cabac.c +++ b/src/cabac.c @@ -65,23 +65,6 @@ const uint8_t g_auc_renorm_table[32] = cabac_data cabac; -/** - * \brief Initialize struct cabac_ctx. - */ -void ctx_init(cabac_ctx *ctx, uint32_t qp, uint32_t init_value) -{ - int slope = (init_value >> 4) * 5 - 45; - int offset = ((init_value & 15) << 3) - 16; - int init_state = MIN(MAX(1, ((slope * (int)qp) >> 4) + offset), 126); - uint8_t mp_state = (init_state >= 64) ? 1 : 0; - - if (mp_state) { - ctx->uc_state = (init_state - 64) << 1 + mp_state; - } else { - ctx->uc_state = (63 - init_state) << 1; - } - ctx->bins_coded = 0; -} /** * \brief Initialize struct cabac_data. diff --git a/src/cabac.h b/src/cabac.h index a96be895..52d08c6e 100644 --- a/src/cabac.h +++ b/src/cabac.h @@ -15,15 +15,10 @@ #include "global.h" #include "bitstream.h" +#include "context.h" // Types -typedef struct -{ - uint8_t uc_state; - uint32_t bins_coded; -} cabac_ctx; - typedef struct { cabac_ctx *ctx; @@ -48,8 +43,6 @@ extern cabac_data cabac; // Functions -void ctx_init(cabac_ctx* ctx, uint32_t qp, uint32_t init_value); - void cabac_start(cabac_data *data); void cabac_init(cabac_data *data); void cabac_encode_bin(cabac_data *data, uint32_t bin_value); diff --git a/src/context.c b/src/context.c index 745935b1..3dfed865 100644 --- a/src/context.c +++ b/src/context.c @@ -47,6 +47,24 @@ cabac_ctx g_mvp_idx_model[2]; cabac_ctx g_cu_qt_root_cbf_model; +/** + * \brief Initialize struct cabac_ctx. + */ +void ctx_init(cabac_ctx *ctx, uint32_t qp, uint32_t init_value) +{ + int slope = (init_value >> 4) * 5 - 45; + int offset = ((init_value & 15) << 3) - 16; + int init_state = MIN(MAX(1, ((slope * (int)qp) >> 4) + offset), 126); + uint8_t mp_state = (init_state >= 64) ? 1 : 0; + + if (mp_state) { + ctx->uc_state = (init_state - 64) << 1 + mp_state; + } else { + ctx->uc_state = (63 - init_state) << 1; + } + ctx->bins_coded = 0; +} + /** * \brief Initialize cabac context to be used for coding * \param encoder encoder control struct diff --git a/src/context.h b/src/context.h index 97fe9e5c..c2d5cbf3 100644 --- a/src/context.h +++ b/src/context.h @@ -15,8 +15,18 @@ #include "global.h" #include "encoder.h" -#include "cabac.h" + +// Types +typedef struct +{ + uint8_t uc_state; + uint32_t bins_coded; +} cabac_ctx; + + +// Functions +void ctx_init(cabac_ctx* ctx, uint32_t qp, uint32_t init_value); void init_contexts(encoder_control *encoder, int8_t slice); int32_t context_calc_pattern_sig_ctx( const uint32_t *sig_coeff_group_flag, uint32_t pos_x, uint32_t pos_y, int32_t width);