From: Loren Merritt <pengvado@videolan.org> Date: Sun, 1 Oct 2006 03:05:15 +0000 (+0000) Subject: allow custom deadzones for non-trellis quantization. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f0864a9f5755a02158cbb96c215afee95846639;p=libx264 allow custom deadzones for non-trellis quantization. patch by Alex Wright. git-svn-id: svn://svn.videolan.org/x264/trunk@572 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/common.c b/common/common.c index 1b9768e2..4c17c768 100644 --- a/common/common.c +++ b/common/common.c @@ -122,6 +122,8 @@ void x264_param_default( x264_param_t *param ) param->analyse.i_chroma_qp_offset = 0; param->analyse.b_fast_pskip = 1; param->analyse.b_dct_decimate = 1; + param->analyse.i_luma_deadzone[0] = 21; + param->analyse.i_luma_deadzone[1] = 11; param->analyse.b_psnr = 1; param->analyse.b_ssim = 1; @@ -405,6 +407,10 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value ) p->analyse.b_fast_pskip = atobool(value); OPT("dct-decimate") p->analyse.b_dct_decimate = atobool(value); + OPT("deadzone-inter") + p->analyse.i_luma_deadzone[0] = atoi(value); + OPT("deadzone-intra") + p->analyse.i_luma_deadzone[1] = atoi(value); OPT("nr") p->analyse.i_noise_reduction = atoi(value); OPT("bitrate") @@ -820,10 +826,12 @@ char *x264_param2string( x264_param_t *p, int b_res ) s += sprintf( s, " trellis=%d", p->analyse.i_trellis ); s += sprintf( s, " 8x8dct=%d", p->analyse.b_transform_8x8 ); s += sprintf( s, " cqm=%d", p->i_cqm_preset ); + s += sprintf( s, " deadzone=%d,%d", p->analyse.i_luma_deadzone[0], p->analyse.i_luma_deadzone[1] ); s += sprintf( s, " chroma_qp_offset=%d", p->analyse.i_chroma_qp_offset ); s += sprintf( s, " slices=%d", p->i_threads ); s += sprintf( s, " nr=%d", p->analyse.i_noise_reduction ); s += sprintf( s, " decimate=%d", p->analyse.b_dct_decimate ); + s += sprintf( s, " mbaff=%d", p->b_interlaced ); s += sprintf( s, " bframes=%d", p->i_bframe ); if( p->i_bframe ) diff --git a/common/common.h b/common/common.h index 6e145a4a..da003e35 100644 --- a/common/common.h +++ b/common/common.h @@ -401,6 +401,9 @@ struct x264_t int b_interlaced; + /* Inverted luma quantization deadzone */ + int i_luma_deadzone[2]; // {inter, intra} + /* Allowed qpel MV range to stay within the picture + emulated edge pixels */ int mv_min[2]; int mv_max[2]; diff --git a/encoder/encoder.c b/encoder/encoder.c index 147e0eb3..620f3139 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -423,6 +423,10 @@ static int x264_validate_parameters( x264_t *h ) h->param.i_deblocking_filter_alphac0 = x264_clip3( h->param.i_deblocking_filter_alphac0, -6, 6 ); h->param.i_deblocking_filter_beta = x264_clip3( h->param.i_deblocking_filter_beta, -6, 6 ); + h->param.analyse.i_luma_deadzone[0] = x264_clip3( h->param.analyse.i_luma_deadzone[0], 0, 32 ); + h->param.analyse.i_luma_deadzone[1] = x264_clip3( h->param.analyse.i_luma_deadzone[1], 0, 32 ); + h->mb.i_luma_deadzone[0] = 32 - h->param.analyse.i_luma_deadzone[0]; + h->mb.i_luma_deadzone[1] = 32 - h->param.analyse.i_luma_deadzone[1]; h->param.i_cabac_init_idc = x264_clip3( h->param.i_cabac_init_idc, 0, 2 ); diff --git a/encoder/macroblock.c b/encoder/macroblock.c index ebfb6be2..e63dd36b 100644 --- a/encoder/macroblock.c +++ b/encoder/macroblock.c @@ -61,10 +61,17 @@ static void quant_8x8( x264_t *h, int16_t dct[8][8], int quant_mf[6][8][8], int { const int i_qbits = 16 + i_qscale / 6; const int i_mf = i_qscale % 6; - const int f = ( 1 << (i_qbits + b_intra) ) / 6; + const int f = h->mb.i_luma_deadzone[b_intra] << (i_qbits-6); h->quantf.quant_8x8_core( dct, quant_mf[i_mf], i_qbits, f ); } static void quant_4x4( x264_t *h, int16_t dct[4][4], int quant_mf[6][4][4], int i_qscale, int b_intra ) +{ + const int i_qbits = 15 + i_qscale / 6; + const int i_mf = i_qscale % 6; + const int f = h->mb.i_luma_deadzone[b_intra] << (i_qbits-6); + h->quantf.quant_4x4_core( dct, quant_mf[i_mf], i_qbits, f ); +} +static void quant_4x4_chroma( x264_t *h, int16_t dct[4][4], int quant_mf[6][4][4], int i_qscale, int b_intra ) { const int i_qbits = 15 + i_qscale / 6; const int i_mf = i_qscale % 6; @@ -75,7 +82,7 @@ static void quant_4x4_dc( x264_t *h, int16_t dct[4][4], int quant_mf[6][4][4], i { const int i_qbits = 16 + i_qscale / 6; const int i_mf = i_qscale % 6; - const int f = ( 1 << i_qbits ) / 3; + const int f = h->mb.i_luma_deadzone[1] << (i_qbits-6); h->quantf.quant_4x4_dc_core( dct, quant_mf[i_mf][0][0], i_qbits, f ); } static void quant_2x2_dc( x264_t *h, int16_t dct[2][2], int quant_mf[6][4][4], int i_qscale, int b_intra ) @@ -270,7 +277,7 @@ static void x264_mb_encode_8x8_chroma( x264_t *h, int b_inter, int i_qscale ) dct2x2[block_idx_y[i]][block_idx_x[i]] = dct4x4[i][0][0]; /* no trellis; it doesn't seem to help chroma noticeably */ - quant_4x4( h, dct4x4[i], h->quant4_mf[CQM_4IC + b_inter], i_qscale, !b_inter ); + quant_4x4_chroma( h, dct4x4[i], h->quant4_mf[CQM_4IC + b_inter], i_qscale, !b_inter ); h->zigzagf.scan_4x4ac( h->dct.block[16+i+ch*4].residual_ac, dct4x4[i] ); if( b_decimate ) @@ -741,7 +748,7 @@ int x264_macroblock_probe_skip( x264_t *h, int b_bidir ) /* calculate dct coeffs */ for( i4x4 = 0, i_decimate_mb = 0; i4x4 < 4; i4x4++ ) { - quant_4x4( h, dct4x4[i4x4], (int(*)[4][4])def_quant4_mf, i_qp, 0 ); + quant_4x4_chroma( h, dct4x4[i4x4], (int(*)[4][4])def_quant4_mf, i_qp, 0 ); h->zigzagf.scan_4x4ac( dctscan, dct4x4[i4x4] ); i_decimate_mb += x264_mb_decimate_score( dctscan, 15 ); @@ -886,7 +893,7 @@ void x264_macroblock_encode_p8x8( x264_t *h, int i8 ) p_fdec = h->mb.pic.p_fdec[1+ch] + (i8&1)*4 + (i8>>1)*4*FDEC_STRIDE; h->dctf.sub4x4_dct( dct4x4, p_fenc, p_fdec ); - quant_4x4( h, dct4x4, h->quant4_mf[CQM_4PC], i_qp, 0 ); + quant_4x4_chroma( h, dct4x4, h->quant4_mf[CQM_4PC], i_qp, 0 ); h->zigzagf.scan_4x4ac( h->dct.block[16+i8+ch*4].residual_ac, dct4x4 ); if( array_non_zero( (int*)dct4x4, sizeof(dct4x4)/sizeof(int) ) ) { diff --git a/x264.c b/x264.c index 67fc060a..6dabaeda 100644 --- a/x264.c +++ b/x264.c @@ -233,6 +233,9 @@ static void Help( x264_param_t *defaults, int b_longhelp ) H0( " --no-dct-decimate Disables coefficient thresholding on P-frames\n" ); H0( " --nr <integer> Noise reduction [%d]\n", defaults->analyse.i_noise_reduction ); H1( "\n" ); + H1( " --deadzone-inter <int> Set the size of the inter luma quantization deadzone [%d]\n", defaults->analyse.i_luma_deadzone[0] ); + H1( " --deadzone-intra <int> Set the size of the intra luma quantization deadzone [%d]\n", defaults->analyse.i_luma_deadzone[1] ); + H1( " Deadzones should be in the range 0 - 32.\n" ); H1( " --cqm <string> Preset quant matrices [\"flat\"]\n" " - jvt, flat\n" ); H0( " --cqmfile <string> Read custom quant matrices from a JM-compatible file\n" ); @@ -383,6 +386,8 @@ static int Parse( int argc, char **argv, { "trellis", required_argument, NULL, 't' }, { "no-fast-pskip", no_argument, NULL, 0 }, { "no-dct-decimate", no_argument, NULL, 0 }, + { "deadzone-inter", required_argument, NULL, '0' }, + { "deadzone-intra", required_argument, NULL, '0' }, { "level", required_argument, NULL, 0 }, { "ratetol", required_argument, NULL, 0 }, { "vbv-maxrate", required_argument, NULL, 0 }, diff --git a/x264.h b/x264.h index c95b128d..036afb2f 100644 --- a/x264.h +++ b/x264.h @@ -218,6 +218,9 @@ typedef struct int b_dct_decimate; /* transform coefficient thresholding on P-frames */ int i_noise_reduction; /* adaptive pseudo-deadzone */ + /* the deadzone size that will be used in luma quantization */ + int i_luma_deadzone[2]; // {inter, intra} + int b_psnr; /* compute and print PSNR stats */ int b_ssim; /* compute and print SSIM stats */ } analyse;