if( i_prefix != 0 )
{
const int i_ctxIdxInc = 5 + X264_MIN( 4, i_abslevelgt1 ) + i_ctx_level;
+#ifdef RDO_SKIP_BS
+ cb->f8_bits_encoded += cabac_prefix_size[i_prefix][cb->state[i_ctxIdxInc]];
+ cb->state[i_ctxIdxInc] = cabac_prefix_transition[i_prefix][cb->state[i_ctxIdxInc]];
+#else
int j;
for( j = 0; j < i_prefix - 1; j++ )
x264_cabac_encode_decision( cb, i_ctxIdxInc, 1 );
if( i_prefix < 14 )
x264_cabac_encode_decision( cb, i_ctxIdxInc, 0 );
- else /* suffix */
+#endif
+ if( i_prefix >= 14 )
x264_cabac_encode_ue_bypass( cb, 0, i_coeff_abs_m1[i] - 14 );
i_abslevelgt1++;
i_abslevel1++;
/* write sign */
+#ifdef RDO_SKIP_BS
+ if( i_prefix == 0 )
+#endif
x264_cabac_encode_bypass( cb, i_coeff_sign[i] );
}
}
#define RDO_SKIP_BS
+static int cabac_prefix_transition[15][128];
+static int cabac_prefix_size[15][128];
+
/* CAVLC: produces exactly the same bit count as a normal encode */
/* this probably still leaves some unnecessary computations */
#define bs_write1(s,v) ((s)->i_bits_encoded += 1)
#define LAMBDA_BITS 4
/* precalculate the cost of coding abs_level_m1 */
-static int cabac_prefix_transition[15][128];
-static int cabac_prefix_size[15][128];
void x264_rdo_init( )
{
int i_prefix;
uint8_t cabac_state_last[64];
const int b_interlaced = h->mb.b_interlaced;
const int f = 1 << 15; // no deadzone
- int i_last_nnz = -1;
+ int i_last_nnz;
int i, j;
// (# of coefs) * (# of ctx) * (# of levels tried) = 1024
int i_levels_used = 1;
/* init coefs */
- for( i = b_ac; i < i_coefs; i++ )
- {
- int coef = dct[zigzag[i]];
- abs_coefs[i] = abs(coef);
- signs[i] = coef < 0 ? -1 : 1;
- if( f <= abs_coefs[i] * quant_mf[zigzag[i]] )
- i_last_nnz = i;
- }
+ for( i = i_coefs-1; i >= b_ac; i-- )
+ if( (unsigned)(dct[zigzag[i]] * quant_mf[zigzag[i]] + f-1) >= 2*f )
+ break;
- if( i_last_nnz == -1 )
+ if( i < b_ac )
{
memset( dct, 0, i_coefs * sizeof(*dct) );
return;
}
+ i_last_nnz = i;
+
+ for( ; i >= b_ac; i-- )
+ {
+ int coef = dct[zigzag[i]];
+ abs_coefs[i] = abs(coef);
+ signs[i] = coef < 0 ? -1 : 1;
+ }
+
/* init trellis */
for( i = 1; i < 8; i++ )
nodes_cur[i].score = TRELLIS_SCORE_MAX;