summaryrefslogtreecommitdiff
path: root/libavcodec/h264_loopfilter.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-11 05:34:17 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-11 05:47:02 +0200
commit59eb12faff9505da49f54d499dd43404226e37f6 (patch)
tree26e11596a990bdf855114b1c6c569073c1aeb195 /libavcodec/h264_loopfilter.c
parent580fa76c5c8b4372247221a4602527a060e2d5b4 (diff)
parentb66752790a94820c23b0ac994d6190dd9048582d (diff)
Merge remote branch 'qatar/master'
* qatar/master: (30 commits) AVOptions: make default_val a union, as proposed in AVOption2. arm/h264pred: add missing argument type. h264dsp_mmx: place bracket outside #if/#endif block. lavf/utils: fix ff_interleave_compare_dts corner case. fate: add 10-bit H264 tests. h264: do not print "too many references" warning for intra-only. Enable decoding of high bit depth h264. Adds 8-, 9- and 10-bit versions of some of the functions used by the h264 decoder. Add support for higher QP values in h264. Add the notion of pixel size in h264 related functions. Make the h264 loop filter bit depth aware. Template dsputil_template.c with respect to pixel size, etc. Template h264idct_template.c with respect to pixel size, etc. Preparatory patch for high bit depth h264 decoding support. Move some functions in dsputil.c into a new file dsputil_template.c. Move the functions in h264idct into a new file h264idct_template.c. Move the functions in h264pred.c into a new file h264pred_template.c. Preparatory patch for high bit depth h264 decoding support. Add pixel formats for 9- and 10-bit yuv420p. Choose h264 chroma dc dequant function dynamically. ... Conflicts: doc/APIchanges ffmpeg.c ffplay.c libavcodec/alpha/dsputil_alpha.c libavcodec/arm/dsputil_init_arm.c libavcodec/arm/dsputil_init_armv6.c libavcodec/arm/dsputil_init_neon.c libavcodec/arm/dsputil_iwmmxt.c libavcodec/arm/h264pred_init_arm.c libavcodec/bfin/dsputil_bfin.c libavcodec/dsputil.c libavcodec/h264.c libavcodec/h264.h libavcodec/h264_cabac.c libavcodec/h264_cavlc.c libavcodec/h264_loopfilter.c libavcodec/h264_ps.c libavcodec/h264_refs.c libavcodec/h264dsp.c libavcodec/h264idct.c libavcodec/h264pred.c libavcodec/mlib/dsputil_mlib.c libavcodec/options.c libavcodec/ppc/dsputil_altivec.c libavcodec/ppc/dsputil_ppc.c libavcodec/ppc/h264_altivec.c libavcodec/ps2/dsputil_mmi.c libavcodec/sh4/dsputil_align.c libavcodec/sh4/dsputil_sh4.c libavcodec/sparc/dsputil_vis.c libavcodec/utils.c libavcodec/version.h libavcodec/x86/dsputil_mmx.c libavformat/options.c libavformat/utils.c libavutil/pixfmt.h libswscale/swscale.c libswscale/swscale_internal.h libswscale/swscale_template.c tests/ref/seek/lavf_avi Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/h264_loopfilter.c')
-rw-r--r--libavcodec/h264_loopfilter.c224
1 files changed, 59 insertions, 165 deletions
diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c
index 325fd3cc61..2e61a3110a 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 );