dct.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 <math.h>
  11. #include "./vp8_rtcd.h"
  12. void vp8_short_fdct4x4_c(short *input, short *output, int pitch) {
  13. int i;
  14. int a1, b1, c1, d1;
  15. short *ip = input;
  16. short *op = output;
  17. for (i = 0; i < 4; ++i) {
  18. a1 = ((ip[0] + ip[3]) * 8);
  19. b1 = ((ip[1] + ip[2]) * 8);
  20. c1 = ((ip[1] - ip[2]) * 8);
  21. d1 = ((ip[0] - ip[3]) * 8);
  22. op[0] = a1 + b1;
  23. op[2] = a1 - b1;
  24. op[1] = (c1 * 2217 + d1 * 5352 + 14500) >> 12;
  25. op[3] = (d1 * 2217 - c1 * 5352 + 7500) >> 12;
  26. ip += pitch / 2;
  27. op += 4;
  28. }
  29. ip = output;
  30. op = output;
  31. for (i = 0; i < 4; ++i) {
  32. a1 = ip[0] + ip[12];
  33. b1 = ip[4] + ip[8];
  34. c1 = ip[4] - ip[8];
  35. d1 = ip[0] - ip[12];
  36. op[0] = (a1 + b1 + 7) >> 4;
  37. op[8] = (a1 - b1 + 7) >> 4;
  38. op[4] = ((c1 * 2217 + d1 * 5352 + 12000) >> 16) + (d1 != 0);
  39. op[12] = (d1 * 2217 - c1 * 5352 + 51000) >> 16;
  40. ip++;
  41. op++;
  42. }
  43. }
  44. void vp8_short_fdct8x4_c(short *input, short *output, int pitch) {
  45. vp8_short_fdct4x4_c(input, output, pitch);
  46. vp8_short_fdct4x4_c(input + 4, output + 16, pitch);
  47. }
  48. void vp8_short_walsh4x4_c(short *input, short *output, int pitch) {
  49. int i;
  50. int a1, b1, c1, d1;
  51. int a2, b2, c2, d2;
  52. short *ip = input;
  53. short *op = output;
  54. for (i = 0; i < 4; ++i) {
  55. a1 = ((ip[0] + ip[2]) * 4);
  56. d1 = ((ip[1] + ip[3]) * 4);
  57. c1 = ((ip[1] - ip[3]) * 4);
  58. b1 = ((ip[0] - ip[2]) * 4);
  59. op[0] = a1 + d1 + (a1 != 0);
  60. op[1] = b1 + c1;
  61. op[2] = b1 - c1;
  62. op[3] = a1 - d1;
  63. ip += pitch / 2;
  64. op += 4;
  65. }
  66. ip = output;
  67. op = output;
  68. for (i = 0; i < 4; ++i) {
  69. a1 = ip[0] + ip[8];
  70. d1 = ip[4] + ip[12];
  71. c1 = ip[4] - ip[12];
  72. b1 = ip[0] - ip[8];
  73. a2 = a1 + d1;
  74. b2 = b1 + c1;
  75. c2 = b1 - c1;
  76. d2 = a1 - d1;
  77. a2 += a2 < 0;
  78. b2 += b2 < 0;
  79. c2 += c2 < 0;
  80. d2 += d2 < 0;
  81. op[0] = (a2 + 3) >> 3;
  82. op[4] = (b2 + 3) >> 3;
  83. op[8] = (c2 + 3) >> 3;
  84. op[12] = (d2 + 3) >> 3;
  85. ip++;
  86. op++;
  87. }
  88. }