OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license | 5 * Use of this source code is governed by a BSD-style license |
6 * that can be found in the LICENSE file in the root of the source | 6 * that can be found in the LICENSE file in the root of the source |
7 * tree. An additional intellectual property rights grant can be found | 7 * tree. An additional intellectual property rights grant can be found |
8 * in the file PATENTS. All contributing project authors may | 8 * in the file PATENTS. All contributing project authors may |
9 * be found in the AUTHORS file in the root of the source tree. | 9 * be found in the AUTHORS file in the root of the source tree. |
10 */ | 10 */ |
11 | 11 |
12 #include <limits.h> | 12 #include <limits.h> |
13 | 13 |
14 #include "vp9/common/vp9_common.h" | 14 #include "vp9/common/vp9_common.h" |
15 #include "vp9/common/vp9_pred_common.h" | 15 #include "vp9/common/vp9_pred_common.h" |
16 #include "vp9/common/vp9_seg_common.h" | 16 #include "vp9/common/vp9_seg_common.h" |
17 #include "vp9/common/vp9_treecoder.h" | 17 #include "vp9/common/vp9_treecoder.h" |
18 | 18 |
19 static INLINE const MB_MODE_INFO *get_above_mbmi(const MODE_INFO *const above) { | 19 static INLINE const MB_MODE_INFO *get_above_mbmi(const MODE_INFO *const above) { |
20 return (above != NULL) ? &above->mbmi : NULL; | 20 return (above != NULL) ? &above->mbmi : NULL; |
21 } | 21 } |
22 | 22 |
23 static INLINE const MB_MODE_INFO *get_left_mbmi(const MODE_INFO *const left) { | 23 static INLINE const MB_MODE_INFO *get_left_mbmi(const MODE_INFO *const left) { |
24 return (left != NULL) ? &left->mbmi : NULL; | 24 return (left != NULL) ? &left->mbmi : NULL; |
25 } | 25 } |
26 | 26 |
27 // Returns a context number for the given MB prediction signal | 27 // Returns a context number for the given MB prediction signal |
28 unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { | 28 int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { |
29 const MODE_INFO *const above_mi = get_above_mi(xd); | |
30 const MODE_INFO *const left_mi = get_left_mi(xd); | |
31 const int above_in_image = above_mi != NULL; | |
32 const int left_in_image = left_mi != NULL; | |
33 // Note: | 29 // Note: |
34 // The mode info data structure has a one element border above and to the | 30 // The mode info data structure has a one element border above and to the |
35 // left of the entries correpsonding to real macroblocks. | 31 // left of the entries correpsonding to real macroblocks. |
36 // The prediction flags in these dummy entries are initialised to 0. | 32 // The prediction flags in these dummy entries are initialised to 0. |
37 // left | 33 const MODE_INFO *const left_mi = get_left_mi(xd); |
38 const int left_mv_pred = left_in_image ? is_inter_block(&left_mi->mbmi) | 34 const int has_left = left_mi != NULL ? is_inter_block(&left_mi->mbmi) : 0; |
39 : 0; | 35 const int left_type = has_left ? left_mi->mbmi.interp_filter |
40 const int left_interp = left_in_image && left_mv_pred | 36 : SWITCHABLE_FILTERS; |
41 ? left_mi->mbmi.interp_filter | |
42 : SWITCHABLE_FILTERS; | |
43 | 37 |
44 // above | 38 const MODE_INFO *const above_mi = get_above_mi(xd); |
45 const int above_mv_pred = above_in_image ? is_inter_block(&above_mi->mbmi) | 39 const int has_above = above_mi != NULL ? is_inter_block(&above_mi->mbmi) : 0; |
46 : 0; | 40 const int above_type = has_above ? above_mi->mbmi.interp_filter |
47 const int above_interp = above_in_image && above_mv_pred | 41 : SWITCHABLE_FILTERS; |
48 ? above_mi->mbmi.interp_filter | 42 if (left_type == above_type) |
49 : SWITCHABLE_FILTERS; | 43 return left_type; |
50 | 44 else if (left_type == SWITCHABLE_FILTERS && above_type != SWITCHABLE_FILTERS) |
51 if (left_interp == above_interp) | 45 return above_type; |
52 return left_interp; | 46 else if (left_type != SWITCHABLE_FILTERS && above_type == SWITCHABLE_FILTERS) |
53 else if (left_interp == SWITCHABLE_FILTERS && | 47 return left_type; |
54 above_interp != SWITCHABLE_FILTERS) | |
55 return above_interp; | |
56 else if (left_interp != SWITCHABLE_FILTERS && | |
57 above_interp == SWITCHABLE_FILTERS) | |
58 return left_interp; | |
59 else | 48 else |
60 return SWITCHABLE_FILTERS; | 49 return SWITCHABLE_FILTERS; |
61 } | 50 } |
62 // Returns a context number for the given MB prediction signal | 51 // Returns a context number for the given MB prediction signal |
63 unsigned char vp9_get_pred_context_intra_inter(const MACROBLOCKD *xd) { | 52 int vp9_get_intra_inter_context(const MACROBLOCKD *xd) { |
64 const MODE_INFO *const above_mi = get_above_mi(xd); | 53 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(get_above_mi(xd)); |
65 const MODE_INFO *const left_mi = get_left_mi(xd); | 54 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(get_left_mi(xd)); |
66 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); | 55 const int has_above = above_mbmi != NULL; |
67 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); | 56 const int has_left = left_mbmi != NULL; |
68 const int above_in_image = above_mi != NULL; | 57 const int above_intra = has_above ? !is_inter_block(above_mbmi) : 1; |
69 const int left_in_image = left_mi != NULL; | 58 const int left_intra = has_left ? !is_inter_block(left_mbmi) : 1; |
70 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; | |
71 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; | |
72 | 59 |
73 // The mode info data structure has a one element border above and to the | 60 // The mode info data structure has a one element border above and to the |
74 // left of the entries corresponding to real macroblocks. | 61 // left of the entries corresponding to real macroblocks. |
75 // The prediction flags in these dummy entries are initialized to 0. | 62 // The prediction flags in these dummy entries are initialized to 0. |
76 // 0 - inter/inter, inter/--, --/inter, --/-- | 63 // 0 - inter/inter, inter/--, --/inter, --/-- |
77 // 1 - intra/inter, inter/intra | 64 // 1 - intra/inter, inter/intra |
78 // 2 - intra/--, --/intra | 65 // 2 - intra/--, --/intra |
79 // 3 - intra/intra | 66 // 3 - intra/intra |
80 if (above_in_image && left_in_image) // both edges available | 67 if (has_above && has_left) // both edges available |
81 return left_intra && above_intra ? 3 | 68 return left_intra && above_intra ? 3 |
82 : left_intra || above_intra; | 69 : left_intra || above_intra; |
83 else if (above_in_image || left_in_image) // one edge available | 70 else if (has_above || has_left) // one edge available |
84 return 2 * (above_in_image ? above_intra : left_intra); | 71 return 2 * (has_above ? above_intra : left_intra); |
85 else | 72 else |
86 return 0; | 73 return 0; |
87 } | 74 } |
88 // Returns a context number for the given MB prediction signal | 75 |
89 unsigned char vp9_get_pred_context_comp_inter_inter(const VP9_COMMON *cm, | 76 int vp9_get_reference_mode_context(const VP9_COMMON *cm, |
90 const MACROBLOCKD *xd) { | 77 const MACROBLOCKD *xd) { |
91 int pred_context; | 78 int ctx; |
92 const MODE_INFO *const above_mi = get_above_mi(xd); | 79 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(get_above_mi(xd)); |
93 const MODE_INFO *const left_mi = get_left_mi(xd); | 80 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(get_left_mi(xd)); |
94 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); | 81 const int has_above = above_mbmi != NULL; |
95 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); | 82 const int has_left = left_mbmi != NULL; |
96 const int above_in_image = above_mi != NULL; | |
97 const int left_in_image = left_mi != NULL; | |
98 // Note: | 83 // Note: |
99 // The mode info data structure has a one element border above and to the | 84 // The mode info data structure has a one element border above and to the |
100 // left of the entries correpsonding to real macroblocks. | 85 // left of the entries correpsonding to real macroblocks. |
101 // The prediction flags in these dummy entries are initialised to 0. | 86 // The prediction flags in these dummy entries are initialised to 0. |
102 if (above_in_image && left_in_image) { // both edges available | 87 if (has_above && has_left) { // both edges available |
103 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) | 88 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) |
104 // neither edge uses comp pred (0/1) | 89 // neither edge uses comp pred (0/1) |
105 pred_context = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^ | 90 ctx = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^ |
106 (left_mbmi->ref_frame[0] == cm->comp_fixed_ref); | 91 (left_mbmi->ref_frame[0] == cm->comp_fixed_ref); |
107 else if (!has_second_ref(above_mbmi)) | 92 else if (!has_second_ref(above_mbmi)) |
108 // one of two edges uses comp pred (2/3) | 93 // one of two edges uses comp pred (2/3) |
109 pred_context = 2 + (above_mbmi->ref_frame[0] == cm->comp_fixed_ref || | 94 ctx = 2 + (above_mbmi->ref_frame[0] == cm->comp_fixed_ref || |
110 !is_inter_block(above_mbmi)); | 95 !is_inter_block(above_mbmi)); |
111 else if (!has_second_ref(left_mbmi)) | 96 else if (!has_second_ref(left_mbmi)) |
112 // one of two edges uses comp pred (2/3) | 97 // one of two edges uses comp pred (2/3) |
113 pred_context = 2 + (left_mbmi->ref_frame[0] == cm->comp_fixed_ref || | 98 ctx = 2 + (left_mbmi->ref_frame[0] == cm->comp_fixed_ref || |
114 !is_inter_block(left_mbmi)); | 99 !is_inter_block(left_mbmi)); |
115 else // both edges use comp pred (4) | 100 else // both edges use comp pred (4) |
116 pred_context = 4; | 101 ctx = 4; |
117 } else if (above_in_image || left_in_image) { // one edge available | 102 } else if (has_above || has_left) { // one edge available |
118 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; | 103 const MB_MODE_INFO *edge_mbmi = has_above ? above_mbmi : left_mbmi; |
119 | 104 |
120 if (!has_second_ref(edge_mbmi)) | 105 if (!has_second_ref(edge_mbmi)) |
121 // edge does not use comp pred (0/1) | 106 // edge does not use comp pred (0/1) |
122 pred_context = edge_mbmi->ref_frame[0] == cm->comp_fixed_ref; | 107 ctx = edge_mbmi->ref_frame[0] == cm->comp_fixed_ref; |
123 else | 108 else |
124 // edge uses comp pred (3) | 109 // edge uses comp pred (3) |
125 pred_context = 3; | 110 ctx = 3; |
126 } else { // no edges available (1) | 111 } else { // no edges available (1) |
127 pred_context = 1; | 112 ctx = 1; |
128 } | 113 } |
129 assert(pred_context >= 0 && pred_context < COMP_INTER_CONTEXTS); | 114 assert(ctx >= 0 && ctx < COMP_INTER_CONTEXTS); |
130 return pred_context; | 115 return ctx; |
131 } | 116 } |
132 | 117 |
133 // Returns a context number for the given MB prediction signal | 118 // Returns a context number for the given MB prediction signal |
134 unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm, | 119 int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm, |
135 const MACROBLOCKD *xd) { | 120 const MACROBLOCKD *xd) { |
136 int pred_context; | 121 int pred_context; |
137 const MODE_INFO *const above_mi = get_above_mi(xd); | 122 const MODE_INFO *const above_mi = get_above_mi(xd); |
138 const MODE_INFO *const left_mi = get_left_mi(xd); | 123 const MODE_INFO *const left_mi = get_left_mi(xd); |
139 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); | 124 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); |
140 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); | 125 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); |
141 const int above_in_image = above_mi != NULL; | 126 const int above_in_image = above_mi != NULL; |
142 const int left_in_image = left_mi != NULL; | 127 const int left_in_image = left_mi != NULL; |
143 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; | 128 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; |
144 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; | 129 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; |
145 // Note: | 130 // Note: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 else | 190 else |
206 pred_context = 3 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]); | 191 pred_context = 3 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]); |
207 } | 192 } |
208 } else { // no edges available (2) | 193 } else { // no edges available (2) |
209 pred_context = 2; | 194 pred_context = 2; |
210 } | 195 } |
211 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); | 196 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); |
212 | 197 |
213 return pred_context; | 198 return pred_context; |
214 } | 199 } |
215 unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) { | 200 |
| 201 int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) { |
216 int pred_context; | 202 int pred_context; |
217 const MODE_INFO *const above_mi = get_above_mi(xd); | 203 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(get_above_mi(xd)); |
218 const MODE_INFO *const left_mi = get_left_mi(xd); | 204 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(get_left_mi(xd)); |
219 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); | 205 const int has_above = above_mbmi != NULL; |
220 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); | 206 const int has_left = left_mbmi != NULL; |
221 const int above_in_image = above_mi != NULL; | 207 const int above_intra = has_above ? !is_inter_block(above_mbmi) : 1; |
222 const int left_in_image = left_mi != NULL; | 208 const int left_intra = has_left ? !is_inter_block(left_mbmi) : 1; |
223 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; | |
224 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; | |
225 // Note: | 209 // Note: |
226 // The mode info data structure has a one element border above and to the | 210 // The mode info data structure has a one element border above and to the |
227 // left of the entries correpsonding to real macroblocks. | 211 // left of the entries correpsonding to real macroblocks. |
228 // The prediction flags in these dummy entries are initialised to 0. | 212 // The prediction flags in these dummy entries are initialised to 0. |
229 if (above_in_image && left_in_image) { // both edges available | 213 if (has_above && has_left) { // both edges available |
230 if (above_intra && left_intra) { // intra/intra | 214 if (above_intra && left_intra) { // intra/intra |
231 pred_context = 2; | 215 pred_context = 2; |
232 } else if (above_intra || left_intra) { // intra/inter or inter/intra | 216 } else if (above_intra || left_intra) { // intra/inter or inter/intra |
233 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; | 217 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; |
234 if (!has_second_ref(edge_mbmi)) | 218 if (!has_second_ref(edge_mbmi)) |
235 pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME); | 219 pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME); |
236 else | 220 else |
237 pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME || | 221 pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME || |
238 edge_mbmi->ref_frame[1] == LAST_FRAME); | 222 edge_mbmi->ref_frame[1] == LAST_FRAME); |
239 } else { // inter/inter | 223 } else { // inter/inter |
(...skipping 12 matching lines...) Expand all Loading... |
252 above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0]; | 236 above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0]; |
253 const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ? | 237 const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ? |
254 above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1]; | 238 above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1]; |
255 | 239 |
256 if (rfs == LAST_FRAME) | 240 if (rfs == LAST_FRAME) |
257 pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME); | 241 pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME); |
258 else | 242 else |
259 pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME; | 243 pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME; |
260 } | 244 } |
261 } | 245 } |
262 } else if (above_in_image || left_in_image) { // one edge available | 246 } else if (has_above || has_left) { // one edge available |
263 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; | 247 const MB_MODE_INFO *edge_mbmi = has_above ? above_mbmi : left_mbmi; |
264 if (!is_inter_block(edge_mbmi)) { // intra | 248 if (!is_inter_block(edge_mbmi)) { // intra |
265 pred_context = 2; | 249 pred_context = 2; |
266 } else { // inter | 250 } else { // inter |
267 if (!has_second_ref(edge_mbmi)) | 251 if (!has_second_ref(edge_mbmi)) |
268 pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME); | 252 pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME); |
269 else | 253 else |
270 pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME || | 254 pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME || |
271 edge_mbmi->ref_frame[1] == LAST_FRAME); | 255 edge_mbmi->ref_frame[1] == LAST_FRAME); |
272 } | 256 } |
273 } else { // no edges available | 257 } else { // no edges available |
274 pred_context = 2; | 258 pred_context = 2; |
275 } | 259 } |
276 | 260 |
277 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); | 261 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); |
278 return pred_context; | 262 return pred_context; |
279 } | 263 } |
280 | 264 |
281 unsigned char vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) { | 265 int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) { |
282 int pred_context; | 266 int pred_context; |
283 const MODE_INFO *const above_mi = get_above_mi(xd); | 267 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(get_above_mi(xd)); |
284 const MODE_INFO *const left_mi = get_left_mi(xd); | 268 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(get_left_mi(xd)); |
285 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); | 269 const int has_above = above_mbmi != NULL; |
286 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); | 270 const int has_left = left_mbmi != NULL; |
287 const int above_in_image = above_mi != NULL; | 271 const int above_intra = has_above ? !is_inter_block(above_mbmi) : 1; |
288 const int left_in_image = left_mi != NULL; | 272 const int left_intra = has_left ? !is_inter_block(left_mbmi) : 1; |
289 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; | |
290 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; | |
291 | 273 |
292 // Note: | 274 // Note: |
293 // The mode info data structure has a one element border above and to the | 275 // The mode info data structure has a one element border above and to the |
294 // left of the entries correpsonding to real macroblocks. | 276 // left of the entries correpsonding to real macroblocks. |
295 // The prediction flags in these dummy entries are initialised to 0. | 277 // The prediction flags in these dummy entries are initialised to 0. |
296 if (above_in_image && left_in_image) { // both edges available | 278 if (has_above && has_left) { // both edges available |
297 if (above_intra && left_intra) { // intra/intra | 279 if (above_intra && left_intra) { // intra/intra |
298 pred_context = 2; | 280 pred_context = 2; |
299 } else if (above_intra || left_intra) { // intra/inter or inter/intra | 281 } else if (above_intra || left_intra) { // intra/inter or inter/intra |
300 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; | 282 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; |
301 if (!has_second_ref(edge_mbmi)) { | 283 if (!has_second_ref(edge_mbmi)) { |
302 if (edge_mbmi->ref_frame[0] == LAST_FRAME) | 284 if (edge_mbmi->ref_frame[0] == LAST_FRAME) |
303 pred_context = 3; | 285 pred_context = 3; |
304 else | 286 else |
305 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); | 287 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); |
306 } else { | 288 } else { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1]; | 322 above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1]; |
341 | 323 |
342 if (rfs == GOLDEN_FRAME) | 324 if (rfs == GOLDEN_FRAME) |
343 pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME); | 325 pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME); |
344 else if (rfs == ALTREF_FRAME) | 326 else if (rfs == ALTREF_FRAME) |
345 pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME; | 327 pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME; |
346 else | 328 else |
347 pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME); | 329 pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME); |
348 } | 330 } |
349 } | 331 } |
350 } else if (above_in_image || left_in_image) { // one edge available | 332 } else if (has_above || has_left) { // one edge available |
351 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; | 333 const MB_MODE_INFO *edge_mbmi = has_above ? above_mbmi : left_mbmi; |
352 | 334 |
353 if (!is_inter_block(edge_mbmi) || | 335 if (!is_inter_block(edge_mbmi) || |
354 (edge_mbmi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mbmi))) | 336 (edge_mbmi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mbmi))) |
355 pred_context = 2; | 337 pred_context = 2; |
356 else if (!has_second_ref(edge_mbmi)) | 338 else if (!has_second_ref(edge_mbmi)) |
357 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); | 339 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); |
358 else | 340 else |
359 pred_context = 3 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME || | 341 pred_context = 3 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME || |
360 edge_mbmi->ref_frame[1] == GOLDEN_FRAME); | 342 edge_mbmi->ref_frame[1] == GOLDEN_FRAME); |
361 } else { // no edges available (2) | 343 } else { // no edges available (2) |
362 pred_context = 2; | 344 pred_context = 2; |
363 } | 345 } |
364 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); | 346 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); |
365 return pred_context; | 347 return pred_context; |
366 } | 348 } |
367 // Returns a context number for the given MB prediction signal | 349 // Returns a context number for the given MB prediction signal |
368 // The mode info data structure has a one element border above and to the | 350 // The mode info data structure has a one element border above and to the |
369 // left of the entries corresponding to real blocks. | 351 // left of the entries corresponding to real blocks. |
370 // The prediction flags in these dummy entries are initialized to 0. | 352 // The prediction flags in these dummy entries are initialized to 0. |
371 unsigned char vp9_get_pred_context_tx_size(const MACROBLOCKD *xd) { | 353 int vp9_get_tx_size_context(const MACROBLOCKD *xd) { |
372 const MODE_INFO *const above_mi = get_above_mi(xd); | |
373 const MODE_INFO *const left_mi = get_left_mi(xd); | |
374 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); | |
375 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); | |
376 const int above_in_image = above_mi != NULL; | |
377 const int left_in_image = left_mi != NULL; | |
378 const int max_tx_size = max_txsize_lookup[xd->mi_8x8[0]->mbmi.sb_type]; | 354 const int max_tx_size = max_txsize_lookup[xd->mi_8x8[0]->mbmi.sb_type]; |
379 int above_context = max_tx_size; | 355 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(get_above_mi(xd)); |
380 int left_context = max_tx_size; | 356 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(get_left_mi(xd)); |
| 357 const int has_above = above_mbmi != NULL; |
| 358 const int has_left = left_mbmi != NULL; |
| 359 int above_ctx = (has_above && !above_mbmi->skip_coeff) ? above_mbmi->tx_size |
| 360 : max_tx_size; |
| 361 int left_ctx = (has_left && !left_mbmi->skip_coeff) ? left_mbmi->tx_size |
| 362 : max_tx_size; |
| 363 if (!has_left) |
| 364 left_ctx = above_ctx; |
381 | 365 |
382 if (above_in_image) | 366 if (!has_above) |
383 above_context = above_mbmi->skip_coeff ? max_tx_size | 367 above_ctx = left_ctx; |
384 : above_mbmi->tx_size; | |
385 | 368 |
386 if (left_in_image) | 369 return (above_ctx + left_ctx) > max_tx_size; |
387 left_context = left_mbmi->skip_coeff ? max_tx_size | |
388 : left_mbmi->tx_size; | |
389 | |
390 if (!left_in_image) | |
391 left_context = above_context; | |
392 | |
393 if (!above_in_image) | |
394 above_context = left_context; | |
395 | |
396 return above_context + left_context > max_tx_size; | |
397 } | |
398 | |
399 void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, uint8_t pred_flag) { | |
400 xd->mi_8x8[0]->mbmi.seg_id_predicted = pred_flag; | |
401 } | 370 } |
402 | 371 |
403 int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids, | 372 int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids, |
404 BLOCK_SIZE bsize, int mi_row, int mi_col) { | 373 BLOCK_SIZE bsize, int mi_row, int mi_col) { |
405 const int mi_offset = mi_row * cm->mi_cols + mi_col; | 374 const int mi_offset = mi_row * cm->mi_cols + mi_col; |
406 const int bw = 1 << mi_width_log2(bsize); | 375 const int bw = num_8x8_blocks_wide_lookup[bsize]; |
407 const int bh = 1 << mi_height_log2(bsize); | 376 const int bh = num_8x8_blocks_high_lookup[bsize]; |
408 const int xmis = MIN(cm->mi_cols - mi_col, bw); | 377 const int xmis = MIN(cm->mi_cols - mi_col, bw); |
409 const int ymis = MIN(cm->mi_rows - mi_row, bh); | 378 const int ymis = MIN(cm->mi_rows - mi_row, bh); |
410 int x, y, segment_id = INT_MAX; | 379 int x, y, segment_id = INT_MAX; |
411 | 380 |
412 for (y = 0; y < ymis; y++) | 381 for (y = 0; y < ymis; y++) |
413 for (x = 0; x < xmis; x++) | 382 for (x = 0; x < xmis; x++) |
414 segment_id = MIN(segment_id, | 383 segment_id = MIN(segment_id, |
415 segment_ids[mi_offset + y * cm->mi_cols + x]); | 384 segment_ids[mi_offset + y * cm->mi_cols + x]); |
416 | 385 |
417 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); | 386 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
418 return segment_id; | 387 return segment_id; |
419 } | 388 } |
OLD | NEW |