OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "vp9/common/vp9_common.h" | 11 #include "vp9/common/vp9_common.h" |
12 #include "vp9/common/vp9_entropy.h" | 12 #include "vp9/common/vp9_entropy.h" |
13 | 13 |
14 #include "vp9/encoder/vp9_cost.h" | 14 #include "vp9/encoder/vp9_cost.h" |
15 #include "vp9/encoder/vp9_writer.h" | 15 #include "vp9/encoder/vp9_writer.h" |
16 | 16 |
17 #define vp9_cost_upd256 ((int)(vp9_cost_one(upd) - vp9_cost_zero(upd))) | 17 #define vp9_cost_upd256 ((int)(vp9_cost_one(upd) - vp9_cost_zero(upd))) |
18 | 18 |
19 static int update_bits[255]; | 19 static const int update_bits[255] = { |
| 20 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 21 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 22 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 23 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 24 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
| 25 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
| 26 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
| 27 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
| 28 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 29 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 30 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 31 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 32 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 33 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 34 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 35 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 0, |
| 36 }; |
20 | 37 |
21 static int recenter_nonneg(int v, int m) { | 38 static int recenter_nonneg(int v, int m) { |
22 if (v > (m << 1)) | 39 if (v > (m << 1)) |
23 return v; | 40 return v; |
24 else if (v >= m) | 41 else if (v >= m) |
25 return ((v - m) << 1); | 42 return ((v - m) << 1); |
26 else | 43 else |
27 return ((m - v) << 1) - 1; | 44 return ((m - v) << 1) - 1; |
28 } | 45 } |
29 | 46 |
(...skipping 24 matching lines...) Expand all Loading... |
54 m--; | 71 m--; |
55 if ((m << 1) <= MAX_PROB) | 72 if ((m << 1) <= MAX_PROB) |
56 i = recenter_nonneg(v, m) - 1; | 73 i = recenter_nonneg(v, m) - 1; |
57 else | 74 else |
58 i = recenter_nonneg(MAX_PROB - 1 - v, MAX_PROB - 1 - m) - 1; | 75 i = recenter_nonneg(MAX_PROB - 1 - v, MAX_PROB - 1 - m) - 1; |
59 | 76 |
60 i = map_table[i]; | 77 i = map_table[i]; |
61 return i; | 78 return i; |
62 } | 79 } |
63 | 80 |
64 static int count_term_subexp(int word) { | |
65 if (word < 16) | |
66 return 5; | |
67 if (word < 32) | |
68 return 6; | |
69 if (word < 64) | |
70 return 8; | |
71 if (word < 129) | |
72 return 10; | |
73 return 11; | |
74 } | |
75 | |
76 static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) { | 81 static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) { |
77 int delp = remap_prob(newp, oldp); | 82 int delp = remap_prob(newp, oldp); |
78 return update_bits[delp] * 256; | 83 return update_bits[delp] * 256; |
79 } | 84 } |
80 | 85 |
81 static void encode_uniform(vp9_writer *w, int v) { | 86 static void encode_uniform(vp9_writer *w, int v) { |
82 const int l = 8; | 87 const int l = 8; |
83 const int m = (1 << l) - 191; | 88 const int m = (1 << l) - 191; |
84 if (v < m) { | 89 if (v < m) { |
85 vp9_write_literal(w, v, l - 1); | 90 vp9_write_literal(w, v, l - 1); |
(...skipping 18 matching lines...) Expand all Loading... |
104 } else { | 109 } else { |
105 encode_uniform(w, word - 64); | 110 encode_uniform(w, word - 64); |
106 } | 111 } |
107 } | 112 } |
108 | 113 |
109 void vp9_write_prob_diff_update(vp9_writer *w, vp9_prob newp, vp9_prob oldp) { | 114 void vp9_write_prob_diff_update(vp9_writer *w, vp9_prob newp, vp9_prob oldp) { |
110 const int delp = remap_prob(newp, oldp); | 115 const int delp = remap_prob(newp, oldp); |
111 encode_term_subexp(w, delp); | 116 encode_term_subexp(w, delp); |
112 } | 117 } |
113 | 118 |
114 void vp9_compute_update_table() { | |
115 int i; | |
116 for (i = 0; i < 254; i++) | |
117 update_bits[i] = count_term_subexp(i); | |
118 } | |
119 | |
120 int vp9_prob_diff_update_savings_search(const unsigned int *ct, | 119 int vp9_prob_diff_update_savings_search(const unsigned int *ct, |
121 vp9_prob oldp, vp9_prob *bestp, | 120 vp9_prob oldp, vp9_prob *bestp, |
122 vp9_prob upd) { | 121 vp9_prob upd) { |
123 const int old_b = cost_branch256(ct, oldp); | 122 const int old_b = cost_branch256(ct, oldp); |
124 int bestsavings = 0; | 123 int bestsavings = 0; |
125 vp9_prob newp, bestnewp = oldp; | 124 vp9_prob newp, bestnewp = oldp; |
126 const int step = *bestp > oldp ? -1 : 1; | 125 const int step = *bestp > oldp ? -1 : 1; |
127 | 126 |
128 for (newp = *bestp; newp != oldp; newp += step) { | 127 for (newp = *bestp; newp != oldp; newp += step) { |
129 const int new_b = cost_branch256(ct, newp); | 128 const int new_b = cost_branch256(ct, newp); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 upd); | 183 upd); |
185 assert(newp >= 1); | 184 assert(newp >= 1); |
186 if (savings > 0) { | 185 if (savings > 0) { |
187 vp9_write(w, 1, upd); | 186 vp9_write(w, 1, upd); |
188 vp9_write_prob_diff_update(w, newp, *oldp); | 187 vp9_write_prob_diff_update(w, newp, *oldp); |
189 *oldp = newp; | 188 *oldp = newp; |
190 } else { | 189 } else { |
191 vp9_write(w, 0, upd); | 190 vp9_write(w, 0, upd); |
192 } | 191 } |
193 } | 192 } |
OLD | NEW |