| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 Copyright (c) 2010 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_entropy.h" | 11 #include "vp9/common/vp9_entropy.h" |
| 12 | 12 |
| 13 #include "vp9/decoder/vp9_dsubexp.h" | 13 #include "vp9/decoder/vp9_dsubexp.h" |
| 14 | 14 |
| 15 static int inv_recenter_nonneg(int v, int m) { | 15 static int inv_recenter_nonneg(int v, int m) { |
| 16 if (v > 2 * m) | 16 if (v > 2 * m) |
| 17 return v; | 17 return v; |
| 18 | 18 |
| 19 return v % 2 ? m - (v + 1) / 2 : m + v / 2; | 19 return v % 2 ? m - (v + 1) / 2 : m + v / 2; |
| 20 } | 20 } |
| 21 | 21 |
| 22 static int decode_uniform(vp9_reader *r, int n) { | 22 static int decode_uniform(vp9_reader *r) { |
| 23 int v; | 23 const int l = 8; |
| 24 const int l = get_unsigned_bits(n); | 24 const int m = (1 << l) - 191; |
| 25 const int m = (1 << l) - n; | 25 const int v = vp9_read_literal(r, l - 1); |
| 26 if (!l) | |
| 27 return 0; | |
| 28 | |
| 29 v = vp9_read_literal(r, l - 1); | |
| 30 return v < m ? v : (v << 1) - m + vp9_read_bit(r); | 26 return v < m ? v : (v << 1) - m + vp9_read_bit(r); |
| 31 } | 27 } |
| 32 | 28 |
| 33 | 29 |
| 34 static int merge_index(int v, int n, int modulus) { | 30 static int merge_index(int v, int n, int modulus) { |
| 35 int max1 = (n - 1 - modulus / 2) / modulus + 1; | 31 int max1 = (n - 1 - modulus / 2) / modulus + 1; |
| 36 if (v < max1) { | 32 if (v < max1) { |
| 37 v = v * modulus + modulus / 2; | 33 v = v * modulus + modulus / 2; |
| 38 } else { | 34 } else { |
| 39 int w; | 35 int w; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 v = clamp(v, 0, 253); | 67 v = clamp(v, 0, 253); |
| 72 v = inv_map_table[v]; | 68 v = inv_map_table[v]; |
| 73 m--; | 69 m--; |
| 74 if ((m << 1) <= MAX_PROB) { | 70 if ((m << 1) <= MAX_PROB) { |
| 75 return 1 + inv_recenter_nonneg(v + 1, m); | 71 return 1 + inv_recenter_nonneg(v + 1, m); |
| 76 } else { | 72 } else { |
| 77 return MAX_PROB - inv_recenter_nonneg(v + 1, MAX_PROB - 1 - m); | 73 return MAX_PROB - inv_recenter_nonneg(v + 1, MAX_PROB - 1 - m); |
| 78 } | 74 } |
| 79 } | 75 } |
| 80 | 76 |
| 81 static int decode_term_subexp(vp9_reader *r, int k, int num_syms) { | 77 static int decode_term_subexp(vp9_reader *r) { |
| 82 int i = 0, mk = 0, word; | 78 if (!vp9_read_bit(r)) |
| 83 while (1) { | 79 return vp9_read_literal(r, 4); |
| 84 const int b = i ? k + i - 1 : k; | 80 if (!vp9_read_bit(r)) |
| 85 const int a = 1 << b; | 81 return vp9_read_literal(r, 4) + 16; |
| 86 if (num_syms <= mk + 3 * a) { | 82 if (!vp9_read_bit(r)) |
| 87 word = decode_uniform(r, num_syms - mk) + mk; | 83 return vp9_read_literal(r, 5) + 32; |
| 88 break; | 84 return decode_uniform(r) + 64; |
| 89 } else { | |
| 90 if (vp9_read_bit(r)) { | |
| 91 i++; | |
| 92 mk += a; | |
| 93 } else { | |
| 94 word = vp9_read_literal(r, b) + mk; | |
| 95 break; | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 return word; | |
| 100 } | 85 } |
| 101 | 86 |
| 102 void vp9_diff_update_prob(vp9_reader *r, vp9_prob* p) { | 87 void vp9_diff_update_prob(vp9_reader *r, vp9_prob* p) { |
| 103 if (vp9_read(r, DIFF_UPDATE_PROB)) { | 88 if (vp9_read(r, DIFF_UPDATE_PROB)) { |
| 104 const int delp = decode_term_subexp(r, SUBEXP_PARAM, 255); | 89 const int delp = decode_term_subexp(r); |
| 105 *p = (vp9_prob)inv_remap_prob(delp, *p); | 90 *p = (vp9_prob)inv_remap_prob(delp, *p); |
| 106 } | 91 } |
| 107 } | 92 } |
| OLD | NEW |