John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 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 |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 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 LaVarnway | 19987dc | 2011-08-16 16:21:21 -0400 | [diff] [blame] | 18 | #include "vpx_mem/vpx_mem.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 19 | |
| 20 | #define uchar unsigned char /* typedefs can clash */ |
| 21 | #define uint unsigned int |
| 22 | |
| 23 | typedef const uchar cuchar; |
| 24 | typedef const uint cuint; |
| 25 | |
| 26 | typedef vp8_prob Prob; |
| 27 | |
| 28 | #include "coefupdateprobs.h" |
| 29 | |
Scott LaVarnway | a25f6a9 | 2011-07-19 09:17:25 -0400 | [diff] [blame] | 30 | DECLARE_ALIGNED(16, const unsigned char, vp8_norm[256]) = |
| 31 | { |
| 32 | 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4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 | { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}; |
| 55 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 56 | DECLARE_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 | |
Johann | 825adc4 | 2010-12-14 09:35:18 -0500 | [diff] [blame] | 64 | DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) = |
Fritz Koenig | e0cf330 | 2010-12-09 15:00:30 -0800 | [diff] [blame] | 65 | { |
| 66 | 1, 2, 6, 7, |
| 67 | 3, 5, 8, 13, |
| 68 | 4, 9, 12, 14, |
| 69 | 10, 11, 15, 16 |
| 70 | }; |
| 71 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 72 | DECLARE_ALIGNED(16, short, vp8_default_zig_zag_mask[16]); |
| 73 | |
| 74 | const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6}; |
| 75 | |
| 76 | /* Array indices are identical to previously-existing CONTEXT_NODE indices */ |
| 77 | |
| 78 | const 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 Koleszar | b32da7c | 2011-06-28 17:03:47 -0400 | [diff] [blame] | 93 | struct vp8_token_struct vp8_coef_encodings[MAX_ENTROPY_TOKENS]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 94 | |
| 95 | /* Trees for extra bits. Probabilities are constant and |
| 96 | do not depend on previously encoded bits */ |
| 97 | |
| 98 | static const Prob Pcat1[] = { 159}; |
| 99 | static const Prob Pcat2[] = { 165, 145}; |
| 100 | static const Prob Pcat3[] = { 173, 148, 140}; |
| 101 | static const Prob Pcat4[] = { 176, 155, 140, 135}; |
| 102 | static const Prob Pcat5[] = { 180, 157, 141, 134, 130}; |
| 103 | static const Prob Pcat6[] = |
| 104 | { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129}; |
| 105 | |
| 106 | static vp8_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[22]; |
| 107 | |
| 108 | void 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 | |
| 119 | static 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 | |
| 132 | static 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 Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 142 | vp8_extra_bit_struct vp8_extra_bits[12] = |
| 143 | { |
Johann | 825adc4 | 2010-12-14 09:35:18 -0500 | [diff] [blame] | 144 | { 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 Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 156 | }; |
Scott LaVarnway | 19987dc | 2011-08-16 16:21:21 -0400 | [diff] [blame] | 157 | |
| 158 | #include "default_coef_probs.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 159 | |
| 160 | void vp8_default_coef_probs(VP8_COMMON *pc) |
| 161 | { |
Scott LaVarnway | 19987dc | 2011-08-16 16:21:21 -0400 | [diff] [blame] | 162 | vpx_memcpy(pc->fc.coef_probs, default_coef_probs, |
| 163 | sizeof(default_coef_probs)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 164 | } |
| 165 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 166 | void vp8_coef_tree_initialize() |
| 167 | { |
| 168 | init_bit_trees(); |
| 169 | vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree); |
| 170 | } |