Merge branch 'inter_deblock'

This commit is contained in:
Marko Viitanen 2013-10-08 12:14:20 +03:00
commit a477d554d5
3 changed files with 29 additions and 17 deletions

View file

@ -146,7 +146,7 @@ int main(int argc, char *argv[])
encoder->QP = 32; encoder->QP = 32;
encoder->in.video_format = FORMAT_420; encoder->in.video_format = FORMAT_420;
// deblocking filter // deblocking filter
encoder->deblock_enable = 0; encoder->deblock_enable = 1;
encoder->beta_offset_div2 = 0; encoder->beta_offset_div2 = 0;
encoder->tc_offset_div2 = 0; encoder->tc_offset_div2 = 0;
// SAO // SAO

View file

@ -318,10 +318,7 @@ void encode_one_frame(encoder_control *encoder)
} }
// Filtering // Filtering
// TODO: Check for correct deblock condition on inter blocks filter_deblock(encoder);
if (encoder->deblock_enable && encoder->in.cur_pic->slicetype == SLICE_I) {
filter_deblock(encoder);
}
// Calculate checksum // Calculate checksum
add_checksum(encoder); add_checksum(encoder);

View file

@ -157,13 +157,16 @@ void filter_deblock_edge_luma(encoder_control *encoder,
int32_t stride = encoder->in.cur_pic->width; int32_t stride = encoder->in.cur_pic->width;
int32_t offset = stride; int32_t offset = stride;
int32_t beta_offset_div2 = encoder->beta_offset_div2; int32_t beta_offset_div2 = encoder->beta_offset_div2;
int32_t tc_offset_div2 = encoder->tc_offset_div2; int32_t tc_offset_div2 = encoder->tc_offset_div2;
int8_t strength = 2; // Filter strength
// TODO: support 10+bits // TODO: support 10+bits
uint8_t *orig_src = &encoder->in.cur_pic->y_recdata[xpos + ypos*stride]; uint8_t *orig_src = &encoder->in.cur_pic->y_recdata[xpos + ypos*stride];
uint8_t *src = orig_src; uint8_t *src = orig_src;
int32_t step = 1; int32_t step = 1;
cu_info *cu_q = &encoder->in.cur_pic->cu_array[MAX_DEPTH][(xpos>>MIN_SIZE) + (ypos>>MIN_SIZE) * (encoder->in.width_in_lcu << MAX_DEPTH)];
cu_info *cu_p = 0;
int8_t strength = 0;
if(dir == EDGE_VER) { if(dir == EDGE_VER) {
offset = 1; offset = 1;
step = stride; step = stride;
@ -171,23 +174,31 @@ void filter_deblock_edge_luma(encoder_control *encoder,
{ {
int32_t qp = encoder->QP; int32_t qp = encoder->QP;
int32_t bitdepth_scale = 1 << (g_bitdepth - 8); int32_t bitdepth_scale = 1 << (g_bitdepth - 8);
int32_t tc_index = CLIP(0, 51 + 2, (int32_t)(qp + 2*(strength - 1) + (tc_offset_div2 << 1)));
int32_t b_index = CLIP(0, 51, qp + (beta_offset_div2 << 1)); int32_t b_index = CLIP(0, 51, qp + (beta_offset_div2 << 1));
int32_t tc = g_tc_table_8x8[tc_index] * bitdepth_scale;
int32_t beta = g_beta_table_8x8[b_index] * bitdepth_scale; int32_t beta = g_beta_table_8x8[b_index] * bitdepth_scale;
int32_t side_threshold = (beta + (beta >>1 )) >> 3; int32_t side_threshold = (beta + (beta >>1 )) >> 3;
int32_t thr_cut = tc * 10;
uint32_t blocks_in_part = (LCU_WIDTH >> depth) / 4; uint32_t blocks_in_part = (LCU_WIDTH >> depth) / 4;
uint32_t block_idx; uint32_t block_idx;
int32_t tc_index,tc,thr_cut;
// TODO: add CU based QP calculation // TODO: add CU based QP calculation
// For each 4-pixel part in the edge // For each 4-pixel part in the edge
for (block_idx = 0; block_idx < blocks_in_part; ++block_idx) for (block_idx = 0; block_idx < blocks_in_part; ++block_idx) {
{
int32_t dp0, dq0, dp3, dq3, d0, d3, dp, dq, d; int32_t dp0, dq0, dp3, dq3, d0, d3, dp, dq, d;
if((block_idx & 1) == 0)
{
// CU in the side we are filtering, update every 8-pixels
cu_p = &encoder->in.cur_pic->cu_array[MAX_DEPTH][((xpos>>MIN_SIZE)-(dir == EDGE_VER)+(dir == EDGE_HOR?block_idx/2:0)) +
((ypos>>MIN_SIZE)-(dir == EDGE_HOR)+(dir == EDGE_VER?block_idx/2:0)) * (encoder->in.width_in_lcu << MAX_DEPTH)];
// Filter strength
strength = ((cu_q->type == CU_INTRA || cu_p->type == CU_INTRA) ? 2 :
(((abs(cu_q->inter.mv[0] - cu_p->inter.mv[0]) >= 4) || (abs(cu_q->inter.mv[1] - cu_p->inter.mv[1]) >= 4)) ? 1 : 0));
tc_index = CLIP(0, 51 + 2, (int32_t)(qp + 2*(strength - 1) + (tc_offset_div2 << 1)));
tc = g_tc_table_8x8[tc_index] * bitdepth_scale;
thr_cut = tc * 10;
}
if(!strength) continue;
// Check conditions for filtering // Check conditions for filtering
// TODO: Get rid of these inline defines. // TODO: Get rid of these inline defines.
#define calc_DP(s,o) abs( (int16_t)s[-o*3] - (int16_t)2*s[-o*2] + (int16_t)s[-o] ) #define calc_DP(s,o) abs( (int16_t)s[-o*3] - (int16_t)2*s[-o*2] + (int16_t)s[-o] )
@ -242,9 +253,13 @@ void filter_deblock_edge_chroma(encoder_control *encoder,
// Init offset and step to EDGE_HOR // Init offset and step to EDGE_HOR
int32_t offset = stride; int32_t offset = stride;
int32_t step = 1; int32_t step = 1;
cu_info *cu_q = &encoder->in.cur_pic->cu_array[MAX_DEPTH][(x>>(MIN_SIZE-1)) + (y>>(MIN_SIZE-1)) * (encoder->in.width_in_lcu << MAX_DEPTH)];
cu_info *cu_p = &encoder->in.cur_pic->cu_array[MAX_DEPTH][((x>>(MIN_SIZE-1))-(dir == EDGE_VER)) +
((y>>(MIN_SIZE-1))-(dir == EDGE_HOR)) * (encoder->in.width_in_lcu << MAX_DEPTH)];
int8_t strength = (cu_q->type == CU_INTRA || cu_p->type == CU_INTRA) ? 2 : 0; // Filter strength
// We cannot filter edges not on 8x8 grid // We cannot filter edges not on 8x8 grid
if(depth == MAX_DEPTH && (( (y & 0x7) && dir == EDGE_HOR ) || ( (x & 0x7) && dir == EDGE_VER ) ) ) if(strength != 2 || (depth == MAX_DEPTH && (( (y & 0x7) && dir == EDGE_HOR ) || ( (x & 0x7) && dir == EDGE_VER ) ) ))
{ {
return; return;
} }
@ -259,7 +274,7 @@ void filter_deblock_edge_chroma(encoder_control *encoder,
{ {
int32_t QP = g_chroma_scale[encoder->QP]; int32_t QP = g_chroma_scale[encoder->QP];
int32_t bitdepth_scale = 1 << (g_bitdepth-8); int32_t bitdepth_scale = 1 << (g_bitdepth-8);
int32_t TC_index = CLIP(0, 51+2, (int32_t)(QP + 2 + (tc_offset_div2 << 1))); int32_t TC_index = CLIP(0, 51+2, (int32_t)(QP + 2*(strength-1) + (tc_offset_div2 << 1)));
int32_t Tc = g_tc_table_8x8[TC_index]*bitdepth_scale; int32_t Tc = g_tc_table_8x8[TC_index]*bitdepth_scale;
uint32_t blocks_in_part= (LCU_WIDTH>>(depth+1)) / 4; uint32_t blocks_in_part= (LCU_WIDTH>>(depth+1)) / 4;
uint32_t blk_idx; uint32_t blk_idx;