OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "vp9/encoder/vp9_context_tree.h" | 11 #include "vp9/encoder/vp9_context_tree.h" |
| 12 #include "vp9/encoder/vp9_encoder.h" |
12 | 13 |
13 static const BLOCK_SIZE square[] = { | 14 static const BLOCK_SIZE square[] = { |
14 BLOCK_8X8, | 15 BLOCK_8X8, |
15 BLOCK_16X16, | 16 BLOCK_16X16, |
16 BLOCK_32X32, | 17 BLOCK_32X32, |
17 BLOCK_64X64, | 18 BLOCK_64X64, |
18 }; | 19 }; |
19 | 20 |
20 static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk, | 21 static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk, |
21 PICK_MODE_CONTEXT *ctx) { | 22 PICK_MODE_CONTEXT *ctx) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 free_mode_context(&tree->horizontal[0]); | 80 free_mode_context(&tree->horizontal[0]); |
80 free_mode_context(&tree->horizontal[1]); | 81 free_mode_context(&tree->horizontal[1]); |
81 free_mode_context(&tree->vertical[0]); | 82 free_mode_context(&tree->vertical[0]); |
82 free_mode_context(&tree->vertical[1]); | 83 free_mode_context(&tree->vertical[1]); |
83 } | 84 } |
84 | 85 |
85 // This function sets up a tree of contexts such that at each square | 86 // This function sets up a tree of contexts such that at each square |
86 // partition level. There are contexts for none, horizontal, vertical, and | 87 // partition level. There are contexts for none, horizontal, vertical, and |
87 // split. Along with a block_size value and a selected block_size which | 88 // split. Along with a block_size value and a selected block_size which |
88 // represents the state of our search. | 89 // represents the state of our search. |
89 void vp9_setup_pc_tree(VP9_COMMON *cm, MACROBLOCK *x) { | 90 void vp9_setup_pc_tree(VP9_COMMON *cm, VP9_COMP *cpi) { |
90 int i, j; | 91 int i, j; |
91 const int leaf_nodes = 64; | 92 const int leaf_nodes = 64; |
92 const int tree_nodes = 64 + 16 + 4 + 1; | 93 const int tree_nodes = 64 + 16 + 4 + 1; |
93 int pc_tree_index = 0; | 94 int pc_tree_index = 0; |
94 PC_TREE *this_pc; | 95 PC_TREE *this_pc; |
95 PICK_MODE_CONTEXT *this_leaf; | 96 PICK_MODE_CONTEXT *this_leaf; |
96 int square_index = 1; | 97 int square_index = 1; |
97 int nodes; | 98 int nodes; |
98 | 99 |
99 vpx_free(x->leaf_tree); | 100 vpx_free(cpi->leaf_tree); |
100 CHECK_MEM_ERROR(cm, x->leaf_tree, vpx_calloc(leaf_nodes, | 101 CHECK_MEM_ERROR(cm, cpi->leaf_tree, vpx_calloc(leaf_nodes, |
101 sizeof(*x->leaf_tree))); | 102 sizeof(*cpi->leaf_tree))); |
102 vpx_free(x->pc_tree); | 103 vpx_free(cpi->pc_tree); |
103 CHECK_MEM_ERROR(cm, x->pc_tree, vpx_calloc(tree_nodes, sizeof(*x->pc_tree))); | 104 CHECK_MEM_ERROR(cm, cpi->pc_tree, vpx_calloc(tree_nodes, |
| 105 sizeof(*cpi->pc_tree))); |
104 | 106 |
105 this_pc = &x->pc_tree[0]; | 107 this_pc = &cpi->pc_tree[0]; |
106 this_leaf = &x->leaf_tree[0]; | 108 this_leaf = &cpi->leaf_tree[0]; |
107 | 109 |
108 // 4x4 blocks smaller than 8x8 but in the same 8x8 block share the same | 110 // 4x4 blocks smaller than 8x8 but in the same 8x8 block share the same |
109 // context so we only need to allocate 1 for each 8x8 block. | 111 // context so we only need to allocate 1 for each 8x8 block. |
110 for (i = 0; i < leaf_nodes; ++i) | 112 for (i = 0; i < leaf_nodes; ++i) |
111 alloc_mode_context(cm, 1, &x->leaf_tree[i]); | 113 alloc_mode_context(cm, 1, &cpi->leaf_tree[i]); |
112 | 114 |
113 // Sets up all the leaf nodes in the tree. | 115 // Sets up all the leaf nodes in the tree. |
114 for (pc_tree_index = 0; pc_tree_index < leaf_nodes; ++pc_tree_index) { | 116 for (pc_tree_index = 0; pc_tree_index < leaf_nodes; ++pc_tree_index) { |
115 PC_TREE *const tree = &x->pc_tree[pc_tree_index]; | 117 PC_TREE *const tree = &cpi->pc_tree[pc_tree_index]; |
116 tree->block_size = square[0]; | 118 tree->block_size = square[0]; |
117 alloc_tree_contexts(cm, tree, 4); | 119 alloc_tree_contexts(cm, tree, 4); |
118 tree->leaf_split[0] = this_leaf++; | 120 tree->leaf_split[0] = this_leaf++; |
119 for (j = 1; j < 4; j++) | 121 for (j = 1; j < 4; j++) |
120 tree->leaf_split[j] = tree->leaf_split[0]; | 122 tree->leaf_split[j] = tree->leaf_split[0]; |
121 } | 123 } |
122 | 124 |
123 // Each node has 4 leaf nodes, fill each block_size level of the tree | 125 // Each node has 4 leaf nodes, fill each block_size level of the tree |
124 // from leafs to the root. | 126 // from leafs to the root. |
125 for (nodes = 16; nodes > 0; nodes >>= 2) { | 127 for (nodes = 16; nodes > 0; nodes >>= 2) { |
126 for (i = 0; i < nodes; ++i) { | 128 for (i = 0; i < nodes; ++i) { |
127 PC_TREE *const tree = &x->pc_tree[pc_tree_index]; | 129 PC_TREE *const tree = &cpi->pc_tree[pc_tree_index]; |
128 alloc_tree_contexts(cm, tree, 4 << (2 * square_index)); | 130 alloc_tree_contexts(cm, tree, 4 << (2 * square_index)); |
129 tree->block_size = square[square_index]; | 131 tree->block_size = square[square_index]; |
130 for (j = 0; j < 4; j++) | 132 for (j = 0; j < 4; j++) |
131 tree->split[j] = this_pc++; | 133 tree->split[j] = this_pc++; |
132 ++pc_tree_index; | 134 ++pc_tree_index; |
133 } | 135 } |
134 ++square_index; | 136 ++square_index; |
135 } | 137 } |
136 x->pc_root = &x->pc_tree[tree_nodes - 1]; | 138 cpi->pc_root = &cpi->pc_tree[tree_nodes - 1]; |
137 x->pc_root[0].none.best_mode_index = 2; | 139 cpi->pc_root[0].none.best_mode_index = 2; |
138 } | 140 } |
139 | 141 |
140 void vp9_free_pc_tree(MACROBLOCK *x) { | 142 void vp9_free_pc_tree(VP9_COMP *cpi) { |
141 const int tree_nodes = 64 + 16 + 4 + 1; | 143 const int tree_nodes = 64 + 16 + 4 + 1; |
142 int i; | 144 int i; |
143 | 145 |
144 // Set up all 4x4 mode contexts | 146 // Set up all 4x4 mode contexts |
145 for (i = 0; i < 64; ++i) | 147 for (i = 0; i < 64; ++i) |
146 free_mode_context(&x->leaf_tree[i]); | 148 free_mode_context(&cpi->leaf_tree[i]); |
147 | 149 |
148 // Sets up all the leaf nodes in the tree. | 150 // Sets up all the leaf nodes in the tree. |
149 for (i = 0; i < tree_nodes; ++i) | 151 for (i = 0; i < tree_nodes; ++i) |
150 free_tree_contexts(&x->pc_tree[i]); | 152 free_tree_contexts(&cpi->pc_tree[i]); |
151 | 153 |
152 vpx_free(x->pc_tree); | 154 vpx_free(cpi->pc_tree); |
153 x->pc_tree = NULL; | 155 cpi->pc_tree = NULL; |
154 vpx_free(x->leaf_tree); | 156 vpx_free(cpi->leaf_tree); |
155 x->leaf_tree = NULL; | 157 cpi->leaf_tree = NULL; |
156 } | 158 } |
OLD | NEW |