#include "common/common.h"
#include "macroblock.h"
+#ifndef RDO_SKIP_BS
+#define RDO_SKIP_BS 0
+#endif
+
static inline void x264_cabac_mb_type_intra( x264_t *h, x264_cabac_t *cb, int i_mb_type,
int ctx0, int ctx1, int ctx2, int ctx3, int ctx4, int ctx5 )
{
/* Avoid writing a delta quant if we have an empty i16x16 block, e.g. in a completely flat background area */
if( h->mb.i_type == I_16x16 && !h->mb.cbp[h->mb.i_mb_xy] )
{
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
h->mb.i_qp = h->mb.i_last_qp;
#endif
i_dqp = 0;
x264_cabac_encode_decision_noup( cb, 60 + ctx, 0 );
}
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
void x264_cabac_mb_skip( x264_t *h, int b_skip )
{
int ctx = (h->mb.i_mb_type_left >= 0 && !IS_SKIP( h->mb.i_mb_type_left ))
else if( i_abs < 9 )
{
x264_cabac_encode_decision( cb, ctxbase + ctx, 1 );
-#ifdef RDO_SKIP_BS
+#if RDO_SKIP_BS
if( i_abs > 4 )
{
for( i = 1; i < 4; i++ )
else
{
x264_cabac_encode_decision( cb, ctxbase + ctx, 1 );
-#ifdef RDO_SKIP_BS
+#if RDO_SKIP_BS
for( i = 1; i < 4; i++ )
x264_cabac_encode_decision( cb, ctxbase + ctxes[i], 1 );
cb->f8_bits_encoded += cabac_size_5ones[cb->state[ctxbase+6]];
int i_nza = 0;
int i_nzb = 0;
- if( i_cat == DCT_LUMA_DC )
- {
- if( h->mb.i_neighbour & MB_LEFT )
- {
- i_mba_xy = h->mb.i_mb_xy - 1;
- i_nza = h->mb.cbp[i_mba_xy] & 0x100;
- }
- if( h->mb.i_neighbour & MB_TOP )
- {
- i_mbb_xy = h->mb.i_mb_top_xy;
- i_nzb = h->mb.cbp[i_mbb_xy] & 0x100;
- }
- }
- else if( i_cat == DCT_LUMA_AC || i_cat == DCT_LUMA_4x4 )
- {
- if( i_idx & ~10 ) // block_idx_x > 0
- i_mba_xy = h->mb.i_mb_xy;
- else if( h->mb.i_neighbour & MB_LEFT )
- i_mba_xy = h->mb.i_mb_xy - 1;
-
- if( i_idx & ~5 ) // block_idx_y > 0
- i_mbb_xy = h->mb.i_mb_xy;
- else if( h->mb.i_neighbour & MB_TOP )
- i_mbb_xy = h->mb.i_mb_top_xy;
-
- /* no need to test for skip/pcm */
- if( i_mba_xy >= 0 )
- i_nza = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 1];
- if( i_mbb_xy >= 0 )
- i_nzb = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 8];
- }
- else if( i_cat == DCT_CHROMA_DC )
- {
- /* no need to test skip/pcm */
- if( h->mb.i_neighbour & MB_LEFT )
- {
- i_mba_xy = h->mb.i_mb_xy - 1;
- i_nza = h->mb.cbp[i_mba_xy] & (0x200 << i_idx);
- }
- if( h->mb.i_neighbour & MB_TOP )
- {
- i_mbb_xy = h->mb.i_mb_top_xy;
- i_nzb = h->mb.cbp[i_mbb_xy] & (0x200 << i_idx);
- }
- }
- else if( i_cat == DCT_CHROMA_AC )
+ switch( i_cat )
{
- if( i_idx & 1 )
- i_mba_xy = h->mb.i_mb_xy;
- else if( h->mb.i_neighbour & MB_LEFT )
- i_mba_xy = h->mb.i_mb_xy - 1;
-
- if( i_idx & 2 )
- i_mbb_xy = h->mb.i_mb_xy;
- else if( h->mb.i_neighbour & MB_TOP )
- i_mbb_xy = h->mb.i_mb_top_xy;
-
- /* no need to test skip/pcm */
- if( i_mba_xy >= 0 )
- i_nza = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 1];
- if( i_mbb_xy >= 0 )
- i_nzb = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 8];
+ case DCT_LUMA_DC:
+ if( h->mb.i_neighbour & MB_LEFT )
+ {
+ i_mba_xy = h->mb.i_mb_xy - 1;
+ i_nza = h->mb.cbp[i_mba_xy] & 0x100;
+ }
+ if( h->mb.i_neighbour & MB_TOP )
+ {
+ i_mbb_xy = h->mb.i_mb_top_xy;
+ i_nzb = h->mb.cbp[i_mbb_xy] & 0x100;
+ }
+ break;
+ case DCT_LUMA_AC:
+ case DCT_LUMA_4x4:
+ if( i_idx & ~10 ) // block_idx_x > 0
+ i_mba_xy = h->mb.i_mb_xy;
+ else if( h->mb.i_neighbour & MB_LEFT )
+ i_mba_xy = h->mb.i_mb_xy - 1;
+
+ if( i_idx & ~5 ) // block_idx_y > 0
+ i_mbb_xy = h->mb.i_mb_xy;
+ else if( h->mb.i_neighbour & MB_TOP )
+ i_mbb_xy = h->mb.i_mb_top_xy;
+
+ /* no need to test for skip/pcm */
+ if( i_mba_xy >= 0 )
+ i_nza = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 1];
+ if( i_mbb_xy >= 0 )
+ i_nzb = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 8];
+ break;
+ case DCT_CHROMA_DC:
+ /* no need to test skip/pcm */
+ if( h->mb.i_neighbour & MB_LEFT )
+ {
+ i_mba_xy = h->mb.i_mb_xy - 1;
+ i_nza = h->mb.cbp[i_mba_xy] & (0x200 << i_idx);
+ }
+ if( h->mb.i_neighbour & MB_TOP )
+ {
+ i_mbb_xy = h->mb.i_mb_top_xy;
+ i_nzb = h->mb.cbp[i_mbb_xy] & (0x200 << i_idx);
+ }
+ break;
+ case DCT_CHROMA_AC:
+ if( i_idx & 1 )
+ i_mba_xy = h->mb.i_mb_xy;
+ else if( h->mb.i_neighbour & MB_LEFT )
+ i_mba_xy = h->mb.i_mb_xy - 1;
+
+ if( i_idx & 2 )
+ i_mbb_xy = h->mb.i_mb_xy;
+ else if( h->mb.i_neighbour & MB_TOP )
+ i_mbb_xy = h->mb.i_mb_top_xy;
+
+ /* no need to test skip/pcm */
+ if( i_mba_xy >= 0 )
+ i_nza = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 1];
+ if( i_mbb_xy >= 0 )
+ i_nzb = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 8];
}
if( IS_INTRA( h->mb.i_type ) )
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
};
-static const uint8_t identity[16] =
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
// node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
// 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
const int i_ctx_sig = significant_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
const int i_ctx_last = last_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
const int i_ctx_level = coeff_abs_level_m1_offset[i_ctxBlockCat];
+ const uint8_t *significant_coeff_flag_offset = significant_coeff_flag_offset_8x8[h->mb.b_interlaced];
int i_coeff_abs_m1[64];
int UNUSED i_coeff_sign[64];
int node_ctx = 0;
int i, j;
- const uint8_t *significant_coeff_flag_offset;
- const uint8_t *last_coeff_flag_offset;
-
/* yes this is always aligned, and l[-1] exists in the cases where it's used (ac) */
for( j = i_count - 4; j >= -1; j -= 4 )
if( *(uint64_t*)(l+j) )
}
}
- significant_coeff_flag_offset = (i_ctxBlockCat == DCT_LUMA_8x8)
- ? significant_coeff_flag_offset_8x8[h->mb.b_interlaced]
- : identity;
- last_coeff_flag_offset = (i_ctxBlockCat == DCT_LUMA_8x8)
- ? last_coeff_flag_offset_8x8 : identity;
-
for( i = j; i < j+4; i++)
if( l[i] )
i_last = i;
i_sigmap_size = X264_MIN( i_last+1, i_count-1 );
- for( i = 0; i < i_sigmap_size; i++ )
- {
- if( l[i] )
- {
- i_coeff_abs_m1[i_coeff] = abs(l[i]) - 1;
-#ifndef RDO_SKIP_BS
- i_coeff_sign[i_coeff] = l[i] < 0;
-#endif
- i_coeff++;
- x264_cabac_encode_decision( cb, i_ctx_sig + significant_coeff_flag_offset[i], 1 );
- x264_cabac_encode_decision( cb, i_ctx_last + last_coeff_flag_offset[i], i == i_last );
- }
- else
- x264_cabac_encode_decision( cb, i_ctx_sig + significant_coeff_flag_offset[i], 0 );
+#define WRITE_SIGMAP( l8x8 )\
+ for( i = 0; i < i_sigmap_size; i++ )\
+ {\
+ if( l[i] )\
+ {\
+ i_coeff_abs_m1[i_coeff] = abs(l[i]) - 1;\
+ if( !RDO_SKIP_BS )\
+ i_coeff_sign[i_coeff] = l[i] < 0;\
+ i_coeff++;\
+ x264_cabac_encode_decision( cb, i_ctx_sig + (l8x8 ? significant_coeff_flag_offset[i] : i), 1 );\
+ x264_cabac_encode_decision( cb, i_ctx_last + (l8x8 ? last_coeff_flag_offset_8x8[i] : i), i == i_last );\
+ }\
+ else\
+ x264_cabac_encode_decision( cb, i_ctx_sig + (l8x8 ? significant_coeff_flag_offset[i] : i), 0 );\
}
+ if( i_ctxBlockCat == DCT_LUMA_8x8 )
+ WRITE_SIGMAP( 1 )
+ else
+ WRITE_SIGMAP( 0 )
+
if( i == i_last )
{
i_coeff_abs_m1[i_coeff] = abs(l[i]) - 1;
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
i_coeff_sign[i_coeff] = l[i] < 0;
#endif
i_coeff++;
{
x264_cabac_encode_decision( cb, ctx, 1 );
ctx = coeff_abs_levelgt1_ctx[node_ctx] + i_ctx_level;
-#ifdef RDO_SKIP_BS
+#if RDO_SKIP_BS
cb->f8_bits_encoded += cabac_size_unary[i_prefix][cb->state[ctx]];
cb->state[ctx] = cabac_transition_unary[i_prefix][cb->state[ctx]];
#else
{
x264_cabac_encode_decision( cb, ctx, 0 );
node_ctx = coeff_abs_level_transition[0][node_ctx];
-#ifdef RDO_SKIP_BS
+#if RDO_SKIP_BS
x264_cabac_encode_bypass( cb, 0 ); // sign
#endif
}
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
x264_cabac_encode_bypass( cb, i_coeff_sign[i_coeff] );
#endif
} while( i_coeff > 0 );
int i_list;
int i;
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
const int i_mb_pos_start = x264_cabac_pos( cb );
int i_mb_pos_tex;
#endif
/* Write the MB type */
x264_cabac_mb_type( h, cb );
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
if( i_mb_type == I_PCM )
{
i_mb_pos_tex = x264_cabac_pos( cb );
}
}
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
i_mb_pos_tex = x264_cabac_pos( cb );
h->stat.frame.i_mv_bits += i_mb_pos_tex - i_mb_pos_start;
#endif
}
}
-#ifndef RDO_SKIP_BS
+#if !RDO_SKIP_BS
h->stat.frame.i_tex_bits += x264_cabac_pos( cb ) - i_mb_pos_tex;
#endif
}
-#ifdef RDO_SKIP_BS
+#if RDO_SKIP_BS
/*****************************************************************************
* RD only; doesn't generate a valid bitstream
* doesn't write cbp or chroma dc (I don't know how much this matters)