media/libvpx/vp8/encoder/treewriter.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

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.

     1 /*
     2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     3  *
     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
     6  *  tree. An additional intellectual property rights grant can be found
     7  *  in the file PATENTS.  All contributing project authors may
     8  *  be found in the AUTHORS file in the root of the source tree.
     9  */
    12 #ifndef __INC_TREEWRITER_H
    13 #define __INC_TREEWRITER_H
    15 /* Trees map alphabets into huffman-like codes suitable for an arithmetic
    16    bit coder.  Timothy S Murphy  11 October 2004 */
    18 #include "vp8/common/treecoder.h"
    20 #include "boolhuff.h"       /* for now */
    22 typedef BOOL_CODER vp8_writer;
    24 #define vp8_write vp8_encode_bool
    25 #define vp8_write_literal vp8_encode_value
    26 #define vp8_write_bit( W, V) vp8_write( W, V, vp8_prob_half)
    28 #define vp8bc_write vp8bc_write_bool
    29 #define vp8bc_write_literal vp8bc_write_bits
    30 #define vp8bc_write_bit( W, V) vp8bc_write_bits( W, V, 1)
    33 /* Approximate length of an encoded bool in 256ths of a bit at given prob */
    35 #define vp8_cost_zero( x) ( vp8_prob_cost[x])
    36 #define vp8_cost_one( x)  vp8_cost_zero( vp8_complement(x))
    38 #define vp8_cost_bit( x, b) vp8_cost_zero( (b)?  vp8_complement(x) : (x) )
    40 /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */
    43 /* Both of these return bits, not scaled bits. */
    45 static unsigned int vp8_cost_branch(const unsigned int ct[2], vp8_prob p)
    46 {
    47     /* Imitate existing calculation */
    49     return ((ct[0] * vp8_cost_zero(p))
    50             + (ct[1] * vp8_cost_one(p))) >> 8;
    51 }
    53 /* Small functions to write explicit values and tokens, as well as
    54    estimate their lengths. */
    56 static void vp8_treed_write
    57 (
    58     vp8_writer *const w,
    59     vp8_tree t,
    60     const vp8_prob *const p,
    61     int v,
    62     int n               /* number of bits in v, assumed nonzero */
    63 )
    64 {
    65     vp8_tree_index i = 0;
    67     do
    68     {
    69         const int b = (v >> --n) & 1;
    70         vp8_write(w, b, p[i>>1]);
    71         i = t[i+b];
    72     }
    73     while (n);
    74 }
    75 static void vp8_write_token
    76 (
    77     vp8_writer *const w,
    78     vp8_tree t,
    79     const vp8_prob *const p,
    80     vp8_token *const x
    81 )
    82 {
    83     vp8_treed_write(w, t, p, x->value, x->Len);
    84 }
    86 static int vp8_treed_cost(
    87     vp8_tree t,
    88     const vp8_prob *const p,
    89     int v,
    90     int n               /* number of bits in v, assumed nonzero */
    91 )
    92 {
    93     int c = 0;
    94     vp8_tree_index i = 0;
    96     do
    97     {
    98         const int b = (v >> --n) & 1;
    99         c += vp8_cost_bit(p[i>>1], b);
   100         i = t[i+b];
   101     }
   102     while (n);
   104     return c;
   105 }
   106 static int vp8_cost_token
   107 (
   108     vp8_tree t,
   109     const vp8_prob *const p,
   110     vp8_token *const x
   111 )
   112 {
   113     return vp8_treed_cost(t, p, x->value, x->Len);
   114 }
   116 /* Fill array of costs for all possible token values. */
   118 void vp8_cost_tokens(
   119     int *Costs, const vp8_prob *, vp8_tree
   120 );
   122 void vp8_cost_tokens2(
   123     int *Costs, const vp8_prob *, vp8_tree, int
   124 );
   126 #endif

mercurial