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 #include "vp9/common/vp9_entropy.h"
12 #include "vp9/common/vp9_blockd.h"
13 #include "vp9/common/vp9_onyxc_int.h"
14 #include "vp9/common/vp9_entropymode.h"
15 #include "vpx_mem/vpx_mem.h"
16 #include "vpx/vpx_integer.h"
17 
18 // Unconstrained Node Tree
19 const vpx_tree_index vp9_coef_con_tree[TREE_SIZE(ENTROPY_TOKENS)] = {
20   2, 6,                                // 0 = LOW_VAL
21   -TWO_TOKEN, 4,                       // 1 = TWO
22   -THREE_TOKEN, -FOUR_TOKEN,           // 2 = THREE
23   8, 10,                               // 3 = HIGH_LOW
24   -CATEGORY1_TOKEN, -CATEGORY2_TOKEN,  // 4 = CAT_ONE
25   12, 14,                              // 5 = CAT_THREEFOUR
26   -CATEGORY3_TOKEN, -CATEGORY4_TOKEN,  // 6 = CAT_THREE
27   -CATEGORY5_TOKEN, -CATEGORY6_TOKEN   // 7 = CAT_FIVE
28 };
29 
30 const vpx_prob vp9_cat1_prob[] = { 159 };
31 const vpx_prob vp9_cat2_prob[] = { 165, 145 };
32 const vpx_prob vp9_cat3_prob[] = { 173, 148, 140 };
33 const vpx_prob vp9_cat4_prob[] = { 176, 155, 140, 135 };
34 const vpx_prob vp9_cat5_prob[] = { 180, 157, 141, 134, 130 };
35 const vpx_prob vp9_cat6_prob[] = {
36     254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129
37 };
38 #if CONFIG_VP9_HIGHBITDEPTH
39 const vpx_prob vp9_cat1_prob_high10[] = { 159 };
40 const vpx_prob vp9_cat2_prob_high10[] = { 165, 145 };
41 const vpx_prob vp9_cat3_prob_high10[] = { 173, 148, 140 };
42 const vpx_prob vp9_cat4_prob_high10[] = { 176, 155, 140, 135 };
43 const vpx_prob vp9_cat5_prob_high10[] = { 180, 157, 141, 134, 130 };
44 const vpx_prob vp9_cat6_prob_high10[] = {
45     255, 255, 254, 254, 254, 252, 249, 243,
46     230, 196, 177, 153, 140, 133, 130, 129
47 };
48 const vpx_prob vp9_cat1_prob_high12[] = { 159 };
49 const vpx_prob vp9_cat2_prob_high12[] = { 165, 145 };
50 const vpx_prob vp9_cat3_prob_high12[] = { 173, 148, 140 };
51 const vpx_prob vp9_cat4_prob_high12[] = { 176, 155, 140, 135 };
52 const vpx_prob vp9_cat5_prob_high12[] = { 180, 157, 141, 134, 130 };
53 const vpx_prob vp9_cat6_prob_high12[] = {
54     255, 255, 255, 255, 254, 254, 254, 252, 249,
55     243, 230, 196, 177, 153, 140, 133, 130, 129
56 };
57 #endif
58 
59 const uint8_t vp9_coefband_trans_8x8plus[1024] = {
60   0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
61   4, 4, 4, 4, 4, 5,
62   // beyond MAXBAND_INDEX+1 all values are filled as 5
63                     5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
64   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
65   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
66   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
67   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
68   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
69   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
70   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
71   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
72   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
73   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
74   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
75   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
76   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
77   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
78   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
79   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
80   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
81   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
82   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
83   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
84   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
85   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
86   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
87   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
88   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
89   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
90   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
91   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
92   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
93   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
94   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
95   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
96   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
97   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
98   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
99   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
100   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
101   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
102   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
103   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
104   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
105   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
106   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
107   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
108   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
109   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
110   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
111   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
112   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
113   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
114   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
115   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
116   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
117   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
118   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
119   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
120   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
121   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
122   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
123   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
124   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
125   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
126 };
127 
128 const uint8_t vp9_coefband_trans_4x4[16] = {
129   0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5,
130 };
131 
132 const uint8_t vp9_pt_energy_class[ENTROPY_TOKENS] = {
133   0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5
134 };
135 
136 // Model obtained from a 2-sided zero-centerd distribuition derived
137 // from a Pareto distribution. The cdf of the distribution is:
138 // cdf(x) = 0.5 + 0.5 * sgn(x) * [1 - {alpha/(alpha + |x|)} ^ beta]
139 //
140 // For a given beta and a given probablity of the 1-node, the alpha
141 // is first solved, and then the {alpha, beta} pair is used to generate
142 // the probabilities for the rest of the nodes.
143 
144 // beta = 8
145 
146 // Every odd line in this table can be generated from the even lines
147 // by averaging :
148 // vp9_pareto8_full[l][node] = (vp9_pareto8_full[l-1][node] +
149 //                              vp9_pareto8_full[l+1][node] ) >> 1;
150 const vpx_prob vp9_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES] = {
151   {  3,  86, 128,   6,  86,  23,  88,  29},
152   {  6,  86, 128,  11,  87,  42,  91,  52},
153   {  9,  86, 129,  17,  88,  61,  94,  76},
154   { 12,  86, 129,  22,  88,  77,  97,  93},
155   { 15,  87, 129,  28,  89,  93, 100, 110},
156   { 17,  87, 129,  33,  90, 105, 103, 123},
157   { 20,  88, 130,  38,  91, 118, 106, 136},
158   { 23,  88, 130,  43,  91, 128, 108, 146},
159   { 26,  89, 131,  48,  92, 139, 111, 156},
160   { 28,  89, 131,  53,  93, 147, 114, 163},
161   { 31,  90, 131,  58,  94, 156, 117, 171},
162   { 34,  90, 131,  62,  94, 163, 119, 177},
163   { 37,  90, 132,  66,  95, 171, 122, 184},
164   { 39,  90, 132,  70,  96, 177, 124, 189},
165   { 42,  91, 132,  75,  97, 183, 127, 194},
166   { 44,  91, 132,  79,  97, 188, 129, 198},
167   { 47,  92, 133,  83,  98, 193, 132, 202},
168   { 49,  92, 133,  86,  99, 197, 134, 205},
169   { 52,  93, 133,  90, 100, 201, 137, 208},
170   { 54,  93, 133,  94, 100, 204, 139, 211},
171   { 57,  94, 134,  98, 101, 208, 142, 214},
172   { 59,  94, 134, 101, 102, 211, 144, 216},
173   { 62,  94, 135, 105, 103, 214, 146, 218},
174   { 64,  94, 135, 108, 103, 216, 148, 220},
175   { 66,  95, 135, 111, 104, 219, 151, 222},
176   { 68,  95, 135, 114, 105, 221, 153, 223},
177   { 71,  96, 136, 117, 106, 224, 155, 225},
178   { 73,  96, 136, 120, 106, 225, 157, 226},
179   { 76,  97, 136, 123, 107, 227, 159, 228},
180   { 78,  97, 136, 126, 108, 229, 160, 229},
181   { 80,  98, 137, 129, 109, 231, 162, 231},
182   { 82,  98, 137, 131, 109, 232, 164, 232},
183   { 84,  98, 138, 134, 110, 234, 166, 233},
184   { 86,  98, 138, 137, 111, 235, 168, 234},
185   { 89,  99, 138, 140, 112, 236, 170, 235},
186   { 91,  99, 138, 142, 112, 237, 171, 235},
187   { 93, 100, 139, 145, 113, 238, 173, 236},
188   { 95, 100, 139, 147, 114, 239, 174, 237},
189   { 97, 101, 140, 149, 115, 240, 176, 238},
190   { 99, 101, 140, 151, 115, 241, 177, 238},
191   {101, 102, 140, 154, 116, 242, 179, 239},
192   {103, 102, 140, 156, 117, 242, 180, 239},
193   {105, 103, 141, 158, 118, 243, 182, 240},
194   {107, 103, 141, 160, 118, 243, 183, 240},
195   {109, 104, 141, 162, 119, 244, 185, 241},
196   {111, 104, 141, 164, 119, 244, 186, 241},
197   {113, 104, 142, 166, 120, 245, 187, 242},
198   {114, 104, 142, 168, 121, 245, 188, 242},
199   {116, 105, 143, 170, 122, 246, 190, 243},
200   {118, 105, 143, 171, 122, 246, 191, 243},
201   {120, 106, 143, 173, 123, 247, 192, 244},
202   {121, 106, 143, 175, 124, 247, 193, 244},
203   {123, 107, 144, 177, 125, 248, 195, 244},
204   {125, 107, 144, 178, 125, 248, 196, 244},
205   {127, 108, 145, 180, 126, 249, 197, 245},
206   {128, 108, 145, 181, 127, 249, 198, 245},
207   {130, 109, 145, 183, 128, 249, 199, 245},
208   {132, 109, 145, 184, 128, 249, 200, 245},
209   {134, 110, 146, 186, 129, 250, 201, 246},
210   {135, 110, 146, 187, 130, 250, 202, 246},
211   {137, 111, 147, 189, 131, 251, 203, 246},
212   {138, 111, 147, 190, 131, 251, 204, 246},
213   {140, 112, 147, 192, 132, 251, 205, 247},
214   {141, 112, 147, 193, 132, 251, 206, 247},
215   {143, 113, 148, 194, 133, 251, 207, 247},
216   {144, 113, 148, 195, 134, 251, 207, 247},
217   {146, 114, 149, 197, 135, 252, 208, 248},
218   {147, 114, 149, 198, 135, 252, 209, 248},
219   {149, 115, 149, 199, 136, 252, 210, 248},
220   {150, 115, 149, 200, 137, 252, 210, 248},
221   {152, 115, 150, 201, 138, 252, 211, 248},
222   {153, 115, 150, 202, 138, 252, 212, 248},
223   {155, 116, 151, 204, 139, 253, 213, 249},
224   {156, 116, 151, 205, 139, 253, 213, 249},
225   {158, 117, 151, 206, 140, 253, 214, 249},
226   {159, 117, 151, 207, 141, 253, 215, 249},
227   {161, 118, 152, 208, 142, 253, 216, 249},
228   {162, 118, 152, 209, 142, 253, 216, 249},
229   {163, 119, 153, 210, 143, 253, 217, 249},
230   {164, 119, 153, 211, 143, 253, 217, 249},
231   {166, 120, 153, 212, 144, 254, 218, 250},
232   {167, 120, 153, 212, 145, 254, 219, 250},
233   {168, 121, 154, 213, 146, 254, 220, 250},
234   {169, 121, 154, 214, 146, 254, 220, 250},
235   {171, 122, 155, 215, 147, 254, 221, 250},
236   {172, 122, 155, 216, 147, 254, 221, 250},
237   {173, 123, 155, 217, 148, 254, 222, 250},
238   {174, 123, 155, 217, 149, 254, 222, 250},
239   {176, 124, 156, 218, 150, 254, 223, 250},
240   {177, 124, 156, 219, 150, 254, 223, 250},
241   {178, 125, 157, 220, 151, 254, 224, 251},
242   {179, 125, 157, 220, 151, 254, 224, 251},
243   {180, 126, 157, 221, 152, 254, 225, 251},
244   {181, 126, 157, 221, 152, 254, 225, 251},
245   {183, 127, 158, 222, 153, 254, 226, 251},
246   {184, 127, 158, 223, 154, 254, 226, 251},
247   {185, 128, 159, 224, 155, 255, 227, 251},
248   {186, 128, 159, 224, 155, 255, 227, 251},
249   {187, 129, 160, 225, 156, 255, 228, 251},
250   {188, 130, 160, 225, 156, 255, 228, 251},
251   {189, 131, 160, 226, 157, 255, 228, 251},
252   {190, 131, 160, 226, 158, 255, 228, 251},
253   {191, 132, 161, 227, 159, 255, 229, 251},
254   {192, 132, 161, 227, 159, 255, 229, 251},
255   {193, 133, 162, 228, 160, 255, 230, 252},
256   {194, 133, 162, 229, 160, 255, 230, 252},
257   {195, 134, 163, 230, 161, 255, 231, 252},
258   {196, 134, 163, 230, 161, 255, 231, 252},
259   {197, 135, 163, 231, 162, 255, 231, 252},
260   {198, 135, 163, 231, 162, 255, 231, 252},
261   {199, 136, 164, 232, 163, 255, 232, 252},
262   {200, 136, 164, 232, 164, 255, 232, 252},
263   {201, 137, 165, 233, 165, 255, 233, 252},
264   {201, 137, 165, 233, 165, 255, 233, 252},
265   {202, 138, 166, 233, 166, 255, 233, 252},
266   {203, 138, 166, 233, 166, 255, 233, 252},
267   {204, 139, 166, 234, 167, 255, 234, 252},
268   {205, 139, 166, 234, 167, 255, 234, 252},
269   {206, 140, 167, 235, 168, 255, 235, 252},
270   {206, 140, 167, 235, 168, 255, 235, 252},
271   {207, 141, 168, 236, 169, 255, 235, 252},
272   {208, 141, 168, 236, 170, 255, 235, 252},
273   {209, 142, 169, 237, 171, 255, 236, 252},
274   {209, 143, 169, 237, 171, 255, 236, 252},
275   {210, 144, 169, 237, 172, 255, 236, 252},
276   {211, 144, 169, 237, 172, 255, 236, 252},
277   {212, 145, 170, 238, 173, 255, 237, 252},
278   {213, 145, 170, 238, 173, 255, 237, 252},
279   {214, 146, 171, 239, 174, 255, 237, 253},
280   {214, 146, 171, 239, 174, 255, 237, 253},
281   {215, 147, 172, 240, 175, 255, 238, 253},
282   {215, 147, 172, 240, 175, 255, 238, 253},
283   {216, 148, 173, 240, 176, 255, 238, 253},
284   {217, 148, 173, 240, 176, 255, 238, 253},
285   {218, 149, 173, 241, 177, 255, 239, 253},
286   {218, 149, 173, 241, 178, 255, 239, 253},
287   {219, 150, 174, 241, 179, 255, 239, 253},
288   {219, 151, 174, 241, 179, 255, 239, 253},
289   {220, 152, 175, 242, 180, 255, 240, 253},
290   {221, 152, 175, 242, 180, 255, 240, 253},
291   {222, 153, 176, 242, 181, 255, 240, 253},
292   {222, 153, 176, 242, 181, 255, 240, 253},
293   {223, 154, 177, 243, 182, 255, 240, 253},
294   {223, 154, 177, 243, 182, 255, 240, 253},
295   {224, 155, 178, 244, 183, 255, 241, 253},
296   {224, 155, 178, 244, 183, 255, 241, 253},
297   {225, 156, 178, 244, 184, 255, 241, 253},
298   {225, 157, 178, 244, 184, 255, 241, 253},
299   {226, 158, 179, 244, 185, 255, 242, 253},
300   {227, 158, 179, 244, 185, 255, 242, 253},
301   {228, 159, 180, 245, 186, 255, 242, 253},
302   {228, 159, 180, 245, 186, 255, 242, 253},
303   {229, 160, 181, 245, 187, 255, 242, 253},
304   {229, 160, 181, 245, 187, 255, 242, 253},
305   {230, 161, 182, 246, 188, 255, 243, 253},
306   {230, 162, 182, 246, 188, 255, 243, 253},
307   {231, 163, 183, 246, 189, 255, 243, 253},
308   {231, 163, 183, 246, 189, 255, 243, 253},
309   {232, 164, 184, 247, 190, 255, 243, 253},
310   {232, 164, 184, 247, 190, 255, 243, 253},
311   {233, 165, 185, 247, 191, 255, 244, 253},
312   {233, 165, 185, 247, 191, 255, 244, 253},
313   {234, 166, 185, 247, 192, 255, 244, 253},
314   {234, 167, 185, 247, 192, 255, 244, 253},
315   {235, 168, 186, 248, 193, 255, 244, 253},
316   {235, 168, 186, 248, 193, 255, 244, 253},
317   {236, 169, 187, 248, 194, 255, 244, 253},
318   {236, 169, 187, 248, 194, 255, 244, 253},
319   {236, 170, 188, 248, 195, 255, 245, 253},
320   {236, 170, 188, 248, 195, 255, 245, 253},
321   {237, 171, 189, 249, 196, 255, 245, 254},
322   {237, 172, 189, 249, 196, 255, 245, 254},
323   {238, 173, 190, 249, 197, 255, 245, 254},
324   {238, 173, 190, 249, 197, 255, 245, 254},
325   {239, 174, 191, 249, 198, 255, 245, 254},
326   {239, 174, 191, 249, 198, 255, 245, 254},
327   {240, 175, 192, 249, 199, 255, 246, 254},
328   {240, 176, 192, 249, 199, 255, 246, 254},
329   {240, 177, 193, 250, 200, 255, 246, 254},
330   {240, 177, 193, 250, 200, 255, 246, 254},
331   {241, 178, 194, 250, 201, 255, 246, 254},
332   {241, 178, 194, 250, 201, 255, 246, 254},
333   {242, 179, 195, 250, 202, 255, 246, 254},
334   {242, 180, 195, 250, 202, 255, 246, 254},
335   {242, 181, 196, 250, 203, 255, 247, 254},
336   {242, 181, 196, 250, 203, 255, 247, 254},
337   {243, 182, 197, 251, 204, 255, 247, 254},
338   {243, 183, 197, 251, 204, 255, 247, 254},
339   {244, 184, 198, 251, 205, 255, 247, 254},
340   {244, 184, 198, 251, 205, 255, 247, 254},
341   {244, 185, 199, 251, 206, 255, 247, 254},
342   {244, 185, 199, 251, 206, 255, 247, 254},
343   {245, 186, 200, 251, 207, 255, 247, 254},
344   {245, 187, 200, 251, 207, 255, 247, 254},
345   {246, 188, 201, 252, 207, 255, 248, 254},
346   {246, 188, 201, 252, 207, 255, 248, 254},
347   {246, 189, 202, 252, 208, 255, 248, 254},
348   {246, 190, 202, 252, 208, 255, 248, 254},
349   {247, 191, 203, 252, 209, 255, 248, 254},
350   {247, 191, 203, 252, 209, 255, 248, 254},
351   {247, 192, 204, 252, 210, 255, 248, 254},
352   {247, 193, 204, 252, 210, 255, 248, 254},
353   {248, 194, 205, 252, 211, 255, 248, 254},
354   {248, 194, 205, 252, 211, 255, 248, 254},
355   {248, 195, 206, 252, 212, 255, 249, 254},
356   {248, 196, 206, 252, 212, 255, 249, 254},
357   {249, 197, 207, 253, 213, 255, 249, 254},
358   {249, 197, 207, 253, 213, 255, 249, 254},
359   {249, 198, 208, 253, 214, 255, 249, 254},
360   {249, 199, 209, 253, 214, 255, 249, 254},
361   {250, 200, 210, 253, 215, 255, 249, 254},
362   {250, 200, 210, 253, 215, 255, 249, 254},
363   {250, 201, 211, 253, 215, 255, 249, 254},
364   {250, 202, 211, 253, 215, 255, 249, 254},
365   {250, 203, 212, 253, 216, 255, 249, 254},
366   {250, 203, 212, 253, 216, 255, 249, 254},
367   {251, 204, 213, 253, 217, 255, 250, 254},
368   {251, 205, 213, 253, 217, 255, 250, 254},
369   {251, 206, 214, 254, 218, 255, 250, 254},
370   {251, 206, 215, 254, 218, 255, 250, 254},
371   {252, 207, 216, 254, 219, 255, 250, 254},
372   {252, 208, 216, 254, 219, 255, 250, 254},
373   {252, 209, 217, 254, 220, 255, 250, 254},
374   {252, 210, 217, 254, 220, 255, 250, 254},
375   {252, 211, 218, 254, 221, 255, 250, 254},
376   {252, 212, 218, 254, 221, 255, 250, 254},
377   {253, 213, 219, 254, 222, 255, 250, 254},
378   {253, 213, 220, 254, 222, 255, 250, 254},
379   {253, 214, 221, 254, 223, 255, 250, 254},
380   {253, 215, 221, 254, 223, 255, 250, 254},
381   {253, 216, 222, 254, 224, 255, 251, 254},
382   {253, 217, 223, 254, 224, 255, 251, 254},
383   {253, 218, 224, 254, 225, 255, 251, 254},
384   {253, 219, 224, 254, 225, 255, 251, 254},
385   {254, 220, 225, 254, 225, 255, 251, 254},
386   {254, 221, 226, 254, 225, 255, 251, 254},
387   {254, 222, 227, 255, 226, 255, 251, 254},
388   {254, 223, 227, 255, 226, 255, 251, 254},
389   {254, 224, 228, 255, 227, 255, 251, 254},
390   {254, 225, 229, 255, 227, 255, 251, 254},
391   {254, 226, 230, 255, 228, 255, 251, 254},
392   {254, 227, 230, 255, 229, 255, 251, 254},
393   {255, 228, 231, 255, 230, 255, 251, 254},
394   {255, 229, 232, 255, 230, 255, 251, 254},
395   {255, 230, 233, 255, 231, 255, 252, 254},
396   {255, 231, 234, 255, 231, 255, 252, 254},
397   {255, 232, 235, 255, 232, 255, 252, 254},
398   {255, 233, 236, 255, 232, 255, 252, 254},
399   {255, 235, 237, 255, 233, 255, 252, 254},
400   {255, 236, 238, 255, 234, 255, 252, 254},
401   {255, 238, 240, 255, 235, 255, 252, 255},
402   {255, 239, 241, 255, 235, 255, 252, 254},
403   {255, 241, 243, 255, 236, 255, 252, 254},
404   {255, 243, 245, 255, 237, 255, 252, 254},
405   {255, 246, 247, 255, 239, 255, 253, 255},
406   {255, 246, 247, 255, 239, 255, 253, 255},
407 };
408 
409 static const vp9_coeff_probs_model default_coef_probs_4x4[PLANE_TYPES] = {
410   {  // Y plane
411     {  // Intra
412       {  // Band 0
413         { 195,  29, 183 }, {  84,  49, 136 }, {   8,  42,  71 }
414       }, {  // Band 1
415         {  31, 107, 169 }, {  35,  99, 159 }, {  17,  82, 140 },
416         {   8,  66, 114 }, {   2,  44,  76 }, {   1,  19,  32 }
417       }, {  // Band 2
418         {  40, 132, 201 }, {  29, 114, 187 }, {  13,  91, 157 },
419         {   7,  75, 127 }, {   3,  58,  95 }, {   1,  28,  47 }
420       }, {  // Band 3
421         {  69, 142, 221 }, {  42, 122, 201 }, {  15,  91, 159 },
422         {   6,  67, 121 }, {   1,  42,  77 }, {   1,  17,  31 }
423       }, {  // Band 4
424         { 102, 148, 228 }, {  67, 117, 204 }, {  17,  82, 154 },
425         {   6,  59, 114 }, {   2,  39,  75 }, {   1,  15,  29 }
426       }, {  // Band 5
427         { 156,  57, 233 }, { 119,  57, 212 }, {  58,  48, 163 },
428         {  29,  40, 124 }, {  12,  30,  81 }, {   3,  12,  31 }
429       }
430     }, {  // Inter
431       {  // Band 0
432         { 191, 107, 226 }, { 124, 117, 204 }, {  25,  99, 155 }
433       }, {  // Band 1
434         {  29, 148, 210 }, {  37, 126, 194 }, {   8,  93, 157 },
435         {   2,  68, 118 }, {   1,  39,  69 }, {   1,  17,  33 }
436       }, {  // Band 2
437         {  41, 151, 213 }, {  27, 123, 193 }, {   3,  82, 144 },
438         {   1,  58, 105 }, {   1,  32,  60 }, {   1,  13,  26 }
439       }, {  // Band 3
440         {  59, 159, 220 }, {  23, 126, 198 }, {   4,  88, 151 },
441         {   1,  66, 114 }, {   1,  38,  71 }, {   1,  18,  34 }
442       }, {  // Band 4
443         { 114, 136, 232 }, {  51, 114, 207 }, {  11,  83, 155 },
444         {   3,  56, 105 }, {   1,  33,  65 }, {   1,  17,  34 }
445       }, {  // Band 5
446         { 149,  65, 234 }, { 121,  57, 215 }, {  61,  49, 166 },
447         {  28,  36, 114 }, {  12,  25,  76 }, {   3,  16,  42 }
448       }
449     }
450   }, {  // UV plane
451     {  // Intra
452       {  // Band 0
453         { 214,  49, 220 }, { 132,  63, 188 }, {  42,  65, 137 }
454       }, {  // Band 1
455         {  85, 137, 221 }, { 104, 131, 216 }, {  49, 111, 192 },
456         {  21,  87, 155 }, {   2,  49,  87 }, {   1,  16,  28 }
457       }, {  // Band 2
458         {  89, 163, 230 }, {  90, 137, 220 }, {  29, 100, 183 },
459         {  10,  70, 135 }, {   2,  42,  81 }, {   1,  17,  33 }
460       }, {  // Band 3
461         { 108, 167, 237 }, {  55, 133, 222 }, {  15,  97, 179 },
462         {   4,  72, 135 }, {   1,  45,  85 }, {   1,  19,  38 }
463       }, {  // Band 4
464         { 124, 146, 240 }, {  66, 124, 224 }, {  17,  88, 175 },
465         {   4,  58, 122 }, {   1,  36,  75 }, {   1,  18,  37 }
466       }, {  //  Band 5
467         { 141,  79, 241 }, { 126,  70, 227 }, {  66,  58, 182 },
468         {  30,  44, 136 }, {  12,  34,  96 }, {   2,  20,  47 }
469       }
470     }, {  // Inter
471       {  // Band 0
472         { 229,  99, 249 }, { 143, 111, 235 }, {  46, 109, 192 }
473       }, {  // Band 1
474         {  82, 158, 236 }, {  94, 146, 224 }, {  25, 117, 191 },
475         {   9,  87, 149 }, {   3,  56,  99 }, {   1,  33,  57 }
476       }, {  // Band 2
477         {  83, 167, 237 }, {  68, 145, 222 }, {  10, 103, 177 },
478         {   2,  72, 131 }, {   1,  41,  79 }, {   1,  20,  39 }
479       }, {  // Band 3
480         {  99, 167, 239 }, {  47, 141, 224 }, {  10, 104, 178 },
481         {   2,  73, 133 }, {   1,  44,  85 }, {   1,  22,  47 }
482       }, {  // Band 4
483         { 127, 145, 243 }, {  71, 129, 228 }, {  17,  93, 177 },
484         {   3,  61, 124 }, {   1,  41,  84 }, {   1,  21,  52 }
485       }, {  // Band 5
486         { 157,  78, 244 }, { 140,  72, 231 }, {  69,  58, 184 },
487         {  31,  44, 137 }, {  14,  38, 105 }, {   8,  23,  61 }
488       }
489     }
490   }
491 };
492 
493 static const vp9_coeff_probs_model default_coef_probs_8x8[PLANE_TYPES] = {
494   {  // Y plane
495     {  // Intra
496       {  // Band 0
497         { 125,  34, 187 }, {  52,  41, 133 }, {   6,  31,  56 }
498       }, {  // Band 1
499         {  37, 109, 153 }, {  51, 102, 147 }, {  23,  87, 128 },
500         {   8,  67, 101 }, {   1,  41,  63 }, {   1,  19,  29 }
501       }, {  // Band 2
502         {  31, 154, 185 }, {  17, 127, 175 }, {   6,  96, 145 },
503         {   2,  73, 114 }, {   1,  51,  82 }, {   1,  28,  45 }
504       }, {  // Band 3
505         {  23, 163, 200 }, {  10, 131, 185 }, {   2,  93, 148 },
506         {   1,  67, 111 }, {   1,  41,  69 }, {   1,  14,  24 }
507       }, {  // Band 4
508         {  29, 176, 217 }, {  12, 145, 201 }, {   3, 101, 156 },
509         {   1,  69, 111 }, {   1,  39,  63 }, {   1,  14,  23 }
510       }, {  // Band 5
511         {  57, 192, 233 }, {  25, 154, 215 }, {   6, 109, 167 },
512         {   3,  78, 118 }, {   1,  48,  69 }, {   1,  21,  29 }
513       }
514     }, {  // Inter
515       {  // Band 0
516         { 202, 105, 245 }, { 108, 106, 216 }, {  18,  90, 144 }
517       }, {  // Band 1
518         {  33, 172, 219 }, {  64, 149, 206 }, {  14, 117, 177 },
519         {   5,  90, 141 }, {   2,  61,  95 }, {   1,  37,  57 }
520       }, {  // Band 2
521         {  33, 179, 220 }, {  11, 140, 198 }, {   1,  89, 148 },
522         {   1,  60, 104 }, {   1,  33,  57 }, {   1,  12,  21 }
523       }, {  // Band 3
524         {  30, 181, 221 }, {   8, 141, 198 }, {   1,  87, 145 },
525         {   1,  58, 100 }, {   1,  31,  55 }, {   1,  12,  20 }
526       }, {  // Band 4
527         {  32, 186, 224 }, {   7, 142, 198 }, {   1,  86, 143 },
528         {   1,  58, 100 }, {   1,  31,  55 }, {   1,  12,  22 }
529       }, {  // Band 5
530         {  57, 192, 227 }, {  20, 143, 204 }, {   3,  96, 154 },
531         {   1,  68, 112 }, {   1,  42,  69 }, {   1,  19,  32 }
532       }
533     }
534   }, {  // UV plane
535     {  // Intra
536       {  // Band 0
537         { 212,  35, 215 }, { 113,  47, 169 }, {  29,  48, 105 }
538       }, {  // Band 1
539         {  74, 129, 203 }, { 106, 120, 203 }, {  49, 107, 178 },
540         {  19,  84, 144 }, {   4,  50,  84 }, {   1,  15,  25 }
541       }, {  // Band 2
542         {  71, 172, 217 }, {  44, 141, 209 }, {  15, 102, 173 },
543         {   6,  76, 133 }, {   2,  51,  89 }, {   1,  24,  42 }
544       }, {  // Band 3
545         {  64, 185, 231 }, {  31, 148, 216 }, {   8, 103, 175 },
546         {   3,  74, 131 }, {   1,  46,  81 }, {   1,  18,  30 }
547       }, {  // Band 4
548         {  65, 196, 235 }, {  25, 157, 221 }, {   5, 105, 174 },
549         {   1,  67, 120 }, {   1,  38,  69 }, {   1,  15,  30 }
550       }, {  // Band 5
551         {  65, 204, 238 }, {  30, 156, 224 }, {   7, 107, 177 },
552         {   2,  70, 124 }, {   1,  42,  73 }, {   1,  18,  34 }
553       }
554     }, {  // Inter
555       {  // Band 0
556         { 225,  86, 251 }, { 144, 104, 235 }, {  42,  99, 181 }
557       }, {  // Band 1
558         {  85, 175, 239 }, { 112, 165, 229 }, {  29, 136, 200 },
559         {  12, 103, 162 }, {   6,  77, 123 }, {   2,  53,  84 }
560       }, {  // Band 2
561         {  75, 183, 239 }, {  30, 155, 221 }, {   3, 106, 171 },
562         {   1,  74, 128 }, {   1,  44,  76 }, {   1,  17,  28 }
563       }, {  // Band 3
564         {  73, 185, 240 }, {  27, 159, 222 }, {   2, 107, 172 },
565         {   1,  75, 127 }, {   1,  42,  73 }, {   1,  17,  29 }
566       }, {  // Band 4
567         {  62, 190, 238 }, {  21, 159, 222 }, {   2, 107, 172 },
568         {   1,  72, 122 }, {   1,  40,  71 }, {   1,  18,  32 }
569       }, {  // Band 5
570         {  61, 199, 240 }, {  27, 161, 226 }, {   4, 113, 180 },
571         {   1,  76, 129 }, {   1,  46,  80 }, {   1,  23,  41 }
572       }
573     }
574   }
575 };
576 
577 static const vp9_coeff_probs_model default_coef_probs_16x16[PLANE_TYPES] = {
578   {  // Y plane
579     {  // Intra
580       {  // Band 0
581         {   7,  27, 153 }, {   5,  30,  95 }, {   1,  16,  30 }
582       }, {  // Band 1
583         {  50,  75, 127 }, {  57,  75, 124 }, {  27,  67, 108 },
584         {  10,  54,  86 }, {   1,  33,  52 }, {   1,  12,  18 }
585       }, {  // Band 2
586         {  43, 125, 151 }, {  26, 108, 148 }, {   7,  83, 122 },
587         {   2,  59,  89 }, {   1,  38,  60 }, {   1,  17,  27 }
588       }, {  // Band 3
589         {  23, 144, 163 }, {  13, 112, 154 }, {   2,  75, 117 },
590         {   1,  50,  81 }, {   1,  31,  51 }, {   1,  14,  23 }
591       }, {  // Band 4
592         {  18, 162, 185 }, {   6, 123, 171 }, {   1,  78, 125 },
593         {   1,  51,  86 }, {   1,  31,  54 }, {   1,  14,  23 }
594       }, {  // Band 5
595         {  15, 199, 227 }, {   3, 150, 204 }, {   1,  91, 146 },
596         {   1,  55,  95 }, {   1,  30,  53 }, {   1,  11,  20 }
597       }
598     }, {  // Inter
599       {  // Band 0
600         {  19,  55, 240 }, {  19,  59, 196 }, {   3,  52, 105 }
601       }, {  // Band 1
602         {  41, 166, 207 }, { 104, 153, 199 }, {  31, 123, 181 },
603         {  14, 101, 152 }, {   5,  72, 106 }, {   1,  36,  52 }
604       }, {  // Band 2
605         {  35, 176, 211 }, {  12, 131, 190 }, {   2,  88, 144 },
606         {   1,  60, 101 }, {   1,  36,  60 }, {   1,  16,  28 }
607       }, {  // Band 3
608         {  28, 183, 213 }, {   8, 134, 191 }, {   1,  86, 142 },
609         {   1,  56,  96 }, {   1,  30,  53 }, {   1,  12,  20 }
610       }, {  // Band 4
611         {  20, 190, 215 }, {   4, 135, 192 }, {   1,  84, 139 },
612         {   1,  53,  91 }, {   1,  28,  49 }, {   1,  11,  20 }
613       }, {  // Band 5
614         {  13, 196, 216 }, {   2, 137, 192 }, {   1,  86, 143 },
615         {   1,  57,  99 }, {   1,  32,  56 }, {   1,  13,  24 }
616       }
617     }
618   }, {  // UV plane
619     {  // Intra
620       {  // Band 0
621         { 211,  29, 217 }, {  96,  47, 156 }, {  22,  43,  87 }
622       }, {  // Band 1
623         {  78, 120, 193 }, { 111, 116, 186 }, {  46, 102, 164 },
624         {  15,  80, 128 }, {   2,  49,  76 }, {   1,  18,  28 }
625       }, {  // Band 2
626         {  71, 161, 203 }, {  42, 132, 192 }, {  10,  98, 150 },
627         {   3,  69, 109 }, {   1,  44,  70 }, {   1,  18,  29 }
628       }, {  // Band 3
629         {  57, 186, 211 }, {  30, 140, 196 }, {   4,  93, 146 },
630         {   1,  62, 102 }, {   1,  38,  65 }, {   1,  16,  27 }
631       }, {  // Band 4
632         {  47, 199, 217 }, {  14, 145, 196 }, {   1,  88, 142 },
633         {   1,  57,  98 }, {   1,  36,  62 }, {   1,  15,  26 }
634       }, {  // Band 5
635         {  26, 219, 229 }, {   5, 155, 207 }, {   1,  94, 151 },
636         {   1,  60, 104 }, {   1,  36,  62 }, {   1,  16,  28 }
637       }
638     }, {  // Inter
639       {  // Band 0
640         { 233,  29, 248 }, { 146,  47, 220 }, {  43,  52, 140 }
641       }, {  // Band 1
642         { 100, 163, 232 }, { 179, 161, 222 }, {  63, 142, 204 },
643         {  37, 113, 174 }, {  26,  89, 137 }, {  18,  68,  97 }
644       }, {  // Band 2
645         {  85, 181, 230 }, {  32, 146, 209 }, {   7, 100, 164 },
646         {   3,  71, 121 }, {   1,  45,  77 }, {   1,  18,  30 }
647       }, {  // Band 3
648         {  65, 187, 230 }, {  20, 148, 207 }, {   2,  97, 159 },
649         {   1,  68, 116 }, {   1,  40,  70 }, {   1,  14,  29 }
650       }, {  // Band 4
651         {  40, 194, 227 }, {   8, 147, 204 }, {   1,  94, 155 },
652         {   1,  65, 112 }, {   1,  39,  66 }, {   1,  14,  26 }
653       }, {  // Band 5
654         {  16, 208, 228 }, {   3, 151, 207 }, {   1,  98, 160 },
655         {   1,  67, 117 }, {   1,  41,  74 }, {   1,  17,  31 }
656       }
657     }
658   }
659 };
660 
661 static const vp9_coeff_probs_model default_coef_probs_32x32[PLANE_TYPES] = {
662   {  // Y plane
663     {  // Intra
664       {  // Band 0
665         {  17,  38, 140 }, {   7,  34,  80 }, {   1,  17,  29 }
666       }, {  // Band 1
667         {  37,  75, 128 }, {  41,  76, 128 }, {  26,  66, 116 },
668         {  12,  52,  94 }, {   2,  32,  55 }, {   1,  10,  16 }
669       }, {  // Band 2
670         {  50, 127, 154 }, {  37, 109, 152 }, {  16,  82, 121 },
671         {   5,  59,  85 }, {   1,  35,  54 }, {   1,  13,  20 }
672       }, {  // Band 3
673         {  40, 142, 167 }, {  17, 110, 157 }, {   2,  71, 112 },
674         {   1,  44,  72 }, {   1,  27,  45 }, {   1,  11,  17 }
675       }, {  // Band 4
676         {  30, 175, 188 }, {   9, 124, 169 }, {   1,  74, 116 },
677         {   1,  48,  78 }, {   1,  30,  49 }, {   1,  11,  18 }
678       }, {  // Band 5
679         {  10, 222, 223 }, {   2, 150, 194 }, {   1,  83, 128 },
680         {   1,  48,  79 }, {   1,  27,  45 }, {   1,  11,  17 }
681       }
682     }, {  // Inter
683       {  // Band 0
684         {  36,  41, 235 }, {  29,  36, 193 }, {  10,  27, 111 }
685       }, {  // Band 1
686         {  85, 165, 222 }, { 177, 162, 215 }, { 110, 135, 195 },
687         {  57, 113, 168 }, {  23,  83, 120 }, {  10,  49,  61 }
688       }, {  // Band 2
689         {  85, 190, 223 }, {  36, 139, 200 }, {   5,  90, 146 },
690         {   1,  60, 103 }, {   1,  38,  65 }, {   1,  18,  30 }
691       }, {  // Band 3
692         {  72, 202, 223 }, {  23, 141, 199 }, {   2,  86, 140 },
693         {   1,  56,  97 }, {   1,  36,  61 }, {   1,  16,  27 }
694       }, {  // Band 4
695         {  55, 218, 225 }, {  13, 145, 200 }, {   1,  86, 141 },
696         {   1,  57,  99 }, {   1,  35,  61 }, {   1,  13,  22 }
697       }, {  // Band 5
698         {  15, 235, 212 }, {   1, 132, 184 }, {   1,  84, 139 },
699         {   1,  57,  97 }, {   1,  34,  56 }, {   1,  14,  23 }
700       }
701     }
702   }, {  // UV plane
703     {  // Intra
704       {  // Band 0
705         { 181,  21, 201 }, {  61,  37, 123 }, {  10,  38,  71 }
706       }, {  // Band 1
707         {  47, 106, 172 }, {  95, 104, 173 }, {  42,  93, 159 },
708         {  18,  77, 131 }, {   4,  50,  81 }, {   1,  17,  23 }
709       }, {  // Band 2
710         {  62, 147, 199 }, {  44, 130, 189 }, {  28, 102, 154 },
711         {  18,  75, 115 }, {   2,  44,  65 }, {   1,  12,  19 }
712       }, {  // Band 3
713         {  55, 153, 210 }, {  24, 130, 194 }, {   3,  93, 146 },
714         {   1,  61,  97 }, {   1,  31,  50 }, {   1,  10,  16 }
715       }, {  // Band 4
716         {  49, 186, 223 }, {  17, 148, 204 }, {   1,  96, 142 },
717         {   1,  53,  83 }, {   1,  26,  44 }, {   1,  11,  17 }
718       }, {  // Band 5
719         {  13, 217, 212 }, {   2, 136, 180 }, {   1,  78, 124 },
720         {   1,  50,  83 }, {   1,  29,  49 }, {   1,  14,  23 }
721       }
722     }, {  // Inter
723       {  // Band 0
724         { 197,  13, 247 }, {  82,  17, 222 }, {  25,  17, 162 }
725       }, {  // Band 1
726         { 126, 186, 247 }, { 234, 191, 243 }, { 176, 177, 234 },
727         { 104, 158, 220 }, {  66, 128, 186 }, {  55,  90, 137 }
728       }, {  // Band 2
729         { 111, 197, 242 }, {  46, 158, 219 }, {   9, 104, 171 },
730         {   2,  65, 125 }, {   1,  44,  80 }, {   1,  17,  91 }
731       }, {  // Band 3
732         { 104, 208, 245 }, {  39, 168, 224 }, {   3, 109, 162 },
733         {   1,  79, 124 }, {   1,  50, 102 }, {   1,  43, 102 }
734       }, {  // Band 4
735         {  84, 220, 246 }, {  31, 177, 231 }, {   2, 115, 180 },
736         {   1,  79, 134 }, {   1,  55,  77 }, {   1,  60,  79 }
737       }, {  // Band 5
738         {  43, 243, 240 }, {   8, 180, 217 }, {   1, 115, 166 },
739         {   1,  84, 121 }, {   1,  51,  67 }, {   1,  16,   6 }
740       }
741     }
742   }
743 };
744 
extend_to_full_distribution(vpx_prob * probs,vpx_prob p)745 static void extend_to_full_distribution(vpx_prob *probs, vpx_prob p) {
746   memcpy(probs, vp9_pareto8_full[p = 0 ? 0 : p - 1],
747          MODEL_NODES * sizeof(vpx_prob));
748 }
749 
vp9_model_to_full_probs(const vpx_prob * model,vpx_prob * full)750 void vp9_model_to_full_probs(const vpx_prob *model, vpx_prob *full) {
751   if (full != model)
752     memcpy(full, model, sizeof(vpx_prob) * UNCONSTRAINED_NODES);
753   extend_to_full_distribution(&full[UNCONSTRAINED_NODES], model[PIVOT_NODE]);
754 }
755 
vp9_default_coef_probs(VP9_COMMON * cm)756 void vp9_default_coef_probs(VP9_COMMON *cm) {
757   vp9_copy(cm->fc->coef_probs[TX_4X4], default_coef_probs_4x4);
758   vp9_copy(cm->fc->coef_probs[TX_8X8], default_coef_probs_8x8);
759   vp9_copy(cm->fc->coef_probs[TX_16X16], default_coef_probs_16x16);
760   vp9_copy(cm->fc->coef_probs[TX_32X32], default_coef_probs_32x32);
761 }
762 
763 #define COEF_COUNT_SAT 24
764 #define COEF_MAX_UPDATE_FACTOR 112
765 #define COEF_COUNT_SAT_KEY 24
766 #define COEF_MAX_UPDATE_FACTOR_KEY 112
767 #define COEF_COUNT_SAT_AFTER_KEY 24
768 #define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128
769 
adapt_coef_probs(VP9_COMMON * cm,TX_SIZE tx_size,unsigned int count_sat,unsigned int update_factor)770 static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE tx_size,
771                              unsigned int count_sat,
772                              unsigned int update_factor) {
773   const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx];
774   vp9_coeff_probs_model *const probs = cm->fc->coef_probs[tx_size];
775   const vp9_coeff_probs_model *const pre_probs = pre_fc->coef_probs[tx_size];
776   vp9_coeff_count_model *counts = cm->counts.coef[tx_size];
777   unsigned int (*eob_counts)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] =
778       cm->counts.eob_branch[tx_size];
779   int i, j, k, l, m;
780 
781   for (i = 0; i < PLANE_TYPES; ++i)
782     for (j = 0; j < REF_TYPES; ++j)
783       for (k = 0; k < COEF_BANDS; ++k)
784         for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
785           const int n0 = counts[i][j][k][l][ZERO_TOKEN];
786           const int n1 = counts[i][j][k][l][ONE_TOKEN];
787           const int n2 = counts[i][j][k][l][TWO_TOKEN];
788           const int neob = counts[i][j][k][l][EOB_MODEL_TOKEN];
789           const unsigned int branch_ct[UNCONSTRAINED_NODES][2] = {
790             { neob, eob_counts[i][j][k][l] - neob },
791             { n0, n1 + n2 },
792             { n1, n2 }
793           };
794           for (m = 0; m < UNCONSTRAINED_NODES; ++m)
795             probs[i][j][k][l][m] = merge_probs(pre_probs[i][j][k][l][m],
796                                                branch_ct[m],
797                                                count_sat, update_factor);
798         }
799 }
800 
vp9_adapt_coef_probs(VP9_COMMON * cm)801 void vp9_adapt_coef_probs(VP9_COMMON *cm) {
802   TX_SIZE t;
803   unsigned int count_sat, update_factor;
804 
805   if (frame_is_intra_only(cm)) {
806     update_factor = COEF_MAX_UPDATE_FACTOR_KEY;
807     count_sat = COEF_COUNT_SAT_KEY;
808   } else if (cm->last_frame_type == KEY_FRAME) {
809     update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY;  /* adapt quickly */
810     count_sat = COEF_COUNT_SAT_AFTER_KEY;
811   } else {
812     update_factor = COEF_MAX_UPDATE_FACTOR;
813     count_sat = COEF_COUNT_SAT;
814   }
815   for (t = TX_4X4; t <= TX_32X32; t++)
816     adapt_coef_probs(cm, t, count_sat, update_factor);
817 }
818