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 | 17 |
18 static INLINE const MB_MODE_INFO *get_mbmi(const MODE_INFO *const mi) { | |
19 return (mi != NULL) ? &mi->mbmi : NULL; | |
20 } | |
21 | |
22 // Returns a context number for the given MB prediction signal | 18 // Returns a context number for the given MB prediction signal |
23 int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { | 19 int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { |
24 // Note: | 20 // Note: |
25 // The mode info data structure has a one element border above and to the | 21 // The mode info data structure has a one element border above and to the |
26 // left of the entries correpsonding to real macroblocks. | 22 // left of the entries correpsonding to real macroblocks. |
27 // The prediction flags in these dummy entries are initialised to 0. | 23 // The prediction flags in these dummy entries are initialised to 0. |
28 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 24 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
29 const int left_type = left_mbmi != NULL && is_inter_block(left_mbmi) ? | 25 const int left_type = xd->left_available && is_inter_block(left_mbmi) ? |
30 left_mbmi->interp_filter : SWITCHABLE_FILTERS; | 26 left_mbmi->interp_filter : SWITCHABLE_FILTERS; |
31 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 27 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
32 const int above_type = above_mbmi != NULL && is_inter_block(above_mbmi) ? | 28 const int above_type = xd->up_available && is_inter_block(above_mbmi) ? |
33 above_mbmi->interp_filter : SWITCHABLE_FILTERS; | 29 above_mbmi->interp_filter : SWITCHABLE_FILTERS; |
34 | 30 |
35 if (left_type == above_type) | 31 if (left_type == above_type) |
36 return left_type; | 32 return left_type; |
37 else if (left_type == SWITCHABLE_FILTERS && above_type != SWITCHABLE_FILTERS) | 33 else if (left_type == SWITCHABLE_FILTERS && above_type != SWITCHABLE_FILTERS) |
38 return above_type; | 34 return above_type; |
39 else if (left_type != SWITCHABLE_FILTERS && above_type == SWITCHABLE_FILTERS) | 35 else if (left_type != SWITCHABLE_FILTERS && above_type == SWITCHABLE_FILTERS) |
40 return left_type; | 36 return left_type; |
41 else | 37 else |
42 return SWITCHABLE_FILTERS; | 38 return SWITCHABLE_FILTERS; |
43 } | 39 } |
44 | 40 |
45 // The mode info data structure has a one element border above and to the | 41 // The mode info data structure has a one element border above and to the |
46 // left of the entries corresponding to real macroblocks. | 42 // left of the entries corresponding to real macroblocks. |
47 // The prediction flags in these dummy entries are initialized to 0. | 43 // The prediction flags in these dummy entries are initialized to 0. |
48 // 0 - inter/inter, inter/--, --/inter, --/-- | 44 // 0 - inter/inter, inter/--, --/inter, --/-- |
49 // 1 - intra/inter, inter/intra | 45 // 1 - intra/inter, inter/intra |
50 // 2 - intra/--, --/intra | 46 // 2 - intra/--, --/intra |
51 // 3 - intra/intra | 47 // 3 - intra/intra |
52 int vp9_get_intra_inter_context(const MACROBLOCKD *xd) { | 48 int vp9_get_intra_inter_context(const MACROBLOCKD *xd) { |
53 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 49 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
54 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 50 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
55 const int has_above = above_mbmi != NULL; | 51 const int has_above = xd->up_available; |
56 const int has_left = left_mbmi != NULL; | 52 const int has_left = xd->left_available; |
57 | 53 |
58 if (has_above && has_left) { // both edges available | 54 if (has_above && has_left) { // both edges available |
59 const int above_intra = !is_inter_block(above_mbmi); | 55 const int above_intra = !is_inter_block(above_mbmi); |
60 const int left_intra = !is_inter_block(left_mbmi); | 56 const int left_intra = !is_inter_block(left_mbmi); |
61 return left_intra && above_intra ? 3 | 57 return left_intra && above_intra ? 3 |
62 : left_intra || above_intra; | 58 : left_intra || above_intra; |
63 } else if (has_above || has_left) { // one edge available | 59 } else if (has_above || has_left) { // one edge available |
64 return 2 * !is_inter_block(has_above ? above_mbmi : left_mbmi); | 60 return 2 * !is_inter_block(has_above ? above_mbmi : left_mbmi); |
65 } else { | 61 } else { |
66 return 0; | 62 return 0; |
67 } | 63 } |
68 } | 64 } |
69 | 65 |
70 int vp9_get_reference_mode_context(const VP9_COMMON *cm, | 66 int vp9_get_reference_mode_context(const VP9_COMMON *cm, |
71 const MACROBLOCKD *xd) { | 67 const MACROBLOCKD *xd) { |
72 int ctx; | 68 int ctx; |
73 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 69 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
74 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 70 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
75 const int has_above = above_mbmi != NULL; | 71 const int has_above = xd->up_available; |
76 const int has_left = left_mbmi != NULL; | 72 const int has_left = xd->left_available; |
77 // Note: | 73 // Note: |
78 // The mode info data structure has a one element border above and to the | 74 // The mode info data structure has a one element border above and to the |
79 // left of the entries correpsonding to real macroblocks. | 75 // left of the entries correpsonding to real macroblocks. |
80 // The prediction flags in these dummy entries are initialised to 0. | 76 // The prediction flags in these dummy entries are initialised to 0. |
81 if (has_above && has_left) { // both edges available | 77 if (has_above && has_left) { // both edges available |
82 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) | 78 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) |
83 // neither edge uses comp pred (0/1) | 79 // neither edge uses comp pred (0/1) |
84 ctx = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^ | 80 ctx = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^ |
85 (left_mbmi->ref_frame[0] == cm->comp_fixed_ref); | 81 (left_mbmi->ref_frame[0] == cm->comp_fixed_ref); |
86 else if (!has_second_ref(above_mbmi)) | 82 else if (!has_second_ref(above_mbmi)) |
(...skipping 19 matching lines...) Expand all Loading... |
106 ctx = 1; | 102 ctx = 1; |
107 } | 103 } |
108 assert(ctx >= 0 && ctx < COMP_INTER_CONTEXTS); | 104 assert(ctx >= 0 && ctx < COMP_INTER_CONTEXTS); |
109 return ctx; | 105 return ctx; |
110 } | 106 } |
111 | 107 |
112 // Returns a context number for the given MB prediction signal | 108 // Returns a context number for the given MB prediction signal |
113 int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm, | 109 int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm, |
114 const MACROBLOCKD *xd) { | 110 const MACROBLOCKD *xd) { |
115 int pred_context; | 111 int pred_context; |
116 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 112 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
117 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 113 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
118 const int above_in_image = above_mbmi != NULL; | 114 const int above_in_image = xd->up_available; |
119 const int left_in_image = left_mbmi != NULL; | 115 const int left_in_image = xd->left_available; |
120 | 116 |
121 // Note: | 117 // Note: |
122 // The mode info data structure has a one element border above and to the | 118 // The mode info data structure has a one element border above and to the |
123 // left of the entries correpsonding to real macroblocks. | 119 // left of the entries correpsonding to real macroblocks. |
124 // The prediction flags in these dummy entries are initialised to 0. | 120 // The prediction flags in these dummy entries are initialised to 0. |
125 const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; | 121 const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; |
126 const int var_ref_idx = !fix_ref_idx; | 122 const int var_ref_idx = !fix_ref_idx; |
127 | 123 |
128 if (above_in_image && left_in_image) { // both edges available | 124 if (above_in_image && left_in_image) { // both edges available |
129 const int above_intra = !is_inter_block(above_mbmi); | 125 const int above_intra = !is_inter_block(above_mbmi); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } else { // no edges available (2) | 183 } else { // no edges available (2) |
188 pred_context = 2; | 184 pred_context = 2; |
189 } | 185 } |
190 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); | 186 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); |
191 | 187 |
192 return pred_context; | 188 return pred_context; |
193 } | 189 } |
194 | 190 |
195 int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) { | 191 int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) { |
196 int pred_context; | 192 int pred_context; |
197 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 193 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
198 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 194 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
199 const int has_above = above_mbmi != NULL; | 195 const int has_above = xd->up_available; |
200 const int has_left = left_mbmi != NULL; | 196 const int has_left = xd->left_available; |
201 // Note: | 197 // Note: |
202 // The mode info data structure has a one element border above and to the | 198 // The mode info data structure has a one element border above and to the |
203 // left of the entries correpsonding to real macroblocks. | 199 // left of the entries correpsonding to real macroblocks. |
204 // The prediction flags in these dummy entries are initialised to 0. | 200 // The prediction flags in these dummy entries are initialised to 0. |
205 if (has_above && has_left) { // both edges available | 201 if (has_above && has_left) { // both edges available |
206 const int above_intra = !is_inter_block(above_mbmi); | 202 const int above_intra = !is_inter_block(above_mbmi); |
207 const int left_intra = !is_inter_block(left_mbmi); | 203 const int left_intra = !is_inter_block(left_mbmi); |
208 | 204 |
209 if (above_intra && left_intra) { // intra/intra | 205 if (above_intra && left_intra) { // intra/intra |
210 pred_context = 2; | 206 pred_context = 2; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } else { // no edges available | 249 } else { // no edges available |
254 pred_context = 2; | 250 pred_context = 2; |
255 } | 251 } |
256 | 252 |
257 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); | 253 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); |
258 return pred_context; | 254 return pred_context; |
259 } | 255 } |
260 | 256 |
261 int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) { | 257 int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) { |
262 int pred_context; | 258 int pred_context; |
263 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 259 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
264 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 260 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
265 const int has_above = above_mbmi != NULL; | 261 const int has_above = xd->up_available; |
266 const int has_left = left_mbmi != NULL; | 262 const int has_left = xd->left_available; |
267 | 263 |
268 // Note: | 264 // Note: |
269 // The mode info data structure has a one element border above and to the | 265 // The mode info data structure has a one element border above and to the |
270 // left of the entries correpsonding to real macroblocks. | 266 // left of the entries correpsonding to real macroblocks. |
271 // The prediction flags in these dummy entries are initialised to 0. | 267 // The prediction flags in these dummy entries are initialised to 0. |
272 if (has_above && has_left) { // both edges available | 268 if (has_above && has_left) { // both edges available |
273 const int above_intra = !is_inter_block(above_mbmi); | 269 const int above_intra = !is_inter_block(above_mbmi); |
274 const int left_intra = !is_inter_block(left_mbmi); | 270 const int left_intra = !is_inter_block(left_mbmi); |
275 | 271 |
276 if (above_intra && left_intra) { // intra/intra | 272 if (above_intra && left_intra) { // intra/intra |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 338 } |
343 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); | 339 assert(pred_context >= 0 && pred_context < REF_CONTEXTS); |
344 return pred_context; | 340 return pred_context; |
345 } | 341 } |
346 // Returns a context number for the given MB prediction signal | 342 // Returns a context number for the given MB prediction signal |
347 // The mode info data structure has a one element border above and to the | 343 // The mode info data structure has a one element border above and to the |
348 // left of the entries corresponding to real blocks. | 344 // left of the entries corresponding to real blocks. |
349 // The prediction flags in these dummy entries are initialized to 0. | 345 // The prediction flags in these dummy entries are initialized to 0. |
350 int vp9_get_tx_size_context(const MACROBLOCKD *xd) { | 346 int vp9_get_tx_size_context(const MACROBLOCKD *xd) { |
351 const int max_tx_size = max_txsize_lookup[xd->mi[0].src_mi->mbmi.sb_type]; | 347 const int max_tx_size = max_txsize_lookup[xd->mi[0].src_mi->mbmi.sb_type]; |
352 const MB_MODE_INFO *const above_mbmi = get_mbmi(get_above_mi(xd)); | 348 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
353 const MB_MODE_INFO *const left_mbmi = get_mbmi(get_left_mi(xd)); | 349 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
354 const int has_above = above_mbmi != NULL; | 350 const int has_above = xd->up_available; |
355 const int has_left = left_mbmi != NULL; | 351 const int has_left = xd->left_available; |
356 int above_ctx = (has_above && !above_mbmi->skip) ? (int)above_mbmi->tx_size | 352 int above_ctx = (has_above && !above_mbmi->skip) ? (int)above_mbmi->tx_size |
357 : max_tx_size; | 353 : max_tx_size; |
358 int left_ctx = (has_left && !left_mbmi->skip) ? (int)left_mbmi->tx_size | 354 int left_ctx = (has_left && !left_mbmi->skip) ? (int)left_mbmi->tx_size |
359 : max_tx_size; | 355 : max_tx_size; |
360 if (!has_left) | 356 if (!has_left) |
361 left_ctx = above_ctx; | 357 left_ctx = above_ctx; |
362 | 358 |
363 if (!has_above) | 359 if (!has_above) |
364 above_ctx = left_ctx; | 360 above_ctx = left_ctx; |
365 | 361 |
(...skipping 10 matching lines...) Expand all Loading... |
376 int x, y, segment_id = INT_MAX; | 372 int x, y, segment_id = INT_MAX; |
377 | 373 |
378 for (y = 0; y < ymis; y++) | 374 for (y = 0; y < ymis; y++) |
379 for (x = 0; x < xmis; x++) | 375 for (x = 0; x < xmis; x++) |
380 segment_id = MIN(segment_id, | 376 segment_id = MIN(segment_id, |
381 segment_ids[mi_offset + y * cm->mi_cols + x]); | 377 segment_ids[mi_offset + y * cm->mi_cols + x]); |
382 | 378 |
383 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); | 379 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
384 return segment_id; | 380 return segment_id; |
385 } | 381 } |
OLD | NEW |