quant_common.c 3.3 KB

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