iDCT コード

  1. static const INT32 COS[8] = {
  2. 65536,
  3. 64277,
  4. 60547,
  5. 54491,
  6. 46341,
  7. 36410,
  8. 25080,
  9. 12785
  10. };
  11. #define MUL(T,X) ((COS[T] * (X)) >> 16)
  12. static void IDCT_8(
  13. const INT16* x,
  14. INT16* y)
  15. {
  16. INT32 t[8];
  17. INT32 t_3, t_2, t_5;
  18. INT16 s[2];
  19. /* Stage.1 */
  20. s[0] = x[0] + x[4];
  21. s[1] = x[0] - x[4];
  22. t[0] = MUL(4, s[0]);
  23. t[1] = MUL(4, s[1]);
  24. t[2] = MUL(6, x[2]) - MUL(2, x[6]);
  25. t[3] = MUL(2, x[2]) + MUL(6, x[6]);
  26. t[4] = MUL(7, x[1]) - MUL(1, x[7]);
  27. t[5] = MUL(3, x[5]) - MUL(5, x[3]);
  28. t[6] = MUL(5, x[5]) + MUL(3, x[3]);
  29. t[7] = MUL(1, x[1]) + MUL(7, x[7]);
  30. /* Stage.2 */
  31. s[0] = t[4] - t[5];
  32. s[1] = t[7] - t[6];
  33. t[4] += t[5];
  34. t[5] = MUL(4, s[0]);
  35. t[7] += t[6];
  36. t[6] = MUL(4, s[1]);
  37. /* Stage.3 */
  38. t_3 = t[0] - t[3];
  39. t_2 = t[1] - t[2];
  40. t_5 = t[6] - t[5];
  41. t[0] += t[3];
  42. t[1] += t[2];
  43. t[6] += t[5];
  44. /* Stage.4 */
  45. y[0*8] = t[0] + t[7];
  46. y[1*8] = t[1] + t[6];
  47. y[2*8] = t_2 + t_5 ;
  48. y[3*8] = t_3 + t[4];
  49. y[4*8] = t_3 - t[4];
  50. y[5*8] = t_2 - t_5 ;
  51. y[6*8] = t[1] - t[6];
  52. y[7*8] = t[0] - t[7];
  53. }
  54. /* */
  55. void IDCT_8x8(
  56. const INT16* x,
  57. INT16* y)
  58. {
  59. const INT16* xx;
  60. INT16* yy;
  61. INT16* end;
  62. INT16 w[64];
  63. for (xx = x, yy = w, end = yy + 8; yy < end; xx += 4*8, yy += 4) {
  64. IDCT_8(xx + 0*8, yy + 0);
  65. IDCT_8(xx + 1*8, yy + 1);
  66. IDCT_8(xx + 2*8, yy + 2);
  67. IDCT_8(xx + 3*8, yy + 3);
  68. }
  69. for (xx = w, yy = y, end = yy + 8; yy < end; xx += 4*8, yy += 4) {
  70. IDCT_8(xx + 0*8, yy + 0);
  71. IDCT_8(xx + 1*8, yy + 1);
  72. IDCT_8(xx + 2*8, yy + 2);
  73. IDCT_8(xx + 3*8, yy + 3);
  74. }
  75. for (yy = y, end = yy + 64; yy < end; yy += 4) {
  76. yy[0] = (yy[0] + 8) >> 4;
  77. yy[1] = (yy[1] + 8) >> 4;
  78. yy[2] = (yy[2] + 8) >> 4;
  79. yy[3] = (yy[3] + 8) >> 4;
  80. }
  81. }