Merge "vp8_rd_pick_best_mbsegmentation code restructure"
[libvpx.git] / vp8 / common / entropymode.c
blobe9dc668b2c9b42dda41f33a98fe4898c27ebab51
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
12 #include "entropymode.h"
13 #include "entropy.h"
14 #include "vpx_mem/vpx_mem.h"
16 static const unsigned int kf_y_mode_cts[VP8_YMODES] = { 1607, 915, 812, 811, 5455};
17 static const unsigned int y_mode_cts [VP8_YMODES] = { 8080, 1908, 1582, 1007, 5874};
19 static const unsigned int uv_mode_cts [VP8_UV_MODES] = { 59483, 13605, 16492, 4230};
20 static const unsigned int kf_uv_mode_cts[VP8_UV_MODES] = { 5319, 1904, 1703, 674};
22 static const unsigned int bmode_cts[VP8_BINTRAMODES] =
24 43891, 17694, 10036, 3920, 3363, 2546, 5119, 3221, 2471, 1723
27 typedef enum
29 SUBMVREF_NORMAL,
30 SUBMVREF_LEFT_ZED,
31 SUBMVREF_ABOVE_ZED,
32 SUBMVREF_LEFT_ABOVE_SAME,
33 SUBMVREF_LEFT_ABOVE_ZED
34 } sumvfref_t;
36 int vp8_mv_cont(const MV *l, const MV *a)
38 int lez = (l->row == 0 && l->col == 0);
39 int aez = (a->row == 0 && a->col == 0);
40 int lea = (l->row == a->row && l->col == a->col);
42 if (lea && lez)
43 return SUBMVREF_LEFT_ABOVE_ZED;
45 if (lea)
46 return SUBMVREF_LEFT_ABOVE_SAME;
48 if (aez)
49 return SUBMVREF_ABOVE_ZED;
51 if (lez)
52 return SUBMVREF_LEFT_ZED;
54 return SUBMVREF_NORMAL;
57 static const vp8_prob sub_mv_ref_prob [VP8_SUBMVREFS-1] = { 180, 162, 25};
59 const vp8_prob vp8_sub_mv_ref_prob2 [SUBMVREF_COUNT][VP8_SUBMVREFS-1] =
61 { 147, 136, 18 },
62 { 106, 145, 1 },
63 { 179, 121, 1 },
64 { 223, 1 , 34 },
65 { 208, 1 , 1 }
70 vp8_mbsplit vp8_mbsplits [VP8_NUMMBSPLITS] =
73 0, 0, 0, 0,
74 0, 0, 0, 0,
75 1, 1, 1, 1,
76 1, 1, 1, 1,
79 0, 0, 1, 1,
80 0, 0, 1, 1,
81 0, 0, 1, 1,
82 0, 0, 1, 1,
85 0, 0, 1, 1,
86 0, 0, 1, 1,
87 2, 2, 3, 3,
88 2, 2, 3, 3,
91 0, 1, 2, 3,
92 4, 5, 6, 7,
93 8, 9, 10, 11,
94 12, 13, 14, 15,
98 const int vp8_mbsplit_count [VP8_NUMMBSPLITS] = { 2, 2, 4, 16};
100 const vp8_prob vp8_mbsplit_probs [VP8_NUMMBSPLITS-1] = { 110, 111, 150};
103 /* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
105 const vp8_tree_index vp8_bmode_tree[18] = /* INTRAMODECONTEXTNODE value */
107 -B_DC_PRED, 2, /* 0 = DC_NODE */
108 -B_TM_PRED, 4, /* 1 = TM_NODE */
109 -B_VE_PRED, 6, /* 2 = VE_NODE */
110 8, 12, /* 3 = COM_NODE */
111 -B_HE_PRED, 10, /* 4 = HE_NODE */
112 -B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
113 -B_LD_PRED, 14, /* 6 = LD_NODE */
114 -B_VL_PRED, 16, /* 7 = VL_NODE */
115 -B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */
118 /* Again, these trees use the same probability indices as their
119 explicitly-programmed predecessors. */
121 const vp8_tree_index vp8_ymode_tree[8] =
123 -DC_PRED, 2,
124 4, 6,
125 -V_PRED, -H_PRED,
126 -TM_PRED, -B_PRED
129 const vp8_tree_index vp8_kf_ymode_tree[8] =
131 -B_PRED, 2,
132 4, 6,
133 -DC_PRED, -V_PRED,
134 -H_PRED, -TM_PRED
137 const vp8_tree_index vp8_uv_mode_tree[6] =
139 -DC_PRED, 2,
140 -V_PRED, 4,
141 -H_PRED, -TM_PRED
144 const vp8_tree_index vp8_mbsplit_tree[6] =
146 -3, 2,
147 -2, 4,
148 -0, -1
151 const vp8_tree_index vp8_mv_ref_tree[8] =
153 -ZEROMV, 2,
154 -NEARESTMV, 4,
155 -NEARMV, 6,
156 -NEWMV, -SPLITMV
159 const vp8_tree_index vp8_sub_mv_ref_tree[6] =
161 -LEFT4X4, 2,
162 -ABOVE4X4, 4,
163 -ZERO4X4, -NEW4X4
167 struct vp8_token_struct vp8_bmode_encodings [VP8_BINTRAMODES];
168 struct vp8_token_struct vp8_ymode_encodings [VP8_YMODES];
169 struct vp8_token_struct vp8_kf_ymode_encodings [VP8_YMODES];
170 struct vp8_token_struct vp8_uv_mode_encodings [VP8_UV_MODES];
171 struct vp8_token_struct vp8_mbsplit_encodings [VP8_NUMMBSPLITS];
173 struct vp8_token_struct vp8_mv_ref_encoding_array [VP8_MVREFS];
174 struct vp8_token_struct vp8_sub_mv_ref_encoding_array [VP8_SUBMVREFS];
177 const vp8_tree_index vp8_small_mvtree [14] =
179 2, 8,
180 4, 6,
181 -0, -1,
182 -2, -3,
183 10, 12,
184 -4, -5,
185 -6, -7
188 struct vp8_token_struct vp8_small_mvencodings [8];
190 void vp8_init_mbmode_probs(VP8_COMMON *x)
192 unsigned int bct [VP8_YMODES] [2]; /* num Ymodes > num UV modes */
194 vp8_tree_probs_from_distribution(
195 VP8_YMODES, vp8_ymode_encodings, vp8_ymode_tree,
196 x->fc.ymode_prob, bct, y_mode_cts,
197 256, 1
199 vp8_tree_probs_from_distribution(
200 VP8_YMODES, vp8_kf_ymode_encodings, vp8_kf_ymode_tree,
201 x->kf_ymode_prob, bct, kf_y_mode_cts,
202 256, 1
204 vp8_tree_probs_from_distribution(
205 VP8_UV_MODES, vp8_uv_mode_encodings, vp8_uv_mode_tree,
206 x->fc.uv_mode_prob, bct, uv_mode_cts,
207 256, 1
209 vp8_tree_probs_from_distribution(
210 VP8_UV_MODES, vp8_uv_mode_encodings, vp8_uv_mode_tree,
211 x->kf_uv_mode_prob, bct, kf_uv_mode_cts,
212 256, 1
214 vpx_memcpy(x->fc.sub_mv_ref_prob, sub_mv_ref_prob, sizeof(sub_mv_ref_prob));
218 static void intra_bmode_probs_from_distribution(
219 vp8_prob p [VP8_BINTRAMODES-1],
220 unsigned int branch_ct [VP8_BINTRAMODES-1] [2],
221 const unsigned int events [VP8_BINTRAMODES]
224 vp8_tree_probs_from_distribution(
225 VP8_BINTRAMODES, vp8_bmode_encodings, vp8_bmode_tree,
226 p, branch_ct, events,
227 256, 1
231 void vp8_default_bmode_probs(vp8_prob p [VP8_BINTRAMODES-1])
233 unsigned int branch_ct [VP8_BINTRAMODES-1] [2];
234 intra_bmode_probs_from_distribution(p, branch_ct, bmode_cts);
237 void vp8_kf_default_bmode_probs(vp8_prob p [VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES-1])
239 unsigned int branch_ct [VP8_BINTRAMODES-1] [2];
241 int i = 0;
245 int j = 0;
249 intra_bmode_probs_from_distribution(
250 p[i][j], branch_ct, vp8_kf_default_bmode_counts[i][j]);
253 while (++j < VP8_BINTRAMODES);
255 while (++i < VP8_BINTRAMODES);
259 void vp8_entropy_mode_init()
261 vp8_tokens_from_tree(vp8_bmode_encodings, vp8_bmode_tree);
262 vp8_tokens_from_tree(vp8_ymode_encodings, vp8_ymode_tree);
263 vp8_tokens_from_tree(vp8_kf_ymode_encodings, vp8_kf_ymode_tree);
264 vp8_tokens_from_tree(vp8_uv_mode_encodings, vp8_uv_mode_tree);
265 vp8_tokens_from_tree(vp8_mbsplit_encodings, vp8_mbsplit_tree);
267 vp8_tokens_from_tree_offset(vp8_mv_ref_encoding_array,
268 vp8_mv_ref_tree, NEARESTMV);
269 vp8_tokens_from_tree_offset(vp8_sub_mv_ref_encoding_array,
270 vp8_sub_mv_ref_tree, LEFT4X4);
272 vp8_tokens_from_tree(vp8_small_mvencodings, vp8_small_mvtree);