mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-23 18:14:06 +00:00
More work on coeff coding
This commit is contained in:
parent
982170382b
commit
2e3c313932
14
src/cabac.c
14
src/cabac.c
|
@ -80,7 +80,7 @@ uint8_t g_nextState[128][2];
|
|||
cabac_data cabac;
|
||||
|
||||
|
||||
void cxt_init(cabac_ctx* ctx, uint32_t qp, uint32_t initValue )
|
||||
void ctx_init(cabac_ctx* ctx, uint32_t qp, uint32_t initValue )
|
||||
{
|
||||
int slope = (initValue>>4)*5 - 45;
|
||||
int offset = ((initValue&15)<<3)-16;
|
||||
|
@ -91,7 +91,7 @@ void cxt_init(cabac_ctx* ctx, uint32_t qp, uint32_t initValue )
|
|||
}
|
||||
|
||||
|
||||
void cxt_buildNextStateTable()
|
||||
void ctx_buildNextStateTable()
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < 128; i++)
|
||||
|
@ -112,7 +112,7 @@ void cabac_init(cabac_data* data)
|
|||
data->fracBits = 0;
|
||||
data->binCountIncrement = 0;
|
||||
data->uiBinsCoded = 0;
|
||||
cxt_buildNextStateTable();
|
||||
ctx_buildNextStateTable();
|
||||
}
|
||||
|
||||
void cabac_start(cabac_data* data)
|
||||
|
@ -133,9 +133,11 @@ void cabac_encodeBin(cabac_data* data, uint32_t binValue )
|
|||
|
||||
uiLPS = g_aucLPSTable[ CTX_STATE(data->ctx) ][ ( data->uiRange >> 6 ) & 3 ];
|
||||
data->uiRange -= uiLPS;
|
||||
#ifdef _DEBUG
|
||||
printf("\tencodeBin m_uiRange %d uiLPS %d m_uiValue %d ", data->uiRange,uiLPS,data->uiLow);
|
||||
#endif
|
||||
|
||||
//Not the Most Propable Symbol?
|
||||
//Not the Most Probable Symbol?
|
||||
if( binValue != CTX_MPS(data->ctx) )
|
||||
{
|
||||
int numBits = g_aucRenormTable[ uiLPS >> 3 ];
|
||||
|
@ -151,7 +153,9 @@ void cabac_encodeBin(cabac_data* data, uint32_t binValue )
|
|||
ctx_update_MPS(data->ctx);
|
||||
if ( data->uiRange >= 256 )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("enduiValue %d \n",data->uiLow);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -164,7 +168,9 @@ void cabac_encodeBin(cabac_data* data, uint32_t binValue )
|
|||
{
|
||||
cabac_write(data);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
printf("enduiValue %d \n",data->uiLow);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cabac_write(cabac_data* data)
|
||||
|
|
|
@ -30,8 +30,8 @@ typedef struct
|
|||
#define CTX_STATE(ctx) (ctx->ucState>>1)
|
||||
#define CTX_MPS(ctx) (ctx->ucState&1)
|
||||
|
||||
void cxt_init(cabac_ctx* ctx,uint32_t qp, uint32_t initValue );
|
||||
void cxt_buildNextStateTable();
|
||||
void ctx_init(cabac_ctx* ctx,uint32_t qp, uint32_t initValue );
|
||||
void ctx_buildNextStateTable();
|
||||
void ctx_update(cabac_ctx* ctx, int val );
|
||||
//void ctx_update_LPS(cabac_ctx* ctx);
|
||||
//void ctx_update_MPS(cabac_ctx* ctx);
|
||||
|
@ -72,6 +72,7 @@ void cabac_encodeBinTrm(cabac_data* data, uint8_t binValue );
|
|||
#define CABAC_BIN(data, value, name) { uint32_t prev_state = (data)->ctx->ucState;\
|
||||
cabac_encodeBin(data, value); \
|
||||
printf("%s = %d prev_state=%d state=%d\n",name,value,prev_state, (data)->ctx->ucState);}
|
||||
|
||||
#define CABAC_BINS_EP(data, value,bins, name) { uint32_t prev_state = (data)->ctx->ucState;\
|
||||
cabac_encodeBinsEP(data, value,bins); \
|
||||
printf("%s = %d prev_state=%d state=%d\n",name,value,prev_state, (data)->ctx->ucState);}
|
||||
|
|
|
@ -260,50 +260,56 @@ cabac_ctx g_QtCbfSCModelU[3];
|
|||
//cabac_ctx g_QtCbfSCModelV[3];
|
||||
cabac_ctx g_PartSizeSCModel;
|
||||
cabac_ctx g_CUSigCoeffGroupSCModel[4];
|
||||
cabac_ctx g_CUSigSCModel[45];
|
||||
cabac_ctx g_CUSigSCModel_luma[24];
|
||||
cabac_ctx g_CUSigSCModel_chroma[24];
|
||||
cabac_ctx g_CuCtxLastY_luma[15];
|
||||
cabac_ctx g_CuCtxLastY_chroma[15];
|
||||
cabac_ctx g_CuCtxLastX_luma[15];
|
||||
cabac_ctx g_CuCtxLastX_chroma[15];
|
||||
|
||||
|
||||
void encode_slice_data(encoder_control* encoder)
|
||||
{
|
||||
uint16_t xCtb,yCtb,i;
|
||||
/* Initialize contexts */
|
||||
/* ToDo: add P/B slice */
|
||||
cxt_init(&g_SplitFlagSCModel[0], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][0]);
|
||||
cxt_init(&g_SplitFlagSCModel[1], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][1]);
|
||||
cxt_init(&g_SplitFlagSCModel[2], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][2]);
|
||||
ctx_init(&g_SplitFlagSCModel[0], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][0]);
|
||||
ctx_init(&g_SplitFlagSCModel[1], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][1]);
|
||||
ctx_init(&g_SplitFlagSCModel[2], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][2]);
|
||||
|
||||
cxt_init(&g_IntraModeSCModel, encoder->QP, INIT_INTRA_PRED_MODE[SLICE_I]);
|
||||
ctx_init(&g_IntraModeSCModel, encoder->QP, INIT_INTRA_PRED_MODE[SLICE_I]);
|
||||
|
||||
cxt_init(&g_ChromaPredSCModel[0], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][0]);
|
||||
cxt_init(&g_ChromaPredSCModel[1], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][1]);
|
||||
ctx_init(&g_ChromaPredSCModel[0], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][0]);
|
||||
ctx_init(&g_ChromaPredSCModel[1], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][1]);
|
||||
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
cxt_init(&g_TransSubdivSCModel[i], encoder->QP, INIT_TRANS_SUBDIV_FLAG[SLICE_I][i]);
|
||||
cxt_init(&g_CUSigCoeffGroupSCModel[i], encoder->QP, INIT_SIG_CG_FLAG[SLICE_I][i]);
|
||||
ctx_init(&g_TransSubdivSCModel[i], encoder->QP, INIT_TRANS_SUBDIV_FLAG[SLICE_I][i]);
|
||||
ctx_init(&g_CUSigCoeffGroupSCModel[i], encoder->QP, INIT_SIG_CG_FLAG[SLICE_I][i]);
|
||||
}
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
cxt_init(&g_QtCbfSCModelY[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
cxt_init(&g_QtCbfSCModelU[i], encoder->QP, INIT_QT_CBF[SLICE_I][i+3]);
|
||||
ctx_init(&g_QtCbfSCModelY[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
ctx_init(&g_QtCbfSCModelU[i], encoder->QP, INIT_QT_CBF[SLICE_I][i+3]);
|
||||
//cxt_init(&g_QtCbfSCModelV[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
}
|
||||
for(i = 0; i < 15; i++)
|
||||
{
|
||||
cxt_init(&g_CuCtxLastY_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
cxt_init(&g_CuCtxLastX_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
ctx_init(&g_CuCtxLastY_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
ctx_init(&g_CuCtxLastX_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
|
||||
cxt_init(&g_CuCtxLastY_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
cxt_init(&g_CuCtxLastX_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
ctx_init(&g_CuCtxLastY_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
ctx_init(&g_CuCtxLastX_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
}
|
||||
|
||||
for(i = 0; i < 45; i++)
|
||||
for(i = 0; i < 24; i++)
|
||||
{
|
||||
cxt_init(&g_CUSigSCModel[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i]);
|
||||
ctx_init(&g_CUSigSCModel_luma[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i]);
|
||||
if(i < 21)
|
||||
{
|
||||
ctx_init(&g_CUSigSCModel_chroma[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i+24]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -460,7 +466,7 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
CABAC_BIN(&cabac,CbU,"cbf_chroma_u");
|
||||
|
||||
/* Non-zero chroma V Tcoeffs */
|
||||
cabac.ctx = &g_QtCbfSCModelU[0];
|
||||
/* Using the same ctx as before */
|
||||
CABAC_BIN(&cabac,CbV,"cbf_chroma_v");
|
||||
|
||||
/* Non-zero luma Tcoeffs */
|
||||
|
@ -472,6 +478,7 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
{
|
||||
/* Residual Coding */
|
||||
/* LastSignificantXY */
|
||||
/* ToDo: separate to a function */
|
||||
//encode_lastSignificantXY(uint8_t lastpos_x, uint8_t lastpos_y, uint8_t width, uint8_t height, uint8_t type, uint8_t scan)
|
||||
uint8_t lastpos_x = 31, lastpos_y = 31;
|
||||
uint8_t last_x = 1, last_y = 1;
|
||||
|
@ -531,14 +538,23 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
}
|
||||
/* end LastSignificantXY */
|
||||
|
||||
for(i = 15; i >= 0; i-- )
|
||||
{
|
||||
/* significant_coeff_flag */
|
||||
cabac.ctx = &g_CUSigSCModel_luma[21]; /* 21 = uiCtxSig =TComTrQuant::getSigCtxInc( patternSigCtx, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );*/
|
||||
CABAC_BIN(&cabac,0,"significant_coeff_flag");
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
/* significant_coeff_flag */
|
||||
cabac.ctx = &g_CUSigSCModel_luma[8]; /* 8 = 4 * uiCtxSet */
|
||||
CABAC_BIN(&cabac,0,"significant_coeff_flag");
|
||||
}
|
||||
|
||||
/* end Residual Coding */
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
typedef struct encoder_control;
|
||||
|
||||
//ToDo: add ME data
|
||||
/* ToDo: add ME data */
|
||||
typedef struct
|
||||
{
|
||||
void (*IME)();
|
||||
|
@ -41,6 +41,7 @@ typedef struct
|
|||
uint8_t video_format;
|
||||
} encoder_input;
|
||||
|
||||
/* Encoder control options, the main struct */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t frame;
|
||||
|
@ -66,7 +67,9 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
|
||||
|
||||
static const uint8_t INIT_SPLIT_FLAG[3][3] =
|
||||
{ { 107, 139, 126 }, { 107, 139, 126 }, { 139, 141, 157 } };
|
||||
{ { 107, 139, 126 },
|
||||
{ 107, 139, 126 },
|
||||
{ 139, 141, 157 } };
|
||||
|
||||
static const uint8_t INIT_INTRA_PRED_MODE[3] = { 183,154,184 };
|
||||
|
||||
|
@ -91,9 +94,14 @@ static const uint8_t INIT_SIG_CG_FLAG[3][4] =
|
|||
{ { 121, 140, 61, 154 }, { 121, 140, 61, 154 }, { 91, 171, 134, 141 } };
|
||||
|
||||
static const uint8_t INIT_SIG_FLAG[3][45] =
|
||||
{{170,154,139,153,139,123,123, 63,124,153,153,152,152,152,137,152,137,137,166,183,140,136,153,154,170,153,138,138,122,121,122,121,167,153,167,136,121,122,136,121,122,91,151,183,140,},
|
||||
{155,154,139,153,139,123,123, 63,153,153,153,152,152,152,137,152,137,122,166,183,140,136,153,154,170,153,123,123,107,121,107,121,167,153,167,136,149,107,136,121,122,91,151,183,140,},
|
||||
{111,111,125,110,110, 94,124,108,124,139,139,139,168,124,138,124,138,107,107,125,141,179,153,125,140,139,182,182,152,136,152,136,153,182,137,149,192,152,224,136,31,136,136,139,111,} };
|
||||
{{170,154,139,153,139,123,123, 63,124,153,153,152,152,152,137,152,137,137,166,183,140,136,153,
|
||||
154,170,153,138,138,122,121,122,121,167,153,167,136,121,122,136,121,122, 91,151,183,140,},
|
||||
|
||||
{155,154,139,153,139,123,123, 63,153,153,153,152,152,152,137,152,137,122,166,183,140,136,153,
|
||||
154,170,153,123,123,107,121,107,121,167,153,167,136,149,107,136,121,122, 91,151,183,140,},
|
||||
|
||||
{111,111,125,110,110, 94,124,108,124,139,139,139,168,124,138,124,138,107,107,125,141,179,153,
|
||||
125,140,139,182,182,152,136,152,136,153,182,137,149,192,152,224,136, 31,136,136,139,111,} };
|
||||
|
||||
static const uint8_t INIT_LAST[3][30] =
|
||||
{
|
||||
|
@ -107,5 +115,16 @@ static const uint8_t INIT_LAST[3][30] =
|
|||
|
||||
static const uint8_t g_uiGroupIdx[ 32 ] = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9};
|
||||
static const uint8_t g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24};
|
||||
static const uint8_t g_sigLastScanCG32x32[ 64 ] =
|
||||
{ 0, 8, 1,16, 9, 2,24,17,
|
||||
10, 3,32,25,18,11, 4,40,
|
||||
33,26,19,12, 5,48,41,34,
|
||||
27,20,13, 6,56,49,42,35,
|
||||
28,21,14, 7,57,50,43,36,
|
||||
29,22,15,58,51,44,37,30,
|
||||
23,59,52,45,38,31,60,53,
|
||||
46,39,61,54,47,62,55,63 };
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue