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 "entropy.h" 12 #include "blockd.h" 13 #include "onyxc_int.h" 14 #include "vpx_mem/vpx_mem.h" 15 16 #include "coefupdateprobs.h" 17 18 DECLARE_ALIGNED(16, const unsigned char, vp8_norm[256]) = 19 { 20 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 21 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 22 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 23 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 24 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 25 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 26 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 36 }; 37 38 DECLARE_ALIGNED(16, const unsigned char, vp8_coef_bands[16]) = 39 { 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7}; 40 41 DECLARE_ALIGNED(16, const unsigned char, 42 vp8_prev_token_class[MAX_ENTROPY_TOKENS]) = 43 { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}; 44 45 DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]) = 46 { 47 0, 1, 4, 8, 48 5, 2, 3, 6, 49 9, 12, 13, 10, 50 7, 11, 14, 15, 51 }; 52 53 DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) = 54 { 55 1, 2, 6, 7, 56 3, 5, 8, 13, 57 4, 9, 12, 14, 58 10, 11, 15, 16 59 }; 60 61 /* vp8_default_zig_zag_mask generated with: 62 63 void vp8_init_scan_order_mask() 64 { 65 int i; 66 67 for (i = 0; i < 16; i++) 68 { 69 vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i; 70 } 71 72 } 73 */ 74 DECLARE_ALIGNED(16, const short, vp8_default_zig_zag_mask[16]) = 75 { 76 1, 2, 32, 64, 77 4, 16, 128, 4096, 78 8, 256, 2048, 8192, 79 512, 1024, 16384, -32768 80 }; 81 82 const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6}; 83 84 /* Array indices are identical to previously-existing CONTEXT_NODE indices */ 85 86 const vp8_tree_index vp8_coef_tree[ 22] = /* corresponding _CONTEXT_NODEs */ 87 { 88 -DCT_EOB_TOKEN, 2, /* 0 = EOB */ 89 -ZERO_TOKEN, 4, /* 1 = ZERO */ 90 -ONE_TOKEN, 6, /* 2 = ONE */ 91 8, 12, /* 3 = LOW_VAL */ 92 -TWO_TOKEN, 10, /* 4 = TWO */ 93 -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */ 94 14, 16, /* 6 = HIGH_LOW */ 95 -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */ 96 18, 20, /* 8 = CAT_THREEFOUR */ 97 -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */ 98 -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */ 99 }; 100 101 /* vp8_coef_encodings generated with: 102 vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree); 103 */ 104 vp8_token vp8_coef_encodings[MAX_ENTROPY_TOKENS] = 105 { 106 {2, 2}, 107 {6, 3}, 108 {28, 5}, 109 {58, 6}, 110 {59, 6}, 111 {60, 6}, 112 {61, 6}, 113 {124, 7}, 114 {125, 7}, 115 {126, 7}, 116 {127, 7}, 117 {0, 1} 118 }; 119 120 /* Trees for extra bits. Probabilities are constant and 121 do not depend on previously encoded bits */ 122 123 static const vp8_prob Pcat1[] = { 159}; 124 static const vp8_prob Pcat2[] = { 165, 145}; 125 static const vp8_prob Pcat3[] = { 173, 148, 140}; 126 static const vp8_prob Pcat4[] = { 176, 155, 140, 135}; 127 static const vp8_prob Pcat5[] = { 180, 157, 141, 134, 130}; 128 static const vp8_prob Pcat6[] = 129 { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129}; 130 131 132 /* tree index tables generated with: 133 134 void init_bit_tree(vp8_tree_index *p, int n) 135 { 136 int i = 0; 137 138 while (++i < n) 139 { 140 p[0] = p[1] = i << 1; 141 p += 2; 142 } 143 144 p[0] = p[1] = 0; 145 } 146 147 void init_bit_trees() 148 { 149 init_bit_tree(cat1, 1); 150 init_bit_tree(cat2, 2); 151 init_bit_tree(cat3, 3); 152 init_bit_tree(cat4, 4); 153 init_bit_tree(cat5, 5); 154 init_bit_tree(cat6, 11); 155 } 156 */ 157 158 static const vp8_tree_index cat1[2] = { 0, 0 }; 159 static const vp8_tree_index cat2[4] = { 2, 2, 0, 0 }; 160 static const vp8_tree_index cat3[6] = { 2, 2, 4, 4, 0, 0 }; 161 static const vp8_tree_index cat4[8] = { 2, 2, 4, 4, 6, 6, 0, 0 }; 162 static const vp8_tree_index cat5[10] = { 2, 2, 4, 4, 6, 6, 8, 8, 0, 0 }; 163 static const vp8_tree_index cat6[22] = { 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 164 14, 14, 16, 16, 18, 18, 20, 20, 0, 0 }; 165 166 const vp8_extra_bit_struct vp8_extra_bits[12] = 167 { 168 { 0, 0, 0, 0}, 169 { 0, 0, 0, 1}, 170 { 0, 0, 0, 2}, 171 { 0, 0, 0, 3}, 172 { 0, 0, 0, 4}, 173 { cat1, Pcat1, 1, 5}, 174 { cat2, Pcat2, 2, 7}, 175 { cat3, Pcat3, 3, 11}, 176 { cat4, Pcat4, 4, 19}, 177 { cat5, Pcat5, 5, 35}, 178 { cat6, Pcat6, 11, 67}, 179 { 0, 0, 0, 0} 180 }; 181 182 #include "default_coef_probs.h" 183 184 void vp8_default_coef_probs(VP8_COMMON *pc) 185 { 186 vpx_memcpy(pc->fc.coef_probs, default_coef_probs, 187 sizeof(default_coef_probs)); 188 } 189 190