OLD | NEW |
(Empty) | |
| 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 */ |
| 10 |
| 11 |
| 12 #include "vp9/common/vp9_quant_common.h" |
| 13 |
| 14 static int dc_qlookup[QINDEX_RANGE]; |
| 15 static int ac_qlookup[QINDEX_RANGE]; |
| 16 |
| 17 #define ACDC_MIN 4 |
| 18 |
| 19 void vp9_init_quant_tables() { |
| 20 int i; |
| 21 int current_val = 4; |
| 22 int last_val = 4; |
| 23 int ac_val; |
| 24 |
| 25 for (i = 0; i < QINDEX_RANGE; i++) { |
| 26 ac_qlookup[i] = current_val; |
| 27 current_val = (int)((double)current_val * 1.02); |
| 28 if (current_val == last_val) |
| 29 current_val++; |
| 30 last_val = current_val; |
| 31 |
| 32 ac_val = ac_qlookup[i]; |
| 33 dc_qlookup[i] = (int)((0.000000305 * ac_val * ac_val * ac_val) + |
| 34 (-0.00065 * ac_val * ac_val) + |
| 35 (0.9 * ac_val) + 0.5); |
| 36 if (dc_qlookup[i] < ACDC_MIN) |
| 37 dc_qlookup[i] = ACDC_MIN; |
| 38 } |
| 39 } |
| 40 |
| 41 int vp9_dc_quant(int QIndex, int Delta) { |
| 42 int retval; |
| 43 |
| 44 QIndex = QIndex + Delta; |
| 45 |
| 46 if (QIndex > MAXQ) |
| 47 QIndex = MAXQ; |
| 48 else if (QIndex < 0) |
| 49 QIndex = 0; |
| 50 |
| 51 retval = dc_qlookup[ QIndex ]; |
| 52 return retval; |
| 53 } |
| 54 |
| 55 int vp9_dc2quant(int QIndex, int Delta) { |
| 56 int retval; |
| 57 |
| 58 QIndex = QIndex + Delta; |
| 59 |
| 60 if (QIndex > MAXQ) |
| 61 QIndex = MAXQ; |
| 62 else if (QIndex < 0) |
| 63 QIndex = 0; |
| 64 |
| 65 retval = dc_qlookup[ QIndex ]; |
| 66 |
| 67 return retval; |
| 68 |
| 69 } |
| 70 int vp9_dc_uv_quant(int QIndex, int Delta) { |
| 71 int retval; |
| 72 |
| 73 QIndex = QIndex + Delta; |
| 74 |
| 75 if (QIndex > MAXQ) |
| 76 QIndex = MAXQ; |
| 77 else if (QIndex < 0) |
| 78 QIndex = 0; |
| 79 |
| 80 retval = dc_qlookup[ QIndex ]; |
| 81 |
| 82 return retval; |
| 83 } |
| 84 |
| 85 int vp9_ac_yquant(int QIndex) { |
| 86 int retval; |
| 87 |
| 88 if (QIndex > MAXQ) |
| 89 QIndex = MAXQ; |
| 90 else if (QIndex < 0) |
| 91 QIndex = 0; |
| 92 |
| 93 retval = ac_qlookup[ QIndex ]; |
| 94 return retval; |
| 95 } |
| 96 |
| 97 int vp9_ac2quant(int QIndex, int Delta) { |
| 98 int retval; |
| 99 |
| 100 QIndex = QIndex + Delta; |
| 101 |
| 102 if (QIndex > MAXQ) |
| 103 QIndex = MAXQ; |
| 104 else if (QIndex < 0) |
| 105 QIndex = 0; |
| 106 |
| 107 retval = (ac_qlookup[ QIndex ] * 775) / 1000; |
| 108 if (retval < 4) |
| 109 retval = 4; |
| 110 |
| 111 return retval; |
| 112 } |
| 113 int vp9_ac_uv_quant(int QIndex, int Delta) { |
| 114 int retval; |
| 115 |
| 116 QIndex = QIndex + Delta; |
| 117 |
| 118 if (QIndex > MAXQ) |
| 119 QIndex = MAXQ; |
| 120 else if (QIndex < 0) |
| 121 QIndex = 0; |
| 122 |
| 123 retval = ac_qlookup[ QIndex ]; |
| 124 return retval; |
| 125 } |
OLD | NEW |