1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_quant_common.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#include "vp9/common/vp9_common.h" 1.15 +#include "vp9/common/vp9_quant_common.h" 1.16 +#include "vp9/common/vp9_seg_common.h" 1.17 + 1.18 +#if 1 1.19 +static const int16_t dc_qlookup[QINDEX_RANGE] = { 1.20 + 4, 8, 8, 9, 10, 11, 12, 12, 1.21 + 13, 14, 15, 16, 17, 18, 19, 19, 1.22 + 20, 21, 22, 23, 24, 25, 26, 26, 1.23 + 27, 28, 29, 30, 31, 32, 32, 33, 1.24 + 34, 35, 36, 37, 38, 38, 39, 40, 1.25 + 41, 42, 43, 43, 44, 45, 46, 47, 1.26 + 48, 48, 49, 50, 51, 52, 53, 53, 1.27 + 54, 55, 56, 57, 57, 58, 59, 60, 1.28 + 61, 62, 62, 63, 64, 65, 66, 66, 1.29 + 67, 68, 69, 70, 70, 71, 72, 73, 1.30 + 74, 74, 75, 76, 77, 78, 78, 79, 1.31 + 80, 81, 81, 82, 83, 84, 85, 85, 1.32 + 87, 88, 90, 92, 93, 95, 96, 98, 1.33 + 99, 101, 102, 104, 105, 107, 108, 110, 1.34 + 111, 113, 114, 116, 117, 118, 120, 121, 1.35 + 123, 125, 127, 129, 131, 134, 136, 138, 1.36 + 140, 142, 144, 146, 148, 150, 152, 154, 1.37 + 156, 158, 161, 164, 166, 169, 172, 174, 1.38 + 177, 180, 182, 185, 187, 190, 192, 195, 1.39 + 199, 202, 205, 208, 211, 214, 217, 220, 1.40 + 223, 226, 230, 233, 237, 240, 243, 247, 1.41 + 250, 253, 257, 261, 265, 269, 272, 276, 1.42 + 280, 284, 288, 292, 296, 300, 304, 309, 1.43 + 313, 317, 322, 326, 330, 335, 340, 344, 1.44 + 349, 354, 359, 364, 369, 374, 379, 384, 1.45 + 389, 395, 400, 406, 411, 417, 423, 429, 1.46 + 435, 441, 447, 454, 461, 467, 475, 482, 1.47 + 489, 497, 505, 513, 522, 530, 539, 549, 1.48 + 559, 569, 579, 590, 602, 614, 626, 640, 1.49 + 654, 668, 684, 700, 717, 736, 755, 775, 1.50 + 796, 819, 843, 869, 896, 925, 955, 988, 1.51 + 1022, 1058, 1098, 1139, 1184, 1232, 1282, 1336, 1.52 +}; 1.53 + 1.54 +static const int16_t ac_qlookup[QINDEX_RANGE] = { 1.55 + 4, 8, 9, 10, 11, 12, 13, 14, 1.56 + 15, 16, 17, 18, 19, 20, 21, 22, 1.57 + 23, 24, 25, 26, 27, 28, 29, 30, 1.58 + 31, 32, 33, 34, 35, 36, 37, 38, 1.59 + 39, 40, 41, 42, 43, 44, 45, 46, 1.60 + 47, 48, 49, 50, 51, 52, 53, 54, 1.61 + 55, 56, 57, 58, 59, 60, 61, 62, 1.62 + 63, 64, 65, 66, 67, 68, 69, 70, 1.63 + 71, 72, 73, 74, 75, 76, 77, 78, 1.64 + 79, 80, 81, 82, 83, 84, 85, 86, 1.65 + 87, 88, 89, 90, 91, 92, 93, 94, 1.66 + 95, 96, 97, 98, 99, 100, 101, 102, 1.67 + 104, 106, 108, 110, 112, 114, 116, 118, 1.68 + 120, 122, 124, 126, 128, 130, 132, 134, 1.69 + 136, 138, 140, 142, 144, 146, 148, 150, 1.70 + 152, 155, 158, 161, 164, 167, 170, 173, 1.71 + 176, 179, 182, 185, 188, 191, 194, 197, 1.72 + 200, 203, 207, 211, 215, 219, 223, 227, 1.73 + 231, 235, 239, 243, 247, 251, 255, 260, 1.74 + 265, 270, 275, 280, 285, 290, 295, 300, 1.75 + 305, 311, 317, 323, 329, 335, 341, 347, 1.76 + 353, 359, 366, 373, 380, 387, 394, 401, 1.77 + 408, 416, 424, 432, 440, 448, 456, 465, 1.78 + 474, 483, 492, 501, 510, 520, 530, 540, 1.79 + 550, 560, 571, 582, 593, 604, 615, 627, 1.80 + 639, 651, 663, 676, 689, 702, 715, 729, 1.81 + 743, 757, 771, 786, 801, 816, 832, 848, 1.82 + 864, 881, 898, 915, 933, 951, 969, 988, 1.83 + 1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151, 1.84 + 1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343, 1.85 + 1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567, 1.86 + 1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828, 1.87 +}; 1.88 + 1.89 +void vp9_init_quant_tables(void) { } 1.90 +#else 1.91 +static int16_t dc_qlookup[QINDEX_RANGE]; 1.92 +static int16_t ac_qlookup[QINDEX_RANGE]; 1.93 + 1.94 +#define ACDC_MIN 8 1.95 + 1.96 +// TODO(dkovalev) move to common and reuse 1.97 +static double poly3(double a, double b, double c, double d, double x) { 1.98 + return a*x*x*x + b*x*x + c*x + d; 1.99 +} 1.100 + 1.101 +void vp9_init_quant_tables() { 1.102 + int i, val = 4; 1.103 + 1.104 + // A "real" q of 1.0 forces lossless mode. 1.105 + // In practice non lossless Q's between 1.0 and 2.0 (represented here by 1.106 + // integer values from 5-7 give poor rd results (lower psnr and often 1.107 + // larger size than the lossless encode. To block out those "not very useful" 1.108 + // values we increment the ac and dc q lookup values by 4 after position 0. 1.109 + ac_qlookup[0] = val; 1.110 + dc_qlookup[0] = val; 1.111 + val += 4; 1.112 + 1.113 + for (i = 1; i < QINDEX_RANGE; i++) { 1.114 + const int ac_val = val; 1.115 + 1.116 + val = (int)(val * 1.01975); 1.117 + if (val == ac_val) 1.118 + ++val; 1.119 + 1.120 + ac_qlookup[i] = (int16_t)ac_val; 1.121 + dc_qlookup[i] = (int16_t)MAX(ACDC_MIN, poly3(0.000000305, -0.00065, 0.9, 1.122 + 0.5, ac_val)); 1.123 + } 1.124 +} 1.125 +#endif 1.126 + 1.127 +int16_t vp9_dc_quant(int qindex, int delta) { 1.128 + return dc_qlookup[clamp(qindex + delta, 0, MAXQ)]; 1.129 +} 1.130 + 1.131 +int16_t vp9_ac_quant(int qindex, int delta) { 1.132 + return ac_qlookup[clamp(qindex + delta, 0, MAXQ)]; 1.133 +} 1.134 + 1.135 + 1.136 +int vp9_get_qindex(struct segmentation *seg, int segment_id, int base_qindex) { 1.137 + if (vp9_segfeature_active(seg, segment_id, SEG_LVL_ALT_Q)) { 1.138 + const int data = vp9_get_segdata(seg, segment_id, SEG_LVL_ALT_Q); 1.139 + return seg->abs_delta == SEGMENT_ABSDATA ? 1.140 + data : // Abs value 1.141 + clamp(base_qindex + data, 0, MAXQ); // Delta value 1.142 + } else { 1.143 + return base_qindex; 1.144 + } 1.145 +} 1.146 +