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.
12 #include "entropymode.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
32 SUBMVREF_LEFT_ABOVE_SAME
,
33 SUBMVREF_LEFT_ABOVE_ZED
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
);
43 return SUBMVREF_LEFT_ABOVE_ZED
;
46 return SUBMVREF_LEFT_ABOVE_SAME
;
49 return SUBMVREF_ABOVE_ZED
;
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] =
70 vp8_mbsplit vp8_mbsplits
[VP8_NUMMBSPLITS
] =
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] =
129 const vp8_tree_index vp8_kf_ymode_tree
[8] =
137 const vp8_tree_index vp8_uv_mode_tree
[6] =
144 const vp8_tree_index vp8_mbsplit_tree
[6] =
151 const vp8_tree_index vp8_mv_ref_tree
[8] =
159 const vp8_tree_index vp8_sub_mv_ref_tree
[6] =
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] =
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
,
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
,
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
,
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
,
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
,
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];
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
);