Refactor: Move ctx_init from cabac to context.

This commit is contained in:
Ari Koivula 2013-09-19 12:47:39 +03:00
parent d47391163c
commit 996769c725
4 changed files with 30 additions and 26 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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

View file

@ -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);