OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2010 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 |
| 12 #include "vp9/common/vp9_onyxc_int.h" |
| 13 #include "vp9/common/vp9_modecont.h" |
| 14 #include "vpx_mem/vpx_mem.h" |
| 15 |
| 16 |
| 17 static const unsigned int kf_y_mode_cts[8][VP9_YMODES] = { |
| 18 /* DC V H D45 135 117 153 D27 D63 TM i8x8 BPRED */ |
| 19 {12, 6, 5, 5, 5, 5, 5, 5, 5, 2, 22, 200}, |
| 20 {25, 13, 13, 7, 7, 7, 7, 7, 7, 6, 27, 160}, |
| 21 {31, 17, 18, 8, 8, 8, 8, 8, 8, 9, 26, 139}, |
| 22 {40, 22, 23, 8, 8, 8, 8, 8, 8, 12, 27, 116}, |
| 23 {53, 26, 28, 8, 8, 8, 8, 8, 8, 13, 26, 94}, |
| 24 {68, 33, 35, 8, 8, 8, 8, 8, 8, 17, 20, 68}, |
| 25 {78, 38, 38, 8, 8, 8, 8, 8, 8, 19, 16, 52}, |
| 26 {89, 42, 42, 8, 8, 8, 8, 8, 8, 21, 12, 34}, |
| 27 }; |
| 28 |
| 29 static const unsigned int y_mode_cts [VP9_YMODES] = { |
| 30 /* DC V H D45 135 117 153 D27 D63 TM i8x8 BPRED */ |
| 31 98, 19, 15, 14, 14, 14, 14, 12, 12, 13, 16, 70 |
| 32 }; |
| 33 |
| 34 static const unsigned int uv_mode_cts [VP9_YMODES] [VP9_UV_MODES] = { |
| 35 /* DC V H D45 135 117 153 D27 D63 TM */ |
| 36 { 200, 15, 15, 10, 10, 10, 10, 10, 10, 6}, /* DC */ |
| 37 { 130, 75, 10, 10, 10, 10, 10, 10, 10, 6}, /* V */ |
| 38 { 130, 10, 75, 10, 10, 10, 10, 10, 10, 6}, /* H */ |
| 39 { 130, 15, 10, 75, 10, 10, 10, 10, 10, 6}, /* D45 */ |
| 40 { 150, 15, 10, 10, 75, 10, 10, 10, 10, 6}, /* D135 */ |
| 41 { 150, 15, 10, 10, 10, 75, 10, 10, 10, 6}, /* D117 */ |
| 42 { 150, 15, 10, 10, 10, 10, 75, 10, 10, 6}, /* D153 */ |
| 43 { 150, 15, 10, 10, 10, 10, 10, 75, 10, 6}, /* D27 */ |
| 44 { 150, 15, 10, 10, 10, 10, 10, 10, 75, 6}, /* D63 */ |
| 45 { 160, 30, 30, 10, 10, 10, 10, 10, 10, 16}, /* TM */ |
| 46 { 132, 46, 40, 10, 10, 10, 10, 10, 10, 18}, /* i8x8 - never used */ |
| 47 { 150, 35, 41, 10, 10, 10, 10, 10, 10, 10}, /* BPRED */ |
| 48 }; |
| 49 |
| 50 static const unsigned int i8x8_mode_cts [VP9_I8X8_MODES] = { |
| 51 /* DC V H D45 135 117 153 D27 D63 TM */ |
| 52 73, 49, 61, 30, 30, 30, 30, 30, 30, 13 |
| 53 }; |
| 54 |
| 55 static const unsigned int kf_uv_mode_cts [VP9_YMODES] [VP9_UV_MODES] = { |
| 56 // DC V H D45 135 117 153 D27 D63 TM |
| 57 { 160, 24, 24, 20, 20, 20, 20, 20, 20, 8}, /* DC */ |
| 58 { 102, 64, 30, 20, 20, 20, 20, 20, 20, 10}, /* V */ |
| 59 { 102, 30, 64, 20, 20, 20, 20, 20, 20, 10}, /* H */ |
| 60 { 102, 33, 20, 64, 20, 20, 20, 20, 20, 14}, /* D45 */ |
| 61 { 102, 33, 20, 20, 64, 20, 20, 20, 20, 14}, /* D135 */ |
| 62 { 122, 33, 20, 20, 20, 64, 20, 20, 20, 14}, /* D117 */ |
| 63 { 102, 33, 20, 20, 20, 20, 64, 20, 20, 14}, /* D153 */ |
| 64 { 102, 33, 20, 20, 20, 20, 20, 64, 20, 14}, /* D27 */ |
| 65 { 102, 33, 20, 20, 20, 20, 20, 20, 64, 14}, /* D63 */ |
| 66 { 132, 36, 30, 20, 20, 20, 20, 20, 20, 18}, /* TM */ |
| 67 { 122, 41, 35, 20, 20, 20, 20, 20, 20, 18}, /* i8x8 - never used */ |
| 68 { 122, 41, 35, 20, 20, 20, 20, 20, 20, 18}, /* BPRED */ |
| 69 }; |
| 70 |
| 71 static const unsigned int bmode_cts[VP9_NKF_BINTRAMODES] = { |
| 72 #if CONFIG_NEWBINTRAMODES |
| 73 #if CONTEXT_PRED_REPLACEMENTS == 6 |
| 74 /* DC TM VE HE CONTEXT */ |
| 75 43891, 17694, 10036, 3920, 20000 |
| 76 #elif CONTEXT_PRED_REPLACEMENTS == 4 |
| 77 /* DC TM VE HE LD RD CONTEXT */ |
| 78 43891, 17694, 10036, 3920, 3363, 2546, 14000 |
| 79 #elif CONTEXT_PRED_REPLACEMENTS == 0 |
| 80 /* DC TM VE HE LD RD VR VL HD HU CONTEXT */ |
| 81 43891, 17694, 10036, 3920, 3363, 2546, 5119, 3221, 2471, 1723, 50000 |
| 82 #endif |
| 83 #else |
| 84 /* DC TM VE HE LD RD VR VL HD HU */ |
| 85 43891, 17694, 10036, 3920, 3363, 2546, 5119, 3221, 2471, 1723 |
| 86 #endif |
| 87 }; |
| 88 |
| 89 typedef enum { |
| 90 SUBMVREF_NORMAL, |
| 91 SUBMVREF_LEFT_ZED, |
| 92 SUBMVREF_ABOVE_ZED, |
| 93 SUBMVREF_LEFT_ABOVE_SAME, |
| 94 SUBMVREF_LEFT_ABOVE_ZED |
| 95 } sumvfref_t; |
| 96 |
| 97 int vp9_mv_cont(const int_mv *l, const int_mv *a) { |
| 98 int lez = (l->as_int == 0); |
| 99 int aez = (a->as_int == 0); |
| 100 int lea = (l->as_int == a->as_int); |
| 101 |
| 102 if (lea && lez) |
| 103 return SUBMVREF_LEFT_ABOVE_ZED; |
| 104 |
| 105 if (lea) |
| 106 return SUBMVREF_LEFT_ABOVE_SAME; |
| 107 |
| 108 if (aez) |
| 109 return SUBMVREF_ABOVE_ZED; |
| 110 |
| 111 if (lez) |
| 112 return SUBMVREF_LEFT_ZED; |
| 113 |
| 114 return SUBMVREF_NORMAL; |
| 115 } |
| 116 |
| 117 const vp9_prob vp9_sub_mv_ref_prob [VP9_SUBMVREFS - 1] = { 180, 162, 25}; |
| 118 |
| 119 const vp9_prob vp9_sub_mv_ref_prob2 [SUBMVREF_COUNT][VP9_SUBMVREFS - 1] = { |
| 120 { 147, 136, 18 }, |
| 121 { 106, 145, 1 }, |
| 122 { 179, 121, 1 }, |
| 123 { 223, 1, 34 }, |
| 124 { 208, 1, 1 } |
| 125 }; |
| 126 |
| 127 vp9_mbsplit vp9_mbsplits [VP9_NUMMBSPLITS] = { |
| 128 { |
| 129 0, 0, 0, 0, |
| 130 0, 0, 0, 0, |
| 131 1, 1, 1, 1, |
| 132 1, 1, 1, 1, |
| 133 }, { |
| 134 0, 0, 1, 1, |
| 135 0, 0, 1, 1, |
| 136 0, 0, 1, 1, |
| 137 0, 0, 1, 1, |
| 138 }, { |
| 139 0, 0, 1, 1, |
| 140 0, 0, 1, 1, |
| 141 2, 2, 3, 3, |
| 142 2, 2, 3, 3, |
| 143 }, { |
| 144 0, 1, 2, 3, |
| 145 4, 5, 6, 7, |
| 146 8, 9, 10, 11, |
| 147 12, 13, 14, 15, |
| 148 }, |
| 149 }; |
| 150 |
| 151 const int vp9_mbsplit_count [VP9_NUMMBSPLITS] = { 2, 2, 4, 16}; |
| 152 |
| 153 const vp9_prob vp9_mbsplit_probs [VP9_NUMMBSPLITS - 1] = { 110, 111, 150}; |
| 154 |
| 155 /* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */ |
| 156 |
| 157 const vp9_tree_index vp9_kf_bmode_tree[VP9_KF_BINTRAMODES * 2 - 2] = { |
| 158 -B_DC_PRED, 2, /* 0 = DC_NODE */ |
| 159 -B_TM_PRED, 4, /* 1 = TM_NODE */ |
| 160 -B_VE_PRED, 6, /* 2 = VE_NODE */ |
| 161 8, 12, /* 3 = COM_NODE */ |
| 162 -B_HE_PRED, 10, /* 4 = HE_NODE */ |
| 163 -B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */ |
| 164 -B_LD_PRED, 14, /* 6 = LD_NODE */ |
| 165 -B_VL_PRED, 16, /* 7 = VL_NODE */ |
| 166 -B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */ |
| 167 }; |
| 168 |
| 169 const vp9_tree_index vp9_bmode_tree[VP9_NKF_BINTRAMODES * 2 - 2] = { |
| 170 #if CONFIG_NEWBINTRAMODES |
| 171 #if CONTEXT_PRED_REPLACEMENTS == 6 |
| 172 -B_DC_PRED, 2, |
| 173 -B_TM_PRED, 4, |
| 174 6, -(B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS), |
| 175 -B_VE_PRED, -B_HE_PRED |
| 176 #elif CONTEXT_PRED_REPLACEMENTS == 4 |
| 177 -B_DC_PRED, 2, |
| 178 -B_TM_PRED, 4, |
| 179 6, 8, |
| 180 -B_VE_PRED, -B_HE_PRED, |
| 181 10, -(B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS), |
| 182 -B_RD_PRED, -B_LD_PRED, |
| 183 #elif CONTEXT_PRED_REPLACEMENTS == 0 |
| 184 -B_DC_PRED, 2, /* 0 = DC_NODE */ |
| 185 -B_TM_PRED, 4, /* 1 = TM_NODE */ |
| 186 -B_VE_PRED, 6, /* 2 = VE_NODE */ |
| 187 8, 12, /* 3 = COM_NODE */ |
| 188 -B_HE_PRED, 10, /* 4 = HE_NODE */ |
| 189 -B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */ |
| 190 -B_LD_PRED, 14, /* 6 = LD_NODE */ |
| 191 -B_VL_PRED, 16, /* 7 = VL_NODE */ |
| 192 -B_HD_PRED, 18, |
| 193 -B_HU_PRED, -B_CONTEXT_PRED |
| 194 #endif |
| 195 #else |
| 196 -B_DC_PRED, 2, /* 0 = DC_NODE */ |
| 197 -B_TM_PRED, 4, /* 1 = TM_NODE */ |
| 198 -B_VE_PRED, 6, /* 2 = VE_NODE */ |
| 199 8, 12, /* 3 = COM_NODE */ |
| 200 -B_HE_PRED, 10, /* 4 = HE_NODE */ |
| 201 -B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */ |
| 202 -B_LD_PRED, 14, /* 6 = LD_NODE */ |
| 203 -B_VL_PRED, 16, /* 7 = VL_NODE */ |
| 204 -B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */ |
| 205 #endif |
| 206 }; |
| 207 |
| 208 /* Again, these trees use the same probability indices as their |
| 209 explicitly-programmed predecessors. */ |
| 210 const vp9_tree_index vp9_ymode_tree[VP9_YMODES * 2 - 2] = { |
| 211 2, 14, |
| 212 -DC_PRED, 4, |
| 213 6, 8, |
| 214 -D45_PRED, -D135_PRED, |
| 215 10, 12, |
| 216 -D117_PRED, -D153_PRED, |
| 217 -D27_PRED, -D63_PRED, |
| 218 16, 18, |
| 219 -V_PRED, -H_PRED, |
| 220 -TM_PRED, 20, |
| 221 -B_PRED, -I8X8_PRED |
| 222 }; |
| 223 |
| 224 const vp9_tree_index vp9_kf_ymode_tree[VP9_YMODES * 2 - 2] = { |
| 225 2, 14, |
| 226 -DC_PRED, 4, |
| 227 6, 8, |
| 228 -D45_PRED, -D135_PRED, |
| 229 10, 12, |
| 230 -D117_PRED, -D153_PRED, |
| 231 -D27_PRED, -D63_PRED, |
| 232 16, 18, |
| 233 -V_PRED, -H_PRED, |
| 234 -TM_PRED, 20, |
| 235 -B_PRED, -I8X8_PRED |
| 236 }; |
| 237 |
| 238 const vp9_tree_index vp9_i8x8_mode_tree[VP9_I8X8_MODES * 2 - 2] = { |
| 239 2, 14, |
| 240 -DC_PRED, 4, |
| 241 6, 8, |
| 242 -D45_PRED, -D135_PRED, |
| 243 10, 12, |
| 244 -D117_PRED, -D153_PRED, |
| 245 -D27_PRED, -D63_PRED, |
| 246 -V_PRED, 16, |
| 247 -H_PRED, -TM_PRED |
| 248 }; |
| 249 |
| 250 const vp9_tree_index vp9_uv_mode_tree[VP9_UV_MODES * 2 - 2] = { |
| 251 2, 14, |
| 252 -DC_PRED, 4, |
| 253 6, 8, |
| 254 -D45_PRED, -D135_PRED, |
| 255 10, 12, |
| 256 -D117_PRED, -D153_PRED, |
| 257 -D27_PRED, -D63_PRED, |
| 258 -V_PRED, 16, |
| 259 -H_PRED, -TM_PRED |
| 260 }; |
| 261 |
| 262 const vp9_tree_index vp9_mbsplit_tree[6] = { |
| 263 -PARTITIONING_4X4, 2, |
| 264 -PARTITIONING_8X8, 4, |
| 265 -PARTITIONING_16X8, -PARTITIONING_8X16, |
| 266 }; |
| 267 |
| 268 const vp9_tree_index vp9_mv_ref_tree[8] = { |
| 269 -ZEROMV, 2, |
| 270 -NEARESTMV, 4, |
| 271 -NEARMV, 6, |
| 272 -NEWMV, -SPLITMV |
| 273 }; |
| 274 |
| 275 #if CONFIG_SUPERBLOCKS |
| 276 const vp9_tree_index vp9_sb_mv_ref_tree[6] = { |
| 277 -ZEROMV, 2, |
| 278 -NEARESTMV, 4, |
| 279 -NEARMV, -NEWMV |
| 280 }; |
| 281 #endif |
| 282 |
| 283 const vp9_tree_index vp9_sub_mv_ref_tree[6] = { |
| 284 -LEFT4X4, 2, |
| 285 -ABOVE4X4, 4, |
| 286 -ZERO4X4, -NEW4X4 |
| 287 }; |
| 288 |
| 289 struct vp9_token_struct vp9_bmode_encodings[VP9_NKF_BINTRAMODES]; |
| 290 struct vp9_token_struct vp9_kf_bmode_encodings[VP9_KF_BINTRAMODES]; |
| 291 struct vp9_token_struct vp9_ymode_encodings[VP9_YMODES]; |
| 292 #if CONFIG_SUPERBLOCKS |
| 293 struct vp9_token_struct vp9_sb_ymode_encodings[VP9_I32X32_MODES]; |
| 294 struct vp9_token_struct vp9_sb_kf_ymode_encodings[VP9_I32X32_MODES]; |
| 295 #endif |
| 296 struct vp9_token_struct vp9_kf_ymode_encodings[VP9_YMODES]; |
| 297 struct vp9_token_struct vp9_uv_mode_encodings[VP9_UV_MODES]; |
| 298 struct vp9_token_struct vp9_i8x8_mode_encodings[VP9_I8X8_MODES]; |
| 299 struct vp9_token_struct vp9_mbsplit_encodings[VP9_NUMMBSPLITS]; |
| 300 |
| 301 struct vp9_token_struct vp9_mv_ref_encoding_array[VP9_MVREFS]; |
| 302 #if CONFIG_SUPERBLOCKS |
| 303 struct vp9_token_struct vp9_sb_mv_ref_encoding_array[VP9_MVREFS]; |
| 304 #endif |
| 305 struct vp9_token_struct vp9_sub_mv_ref_encoding_array[VP9_SUBMVREFS]; |
| 306 |
| 307 void vp9_init_mbmode_probs(VP9_COMMON *x) { |
| 308 unsigned int bct [VP9_YMODES] [2]; /* num Ymodes > num UV modes */ |
| 309 |
| 310 vp9_tree_probs_from_distribution(VP9_YMODES, vp9_ymode_encodings, |
| 311 vp9_ymode_tree, x->fc.ymode_prob, |
| 312 bct, y_mode_cts, 256, 1); |
| 313 #if CONFIG_SUPERBLOCKS |
| 314 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, vp9_sb_ymode_encodings, |
| 315 vp9_sb_ymode_tree, x->fc.sb_ymode_prob, |
| 316 bct, y_mode_cts, 256, 1); |
| 317 #endif |
| 318 { |
| 319 int i; |
| 320 for (i = 0; i < 8; i++) { |
| 321 vp9_tree_probs_from_distribution(VP9_YMODES, vp9_kf_ymode_encodings, |
| 322 vp9_kf_ymode_tree, x->kf_ymode_prob[i], |
| 323 bct, kf_y_mode_cts[i], 256, 1); |
| 324 #if CONFIG_SUPERBLOCKS |
| 325 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, |
| 326 vp9_sb_kf_ymode_encodings, |
| 327 vp9_sb_kf_ymode_tree, |
| 328 x->sb_kf_ymode_prob[i], bct, |
| 329 kf_y_mode_cts[i], 256, 1); |
| 330 #endif |
| 331 } |
| 332 } |
| 333 { |
| 334 int i; |
| 335 for (i = 0; i < VP9_YMODES; i++) { |
| 336 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, |
| 337 vp9_uv_mode_tree, x->kf_uv_mode_prob[i], |
| 338 bct, kf_uv_mode_cts[i], 256, 1); |
| 339 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, |
| 340 vp9_uv_mode_tree, x->fc.uv_mode_prob[i], |
| 341 bct, uv_mode_cts[i], 256, 1); |
| 342 } |
| 343 } |
| 344 |
| 345 vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings, |
| 346 vp9_i8x8_mode_tree, x->fc.i8x8_mode_prob, |
| 347 bct, i8x8_mode_cts, 256, 1); |
| 348 |
| 349 vpx_memcpy(x->fc.sub_mv_ref_prob, vp9_sub_mv_ref_prob2, |
| 350 sizeof(vp9_sub_mv_ref_prob2)); |
| 351 vpx_memcpy(x->fc.mbsplit_prob, vp9_mbsplit_probs, sizeof(vp9_mbsplit_probs)); |
| 352 vpx_memcpy(x->fc.switchable_interp_prob, vp9_switchable_interp_prob, |
| 353 sizeof(vp9_switchable_interp_prob)); |
| 354 #if CONFIG_COMP_INTERINTRA_PRED |
| 355 x->fc.interintra_prob = VP9_DEF_INTERINTRA_PROB; |
| 356 #endif |
| 357 } |
| 358 |
| 359 |
| 360 static void intra_bmode_probs_from_distribution( |
| 361 vp9_prob p[VP9_NKF_BINTRAMODES - 1], |
| 362 unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2], |
| 363 const unsigned int events[VP9_NKF_BINTRAMODES]) { |
| 364 vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, |
| 365 vp9_bmode_tree, p, branch_ct, events, 256, 1); |
| 366 } |
| 367 |
| 368 void vp9_default_bmode_probs(vp9_prob p[VP9_NKF_BINTRAMODES - 1]) { |
| 369 unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2]; |
| 370 intra_bmode_probs_from_distribution(p, branch_ct, bmode_cts); |
| 371 } |
| 372 |
| 373 static void intra_kf_bmode_probs_from_distribution( |
| 374 vp9_prob p[VP9_KF_BINTRAMODES - 1], |
| 375 unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2], |
| 376 const unsigned int events[VP9_KF_BINTRAMODES]) { |
| 377 vp9_tree_probs_from_distribution(VP9_KF_BINTRAMODES, vp9_kf_bmode_encodings, |
| 378 vp9_kf_bmode_tree, p, branch_ct, events, 256, 1); |
| 379 } |
| 380 |
| 381 void vp9_kf_default_bmode_probs(vp9_prob p[VP9_KF_BINTRAMODES] |
| 382 [VP9_KF_BINTRAMODES] |
| 383 [VP9_KF_BINTRAMODES - 1]) { |
| 384 unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2]; |
| 385 int i, j; |
| 386 |
| 387 for (i = 0; i < VP9_KF_BINTRAMODES; ++i) { |
| 388 for (j = 0; j < VP9_KF_BINTRAMODES; ++j) { |
| 389 intra_kf_bmode_probs_from_distribution( |
| 390 p[i][j], branch_ct, vp9_kf_default_bmode_counts[i][j]); |
| 391 } |
| 392 } |
| 393 } |
| 394 |
| 395 #if VP9_SWITCHABLE_FILTERS == 3 |
| 396 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = { |
| 397 -0, 2, |
| 398 -1, -2 |
| 399 }; |
| 400 struct vp9_token_struct vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS]; |
| 401 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = { |
| 402 EIGHTTAP, SIXTAP, EIGHTTAP_SHARP}; |
| 403 const int vp9_switchable_interp_map[SWITCHABLE+1] = {1, -1, 0, 2, -1}; |
| 404 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1] |
| 405 [VP9_SWITCHABLE_FILTERS-1] = { |
| 406 {248, 192}, { 32, 248}, { 32, 32}, {192, 160} |
| 407 }; |
| 408 #elif VP9_SWITCHABLE_FILTERS == 2 |
| 409 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = { |
| 410 -0, -1, |
| 411 }; |
| 412 struct vp9_token_struct vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS]; |
| 413 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1] |
| 414 [VP9_SWITCHABLE_FILTERS-1] = { |
| 415 {248}, |
| 416 { 64}, |
| 417 {192}, |
| 418 }; |
| 419 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = { |
| 420 EIGHTTAP, EIGHTTAP_SHARP}; |
| 421 const int vp9_switchable_interp_map[SWITCHABLE+1] = {-1, -1, 0, 1, -1}; //8, 8s |
| 422 #endif |
| 423 |
| 424 void vp9_entropy_mode_init() { |
| 425 vp9_tokens_from_tree(vp9_kf_bmode_encodings, vp9_kf_bmode_tree); |
| 426 vp9_tokens_from_tree(vp9_bmode_encodings, vp9_bmode_tree); |
| 427 vp9_tokens_from_tree(vp9_ymode_encodings, vp9_ymode_tree); |
| 428 vp9_tokens_from_tree(vp9_kf_ymode_encodings, vp9_kf_ymode_tree); |
| 429 #if CONFIG_SUPERBLOCKS |
| 430 vp9_tokens_from_tree(vp9_sb_ymode_encodings, vp9_sb_ymode_tree); |
| 431 vp9_tokens_from_tree(vp9_sb_kf_ymode_encodings, vp9_sb_kf_ymode_tree); |
| 432 #endif |
| 433 vp9_tokens_from_tree(vp9_uv_mode_encodings, vp9_uv_mode_tree); |
| 434 vp9_tokens_from_tree(vp9_i8x8_mode_encodings, vp9_i8x8_mode_tree); |
| 435 vp9_tokens_from_tree(vp9_mbsplit_encodings, vp9_mbsplit_tree); |
| 436 vp9_tokens_from_tree(vp9_switchable_interp_encodings, |
| 437 vp9_switchable_interp_tree); |
| 438 |
| 439 vp9_tokens_from_tree_offset(vp9_mv_ref_encoding_array, |
| 440 vp9_mv_ref_tree, NEARESTMV); |
| 441 #if CONFIG_SUPERBLOCKS |
| 442 vp9_tokens_from_tree_offset(vp9_sb_mv_ref_encoding_array, |
| 443 vp9_sb_mv_ref_tree, NEARESTMV); |
| 444 #endif |
| 445 vp9_tokens_from_tree_offset(vp9_sub_mv_ref_encoding_array, |
| 446 vp9_sub_mv_ref_tree, LEFT4X4); |
| 447 } |
| 448 |
| 449 void vp9_init_mode_contexts(VP9_COMMON *pc) { |
| 450 vpx_memset(pc->fc.mv_ref_ct, 0, sizeof(pc->fc.mv_ref_ct)); |
| 451 vpx_memcpy(pc->fc.vp9_mode_contexts, |
| 452 vp9_default_mode_contexts, |
| 453 sizeof(vp9_default_mode_contexts)); |
| 454 } |
| 455 |
| 456 void vp9_accum_mv_refs(VP9_COMMON *pc, |
| 457 MB_PREDICTION_MODE m, |
| 458 const int context) { |
| 459 unsigned int (*mv_ref_ct)[4][2]; |
| 460 |
| 461 mv_ref_ct = pc->fc.mv_ref_ct; |
| 462 |
| 463 if (m == ZEROMV) { |
| 464 ++mv_ref_ct[context][0][0]; |
| 465 } else { |
| 466 ++mv_ref_ct[context][0][1]; |
| 467 if (m == NEARESTMV) { |
| 468 ++mv_ref_ct[context][1][0]; |
| 469 } else { |
| 470 ++mv_ref_ct[context][1][1]; |
| 471 if (m == NEARMV) { |
| 472 ++mv_ref_ct[context][2][0]; |
| 473 } else { |
| 474 ++mv_ref_ct[context][2][1]; |
| 475 if (m == NEWMV) { |
| 476 ++mv_ref_ct[context][3][0]; |
| 477 } else { |
| 478 ++mv_ref_ct[context][3][1]; |
| 479 } |
| 480 } |
| 481 } |
| 482 } |
| 483 } |
| 484 |
| 485 #define MVREF_COUNT_SAT 20 |
| 486 #define MVREF_MAX_UPDATE_FACTOR 128 |
| 487 void vp9_update_mode_context(VP9_COMMON *pc) { |
| 488 int i, j; |
| 489 unsigned int (*mv_ref_ct)[4][2]; |
| 490 int (*mode_context)[4]; |
| 491 |
| 492 mode_context = pc->fc.vp9_mode_contexts; |
| 493 |
| 494 mv_ref_ct = pc->fc.mv_ref_ct; |
| 495 |
| 496 for (j = 0; j < INTER_MODE_CONTEXTS; j++) { |
| 497 for (i = 0; i < 4; i++) { |
| 498 int this_prob; |
| 499 int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1]; |
| 500 int factor; |
| 501 { |
| 502 this_prob = count > 0 ? 256 * mv_ref_ct[j][i][0] / count : 128; |
| 503 count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count; |
| 504 factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT); |
| 505 this_prob = (pc->fc.vp9_mode_contexts[j][i] * (256 - factor) + |
| 506 this_prob * factor + 128) >> 8; |
| 507 mode_context[j][i] = clip_prob(this_prob); |
| 508 } |
| 509 } |
| 510 } |
| 511 } |
| 512 |
| 513 #ifdef MODE_STATS |
| 514 #include "vp9/common/vp9_modecont.h" |
| 515 void print_mode_contexts(VP9_COMMON *pc) { |
| 516 int j, i; |
| 517 printf("\n====================\n"); |
| 518 for (j = 0; j < INTER_MODE_CONTEXTS; j++) { |
| 519 for (i = 0; i < 4; i++) { |
| 520 printf("%4d ", pc->fc.mode_context[j][i]); |
| 521 } |
| 522 printf("\n"); |
| 523 } |
| 524 printf("====================\n"); |
| 525 for (j = 0; j < INTER_MODE_CONTEXTS; j++) { |
| 526 for (i = 0; i < 4; i++) { |
| 527 printf("%4d ", pc->fc.mode_context_a[j][i]); |
| 528 } |
| 529 printf("\n"); |
| 530 } |
| 531 } |
| 532 #endif |
| 533 |
| 534 // #define MODE_COUNT_TESTING |
| 535 #define MODE_COUNT_SAT 20 |
| 536 #define MODE_MAX_UPDATE_FACTOR 144 |
| 537 void vp9_adapt_mode_probs(VP9_COMMON *cm) { |
| 538 int i, t, count, factor; |
| 539 unsigned int branch_ct[32][2]; |
| 540 vp9_prob ymode_probs[VP9_YMODES - 1]; |
| 541 #if CONFIG_SUPERBLOCKS |
| 542 vp9_prob sb_ymode_probs[VP9_I32X32_MODES - 1]; |
| 543 #endif |
| 544 vp9_prob uvmode_probs[VP9_UV_MODES - 1]; |
| 545 vp9_prob bmode_probs[VP9_NKF_BINTRAMODES - 1]; |
| 546 vp9_prob i8x8_mode_probs[VP9_I8X8_MODES - 1]; |
| 547 vp9_prob sub_mv_ref_probs[VP9_SUBMVREFS - 1]; |
| 548 vp9_prob mbsplit_probs[VP9_NUMMBSPLITS - 1]; |
| 549 #if CONFIG_COMP_INTERINTRA_PRED |
| 550 vp9_prob interintra_prob; |
| 551 #endif |
| 552 #ifdef MODE_COUNT_TESTING |
| 553 printf("static const unsigned int\nymode_counts" |
| 554 "[VP9_YMODES] = {\n"); |
| 555 for (t = 0; t < VP9_YMODES; ++t) printf("%d, ", cm->fc.ymode_counts[t]); |
| 556 printf("};\n"); |
| 557 printf("static const unsigned int\nuv_mode_counts" |
| 558 "[VP9_YMODES] [VP9_UV_MODES] = {\n"); |
| 559 for (i = 0; i < VP9_YMODES; ++i) { |
| 560 printf(" {"); |
| 561 for (t = 0; t < VP9_UV_MODES; ++t) printf("%d, ", cm->fc.uv_mode_counts[i][t
]); |
| 562 printf("},\n"); |
| 563 } |
| 564 printf("};\n"); |
| 565 printf("static const unsigned int\nbmode_counts" |
| 566 "[VP9_NKF_BINTRAMODES] = {\n"); |
| 567 for (t = 0; t < VP9_NKF_BINTRAMODES; ++t) |
| 568 printf("%d, ", cm->fc.bmode_counts[t]); |
| 569 printf("};\n"); |
| 570 printf("static const unsigned int\ni8x8_mode_counts" |
| 571 "[VP9_I8X8_MODES] = {\n"); |
| 572 for (t = 0; t < VP9_I8X8_MODES; ++t) printf("%d, ", cm->fc.i8x8_mode_counts[t]
); |
| 573 printf("};\n"); |
| 574 printf("static const unsigned int\nsub_mv_ref_counts" |
| 575 "[SUBMVREF_COUNT] [VP9_SUBMVREFS] = {\n"); |
| 576 for (i = 0; i < SUBMVREF_COUNT; ++i) { |
| 577 printf(" {"); |
| 578 for (t = 0; t < VP9_SUBMVREFS; ++t) printf("%d, ", cm->fc.sub_mv_ref_counts[
i][t]); |
| 579 printf("},\n"); |
| 580 } |
| 581 printf("};\n"); |
| 582 printf("static const unsigned int\nmbsplit_counts" |
| 583 "[VP9_NUMMBSPLITS] = {\n"); |
| 584 for (t = 0; t < VP9_NUMMBSPLITS; ++t) printf("%d, ", cm->fc.mbsplit_counts[t])
; |
| 585 printf("};\n"); |
| 586 #if CONFIG_COMP_INTERINTRA_PRED |
| 587 printf("static const unsigned int\ninterintra_counts" |
| 588 "[2] = {\n"); |
| 589 for (t = 0; t < 2; ++t) printf("%d, ", cm->fc.interintra_counts[t]); |
| 590 printf("};\n"); |
| 591 #endif |
| 592 #endif |
| 593 vp9_tree_probs_from_distribution( |
| 594 VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree, |
| 595 ymode_probs, branch_ct, cm->fc.ymode_counts, |
| 596 256, 1); |
| 597 for (t = 0; t < VP9_YMODES - 1; ++t) { |
| 598 int prob; |
| 599 count = branch_ct[t][0] + branch_ct[t][1]; |
| 600 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 601 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 602 prob = ((int)cm->fc.pre_ymode_prob[t] * (256 - factor) + |
| 603 (int)ymode_probs[t] * factor + 128) >> 8; |
| 604 cm->fc.ymode_prob[t] = clip_prob(prob); |
| 605 } |
| 606 #if CONFIG_SUPERBLOCKS |
| 607 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, |
| 608 vp9_sb_ymode_encodings, vp9_sb_ymode_tree, |
| 609 sb_ymode_probs, branch_ct, |
| 610 cm->fc.sb_ymode_counts, |
| 611 256, 1); |
| 612 for (t = 0; t < VP9_I32X32_MODES - 1; ++t) { |
| 613 int prob; |
| 614 count = branch_ct[t][0] + branch_ct[t][1]; |
| 615 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 616 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 617 prob = ((int)cm->fc.pre_sb_ymode_prob[t] * (256 - factor) + |
| 618 (int)sb_ymode_probs[t] * factor + 128) >> 8; |
| 619 cm->fc.sb_ymode_prob[t] = clip_prob(prob); |
| 620 } |
| 621 #endif |
| 622 for (i = 0; i < VP9_YMODES; ++i) { |
| 623 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, |
| 624 vp9_uv_mode_tree, uvmode_probs, branch_ct, |
| 625 cm->fc.uv_mode_counts[i], 256, 1); |
| 626 for (t = 0; t < VP9_UV_MODES - 1; ++t) { |
| 627 int prob; |
| 628 count = branch_ct[t][0] + branch_ct[t][1]; |
| 629 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 630 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 631 prob = ((int)cm->fc.pre_uv_mode_prob[i][t] * (256 - factor) + |
| 632 (int)uvmode_probs[t] * factor + 128) >> 8; |
| 633 cm->fc.uv_mode_prob[i][t] = clip_prob(prob); |
| 634 } |
| 635 } |
| 636 vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, |
| 637 vp9_bmode_tree, bmode_probs, branch_ct, |
| 638 cm->fc.bmode_counts, 256, 1); |
| 639 for (t = 0; t < VP9_NKF_BINTRAMODES - 1; ++t) { |
| 640 int prob; |
| 641 count = branch_ct[t][0] + branch_ct[t][1]; |
| 642 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 643 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 644 prob = ((int)cm->fc.pre_bmode_prob[t] * (256 - factor) + |
| 645 (int)bmode_probs[t] * factor + 128) >> 8; |
| 646 cm->fc.bmode_prob[t] = clip_prob(prob); |
| 647 } |
| 648 vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings, |
| 649 vp9_i8x8_mode_tree, i8x8_mode_probs, |
| 650 branch_ct, cm->fc.i8x8_mode_counts, 256, 1); |
| 651 for (t = 0; t < VP9_I8X8_MODES - 1; ++t) { |
| 652 int prob; |
| 653 count = branch_ct[t][0] + branch_ct[t][1]; |
| 654 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 655 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 656 prob = ((int)cm->fc.pre_i8x8_mode_prob[t] * (256 - factor) + |
| 657 (int)i8x8_mode_probs[t] * factor + 128) >> 8; |
| 658 cm->fc.i8x8_mode_prob[t] = clip_prob(prob); |
| 659 } |
| 660 for (i = 0; i < SUBMVREF_COUNT; ++i) { |
| 661 vp9_tree_probs_from_distribution(VP9_SUBMVREFS, |
| 662 vp9_sub_mv_ref_encoding_array, |
| 663 vp9_sub_mv_ref_tree, sub_mv_ref_probs, |
| 664 branch_ct, cm->fc.sub_mv_ref_counts[i], |
| 665 256, 1); |
| 666 for (t = 0; t < VP9_SUBMVREFS - 1; ++t) { |
| 667 int prob; |
| 668 count = branch_ct[t][0] + branch_ct[t][1]; |
| 669 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 670 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 671 prob = ((int)cm->fc.pre_sub_mv_ref_prob[i][t] * (256 - factor) + |
| 672 (int)sub_mv_ref_probs[t] * factor + 128) >> 8; |
| 673 cm->fc.sub_mv_ref_prob[i][t] = clip_prob(prob); |
| 674 } |
| 675 } |
| 676 vp9_tree_probs_from_distribution(VP9_NUMMBSPLITS, vp9_mbsplit_encodings, |
| 677 vp9_mbsplit_tree, mbsplit_probs, branch_ct, |
| 678 cm->fc.mbsplit_counts, 256, 1); |
| 679 for (t = 0; t < VP9_NUMMBSPLITS - 1; ++t) { |
| 680 int prob; |
| 681 count = branch_ct[t][0] + branch_ct[t][1]; |
| 682 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 683 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 684 prob = ((int)cm->fc.pre_mbsplit_prob[t] * (256 - factor) + |
| 685 (int)mbsplit_probs[t] * factor + 128) >> 8; |
| 686 cm->fc.mbsplit_prob[t] = clip_prob(prob); |
| 687 } |
| 688 #if CONFIG_COMP_INTERINTRA_PRED |
| 689 if (cm->use_interintra) { |
| 690 int prob; |
| 691 interintra_prob = vp9_bin_prob_from_distribution(cm->fc.interintra_counts); |
| 692 count = cm->fc.interintra_counts[0] + cm->fc.interintra_counts[1]; |
| 693 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; |
| 694 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); |
| 695 prob = ((int)cm->fc.pre_interintra_prob * (256 - factor) + |
| 696 (int)interintra_prob * factor + 128) >> 8; |
| 697 if (prob <= 0) |
| 698 cm->fc.interintra_prob = 1; |
| 699 else if (prob > 255) |
| 700 cm->fc.interintra_prob = 255; |
| 701 else |
| 702 cm->fc.interintra_prob = prob; |
| 703 } |
| 704 #endif |
| 705 } |
OLD | NEW |