Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | #ifndef __INC_TREEWRITER_H |
michael@0 | 13 | #define __INC_TREEWRITER_H |
michael@0 | 14 | |
michael@0 | 15 | /* Trees map alphabets into huffman-like codes suitable for an arithmetic |
michael@0 | 16 | bit coder. Timothy S Murphy 11 October 2004 */ |
michael@0 | 17 | |
michael@0 | 18 | #include "vp8/common/treecoder.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "boolhuff.h" /* for now */ |
michael@0 | 21 | |
michael@0 | 22 | typedef BOOL_CODER vp8_writer; |
michael@0 | 23 | |
michael@0 | 24 | #define vp8_write vp8_encode_bool |
michael@0 | 25 | #define vp8_write_literal vp8_encode_value |
michael@0 | 26 | #define vp8_write_bit( W, V) vp8_write( W, V, vp8_prob_half) |
michael@0 | 27 | |
michael@0 | 28 | #define vp8bc_write vp8bc_write_bool |
michael@0 | 29 | #define vp8bc_write_literal vp8bc_write_bits |
michael@0 | 30 | #define vp8bc_write_bit( W, V) vp8bc_write_bits( W, V, 1) |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | /* Approximate length of an encoded bool in 256ths of a bit at given prob */ |
michael@0 | 34 | |
michael@0 | 35 | #define vp8_cost_zero( x) ( vp8_prob_cost[x]) |
michael@0 | 36 | #define vp8_cost_one( x) vp8_cost_zero( vp8_complement(x)) |
michael@0 | 37 | |
michael@0 | 38 | #define vp8_cost_bit( x, b) vp8_cost_zero( (b)? vp8_complement(x) : (x) ) |
michael@0 | 39 | |
michael@0 | 40 | /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */ |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | /* Both of these return bits, not scaled bits. */ |
michael@0 | 44 | |
michael@0 | 45 | static unsigned int vp8_cost_branch(const unsigned int ct[2], vp8_prob p) |
michael@0 | 46 | { |
michael@0 | 47 | /* Imitate existing calculation */ |
michael@0 | 48 | |
michael@0 | 49 | return ((ct[0] * vp8_cost_zero(p)) |
michael@0 | 50 | + (ct[1] * vp8_cost_one(p))) >> 8; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | /* Small functions to write explicit values and tokens, as well as |
michael@0 | 54 | estimate their lengths. */ |
michael@0 | 55 | |
michael@0 | 56 | static void vp8_treed_write |
michael@0 | 57 | ( |
michael@0 | 58 | vp8_writer *const w, |
michael@0 | 59 | vp8_tree t, |
michael@0 | 60 | const vp8_prob *const p, |
michael@0 | 61 | int v, |
michael@0 | 62 | int n /* number of bits in v, assumed nonzero */ |
michael@0 | 63 | ) |
michael@0 | 64 | { |
michael@0 | 65 | vp8_tree_index i = 0; |
michael@0 | 66 | |
michael@0 | 67 | do |
michael@0 | 68 | { |
michael@0 | 69 | const int b = (v >> --n) & 1; |
michael@0 | 70 | vp8_write(w, b, p[i>>1]); |
michael@0 | 71 | i = t[i+b]; |
michael@0 | 72 | } |
michael@0 | 73 | while (n); |
michael@0 | 74 | } |
michael@0 | 75 | static void vp8_write_token |
michael@0 | 76 | ( |
michael@0 | 77 | vp8_writer *const w, |
michael@0 | 78 | vp8_tree t, |
michael@0 | 79 | const vp8_prob *const p, |
michael@0 | 80 | vp8_token *const x |
michael@0 | 81 | ) |
michael@0 | 82 | { |
michael@0 | 83 | vp8_treed_write(w, t, p, x->value, x->Len); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | static int vp8_treed_cost( |
michael@0 | 87 | vp8_tree t, |
michael@0 | 88 | const vp8_prob *const p, |
michael@0 | 89 | int v, |
michael@0 | 90 | int n /* number of bits in v, assumed nonzero */ |
michael@0 | 91 | ) |
michael@0 | 92 | { |
michael@0 | 93 | int c = 0; |
michael@0 | 94 | vp8_tree_index i = 0; |
michael@0 | 95 | |
michael@0 | 96 | do |
michael@0 | 97 | { |
michael@0 | 98 | const int b = (v >> --n) & 1; |
michael@0 | 99 | c += vp8_cost_bit(p[i>>1], b); |
michael@0 | 100 | i = t[i+b]; |
michael@0 | 101 | } |
michael@0 | 102 | while (n); |
michael@0 | 103 | |
michael@0 | 104 | return c; |
michael@0 | 105 | } |
michael@0 | 106 | static int vp8_cost_token |
michael@0 | 107 | ( |
michael@0 | 108 | vp8_tree t, |
michael@0 | 109 | const vp8_prob *const p, |
michael@0 | 110 | vp8_token *const x |
michael@0 | 111 | ) |
michael@0 | 112 | { |
michael@0 | 113 | return vp8_treed_cost(t, p, x->value, x->Len); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | /* Fill array of costs for all possible token values. */ |
michael@0 | 117 | |
michael@0 | 118 | void vp8_cost_tokens( |
michael@0 | 119 | int *Costs, const vp8_prob *, vp8_tree |
michael@0 | 120 | ); |
michael@0 | 121 | |
michael@0 | 122 | void vp8_cost_tokens2( |
michael@0 | 123 | int *Costs, const vp8_prob *, vp8_tree, int |
michael@0 | 124 | ); |
michael@0 | 125 | |
michael@0 | 126 | #endif |