quant_common.c 3.7 KB

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