Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_subexp.c

Issue 168343002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: libvpx: Pull from upstream Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_sad_c.c ('k') | source/libvpx/vp9/encoder/vp9_temporal_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_treewriter.h" 14 #include "vp9/encoder/vp9_treewriter.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 int update_bits[255];
20 20
21 static int count_uniform(int v, int n) {
22 int l = get_unsigned_bits(n);
23 int m;
24 if (l == 0) return 0;
25 m = (1 << l) - n;
26 if (v < m)
27 return l - 1;
28 else
29 return l;
30 }
31
32 static int split_index(int i, int n, int modulus) { 21 static int split_index(int i, int n, int modulus) {
33 int max1 = (n - 1 - modulus / 2) / modulus + 1; 22 int max1 = (n - 1 - modulus / 2) / modulus + 1;
34 if (i % modulus == modulus / 2) 23 if (i % modulus == modulus / 2)
35 i = i / modulus; 24 i = i / modulus;
36 else 25 else
37 i = max1 + i - (i + modulus - modulus / 2) / modulus; 26 i = max1 + i - (i + modulus - modulus / 2) / modulus;
38 return i; 27 return i;
39 } 28 }
40 29
41 static int recenter_nonneg(int v, int m) { 30 static int recenter_nonneg(int v, int m) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 m--; 63 m--;
75 if ((m << 1) <= MAX_PROB) 64 if ((m << 1) <= MAX_PROB)
76 i = recenter_nonneg(v, m) - 1; 65 i = recenter_nonneg(v, m) - 1;
77 else 66 else
78 i = recenter_nonneg(MAX_PROB - 1 - v, MAX_PROB - 1 - m) - 1; 67 i = recenter_nonneg(MAX_PROB - 1 - v, MAX_PROB - 1 - m) - 1;
79 68
80 i = map_table[i]; 69 i = map_table[i];
81 return i; 70 return i;
82 } 71 }
83 72
84 static int count_term_subexp(int word, int k, int num_syms) { 73 static int count_term_subexp(int word) {
85 int count = 0; 74 if (word < 16)
86 int i = 0; 75 return 5;
87 int mk = 0; 76 if (word < 32)
88 while (1) { 77 return 6;
89 int b = (i ? k + i - 1 : k); 78 if (word < 64)
90 int a = (1 << b); 79 return 8;
91 if (num_syms <= mk + 3 * a) { 80 if (word < 129)
92 count += count_uniform(word - mk, num_syms - mk); 81 return 10;
93 break; 82 return 11;
94 } else {
95 int t = (word >= mk + a);
96 count++;
97 if (t) {
98 i = i + 1;
99 mk += a;
100 } else {
101 count += b;
102 break;
103 }
104 }
105 }
106 return count;
107 } 83 }
108 84
109 static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) { 85 static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) {
110 int delp = remap_prob(newp, oldp); 86 int delp = remap_prob(newp, oldp);
111 return update_bits[delp] * 256; 87 return update_bits[delp] * 256;
112 } 88 }
113 89
114 static void encode_uniform(vp9_writer *w, int v, int n) { 90 static void encode_uniform(vp9_writer *w, int v) {
115 int l = get_unsigned_bits(n); 91 const int l = 8;
116 int m; 92 const int m = (1 << l) - 191;
117 if (l == 0)
118 return;
119 m = (1 << l) - n;
120 if (v < m) { 93 if (v < m) {
121 vp9_write_literal(w, v, l - 1); 94 vp9_write_literal(w, v, l - 1);
122 } else { 95 } else {
123 vp9_write_literal(w, m + ((v - m) >> 1), l - 1); 96 vp9_write_literal(w, m + ((v - m) >> 1), l - 1);
124 vp9_write_literal(w, (v - m) & 1, 1); 97 vp9_write_literal(w, (v - m) & 1, 1);
125 } 98 }
126 } 99 }
127 100
128 static void encode_term_subexp(vp9_writer *w, int word, int k, int num_syms) { 101 static INLINE int write_bit_gte(vp9_writer *w, int word, int test) {
129 int i = 0; 102 vp9_write_literal(w, word >= test, 1);
130 int mk = 0; 103 return word >= test;
131 while (1) { 104 }
132 int b = (i ? k + i - 1 : k); 105
133 int a = (1 << b); 106 static void encode_term_subexp(vp9_writer *w, int word) {
134 if (num_syms <= mk + 3 * a) { 107 if (!write_bit_gte(w, word, 16)) {
135 encode_uniform(w, word - mk, num_syms - mk); 108 vp9_write_literal(w, word, 4);
136 break; 109 } else if (!write_bit_gte(w, word, 32)) {
137 } else { 110 vp9_write_literal(w, word - 16, 4);
138 int t = (word >= mk + a); 111 } else if (!write_bit_gte(w, word, 64)) {
139 vp9_write_literal(w, t, 1); 112 vp9_write_literal(w, word - 32, 5);
140 if (t) { 113 } else {
141 i = i + 1; 114 encode_uniform(w, word - 64);
142 mk += a;
143 } else {
144 vp9_write_literal(w, word - mk, b);
145 break;
146 }
147 }
148 } 115 }
149 } 116 }
150 117
151 void vp9_write_prob_diff_update(vp9_writer *w, vp9_prob newp, vp9_prob oldp) { 118 void vp9_write_prob_diff_update(vp9_writer *w, vp9_prob newp, vp9_prob oldp) {
152 const int delp = remap_prob(newp, oldp); 119 const int delp = remap_prob(newp, oldp);
153 encode_term_subexp(w, delp, SUBEXP_PARAM, 255); 120 encode_term_subexp(w, delp);
154 } 121 }
155 122
156 void vp9_compute_update_table() { 123 void vp9_compute_update_table() {
157 int i; 124 int i;
158 for (i = 0; i < 254; i++) 125 for (i = 0; i < 254; i++)
159 update_bits[i] = count_term_subexp(i, SUBEXP_PARAM, 255); 126 update_bits[i] = count_term_subexp(i);
160 } 127 }
161 128
162 int vp9_prob_diff_update_savings_search(const unsigned int *ct, 129 int vp9_prob_diff_update_savings_search(const unsigned int *ct,
163 vp9_prob oldp, vp9_prob *bestp, 130 vp9_prob oldp, vp9_prob *bestp,
164 vp9_prob upd) { 131 vp9_prob upd) {
165 const int old_b = cost_branch256(ct, oldp); 132 const int old_b = cost_branch256(ct, oldp);
166 int bestsavings = 0; 133 int bestsavings = 0;
167 vp9_prob newp, bestnewp = oldp; 134 vp9_prob newp, bestnewp = oldp;
168 const int step = *bestp > oldp ? -1 : 1; 135 const int step = *bestp > oldp ? -1 : 1;
169 136
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 upd); 194 upd);
228 assert(newp >= 1); 195 assert(newp >= 1);
229 if (savings > 0) { 196 if (savings > 0) {
230 vp9_write(w, 1, upd); 197 vp9_write(w, 1, upd);
231 vp9_write_prob_diff_update(w, newp, *oldp); 198 vp9_write_prob_diff_update(w, newp, *oldp);
232 *oldp = newp; 199 *oldp = newp;
233 } else { 200 } else {
234 vp9_write(w, 0, upd); 201 vp9_write(w, 0, upd);
235 } 202 }
236 } 203 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_sad_c.c ('k') | source/libvpx/vp9/encoder/vp9_temporal_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698