Cleaning up encode_sb() and encode_b() functions.

Trying to make encode_sb() more similar to write_modes_sb() and
decode_mode_sb() because essentially all branching logic should be the
same.

Change-Id: Ib7dec7b48fce29418142abad4d1dcfdb1c770735
This commit is contained in:
Dmitry Kovalev 2013-12-11 14:38:22 -08:00
Родитель 345fbfef06
Коммит b8dc52f4a3
1 изменённых файлов: 38 добавлений и 36 удалений

Просмотреть файл

@ -857,16 +857,9 @@ static void save_context(VP9_COMP *cpi, int mi_row, int mi_col,
static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, static void encode_b(VP9_COMP *cpi, const TileInfo *const tile,
TOKENEXTRA **tp, int mi_row, int mi_col, TOKENEXTRA **tp, int mi_row, int mi_col,
int output_enabled, BLOCK_SIZE bsize, int sub_index) { int output_enabled, BLOCK_SIZE bsize) {
VP9_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &cpi->mb; MACROBLOCK *const x = &cpi->mb;
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
return;
if (sub_index != -1)
*get_sb_index(x, bsize) = sub_index;
if (bsize < BLOCK_8X8) { if (bsize < BLOCK_8X8) {
// When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0
// there is nothing to be done. // there is nothing to be done.
@ -890,64 +883,73 @@ static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile,
int output_enabled, BLOCK_SIZE bsize) { int output_enabled, BLOCK_SIZE bsize) {
VP9_COMMON *const cm = &cpi->common; VP9_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &cpi->mb; MACROBLOCK *const x = &cpi->mb;
BLOCK_SIZE c1 = BLOCK_8X8; const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4;
const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; int ctx;
int pl = 0;
PARTITION_TYPE partition; PARTITION_TYPE partition;
BLOCK_SIZE subsize; BLOCK_SIZE subsize;
int i;
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
return; return;
c1 = BLOCK_4X4;
if (bsize >= BLOCK_8X8) { if (bsize >= BLOCK_8X8) {
pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, ctx = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context,
mi_row, mi_col, bsize); mi_row, mi_col, bsize);
c1 = *(get_sb_partitioning(x, bsize)); subsize = *get_sb_partitioning(x, bsize);
} else {
ctx = 0;
subsize = BLOCK_4X4;
} }
partition = partition_lookup[bsl][c1];
partition = partition_lookup[bsl][subsize];
switch (partition) { switch (partition) {
case PARTITION_NONE: case PARTITION_NONE:
if (output_enabled && bsize >= BLOCK_8X8) if (output_enabled && bsize >= BLOCK_8X8)
cm->counts.partition[pl][PARTITION_NONE]++; cm->counts.partition[ctx][PARTITION_NONE]++;
encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, -1); encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
break; break;
case PARTITION_VERT: case PARTITION_VERT:
if (output_enabled) if (output_enabled)
cm->counts.partition[pl][PARTITION_VERT]++; cm->counts.partition[ctx][PARTITION_VERT]++;
encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); *get_sb_index(x, subsize) = 0;
encode_b(cpi, tile, tp, mi_row, mi_col + bs, output_enabled, c1, 1); encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
if (mi_col + hbs < cm->mi_cols) {
*get_sb_index(x, subsize) = 1;
encode_b(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, subsize);
}
break; break;
case PARTITION_HORZ: case PARTITION_HORZ:
if (output_enabled) if (output_enabled)
cm->counts.partition[pl][PARTITION_HORZ]++; cm->counts.partition[ctx][PARTITION_HORZ]++;
encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); *get_sb_index(x, subsize) = 0;
encode_b(cpi, tile, tp, mi_row + bs, mi_col, output_enabled, c1, 1); encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
if (mi_row + hbs < cm->mi_rows) {
*get_sb_index(x, subsize) = 1;
encode_b(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, subsize);
}
break; break;
case PARTITION_SPLIT: case PARTITION_SPLIT:
subsize = get_subsize(bsize, PARTITION_SPLIT); subsize = get_subsize(bsize, PARTITION_SPLIT);
if (output_enabled) if (output_enabled)
cm->counts.partition[pl][PARTITION_SPLIT]++; cm->counts.partition[ctx][PARTITION_SPLIT]++;
for (i = 0; i < 4; i++) { *get_sb_index(x, subsize) = 0;
const int x_idx = i & 1, y_idx = i >> 1; encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
*get_sb_index(x, subsize) = 1;
*get_sb_index(x, subsize) = i; encode_sb(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, subsize);
encode_sb(cpi, tile, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, *get_sb_index(x, subsize) = 2;
output_enabled, subsize); encode_sb(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, subsize);
} *get_sb_index(x, subsize) = 3;
encode_sb(cpi, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled,
subsize);
break; break;
default: default:
assert(0); assert("Invalid partition type.");
break;
} }
if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8)
update_partition_context(cpi->above_seg_context, cpi->left_seg_context, update_partition_context(cpi->above_seg_context, cpi->left_seg_context,
mi_row, mi_col, c1, bsize); mi_row, mi_col, subsize, bsize);
} }
// Check to see if the given partition size is allowed for a specified number // Check to see if the given partition size is allowed for a specified number