Merge "keep values in registers during quantization"
[libvpx.git] / vp8 / common / entropy.c
bloba1fe4f4ab97aaff6b731942775d224d6ac2189ef
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 <stdio.h>
14 #include "entropy.h"
15 #include "string.h"
16 #include "blockd.h"
17 #include "onyxc_int.h"
19 #define uchar unsigned char /* typedefs can clash */
20 #define uint unsigned int
22 typedef const uchar cuchar;
23 typedef const uint cuint;
25 typedef vp8_prob Prob;
27 #include "coefupdateprobs.h"
29 DECLARE_ALIGNED(16, cuchar, vp8_coef_bands[16]) = { 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7};
30 DECLARE_ALIGNED(16, cuchar, vp8_prev_token_class[MAX_ENTROPY_TOKENS]) = { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0};
31 DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]) =
33 0, 1, 4, 8,
34 5, 2, 3, 6,
35 9, 12, 13, 10,
36 7, 11, 14, 15,
39 DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) =
41 1, 2, 6, 7,
42 3, 5, 8, 13,
43 4, 9, 12, 14,
44 10, 11, 15, 16
47 DECLARE_ALIGNED(16, short, vp8_default_zig_zag_mask[16]);
49 const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6};
51 /* Array indices are identical to previously-existing CONTEXT_NODE indices */
53 const vp8_tree_index vp8_coef_tree[ 22] = /* corresponding _CONTEXT_NODEs */
55 -DCT_EOB_TOKEN, 2, /* 0 = EOB */
56 -ZERO_TOKEN, 4, /* 1 = ZERO */
57 -ONE_TOKEN, 6, /* 2 = ONE */
58 8, 12, /* 3 = LOW_VAL */
59 -TWO_TOKEN, 10, /* 4 = TWO */
60 -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */
61 14, 16, /* 6 = HIGH_LOW */
62 -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */
63 18, 20, /* 8 = CAT_THREEFOUR */
64 -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */
65 -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */
68 struct vp8_token_struct vp8_coef_encodings[vp8_coef_tokens];
70 /* Trees for extra bits. Probabilities are constant and
71 do not depend on previously encoded bits */
73 static const Prob Pcat1[] = { 159};
74 static const Prob Pcat2[] = { 165, 145};
75 static const Prob Pcat3[] = { 173, 148, 140};
76 static const Prob Pcat4[] = { 176, 155, 140, 135};
77 static const Prob Pcat5[] = { 180, 157, 141, 134, 130};
78 static const Prob Pcat6[] =
79 { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129};
81 static vp8_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[22];
83 void vp8_init_scan_order_mask()
85 int i;
87 for (i = 0; i < 16; i++)
89 vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i;
94 static void init_bit_tree(vp8_tree_index *p, int n)
96 int i = 0;
98 while (++i < n)
100 p[0] = p[1] = i << 1;
101 p += 2;
104 p[0] = p[1] = 0;
107 static void init_bit_trees()
109 init_bit_tree(cat1, 1);
110 init_bit_tree(cat2, 2);
111 init_bit_tree(cat3, 3);
112 init_bit_tree(cat4, 4);
113 init_bit_tree(cat5, 5);
114 init_bit_tree(cat6, 11);
117 vp8_extra_bit_struct vp8_extra_bits[12] =
119 { 0, 0, 0, 0},
120 { 0, 0, 0, 1},
121 { 0, 0, 0, 2},
122 { 0, 0, 0, 3},
123 { 0, 0, 0, 4},
124 { cat1, Pcat1, 1, 5},
125 { cat2, Pcat2, 2, 7},
126 { cat3, Pcat3, 3, 11},
127 { cat4, Pcat4, 4, 19},
128 { cat5, Pcat5, 5, 35},
129 { cat6, Pcat6, 11, 67},
130 { 0, 0, 0, 0}
132 #include "defaultcoefcounts.h"
134 void vp8_default_coef_probs(VP8_COMMON *pc)
136 int h = 0;
140 int i = 0;
144 int k = 0;
148 unsigned int branch_ct [vp8_coef_tokens-1] [2];
149 vp8_tree_probs_from_distribution(
150 vp8_coef_tokens, vp8_coef_encodings, vp8_coef_tree,
151 pc->fc.coef_probs [h][i][k], branch_ct, default_coef_counts [h][i][k],
152 256, 1);
155 while (++k < PREV_COEF_CONTEXTS);
157 while (++i < COEF_BANDS);
159 while (++h < BLOCK_TYPES);
163 void vp8_coef_tree_initialize()
165 init_bit_trees();
166 vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree);