Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "vp9/common/vp9_entropy.h" |
michael@0 | 12 | #include "vp9/common/vp9_blockd.h" |
michael@0 | 13 | #include "vp9/common/vp9_onyxc_int.h" |
michael@0 | 14 | #include "vp9/common/vp9_entropymode.h" |
michael@0 | 15 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 16 | #include "vpx/vpx_integer.h" |
michael@0 | 17 | |
michael@0 | 18 | #define MODEL_NODES (ENTROPY_NODES - UNCONSTRAINED_NODES) |
michael@0 | 19 | |
michael@0 | 20 | DECLARE_ALIGNED(16, const uint8_t, vp9_norm[256]) = { |
michael@0 | 21 | 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
michael@0 | 22 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
michael@0 | 23 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
michael@0 | 24 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
michael@0 | 25 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
michael@0 | 26 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
michael@0 | 27 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
michael@0 | 28 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
michael@0 | 29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 31 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 32 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 35 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
michael@0 | 36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | DECLARE_ALIGNED(16, const uint8_t, |
michael@0 | 40 | vp9_coefband_trans_8x8plus[1024]) = { |
michael@0 | 41 | 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, |
michael@0 | 42 | 4, 4, 4, 4, 4, 5, |
michael@0 | 43 | // beyond MAXBAND_INDEX+1 all values are filled as 5 |
michael@0 | 44 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 45 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 46 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 47 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 48 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 49 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 50 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 51 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 52 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 53 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 54 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 55 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 56 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 57 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 58 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 59 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 60 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 61 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 62 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 63 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 64 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 65 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 66 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 67 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 68 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 69 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 70 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 71 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 72 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 73 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 74 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 75 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 76 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 77 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 78 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 79 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 80 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 81 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 82 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 83 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 84 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 85 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 86 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 87 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 88 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 89 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 90 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 91 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 92 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 93 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 94 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 95 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 96 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 97 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 98 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 99 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 100 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 101 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 102 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 103 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 104 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 105 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 106 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | DECLARE_ALIGNED(16, const uint8_t, |
michael@0 | 110 | vp9_coefband_trans_4x4[16]) = { |
michael@0 | 111 | 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | DECLARE_ALIGNED(16, const uint8_t, vp9_pt_energy_class[MAX_ENTROPY_TOKENS]) = { |
michael@0 | 115 | 0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5 |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | |
michael@0 | 119 | |
michael@0 | 120 | /* Array indices are identical to previously-existing CONTEXT_NODE indices */ |
michael@0 | 121 | |
michael@0 | 122 | const vp9_tree_index vp9_coef_tree[TREE_SIZE(MAX_ENTROPY_TOKENS)] = { |
michael@0 | 123 | -DCT_EOB_TOKEN, 2, /* 0 = EOB */ |
michael@0 | 124 | -ZERO_TOKEN, 4, /* 1 = ZERO */ |
michael@0 | 125 | -ONE_TOKEN, 6, /* 2 = ONE */ |
michael@0 | 126 | 8, 12, /* 3 = LOW_VAL */ |
michael@0 | 127 | -TWO_TOKEN, 10, /* 4 = TWO */ |
michael@0 | 128 | -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */ |
michael@0 | 129 | 14, 16, /* 6 = HIGH_LOW */ |
michael@0 | 130 | -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */ |
michael@0 | 131 | 18, 20, /* 8 = CAT_THREEFOUR */ |
michael@0 | 132 | -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */ |
michael@0 | 133 | -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */ |
michael@0 | 134 | }; |
michael@0 | 135 | |
michael@0 | 136 | struct vp9_token vp9_coef_encodings[MAX_ENTROPY_TOKENS]; |
michael@0 | 137 | |
michael@0 | 138 | /* Trees for extra bits. Probabilities are constant and |
michael@0 | 139 | do not depend on previously encoded bits */ |
michael@0 | 140 | |
michael@0 | 141 | static const vp9_prob Pcat1[] = { 159}; |
michael@0 | 142 | static const vp9_prob Pcat2[] = { 165, 145}; |
michael@0 | 143 | static const vp9_prob Pcat3[] = { 173, 148, 140}; |
michael@0 | 144 | static const vp9_prob Pcat4[] = { 176, 155, 140, 135}; |
michael@0 | 145 | static const vp9_prob Pcat5[] = { 180, 157, 141, 134, 130}; |
michael@0 | 146 | static const vp9_prob Pcat6[] = { |
michael@0 | 147 | 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129 |
michael@0 | 148 | }; |
michael@0 | 149 | |
michael@0 | 150 | const vp9_tree_index vp9_coefmodel_tree[6] = { |
michael@0 | 151 | -DCT_EOB_MODEL_TOKEN, 2, /* 0 = EOB */ |
michael@0 | 152 | -ZERO_TOKEN, 4, /* 1 = ZERO */ |
michael@0 | 153 | -ONE_TOKEN, -TWO_TOKEN, |
michael@0 | 154 | }; |
michael@0 | 155 | |
michael@0 | 156 | // Model obtained from a 2-sided zero-centerd distribuition derived |
michael@0 | 157 | // from a Pareto distribution. The cdf of the distribution is: |
michael@0 | 158 | // cdf(x) = 0.5 + 0.5 * sgn(x) * [1 - {alpha/(alpha + |x|)} ^ beta] |
michael@0 | 159 | // |
michael@0 | 160 | // For a given beta and a given probablity of the 1-node, the alpha |
michael@0 | 161 | // is first solved, and then the {alpha, beta} pair is used to generate |
michael@0 | 162 | // the probabilities for the rest of the nodes. |
michael@0 | 163 | |
michael@0 | 164 | // beta = 8 |
michael@0 | 165 | static const vp9_prob modelcoefprobs_pareto8[COEFPROB_MODELS][MODEL_NODES] = { |
michael@0 | 166 | { 3, 86, 128, 6, 86, 23, 88, 29}, |
michael@0 | 167 | { 9, 86, 129, 17, 88, 61, 94, 76}, |
michael@0 | 168 | { 15, 87, 129, 28, 89, 93, 100, 110}, |
michael@0 | 169 | { 20, 88, 130, 38, 91, 118, 106, 136}, |
michael@0 | 170 | { 26, 89, 131, 48, 92, 139, 111, 156}, |
michael@0 | 171 | { 31, 90, 131, 58, 94, 156, 117, 171}, |
michael@0 | 172 | { 37, 90, 132, 66, 95, 171, 122, 184}, |
michael@0 | 173 | { 42, 91, 132, 75, 97, 183, 127, 194}, |
michael@0 | 174 | { 47, 92, 133, 83, 98, 193, 132, 202}, |
michael@0 | 175 | { 52, 93, 133, 90, 100, 201, 137, 208}, |
michael@0 | 176 | { 57, 94, 134, 98, 101, 208, 142, 214}, |
michael@0 | 177 | { 62, 94, 135, 105, 103, 214, 146, 218}, |
michael@0 | 178 | { 66, 95, 135, 111, 104, 219, 151, 222}, |
michael@0 | 179 | { 71, 96, 136, 117, 106, 224, 155, 225}, |
michael@0 | 180 | { 76, 97, 136, 123, 107, 227, 159, 228}, |
michael@0 | 181 | { 80, 98, 137, 129, 109, 231, 162, 231}, |
michael@0 | 182 | { 84, 98, 138, 134, 110, 234, 166, 233}, |
michael@0 | 183 | { 89, 99, 138, 140, 112, 236, 170, 235}, |
michael@0 | 184 | { 93, 100, 139, 145, 113, 238, 173, 236}, |
michael@0 | 185 | { 97, 101, 140, 149, 115, 240, 176, 238}, |
michael@0 | 186 | {101, 102, 140, 154, 116, 242, 179, 239}, |
michael@0 | 187 | {105, 103, 141, 158, 118, 243, 182, 240}, |
michael@0 | 188 | {109, 104, 141, 162, 119, 244, 185, 241}, |
michael@0 | 189 | {113, 104, 142, 166, 120, 245, 187, 242}, |
michael@0 | 190 | {116, 105, 143, 170, 122, 246, 190, 243}, |
michael@0 | 191 | {120, 106, 143, 173, 123, 247, 192, 244}, |
michael@0 | 192 | {123, 107, 144, 177, 125, 248, 195, 244}, |
michael@0 | 193 | {127, 108, 145, 180, 126, 249, 197, 245}, |
michael@0 | 194 | {130, 109, 145, 183, 128, 249, 199, 245}, |
michael@0 | 195 | {134, 110, 146, 186, 129, 250, 201, 246}, |
michael@0 | 196 | {137, 111, 147, 189, 131, 251, 203, 246}, |
michael@0 | 197 | {140, 112, 147, 192, 132, 251, 205, 247}, |
michael@0 | 198 | {143, 113, 148, 194, 133, 251, 207, 247}, |
michael@0 | 199 | {146, 114, 149, 197, 135, 252, 208, 248}, |
michael@0 | 200 | {149, 115, 149, 199, 136, 252, 210, 248}, |
michael@0 | 201 | {152, 115, 150, 201, 138, 252, 211, 248}, |
michael@0 | 202 | {155, 116, 151, 204, 139, 253, 213, 249}, |
michael@0 | 203 | {158, 117, 151, 206, 140, 253, 214, 249}, |
michael@0 | 204 | {161, 118, 152, 208, 142, 253, 216, 249}, |
michael@0 | 205 | {163, 119, 153, 210, 143, 253, 217, 249}, |
michael@0 | 206 | {166, 120, 153, 212, 144, 254, 218, 250}, |
michael@0 | 207 | {168, 121, 154, 213, 146, 254, 220, 250}, |
michael@0 | 208 | {171, 122, 155, 215, 147, 254, 221, 250}, |
michael@0 | 209 | {173, 123, 155, 217, 148, 254, 222, 250}, |
michael@0 | 210 | {176, 124, 156, 218, 150, 254, 223, 250}, |
michael@0 | 211 | {178, 125, 157, 220, 151, 254, 224, 251}, |
michael@0 | 212 | {180, 126, 157, 221, 152, 254, 225, 251}, |
michael@0 | 213 | {183, 127, 158, 222, 153, 254, 226, 251}, |
michael@0 | 214 | {185, 128, 159, 224, 155, 255, 227, 251}, |
michael@0 | 215 | {187, 129, 160, 225, 156, 255, 228, 251}, |
michael@0 | 216 | {189, 131, 160, 226, 157, 255, 228, 251}, |
michael@0 | 217 | {191, 132, 161, 227, 159, 255, 229, 251}, |
michael@0 | 218 | {193, 133, 162, 228, 160, 255, 230, 252}, |
michael@0 | 219 | {195, 134, 163, 230, 161, 255, 231, 252}, |
michael@0 | 220 | {197, 135, 163, 231, 162, 255, 231, 252}, |
michael@0 | 221 | {199, 136, 164, 232, 163, 255, 232, 252}, |
michael@0 | 222 | {201, 137, 165, 233, 165, 255, 233, 252}, |
michael@0 | 223 | {202, 138, 166, 233, 166, 255, 233, 252}, |
michael@0 | 224 | {204, 139, 166, 234, 167, 255, 234, 252}, |
michael@0 | 225 | {206, 140, 167, 235, 168, 255, 235, 252}, |
michael@0 | 226 | {207, 141, 168, 236, 169, 255, 235, 252}, |
michael@0 | 227 | {209, 142, 169, 237, 171, 255, 236, 252}, |
michael@0 | 228 | {210, 144, 169, 237, 172, 255, 236, 252}, |
michael@0 | 229 | {212, 145, 170, 238, 173, 255, 237, 252}, |
michael@0 | 230 | {214, 146, 171, 239, 174, 255, 237, 253}, |
michael@0 | 231 | {215, 147, 172, 240, 175, 255, 238, 253}, |
michael@0 | 232 | {216, 148, 173, 240, 176, 255, 238, 253}, |
michael@0 | 233 | {218, 149, 173, 241, 177, 255, 239, 253}, |
michael@0 | 234 | {219, 150, 174, 241, 179, 255, 239, 253}, |
michael@0 | 235 | {220, 152, 175, 242, 180, 255, 240, 253}, |
michael@0 | 236 | {222, 153, 176, 242, 181, 255, 240, 253}, |
michael@0 | 237 | {223, 154, 177, 243, 182, 255, 240, 253}, |
michael@0 | 238 | {224, 155, 178, 244, 183, 255, 241, 253}, |
michael@0 | 239 | {225, 156, 178, 244, 184, 255, 241, 253}, |
michael@0 | 240 | {226, 158, 179, 244, 185, 255, 242, 253}, |
michael@0 | 241 | {228, 159, 180, 245, 186, 255, 242, 253}, |
michael@0 | 242 | {229, 160, 181, 245, 187, 255, 242, 253}, |
michael@0 | 243 | {230, 161, 182, 246, 188, 255, 243, 253}, |
michael@0 | 244 | {231, 163, 183, 246, 189, 255, 243, 253}, |
michael@0 | 245 | {232, 164, 184, 247, 190, 255, 243, 253}, |
michael@0 | 246 | {233, 165, 185, 247, 191, 255, 244, 253}, |
michael@0 | 247 | {234, 166, 185, 247, 192, 255, 244, 253}, |
michael@0 | 248 | {235, 168, 186, 248, 193, 255, 244, 253}, |
michael@0 | 249 | {236, 169, 187, 248, 194, 255, 244, 253}, |
michael@0 | 250 | {236, 170, 188, 248, 195, 255, 245, 253}, |
michael@0 | 251 | {237, 171, 189, 249, 196, 255, 245, 254}, |
michael@0 | 252 | {238, 173, 190, 249, 197, 255, 245, 254}, |
michael@0 | 253 | {239, 174, 191, 249, 198, 255, 245, 254}, |
michael@0 | 254 | {240, 175, 192, 249, 199, 255, 246, 254}, |
michael@0 | 255 | {240, 177, 193, 250, 200, 255, 246, 254}, |
michael@0 | 256 | {241, 178, 194, 250, 201, 255, 246, 254}, |
michael@0 | 257 | {242, 179, 195, 250, 202, 255, 246, 254}, |
michael@0 | 258 | {242, 181, 196, 250, 203, 255, 247, 254}, |
michael@0 | 259 | {243, 182, 197, 251, 204, 255, 247, 254}, |
michael@0 | 260 | {244, 184, 198, 251, 205, 255, 247, 254}, |
michael@0 | 261 | {244, 185, 199, 251, 206, 255, 247, 254}, |
michael@0 | 262 | {245, 186, 200, 251, 207, 255, 247, 254}, |
michael@0 | 263 | {246, 188, 201, 252, 207, 255, 248, 254}, |
michael@0 | 264 | {246, 189, 202, 252, 208, 255, 248, 254}, |
michael@0 | 265 | {247, 191, 203, 252, 209, 255, 248, 254}, |
michael@0 | 266 | {247, 192, 204, 252, 210, 255, 248, 254}, |
michael@0 | 267 | {248, 194, 205, 252, 211, 255, 248, 254}, |
michael@0 | 268 | {248, 195, 206, 252, 212, 255, 249, 254}, |
michael@0 | 269 | {249, 197, 207, 253, 213, 255, 249, 254}, |
michael@0 | 270 | {249, 198, 208, 253, 214, 255, 249, 254}, |
michael@0 | 271 | {250, 200, 210, 253, 215, 255, 249, 254}, |
michael@0 | 272 | {250, 201, 211, 253, 215, 255, 249, 254}, |
michael@0 | 273 | {250, 203, 212, 253, 216, 255, 249, 254}, |
michael@0 | 274 | {251, 204, 213, 253, 217, 255, 250, 254}, |
michael@0 | 275 | {251, 206, 214, 254, 218, 255, 250, 254}, |
michael@0 | 276 | {252, 207, 216, 254, 219, 255, 250, 254}, |
michael@0 | 277 | {252, 209, 217, 254, 220, 255, 250, 254}, |
michael@0 | 278 | {252, 211, 218, 254, 221, 255, 250, 254}, |
michael@0 | 279 | {253, 213, 219, 254, 222, 255, 250, 254}, |
michael@0 | 280 | {253, 214, 221, 254, 223, 255, 250, 254}, |
michael@0 | 281 | {253, 216, 222, 254, 224, 255, 251, 254}, |
michael@0 | 282 | {253, 218, 224, 254, 225, 255, 251, 254}, |
michael@0 | 283 | {254, 220, 225, 254, 225, 255, 251, 254}, |
michael@0 | 284 | {254, 222, 227, 255, 226, 255, 251, 254}, |
michael@0 | 285 | {254, 224, 228, 255, 227, 255, 251, 254}, |
michael@0 | 286 | {254, 226, 230, 255, 228, 255, 251, 254}, |
michael@0 | 287 | {255, 228, 231, 255, 230, 255, 251, 254}, |
michael@0 | 288 | {255, 230, 233, 255, 231, 255, 252, 254}, |
michael@0 | 289 | {255, 232, 235, 255, 232, 255, 252, 254}, |
michael@0 | 290 | {255, 235, 237, 255, 233, 255, 252, 254}, |
michael@0 | 291 | {255, 238, 240, 255, 235, 255, 252, 255}, |
michael@0 | 292 | {255, 241, 243, 255, 236, 255, 252, 254}, |
michael@0 | 293 | {255, 246, 247, 255, 239, 255, 253, 255} |
michael@0 | 294 | }; |
michael@0 | 295 | |
michael@0 | 296 | static void extend_model_to_full_distribution(vp9_prob p, |
michael@0 | 297 | vp9_prob *tree_probs) { |
michael@0 | 298 | const int l = (p - 1) / 2; |
michael@0 | 299 | const vp9_prob (*model)[MODEL_NODES] = modelcoefprobs_pareto8; |
michael@0 | 300 | if (p & 1) { |
michael@0 | 301 | vpx_memcpy(tree_probs + UNCONSTRAINED_NODES, |
michael@0 | 302 | model[l], MODEL_NODES * sizeof(vp9_prob)); |
michael@0 | 303 | } else { |
michael@0 | 304 | // interpolate |
michael@0 | 305 | int i; |
michael@0 | 306 | for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i) |
michael@0 | 307 | tree_probs[i] = (model[l][i - UNCONSTRAINED_NODES] + |
michael@0 | 308 | model[l + 1][i - UNCONSTRAINED_NODES]) >> 1; |
michael@0 | 309 | } |
michael@0 | 310 | } |
michael@0 | 311 | |
michael@0 | 312 | void vp9_model_to_full_probs(const vp9_prob *model, vp9_prob *full) { |
michael@0 | 313 | if (full != model) |
michael@0 | 314 | vpx_memcpy(full, model, sizeof(vp9_prob) * UNCONSTRAINED_NODES); |
michael@0 | 315 | extend_model_to_full_distribution(model[PIVOT_NODE], full); |
michael@0 | 316 | } |
michael@0 | 317 | |
michael@0 | 318 | static vp9_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[28]; |
michael@0 | 319 | |
michael@0 | 320 | static void init_bit_tree(vp9_tree_index *p, int n) { |
michael@0 | 321 | int i = 0; |
michael@0 | 322 | |
michael@0 | 323 | while (++i < n) { |
michael@0 | 324 | p[0] = p[1] = i << 1; |
michael@0 | 325 | p += 2; |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | p[0] = p[1] = 0; |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | static void init_bit_trees() { |
michael@0 | 332 | init_bit_tree(cat1, 1); |
michael@0 | 333 | init_bit_tree(cat2, 2); |
michael@0 | 334 | init_bit_tree(cat3, 3); |
michael@0 | 335 | init_bit_tree(cat4, 4); |
michael@0 | 336 | init_bit_tree(cat5, 5); |
michael@0 | 337 | init_bit_tree(cat6, 14); |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | const vp9_extra_bit vp9_extra_bits[MAX_ENTROPY_TOKENS] = { |
michael@0 | 341 | { 0, 0, 0, 0}, |
michael@0 | 342 | { 0, 0, 0, 1}, |
michael@0 | 343 | { 0, 0, 0, 2}, |
michael@0 | 344 | { 0, 0, 0, 3}, |
michael@0 | 345 | { 0, 0, 0, 4}, |
michael@0 | 346 | { cat1, Pcat1, 1, 5}, |
michael@0 | 347 | { cat2, Pcat2, 2, 7}, |
michael@0 | 348 | { cat3, Pcat3, 3, 11}, |
michael@0 | 349 | { cat4, Pcat4, 4, 19}, |
michael@0 | 350 | { cat5, Pcat5, 5, 35}, |
michael@0 | 351 | { cat6, Pcat6, 14, 67}, |
michael@0 | 352 | { 0, 0, 0, 0} |
michael@0 | 353 | }; |
michael@0 | 354 | |
michael@0 | 355 | #include "vp9/common/vp9_default_coef_probs.h" |
michael@0 | 356 | |
michael@0 | 357 | void vp9_default_coef_probs(VP9_COMMON *cm) { |
michael@0 | 358 | vp9_copy(cm->fc.coef_probs[TX_4X4], default_coef_probs_4x4); |
michael@0 | 359 | vp9_copy(cm->fc.coef_probs[TX_8X8], default_coef_probs_8x8); |
michael@0 | 360 | vp9_copy(cm->fc.coef_probs[TX_16X16], default_coef_probs_16x16); |
michael@0 | 361 | vp9_copy(cm->fc.coef_probs[TX_32X32], default_coef_probs_32x32); |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | void vp9_coef_tree_initialize() { |
michael@0 | 365 | init_bit_trees(); |
michael@0 | 366 | vp9_tokens_from_tree(vp9_coef_encodings, vp9_coef_tree); |
michael@0 | 367 | } |
michael@0 | 368 | |
michael@0 | 369 | // #define COEF_COUNT_TESTING |
michael@0 | 370 | |
michael@0 | 371 | #define COEF_COUNT_SAT 24 |
michael@0 | 372 | #define COEF_MAX_UPDATE_FACTOR 112 |
michael@0 | 373 | #define COEF_COUNT_SAT_KEY 24 |
michael@0 | 374 | #define COEF_MAX_UPDATE_FACTOR_KEY 112 |
michael@0 | 375 | #define COEF_COUNT_SAT_AFTER_KEY 24 |
michael@0 | 376 | #define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128 |
michael@0 | 377 | |
michael@0 | 378 | static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE tx_size, |
michael@0 | 379 | unsigned int count_sat, |
michael@0 | 380 | unsigned int update_factor) { |
michael@0 | 381 | const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
michael@0 | 382 | |
michael@0 | 383 | vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[tx_size]; |
michael@0 | 384 | const vp9_coeff_probs_model *pre_coef_probs = pre_fc->coef_probs[tx_size]; |
michael@0 | 385 | vp9_coeff_count_model *coef_counts = cm->counts.coef[tx_size]; |
michael@0 | 386 | unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] = |
michael@0 | 387 | cm->counts.eob_branch[tx_size]; |
michael@0 | 388 | int i, j, k, l, m; |
michael@0 | 389 | unsigned int branch_ct[UNCONSTRAINED_NODES][2]; |
michael@0 | 390 | |
michael@0 | 391 | for (i = 0; i < BLOCK_TYPES; ++i) |
michael@0 | 392 | for (j = 0; j < REF_TYPES; ++j) |
michael@0 | 393 | for (k = 0; k < COEF_BANDS; ++k) |
michael@0 | 394 | for (l = 0; l < PREV_COEF_CONTEXTS; ++l) { |
michael@0 | 395 | if (l >= 3 && k == 0) |
michael@0 | 396 | continue; |
michael@0 | 397 | vp9_tree_probs_from_distribution(vp9_coefmodel_tree, branch_ct, |
michael@0 | 398 | coef_counts[i][j][k][l]); |
michael@0 | 399 | branch_ct[0][1] = eob_branch_count[i][j][k][l] - branch_ct[0][0]; |
michael@0 | 400 | for (m = 0; m < UNCONSTRAINED_NODES; ++m) |
michael@0 | 401 | dst_coef_probs[i][j][k][l][m] = merge_probs( |
michael@0 | 402 | pre_coef_probs[i][j][k][l][m], |
michael@0 | 403 | branch_ct[m], |
michael@0 | 404 | count_sat, update_factor); |
michael@0 | 405 | } |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | void vp9_adapt_coef_probs(VP9_COMMON *cm) { |
michael@0 | 409 | TX_SIZE t; |
michael@0 | 410 | unsigned int count_sat, update_factor; |
michael@0 | 411 | |
michael@0 | 412 | if (frame_is_intra_only(cm)) { |
michael@0 | 413 | update_factor = COEF_MAX_UPDATE_FACTOR_KEY; |
michael@0 | 414 | count_sat = COEF_COUNT_SAT_KEY; |
michael@0 | 415 | } else if (cm->last_frame_type == KEY_FRAME) { |
michael@0 | 416 | update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY; /* adapt quickly */ |
michael@0 | 417 | count_sat = COEF_COUNT_SAT_AFTER_KEY; |
michael@0 | 418 | } else { |
michael@0 | 419 | update_factor = COEF_MAX_UPDATE_FACTOR; |
michael@0 | 420 | count_sat = COEF_COUNT_SAT; |
michael@0 | 421 | } |
michael@0 | 422 | for (t = TX_4X4; t <= TX_32X32; t++) |
michael@0 | 423 | adapt_coef_probs(cm, t, count_sat, update_factor); |
michael@0 | 424 | } |