Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | #include "vp9/common/vp9_common.h" |
michael@0 | 12 | #include "vp9/common/vp9_quant_common.h" |
michael@0 | 13 | #include "vp9/common/vp9_seg_common.h" |
michael@0 | 14 | |
michael@0 | 15 | #if 1 |
michael@0 | 16 | static const int16_t dc_qlookup[QINDEX_RANGE] = { |
michael@0 | 17 | 4, 8, 8, 9, 10, 11, 12, 12, |
michael@0 | 18 | 13, 14, 15, 16, 17, 18, 19, 19, |
michael@0 | 19 | 20, 21, 22, 23, 24, 25, 26, 26, |
michael@0 | 20 | 27, 28, 29, 30, 31, 32, 32, 33, |
michael@0 | 21 | 34, 35, 36, 37, 38, 38, 39, 40, |
michael@0 | 22 | 41, 42, 43, 43, 44, 45, 46, 47, |
michael@0 | 23 | 48, 48, 49, 50, 51, 52, 53, 53, |
michael@0 | 24 | 54, 55, 56, 57, 57, 58, 59, 60, |
michael@0 | 25 | 61, 62, 62, 63, 64, 65, 66, 66, |
michael@0 | 26 | 67, 68, 69, 70, 70, 71, 72, 73, |
michael@0 | 27 | 74, 74, 75, 76, 77, 78, 78, 79, |
michael@0 | 28 | 80, 81, 81, 82, 83, 84, 85, 85, |
michael@0 | 29 | 87, 88, 90, 92, 93, 95, 96, 98, |
michael@0 | 30 | 99, 101, 102, 104, 105, 107, 108, 110, |
michael@0 | 31 | 111, 113, 114, 116, 117, 118, 120, 121, |
michael@0 | 32 | 123, 125, 127, 129, 131, 134, 136, 138, |
michael@0 | 33 | 140, 142, 144, 146, 148, 150, 152, 154, |
michael@0 | 34 | 156, 158, 161, 164, 166, 169, 172, 174, |
michael@0 | 35 | 177, 180, 182, 185, 187, 190, 192, 195, |
michael@0 | 36 | 199, 202, 205, 208, 211, 214, 217, 220, |
michael@0 | 37 | 223, 226, 230, 233, 237, 240, 243, 247, |
michael@0 | 38 | 250, 253, 257, 261, 265, 269, 272, 276, |
michael@0 | 39 | 280, 284, 288, 292, 296, 300, 304, 309, |
michael@0 | 40 | 313, 317, 322, 326, 330, 335, 340, 344, |
michael@0 | 41 | 349, 354, 359, 364, 369, 374, 379, 384, |
michael@0 | 42 | 389, 395, 400, 406, 411, 417, 423, 429, |
michael@0 | 43 | 435, 441, 447, 454, 461, 467, 475, 482, |
michael@0 | 44 | 489, 497, 505, 513, 522, 530, 539, 549, |
michael@0 | 45 | 559, 569, 579, 590, 602, 614, 626, 640, |
michael@0 | 46 | 654, 668, 684, 700, 717, 736, 755, 775, |
michael@0 | 47 | 796, 819, 843, 869, 896, 925, 955, 988, |
michael@0 | 48 | 1022, 1058, 1098, 1139, 1184, 1232, 1282, 1336, |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | static const int16_t ac_qlookup[QINDEX_RANGE] = { |
michael@0 | 52 | 4, 8, 9, 10, 11, 12, 13, 14, |
michael@0 | 53 | 15, 16, 17, 18, 19, 20, 21, 22, |
michael@0 | 54 | 23, 24, 25, 26, 27, 28, 29, 30, |
michael@0 | 55 | 31, 32, 33, 34, 35, 36, 37, 38, |
michael@0 | 56 | 39, 40, 41, 42, 43, 44, 45, 46, |
michael@0 | 57 | 47, 48, 49, 50, 51, 52, 53, 54, |
michael@0 | 58 | 55, 56, 57, 58, 59, 60, 61, 62, |
michael@0 | 59 | 63, 64, 65, 66, 67, 68, 69, 70, |
michael@0 | 60 | 71, 72, 73, 74, 75, 76, 77, 78, |
michael@0 | 61 | 79, 80, 81, 82, 83, 84, 85, 86, |
michael@0 | 62 | 87, 88, 89, 90, 91, 92, 93, 94, |
michael@0 | 63 | 95, 96, 97, 98, 99, 100, 101, 102, |
michael@0 | 64 | 104, 106, 108, 110, 112, 114, 116, 118, |
michael@0 | 65 | 120, 122, 124, 126, 128, 130, 132, 134, |
michael@0 | 66 | 136, 138, 140, 142, 144, 146, 148, 150, |
michael@0 | 67 | 152, 155, 158, 161, 164, 167, 170, 173, |
michael@0 | 68 | 176, 179, 182, 185, 188, 191, 194, 197, |
michael@0 | 69 | 200, 203, 207, 211, 215, 219, 223, 227, |
michael@0 | 70 | 231, 235, 239, 243, 247, 251, 255, 260, |
michael@0 | 71 | 265, 270, 275, 280, 285, 290, 295, 300, |
michael@0 | 72 | 305, 311, 317, 323, 329, 335, 341, 347, |
michael@0 | 73 | 353, 359, 366, 373, 380, 387, 394, 401, |
michael@0 | 74 | 408, 416, 424, 432, 440, 448, 456, 465, |
michael@0 | 75 | 474, 483, 492, 501, 510, 520, 530, 540, |
michael@0 | 76 | 550, 560, 571, 582, 593, 604, 615, 627, |
michael@0 | 77 | 639, 651, 663, 676, 689, 702, 715, 729, |
michael@0 | 78 | 743, 757, 771, 786, 801, 816, 832, 848, |
michael@0 | 79 | 864, 881, 898, 915, 933, 951, 969, 988, |
michael@0 | 80 | 1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151, |
michael@0 | 81 | 1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343, |
michael@0 | 82 | 1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567, |
michael@0 | 83 | 1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828, |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | void vp9_init_quant_tables(void) { } |
michael@0 | 87 | #else |
michael@0 | 88 | static int16_t dc_qlookup[QINDEX_RANGE]; |
michael@0 | 89 | static int16_t ac_qlookup[QINDEX_RANGE]; |
michael@0 | 90 | |
michael@0 | 91 | #define ACDC_MIN 8 |
michael@0 | 92 | |
michael@0 | 93 | // TODO(dkovalev) move to common and reuse |
michael@0 | 94 | static double poly3(double a, double b, double c, double d, double x) { |
michael@0 | 95 | return a*x*x*x + b*x*x + c*x + d; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void vp9_init_quant_tables() { |
michael@0 | 99 | int i, val = 4; |
michael@0 | 100 | |
michael@0 | 101 | // A "real" q of 1.0 forces lossless mode. |
michael@0 | 102 | // In practice non lossless Q's between 1.0 and 2.0 (represented here by |
michael@0 | 103 | // integer values from 5-7 give poor rd results (lower psnr and often |
michael@0 | 104 | // larger size than the lossless encode. To block out those "not very useful" |
michael@0 | 105 | // values we increment the ac and dc q lookup values by 4 after position 0. |
michael@0 | 106 | ac_qlookup[0] = val; |
michael@0 | 107 | dc_qlookup[0] = val; |
michael@0 | 108 | val += 4; |
michael@0 | 109 | |
michael@0 | 110 | for (i = 1; i < QINDEX_RANGE; i++) { |
michael@0 | 111 | const int ac_val = val; |
michael@0 | 112 | |
michael@0 | 113 | val = (int)(val * 1.01975); |
michael@0 | 114 | if (val == ac_val) |
michael@0 | 115 | ++val; |
michael@0 | 116 | |
michael@0 | 117 | ac_qlookup[i] = (int16_t)ac_val; |
michael@0 | 118 | dc_qlookup[i] = (int16_t)MAX(ACDC_MIN, poly3(0.000000305, -0.00065, 0.9, |
michael@0 | 119 | 0.5, ac_val)); |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | #endif |
michael@0 | 123 | |
michael@0 | 124 | int16_t vp9_dc_quant(int qindex, int delta) { |
michael@0 | 125 | return dc_qlookup[clamp(qindex + delta, 0, MAXQ)]; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | int16_t vp9_ac_quant(int qindex, int delta) { |
michael@0 | 129 | return ac_qlookup[clamp(qindex + delta, 0, MAXQ)]; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | |
michael@0 | 133 | int vp9_get_qindex(struct segmentation *seg, int segment_id, int base_qindex) { |
michael@0 | 134 | if (vp9_segfeature_active(seg, segment_id, SEG_LVL_ALT_Q)) { |
michael@0 | 135 | const int data = vp9_get_segdata(seg, segment_id, SEG_LVL_ALT_Q); |
michael@0 | 136 | return seg->abs_delta == SEGMENT_ABSDATA ? |
michael@0 | 137 | data : // Abs value |
michael@0 | 138 | clamp(base_qindex + data, 0, MAXQ); // Delta value |
michael@0 | 139 | } else { |
michael@0 | 140 | return base_qindex; |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 |