Added LastSignificantXY encoding

This commit is contained in:
Marko Viitanen 2012-06-13 15:15:07 +03:00
parent 53f8d9f83a
commit 982170382b
3 changed files with 101 additions and 5 deletions

View file

@ -75,9 +75,14 @@ void cabac_encodeBinTrm(cabac_data* data, uint8_t binValue );
#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);}
#define CABAC_BIN_EP(data, value, name) { uint32_t prev_state = (data)->ctx->ucState;\
cabac_encodeBinEP(data, value); \
printf("%s = %d prev_state=%d state=%d\n",name,value,prev_state, (data)->ctx->ucState);}
#else
#define CABAC_BIN(data, value, name) cabac_encodeBin(data, value);
#define CABAC_BINS_EP(data, value,bins, name) cabac_encodeBinsEP(data, value,bins);
#define CABAC_BIN_EP(data, value,bins, name) cabac_encodeBinEP(data, value);
#endif
#endif

View file

@ -133,7 +133,7 @@ void encode_pic_parameter_set(encoder_control* encoder)
*/
WRITE_SE(encoder->stream, encoder->QP-26, "pic_init_qp_minus26");
WRITE_U(encoder->stream, 0, 1, "constrained_intra_pred_flag");
WRITE_U(encoder->stream, 0, 1, "enable_temporal_mvp_flag");
WRITE_U(encoder->stream, 0, 1, "enable_temporal_mvp_flag"); /* ToDo: remove this */
WRITE_U(encoder->stream, 0, 2, "slice_granularity");
WRITE_UE(encoder->stream, 0, "max_cu_qp_delta_depth");
WRITE_SE(encoder->stream, 0, "cb_qp_offset");
@ -261,6 +261,10 @@ cabac_ctx g_QtCbfSCModelU[3];
cabac_ctx g_PartSizeSCModel;
cabac_ctx g_CUSigCoeffGroupSCModel[4];
cabac_ctx g_CUSigSCModel[45];
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)
{
@ -288,6 +292,15 @@ void encode_slice_data(encoder_control* encoder)
cxt_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] );
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] );
}
for(i = 0; i < 45; i++)
{
cxt_init(&g_CUSigSCModel[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i]);
@ -432,30 +445,97 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
cabac.ctx = &g_TransSubdivSCModel[1]; /* //uiLog2TransformBlockSize */
CABAC_BIN(&cabac,0,"TransformSubdivFlag");
/* We don't subdiv and we have 64>>depth transform size */
/* ToDo: allow other sized */
{
uint8_t CbY = 0,CbU = 0,CbV = 0;
/*
Quant and transform ...
*/
CbY = 1;
CbY = 1; /* Let's pretend we have LUMA coefficients */
/* Non-zero chroma U Tcoeffs */
cabac.ctx = &g_QtCbfSCModelU[0];
cabac.ctx = &g_QtCbfSCModelU[0];
CABAC_BIN(&cabac,CbU,"cbf_chroma_u");
/* Non-zero chroma V Tcoeffs */
cabac.ctx = &g_QtCbfSCModelU[0];
cabac.ctx = &g_QtCbfSCModelU[0];
CABAC_BIN(&cabac,CbV,"cbf_chroma_v");
/* Non-zero luma Tcoeffs */
cabac.ctx = &g_QtCbfSCModelY[1];
cabac.ctx = &g_QtCbfSCModelY[1];
CABAC_BIN(&cabac,CbY,"cbf_luma");
/* CoeffNxN */
if(CbY)
{
/* Residual Coding */
/* LastSignificantXY */
//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;
uint8_t offset_x = 10,offset_y = 10;
uint8_t shift_x = 1, shift_y = 1;
int uiGroupIdxX = g_uiGroupIdx[ lastpos_x ];
int uiGroupIdxY = g_uiGroupIdx[ lastpos_y ];
int temp;
/*
blkSizeOffsetX = eTType ? 0: (g_aucConvertToBit[ width ] *3 + ((g_aucConvertToBit[ width ] +1)>>2));
blkSizeOffsetY = eTType ? 0: (g_aucConvertToBit[ height ]*3 + ((g_aucConvertToBit[ height ]+1)>>2));
shiftX= eTType ? g_aucConvertToBit[ width ] :((g_aucConvertToBit[ width ]+3)>>2);
shiftY= eTType ? g_aucConvertToBit[ height ] :((g_aucConvertToBit[ height ]+3)>>2);
*/
/* Last X binarization */
for(last_x = 0; last_x < uiGroupIdxX ; last_x++)
{
cabac.ctx = &g_CuCtxLastX_luma[offset_x+(last_x>>shift_x)];
CABAC_BIN(&cabac,1,"LastSignificantX");
}
if(uiGroupIdxX < g_uiGroupIdx[32-1])
{
cabac.ctx = &g_CuCtxLastX_luma[offset_x+(last_x>>shift_x)];
CABAC_BIN(&cabac,0,"LastSignificantX");
}
/* Last Y binarization */
for(last_y = 0; last_y < uiGroupIdxY ; last_y++)
{
cabac.ctx = &g_CuCtxLastY_luma[offset_y+(last_y>>shift_y)];
CABAC_BIN(&cabac,1,"LastSignificantY");
}
if(uiGroupIdxY < g_uiGroupIdx[32-1])
{
cabac.ctx = &g_CuCtxLastY_luma[offset_y+(last_y>>shift_y)];
CABAC_BIN(&cabac,0,"LastSignificantY");
}
/* Last X */
if(uiGroupIdxX > 3)
{
lastpos_x -= g_uiMinInGroup[uiGroupIdxX];
for(i = ((uiGroupIdxX-2)>>1)-1; i>=0; i--)
{
CABAC_BIN_EP(&cabac,(lastpos_x>>i) & 1,"LastSignificantX");
}
}
/* Last Y */
if(uiGroupIdxY > 3)
{
lastpos_y -= g_uiMinInGroup[uiGroupIdxY];
for(i = ((uiGroupIdxY-2)>>1)-1; i>=0; i--)
{
CABAC_BIN_EP(&cabac,(lastpos_y>>i) & 1,"LastSignificantY");
}
}
/* end LastSignificantXY */
/* significant_coeff_flag */
/* end Residual Coding */
}

View file

@ -95,6 +95,17 @@ static const uint8_t INIT_SIG_FLAG[3][45] =
{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] =
{
{ 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, 79,
108, 123, 93, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
{ 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, 94,
108, 123, 108, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
{ 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, 79,
108, 123, 63, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU }
};
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};
#endif