media/libvpx/vp8/common/quant_common.c

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.

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 #include "quant_common.h"
michael@0 13
michael@0 14 static const int dc_qlookup[QINDEX_RANGE] =
michael@0 15 {
michael@0 16 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17,
michael@0 17 18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 28,
michael@0 18 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43,
michael@0 19 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
michael@0 20 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
michael@0 21 75, 76, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
michael@0 22 91, 93, 95, 96, 98, 100, 101, 102, 104, 106, 108, 110, 112, 114, 116, 118,
michael@0 23 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157,
michael@0 24 };
michael@0 25
michael@0 26 static const int ac_qlookup[QINDEX_RANGE] =
michael@0 27 {
michael@0 28 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
michael@0 29 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
michael@0 30 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
michael@0 31 52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76,
michael@0 32 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108,
michael@0 33 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152,
michael@0 34 155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209,
michael@0 35 213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284,
michael@0 36 };
michael@0 37
michael@0 38
michael@0 39 int vp8_dc_quant(int QIndex, int Delta)
michael@0 40 {
michael@0 41 int retval;
michael@0 42
michael@0 43 QIndex = QIndex + Delta;
michael@0 44
michael@0 45 if (QIndex > 127)
michael@0 46 QIndex = 127;
michael@0 47 else if (QIndex < 0)
michael@0 48 QIndex = 0;
michael@0 49
michael@0 50 retval = dc_qlookup[ QIndex ];
michael@0 51 return retval;
michael@0 52 }
michael@0 53
michael@0 54 int vp8_dc2quant(int QIndex, int Delta)
michael@0 55 {
michael@0 56 int retval;
michael@0 57
michael@0 58 QIndex = QIndex + Delta;
michael@0 59
michael@0 60 if (QIndex > 127)
michael@0 61 QIndex = 127;
michael@0 62 else if (QIndex < 0)
michael@0 63 QIndex = 0;
michael@0 64
michael@0 65 retval = dc_qlookup[ QIndex ] * 2;
michael@0 66 return retval;
michael@0 67
michael@0 68 }
michael@0 69 int vp8_dc_uv_quant(int QIndex, int Delta)
michael@0 70 {
michael@0 71 int retval;
michael@0 72
michael@0 73 QIndex = QIndex + Delta;
michael@0 74
michael@0 75 if (QIndex > 127)
michael@0 76 QIndex = 127;
michael@0 77 else if (QIndex < 0)
michael@0 78 QIndex = 0;
michael@0 79
michael@0 80 retval = dc_qlookup[ QIndex ];
michael@0 81
michael@0 82 if (retval > 132)
michael@0 83 retval = 132;
michael@0 84
michael@0 85 return retval;
michael@0 86 }
michael@0 87
michael@0 88 int vp8_ac_yquant(int QIndex)
michael@0 89 {
michael@0 90 int retval;
michael@0 91
michael@0 92 if (QIndex > 127)
michael@0 93 QIndex = 127;
michael@0 94 else if (QIndex < 0)
michael@0 95 QIndex = 0;
michael@0 96
michael@0 97 retval = ac_qlookup[ QIndex ];
michael@0 98 return retval;
michael@0 99 }
michael@0 100
michael@0 101 int vp8_ac2quant(int QIndex, int Delta)
michael@0 102 {
michael@0 103 int retval;
michael@0 104
michael@0 105 QIndex = QIndex + Delta;
michael@0 106
michael@0 107 if (QIndex > 127)
michael@0 108 QIndex = 127;
michael@0 109 else if (QIndex < 0)
michael@0 110 QIndex = 0;
michael@0 111
michael@0 112 /* For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
michael@0 113 * The smallest precision for that is '(x*6349) >> 12' but 16 is a good
michael@0 114 * word size. */
michael@0 115 retval = (ac_qlookup[ QIndex ] * 101581) >> 16;
michael@0 116
michael@0 117 if (retval < 8)
michael@0 118 retval = 8;
michael@0 119
michael@0 120 return retval;
michael@0 121 }
michael@0 122 int vp8_ac_uv_quant(int QIndex, int Delta)
michael@0 123 {
michael@0 124 int retval;
michael@0 125
michael@0 126 QIndex = QIndex + Delta;
michael@0 127
michael@0 128 if (QIndex > 127)
michael@0 129 QIndex = 127;
michael@0 130 else if (QIndex < 0)
michael@0 131 QIndex = 0;
michael@0 132
michael@0 133 retval = ac_qlookup[ QIndex ];
michael@0 134 return retval;
michael@0 135 }

mercurial