| 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 | 11 |
| 12 #ifndef VP8_ENCODER_TREEWRITER_H_ | 12 #ifndef VP8_ENCODER_TREEWRITER_H_ |
| 13 #define VP8_ENCODER_TREEWRITER_H_ | 13 #define VP8_ENCODER_TREEWRITER_H_ |
| 14 | 14 |
| 15 /* Trees map alphabets into huffman-like codes suitable for an arithmetic | 15 /* Trees map alphabets into huffman-like codes suitable for an arithmetic |
| 16 bit coder. Timothy S Murphy 11 October 2004 */ | 16 bit coder. Timothy S Murphy 11 October 2004 */ |
| 17 | 17 |
| 18 #include "./vpx_config.h" |
| 18 #include "vp8/common/treecoder.h" | 19 #include "vp8/common/treecoder.h" |
| 19 | 20 |
| 20 #include "boolhuff.h" /* for now */ | 21 #include "boolhuff.h" /* for now */ |
| 21 | 22 |
| 22 #ifdef __cplusplus | 23 #ifdef __cplusplus |
| 23 extern "C" { | 24 extern "C" { |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 typedef BOOL_CODER vp8_writer; | 27 typedef BOOL_CODER vp8_writer; |
| 27 | 28 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 #define vp8_cost_zero( x) ( vp8_prob_cost[x]) | 40 #define vp8_cost_zero( x) ( vp8_prob_cost[x]) |
| 40 #define vp8_cost_one( x) vp8_cost_zero( vp8_complement(x)) | 41 #define vp8_cost_one( x) vp8_cost_zero( vp8_complement(x)) |
| 41 | 42 |
| 42 #define vp8_cost_bit( x, b) vp8_cost_zero( (b)? vp8_complement(x) : (x) ) | 43 #define vp8_cost_bit( x, b) vp8_cost_zero( (b)? vp8_complement(x) : (x) ) |
| 43 | 44 |
| 44 /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */ | 45 /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */ |
| 45 | 46 |
| 46 | 47 |
| 47 /* Both of these return bits, not scaled bits. */ | 48 /* Both of these return bits, not scaled bits. */ |
| 48 | 49 |
| 49 static unsigned int vp8_cost_branch(const unsigned int ct[2], vp8_prob p) | 50 static INLINE unsigned int vp8_cost_branch(const unsigned int ct[2], vp8_prob p) |
| 50 { | 51 { |
| 51 /* Imitate existing calculation */ | 52 /* Imitate existing calculation */ |
| 52 | 53 |
| 53 return ((ct[0] * vp8_cost_zero(p)) | 54 return ((ct[0] * vp8_cost_zero(p)) |
| 54 + (ct[1] * vp8_cost_one(p))) >> 8; | 55 + (ct[1] * vp8_cost_one(p))) >> 8; |
| 55 } | 56 } |
| 56 | 57 |
| 57 /* Small functions to write explicit values and tokens, as well as | 58 /* Small functions to write explicit values and tokens, as well as |
| 58 estimate their lengths. */ | 59 estimate their lengths. */ |
| 59 | 60 |
| 60 static void vp8_treed_write | 61 static void vp8_treed_write |
| 61 ( | 62 ( |
| 62 vp8_writer *const w, | 63 vp8_writer *const w, |
| 63 vp8_tree t, | 64 vp8_tree t, |
| 64 const vp8_prob *const p, | 65 const vp8_prob *const p, |
| 65 int v, | 66 int v, |
| 66 int n /* number of bits in v, assumed nonzero */ | 67 int n /* number of bits in v, assumed nonzero */ |
| 67 ) | 68 ) |
| 68 { | 69 { |
| 69 vp8_tree_index i = 0; | 70 vp8_tree_index i = 0; |
| 70 | 71 |
| 71 do | 72 do |
| 72 { | 73 { |
| 73 const int b = (v >> --n) & 1; | 74 const int b = (v >> --n) & 1; |
| 74 vp8_write(w, b, p[i>>1]); | 75 vp8_write(w, b, p[i>>1]); |
| 75 i = t[i+b]; | 76 i = t[i+b]; |
| 76 } | 77 } |
| 77 while (n); | 78 while (n); |
| 78 } | 79 } |
| 79 static void vp8_write_token | 80 static INLINE void vp8_write_token |
| 80 ( | 81 ( |
| 81 vp8_writer *const w, | 82 vp8_writer *const w, |
| 82 vp8_tree t, | 83 vp8_tree t, |
| 83 const vp8_prob *const p, | 84 const vp8_prob *const p, |
| 84 vp8_token *const x | 85 vp8_token *const x |
| 85 ) | 86 ) |
| 86 { | 87 { |
| 87 vp8_treed_write(w, t, p, x->value, x->Len); | 88 vp8_treed_write(w, t, p, x->value, x->Len); |
| 88 } | 89 } |
| 89 | 90 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 do | 101 do |
| 101 { | 102 { |
| 102 const int b = (v >> --n) & 1; | 103 const int b = (v >> --n) & 1; |
| 103 c += vp8_cost_bit(p[i>>1], b); | 104 c += vp8_cost_bit(p[i>>1], b); |
| 104 i = t[i+b]; | 105 i = t[i+b]; |
| 105 } | 106 } |
| 106 while (n); | 107 while (n); |
| 107 | 108 |
| 108 return c; | 109 return c; |
| 109 } | 110 } |
| 110 static int vp8_cost_token | 111 static INLINE int vp8_cost_token |
| 111 ( | 112 ( |
| 112 vp8_tree t, | 113 vp8_tree t, |
| 113 const vp8_prob *const p, | 114 const vp8_prob *const p, |
| 114 vp8_token *const x | 115 vp8_token *const x |
| 115 ) | 116 ) |
| 116 { | 117 { |
| 117 return vp8_treed_cost(t, p, x->value, x->Len); | 118 return vp8_treed_cost(t, p, x->value, x->Len); |
| 118 } | 119 } |
| 119 | 120 |
| 120 /* Fill array of costs for all possible token values. */ | 121 /* Fill array of costs for all possible token values. */ |
| 121 | 122 |
| 122 void vp8_cost_tokens( | 123 void vp8_cost_tokens( |
| 123 int *Costs, const vp8_prob *, vp8_tree | 124 int *Costs, const vp8_prob *, vp8_tree |
| 124 ); | 125 ); |
| 125 | 126 |
| 126 void vp8_cost_tokens2( | 127 void vp8_cost_tokens2( |
| 127 int *Costs, const vp8_prob *, vp8_tree, int | 128 int *Costs, const vp8_prob *, vp8_tree, int |
| 128 ); | 129 ); |
| 129 | 130 |
| 130 #ifdef __cplusplus | 131 #ifdef __cplusplus |
| 131 } // extern "C" | 132 } // extern "C" |
| 132 #endif | 133 #endif |
| 133 | 134 |
| 134 #endif // VP8_ENCODER_TREEWRITER_H_ | 135 #endif // VP8_ENCODER_TREEWRITER_H_ |
| OLD | NEW |