diff options
Diffstat (limited to 'libavcodec/h264_loopfilter.c')
-rw-r--r-- | libavcodec/h264_loopfilter.c | 224 |
1 files changed, 59 insertions, 165 deletions
diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c index 325fd3c..2e61a31 100644 --- a/libavcodec/h264_loopfilter.c +++ b/libavcodec/h264_loopfilter.c @@ -101,197 +101,92 @@ static const uint8_t tc0_table[52*3][4] = { }; static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h) { - const int bit_depth = h->sps.bit_depth_luma; - const int qp_bd_offset = 6*(bit_depth-8); + const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; - const int alpha = alpha_table[index_a] << (bit_depth-8); - const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset] << (bit_depth-8); + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 ) { int8_t tc[4]; - tc[0] = tc0_table[index_a][bS[0]] << (bit_depth-8); - tc[1] = tc0_table[index_a][bS[1]] << (bit_depth-8); - tc[2] = tc0_table[index_a][bS[2]] << (bit_depth-8); - tc[3] = tc0_table[index_a][bS[3]] << (bit_depth-8); + tc[0] = tc0_table[index_a][bS[0]]; + tc[1] = tc0_table[index_a][bS[1]]; + tc[2] = tc0_table[index_a][bS[2]]; + tc[3] = tc0_table[index_a][bS[3]]; h->h264dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta); } } static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { - const int bit_depth = h->sps.bit_depth_luma; - const int qp_bd_offset = 6*(bit_depth-8); + const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; - const int alpha = alpha_table[index_a] << (bit_depth-8); - const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset] << (bit_depth-8); + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 ) { int8_t tc[4]; - tc[0] = (tc0_table[index_a][bS[0]] << (bit_depth-8))+1; - tc[1] = (tc0_table[index_a][bS[1]] << (bit_depth-8))+1; - tc[2] = (tc0_table[index_a][bS[2]] << (bit_depth-8))+1; - tc[3] = (tc0_table[index_a][bS[3]] << (bit_depth-8))+1; + tc[0] = tc0_table[index_a][bS[0]]+1; + tc[1] = tc0_table[index_a][bS[1]]+1; + tc[2] = tc0_table[index_a][bS[2]]+1; + tc[3] = tc0_table[index_a][bS[3]]+1; h->h264dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta); } } -static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { - int i; - const int bit_depth = h->sps.bit_depth_luma; - const int qp_bd_offset = 6*(bit_depth-8); +static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[7], int bsi, int qp ) { + const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; - int alpha = alpha_table[index_a] << (bit_depth-8); - int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset] << (bit_depth-8); - for( i = 0; i < 8; i++, pix += stride) { - const int bS_index = (i >> 1) * bsi; - - if( bS[bS_index] == 0 ) { - continue; - } - - if( bS[bS_index] < 4 ) { - const int tc0 = tc0_table[index_a][bS[bS_index]] << (bit_depth-8); - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int p2 = pix[-3]; - const int q0 = pix[0]; - const int q1 = pix[1]; - const int q2 = pix[2]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - int tc = tc0; - int i_delta; - - if( FFABS( p2 - p0 ) < beta ) { - if(tc0) - pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); - tc++; - } - if( FFABS( q2 - q0 ) < beta ) { - if(tc0) - pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); - tc++; - } - - i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); - pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ - pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ - tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); - } - }else{ - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int p2 = pix[-3]; - - const int q0 = pix[0]; - const int q1 = pix[1]; - const int q2 = pix[2]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { + int alpha = alpha_table[index_a]; + int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; + if (alpha ==0 || beta == 0) return; - if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ - if( FFABS( p2 - p0 ) < beta) - { - const int p3 = pix[-4]; - /* p0', p1', p2' */ - pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; - pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; - pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; - } else { - /* p0' */ - pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; - } - if( FFABS( q2 - q0 ) < beta) - { - const int q3 = pix[3]; - /* q0', q1', q2' */ - pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; - pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; - pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; - } else { - /* q0' */ - pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; - } - }else{ - /* p0', q0' */ - pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; - pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; - } - tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); - } - } + if( bS[0] < 4 ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0*bsi]]; + tc[1] = tc0_table[index_a][bS[1*bsi]]; + tc[2] = tc0_table[index_a][bS[2*bsi]]; + tc[3] = tc0_table[index_a][bS[3*bsi]]; + h->h264dsp.h264_h_loop_filter_luma_mbaff(pix, stride, alpha, beta, tc); + } else { + h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta); } } -static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { - int i; - const int bit_depth = h->sps.bit_depth_luma; - const int qp_bd_offset = 6*(bit_depth-8); +static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[7], int bsi, int qp ) { + const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; - int alpha = alpha_table[index_a] << (bit_depth-8); - int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset] << (bit_depth-8); - for( i = 0; i < 4; i++, pix += stride) { - const int bS_index = i*bsi; - - if( bS[bS_index] == 0 ) { - continue; - } + int alpha = alpha_table[index_a]; + int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; + if (alpha ==0 || beta == 0) return; - if( bS[bS_index] < 4 ) { - const int tc = (tc0_table[index_a][bS[bS_index]] << (bit_depth-8)) + 1; - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int q0 = pix[0]; - const int q1 = pix[1]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); - - pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ - pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ - tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); - } - }else{ - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int q0 = pix[0]; - const int q1 = pix[1]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - - pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ - pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ - tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); - } - } + if( bS[0] < 4 ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0*bsi]] + 1; + tc[1] = tc0_table[index_a][bS[1*bsi]] + 1; + tc[2] = tc0_table[index_a][bS[2*bsi]] + 1; + tc[3] = tc0_table[index_a][bS[3*bsi]] + 1; + h->h264dsp.h264_h_loop_filter_chroma_mbaff(pix, stride, alpha, beta, tc); + } else { + h->h264dsp.h264_h_loop_filter_chroma_mbaff_intra(pix, stride, alpha, beta); } } static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { - const int bit_depth = h->sps.bit_depth_luma; - const int qp_bd_offset = 6*(bit_depth-8); + const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; - const int alpha = alpha_table[index_a] << (bit_depth-8); - const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset] << (bit_depth-8); + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 ) { int8_t tc[4]; - tc[0] = tc0_table[index_a][bS[0]] << (bit_depth-8); - tc[1] = tc0_table[index_a][bS[1]] << (bit_depth-8); - tc[2] = tc0_table[index_a][bS[2]] << (bit_depth-8); - tc[3] = tc0_table[index_a][bS[3]] << (bit_depth-8); + tc[0] = tc0_table[index_a][bS[0]]; + tc[1] = tc0_table[index_a][bS[1]]; + tc[2] = tc0_table[index_a][bS[2]]; + tc[3] = tc0_table[index_a][bS[3]]; h->h264dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta); @@ -299,19 +194,18 @@ static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, int16_t } static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { - const int bit_depth = h->sps.bit_depth_luma; - const int qp_bd_offset = 6*(bit_depth-8); + const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; - const int alpha = alpha_table[index_a] << (bit_depth-8); - const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset] << (bit_depth-8); + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 ) { int8_t tc[4]; - tc[0] = (tc0_table[index_a][bS[0]] << (bit_depth-8))+1; - tc[1] = (tc0_table[index_a][bS[1]] << (bit_depth-8))+1; - tc[2] = (tc0_table[index_a][bS[2]] << (bit_depth-8))+1; - tc[3] = (tc0_table[index_a][bS[3]] << (bit_depth-8))+1; + tc[0] = tc0_table[index_a][bS[0]]+1; + tc[1] = tc0_table[index_a][bS[1]]+1; + tc[2] = tc0_table[index_a][bS[2]]+1; + tc[3] = tc0_table[index_a][bS[3]]+1; h->h264dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta); @@ -650,10 +544,10 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } if( dir == 0 ) { - filter_mb_edgev( &img_y[4*edge<<h->pixel_shift], linesize, bS, qp, h ); + filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, h ); if( (edge&1) == 0 ) { - filter_mb_edgecv( &img_cb[2*edge<<h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], h); - filter_mb_edgecv( &img_cr[2*edge<<h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], h); + filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], h); + filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], h); } } else { filter_mb_edgeh( &img_y[4*edge*linesize], linesize, bS, qp, h ); |