void av1_foreach_transformed_block_in_plane( const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane, foreach_transformed_block_visitor visit, void *arg) { const struct macroblockd_plane *const pd = &xd->plane[plane]; const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; // block and transform sizes, in number of 4x4 blocks log 2 ("*_b") // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8 // transform size varies per plane, look it up in a common way. const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi, pd) : mbmi->tx_size; const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); const uint8_t txw_unit = tx_size_wide_unit[tx_size]; const uint8_t txh_unit = tx_size_high_unit[tx_size]; const int step = txw_unit * txh_unit; int i = 0, r, c; // If mb_to_right_edge is < 0 we are in a situation in which // the current block size extends into the UMV and we won't // visit the sub blocks that are wholly within the UMV. const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); const int max_blocks_high = max_block_high(xd, plane_bsize, plane); // Keep track of the row and column of the blocks we use so that we know // if we are in the unrestricted motion border. for (r = 0; r < max_blocks_high; r += txh_unit) { // Skip visiting the sub blocks that are wholly within the UMV. for (c = 0; c < max_blocks_wide; c += txw_unit) { visit(plane, i, r, c, plane_bsize, tx_size, arg); i += step; } } }
static void tokenize_vartx(ThreadData *td, TOKENEXTRA **t, RUN_TYPE dry_run, TX_SIZE tx_size, BLOCK_SIZE plane_bsize, int blk_row, int blk_col, int block, int plane, void *arg) { MACROBLOCK *const x = &td->mb; MACROBLOCKD *const xd = &x->e_mbd; MB_MODE_INFO *const mbmi = xd->mi[0]; const struct macroblockd_plane *const pd = &xd->plane[plane]; const int max_blocks_high = max_block_high(xd, plane_bsize, plane); const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; const TX_SIZE plane_tx_size = plane ? av1_get_max_uv_txsize(mbmi->sb_type, pd->subsampling_x, pd->subsampling_y) : mbmi->inter_tx_size[av1_get_txb_size_index(plane_bsize, blk_row, blk_col)]; if (tx_size == plane_tx_size || plane) { plane_bsize = get_plane_block_size(mbmi->sb_type, pd->subsampling_x, pd->subsampling_y); if (!dry_run) { av1_update_and_record_txb_context(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg); } else if (dry_run == DRY_RUN_NORMAL) { av1_update_txb_context_b(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg); } else { printf("DRY_RUN_COSTCOEFFS is not supported yet\n"); assert(0); } } else { // Half the block size in transform block unit. const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; const int bsw = tx_size_wide_unit[sub_txs]; const int bsh = tx_size_high_unit[sub_txs]; const int step = bsw * bsh; assert(bsw > 0 && bsh > 0); for (int row = 0; row < tx_size_high_unit[tx_size]; row += bsh) { for (int col = 0; col < tx_size_wide_unit[tx_size]; col += bsw) { const int offsetr = blk_row + row; const int offsetc = blk_col + col; if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; tokenize_vartx(td, t, dry_run, sub_txs, plane_bsize, offsetr, offsetc, block, plane, arg); block += step; } } } }
void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, int plane, TX_SIZE tx_size, int has_eob, int aoff, int loff) { ENTROPY_CONTEXT *const a = pd->above_context + aoff; ENTROPY_CONTEXT *const l = pd->left_context + loff; const int txs_wide = tx_size_wide_unit[tx_size]; const int txs_high = tx_size_high_unit[tx_size]; const BLOCK_SIZE bsize = AOMMAX(xd->mi[0]->mbmi.sb_type, BLOCK_8X8); const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); // above if (has_eob && xd->mb_to_right_edge < 0) { int i; const int blocks_wide = max_block_wide(xd, plane_bsize, plane); int above_contexts = txs_wide; if (above_contexts + aoff > blocks_wide) above_contexts = blocks_wide - aoff; for (i = 0; i < above_contexts; ++i) a[i] = has_eob; for (i = above_contexts; i < txs_wide; ++i) a[i] = 0; } else { memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * txs_wide); } // left if (has_eob && xd->mb_to_bottom_edge < 0) { int i; const int blocks_high = max_block_high(xd, plane_bsize, plane); int left_contexts = txs_high; if (left_contexts + loff > blocks_high) left_contexts = blocks_high - loff; for (i = 0; i < left_contexts; ++i) l[i] = has_eob; for (i = left_contexts; i < txs_high; ++i) l[i] = 0; } else { memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * txs_high); } }