OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "vp9/common/vp9_blockd.h" |
| 12 |
| 13 MB_PREDICTION_MODE vp9_left_block_mode(const MODE_INFO *cur_mi, |
| 14 const MODE_INFO *left_mi, int b) { |
| 15 if (b == 0 || b == 2) { |
| 16 if (!left_mi || is_inter_block(&left_mi->mbmi)) |
| 17 return DC_PRED; |
| 18 |
| 19 return left_mi->mbmi.sb_type < BLOCK_8X8 ? left_mi->bmi[b + 1].as_mode |
| 20 : left_mi->mbmi.mode; |
| 21 } else { |
| 22 assert(b == 1 || b == 3); |
| 23 return cur_mi->bmi[b - 1].as_mode; |
| 24 } |
| 25 } |
| 26 |
| 27 MB_PREDICTION_MODE vp9_above_block_mode(const MODE_INFO *cur_mi, |
| 28 const MODE_INFO *above_mi, int b) { |
| 29 if (b == 0 || b == 1) { |
| 30 if (!above_mi || is_inter_block(&above_mi->mbmi)) |
| 31 return DC_PRED; |
| 32 |
| 33 return above_mi->mbmi.sb_type < BLOCK_8X8 ? above_mi->bmi[b + 2].as_mode |
| 34 : above_mi->mbmi.mode; |
| 35 } else { |
| 36 assert(b == 2 || b == 3); |
| 37 return cur_mi->bmi[b - 2].as_mode; |
| 38 } |
| 39 } |
| 40 |
| 41 void vp9_foreach_transformed_block_in_plane( |
| 42 const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane, |
| 43 foreach_transformed_block_visitor visit, void *arg) { |
| 44 const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 45 const MB_MODE_INFO* mbmi = &xd->mi_8x8[0]->mbmi; |
| 46 // block and transform sizes, in number of 4x4 blocks log 2 ("*_b") |
| 47 // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8 |
| 48 // transform size varies per plane, look it up in a common way. |
| 49 const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi) |
| 50 : mbmi->tx_size; |
| 51 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
| 52 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 53 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; |
| 54 const int step = 1 << (tx_size << 1); |
| 55 int i; |
| 56 |
| 57 // If mb_to_right_edge is < 0 we are in a situation in which |
| 58 // the current block size extends into the UMV and we won't |
| 59 // visit the sub blocks that are wholly within the UMV. |
| 60 if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) { |
| 61 int r, c; |
| 62 |
| 63 int max_blocks_wide = num_4x4_w; |
| 64 int max_blocks_high = num_4x4_h; |
| 65 |
| 66 // xd->mb_to_right_edge is in units of pixels * 8. This converts |
| 67 // it to 4x4 block sizes. |
| 68 if (xd->mb_to_right_edge < 0) |
| 69 max_blocks_wide += (xd->mb_to_right_edge >> (5 + pd->subsampling_x)); |
| 70 |
| 71 if (xd->mb_to_bottom_edge < 0) |
| 72 max_blocks_high += (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y)); |
| 73 |
| 74 i = 0; |
| 75 // Unlike the normal case - in here we have to keep track of the |
| 76 // row and column of the blocks we use so that we know if we are in |
| 77 // the unrestricted motion border. |
| 78 for (r = 0; r < num_4x4_h; r += (1 << tx_size)) { |
| 79 for (c = 0; c < num_4x4_w; c += (1 << tx_size)) { |
| 80 if (r < max_blocks_high && c < max_blocks_wide) |
| 81 visit(plane, i, plane_bsize, tx_size, arg); |
| 82 i += step; |
| 83 } |
| 84 } |
| 85 } else { |
| 86 for (i = 0; i < num_4x4_w * num_4x4_h; i += step) |
| 87 visit(plane, i, plane_bsize, tx_size, arg); |
| 88 } |
| 89 } |
| 90 |
| 91 void vp9_foreach_transformed_block(const MACROBLOCKD* const xd, |
| 92 BLOCK_SIZE bsize, |
| 93 foreach_transformed_block_visitor visit, |
| 94 void *arg) { |
| 95 int plane; |
| 96 |
| 97 for (plane = 0; plane < MAX_MB_PLANE; plane++) |
| 98 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, visit, arg); |
| 99 } |
| 100 |
| 101 void vp9_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, |
| 102 BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob, |
| 103 int aoff, int loff) { |
| 104 ENTROPY_CONTEXT *const a = pd->above_context + aoff; |
| 105 ENTROPY_CONTEXT *const l = pd->left_context + loff; |
| 106 const int tx_size_in_blocks = 1 << tx_size; |
| 107 |
| 108 // above |
| 109 if (has_eob && xd->mb_to_right_edge < 0) { |
| 110 int i; |
| 111 const int blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize] + |
| 112 (xd->mb_to_right_edge >> (5 + pd->subsampling_x)); |
| 113 int above_contexts = tx_size_in_blocks; |
| 114 if (above_contexts + aoff > blocks_wide) |
| 115 above_contexts = blocks_wide - aoff; |
| 116 |
| 117 for (i = 0; i < above_contexts; ++i) |
| 118 a[i] = has_eob; |
| 119 for (i = above_contexts; i < tx_size_in_blocks; ++i) |
| 120 a[i] = 0; |
| 121 } else { |
| 122 vpx_memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks); |
| 123 } |
| 124 |
| 125 // left |
| 126 if (has_eob && xd->mb_to_bottom_edge < 0) { |
| 127 int i; |
| 128 const int blocks_high = num_4x4_blocks_high_lookup[plane_bsize] + |
| 129 (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y)); |
| 130 int left_contexts = tx_size_in_blocks; |
| 131 if (left_contexts + loff > blocks_high) |
| 132 left_contexts = blocks_high - loff; |
| 133 |
| 134 for (i = 0; i < left_contexts; ++i) |
| 135 l[i] = has_eob; |
| 136 for (i = left_contexts; i < tx_size_in_blocks; ++i) |
| 137 l[i] = 0; |
| 138 } else { |
| 139 vpx_memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks); |
| 140 } |
| 141 } |
| 142 |
| 143 void vp9_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y) { |
| 144 int i; |
| 145 |
| 146 for (i = 0; i < MAX_MB_PLANE; i++) { |
| 147 xd->plane[i].plane_type = i ? PLANE_TYPE_UV : PLANE_TYPE_Y; |
| 148 xd->plane[i].subsampling_x = i ? ss_x : 0; |
| 149 xd->plane[i].subsampling_y = i ? ss_y : 0; |
| 150 } |
| 151 #if CONFIG_ALPHA |
| 152 // TODO(jkoleszar): Using the Y w/h for now |
| 153 xd->plane[3].plane_type = PLANE_TYPE_Y; |
| 154 xd->plane[3].subsampling_x = 0; |
| 155 xd->plane[3].subsampling_y = 0; |
| 156 #endif |
| 157 } |
OLD | NEW |