blob: f3d5a9cb7e021135793edeef726f8f7402df50da [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
John Koleszarc2140b82010-09-09 08:16:39 -04002 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
John Koleszar94c52e42010-06-18 12:39:21 -04004 * Use of this source code is governed by a BSD-style license
John Koleszar09202d82010-06-04 16:19:40 -04005 * 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
John Koleszar94c52e42010-06-18 12:39:21 -04007 * in the file PATENTS. All contributing project authors may
John Koleszar09202d82010-06-04 16:19:40 -04008 * be found in the AUTHORS file in the root of the source tree.
John Koleszar0ea50ce2010-05-18 11:58:33 -04009 */
10
11
12#include <stdio.h>
13
14#include "entropy.h"
15#include "string.h"
16#include "blockd.h"
17#include "onyxc_int.h"
Scott LaVarnway19987dc2011-08-16 16:21:21 -040018#include "vpx_mem/vpx_mem.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040019
20#define uchar unsigned char /* typedefs can clash */
21#define uint unsigned int
22
23typedef const uchar cuchar;
24typedef const uint cuint;
25
26typedef vp8_prob Prob;
27
28#include "coefupdateprobs.h"
29
Scott LaVarnwaya25f6a92011-07-19 09:17:25 -040030DECLARE_ALIGNED(16, const unsigned char, vp8_norm[256]) =
31{
32 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
33 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
34 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
35 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
36 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
48};
49
50DECLARE_ALIGNED(16, cuchar, vp8_coef_bands[16]) =
51{ 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7};
52
53DECLARE_ALIGNED(16, cuchar, vp8_prev_token_class[MAX_ENTROPY_TOKENS]) =
54{ 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0};
55
John Koleszar0ea50ce2010-05-18 11:58:33 -040056DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]) =
57{
58 0, 1, 4, 8,
59 5, 2, 3, 6,
60 9, 12, 13, 10,
61 7, 11, 14, 15,
62};
63
Johann825adc42010-12-14 09:35:18 -050064DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) =
Fritz Koenige0cf3302010-12-09 15:00:30 -080065{
66 1, 2, 6, 7,
67 3, 5, 8, 13,
68 4, 9, 12, 14,
69 10, 11, 15, 16
70};
71
John Koleszar0ea50ce2010-05-18 11:58:33 -040072DECLARE_ALIGNED(16, short, vp8_default_zig_zag_mask[16]);
73
74const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6};
75
76/* Array indices are identical to previously-existing CONTEXT_NODE indices */
77
78const vp8_tree_index vp8_coef_tree[ 22] = /* corresponding _CONTEXT_NODEs */
79{
80 -DCT_EOB_TOKEN, 2, /* 0 = EOB */
81 -ZERO_TOKEN, 4, /* 1 = ZERO */
82 -ONE_TOKEN, 6, /* 2 = ONE */
83 8, 12, /* 3 = LOW_VAL */
84 -TWO_TOKEN, 10, /* 4 = TWO */
85 -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */
86 14, 16, /* 6 = HIGH_LOW */
87 -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */
88 18, 20, /* 8 = CAT_THREEFOUR */
89 -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */
90 -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */
91};
92
John Koleszarb32da7c2011-06-28 17:03:47 -040093struct vp8_token_struct vp8_coef_encodings[MAX_ENTROPY_TOKENS];
John Koleszar0ea50ce2010-05-18 11:58:33 -040094
95/* Trees for extra bits. Probabilities are constant and
96 do not depend on previously encoded bits */
97
98static const Prob Pcat1[] = { 159};
99static const Prob Pcat2[] = { 165, 145};
100static const Prob Pcat3[] = { 173, 148, 140};
101static const Prob Pcat4[] = { 176, 155, 140, 135};
102static const Prob Pcat5[] = { 180, 157, 141, 134, 130};
103static const Prob Pcat6[] =
104{ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129};
105
106static vp8_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[22];
107
108void vp8_init_scan_order_mask()
109{
110 int i;
111
112 for (i = 0; i < 16; i++)
113 {
114 vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i;
115 }
116
117}
118
119static void init_bit_tree(vp8_tree_index *p, int n)
120{
121 int i = 0;
122
123 while (++i < n)
124 {
125 p[0] = p[1] = i << 1;
126 p += 2;
127 }
128
129 p[0] = p[1] = 0;
130}
131
132static void init_bit_trees()
133{
134 init_bit_tree(cat1, 1);
135 init_bit_tree(cat2, 2);
136 init_bit_tree(cat3, 3);
137 init_bit_tree(cat4, 4);
138 init_bit_tree(cat5, 5);
139 init_bit_tree(cat6, 11);
140}
141
John Koleszar0ea50ce2010-05-18 11:58:33 -0400142vp8_extra_bit_struct vp8_extra_bits[12] =
143{
Johann825adc42010-12-14 09:35:18 -0500144 { 0, 0, 0, 0},
145 { 0, 0, 0, 1},
146 { 0, 0, 0, 2},
147 { 0, 0, 0, 3},
148 { 0, 0, 0, 4},
149 { cat1, Pcat1, 1, 5},
150 { cat2, Pcat2, 2, 7},
151 { cat3, Pcat3, 3, 11},
152 { cat4, Pcat4, 4, 19},
153 { cat5, Pcat5, 5, 35},
154 { cat6, Pcat6, 11, 67},
155 { 0, 0, 0, 0}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400156};
Scott LaVarnway19987dc2011-08-16 16:21:21 -0400157
158#include "default_coef_probs.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400159
160void vp8_default_coef_probs(VP8_COMMON *pc)
161{
Scott LaVarnway19987dc2011-08-16 16:21:21 -0400162 vpx_memcpy(pc->fc.coef_probs, default_coef_probs,
163 sizeof(default_coef_probs));
John Koleszar0ea50ce2010-05-18 11:58:33 -0400164}
165
John Koleszar0ea50ce2010-05-18 11:58:33 -0400166void vp8_coef_tree_initialize()
167{
168 init_bit_trees();
169 vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree);
170}