idctllm.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "./vp8_rtcd.h"
  11. /****************************************************************************
  12. * Notes:
  13. *
  14. * This implementation makes use of 16 bit fixed point verio of two multiply
  15. * constants:
  16. * 1. sqrt(2) * cos (pi/8)
  17. * 2. sqrt(2) * sin (pi/8)
  18. * Becuase the first constant is bigger than 1, to maintain the same 16 bit
  19. * fixed point precision as the second one, we use a trick of
  20. * x * a = x + x*(a-1)
  21. * so
  22. * x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1).
  23. **************************************************************************/
  24. static const int cospi8sqrt2minus1 = 20091;
  25. static const int sinpi8sqrt2 = 35468;
  26. void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr,
  27. int pred_stride, unsigned char *dst_ptr,
  28. int dst_stride) {
  29. int i;
  30. int r, c;
  31. int a1, b1, c1, d1;
  32. short output[16];
  33. short *ip = input;
  34. short *op = output;
  35. int temp1, temp2;
  36. int shortpitch = 4;
  37. for (i = 0; i < 4; ++i) {
  38. a1 = ip[0] + ip[8];
  39. b1 = ip[0] - ip[8];
  40. temp1 = (ip[4] * sinpi8sqrt2) >> 16;
  41. temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
  42. c1 = temp1 - temp2;
  43. temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
  44. temp2 = (ip[12] * sinpi8sqrt2) >> 16;
  45. d1 = temp1 + temp2;
  46. op[shortpitch * 0] = a1 + d1;
  47. op[shortpitch * 3] = a1 - d1;
  48. op[shortpitch * 1] = b1 + c1;
  49. op[shortpitch * 2] = b1 - c1;
  50. ip++;
  51. op++;
  52. }
  53. ip = output;
  54. op = output;
  55. for (i = 0; i < 4; ++i) {
  56. a1 = ip[0] + ip[2];
  57. b1 = ip[0] - ip[2];
  58. temp1 = (ip[1] * sinpi8sqrt2) >> 16;
  59. temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
  60. c1 = temp1 - temp2;
  61. temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
  62. temp2 = (ip[3] * sinpi8sqrt2) >> 16;
  63. d1 = temp1 + temp2;
  64. op[0] = (a1 + d1 + 4) >> 3;
  65. op[3] = (a1 - d1 + 4) >> 3;
  66. op[1] = (b1 + c1 + 4) >> 3;
  67. op[2] = (b1 - c1 + 4) >> 3;
  68. ip += shortpitch;
  69. op += shortpitch;
  70. }
  71. ip = output;
  72. for (r = 0; r < 4; ++r) {
  73. for (c = 0; c < 4; ++c) {
  74. int a = ip[c] + pred_ptr[c];
  75. if (a < 0) a = 0;
  76. if (a > 255) a = 255;
  77. dst_ptr[c] = (unsigned char)a;
  78. }
  79. ip += 4;
  80. dst_ptr += dst_stride;
  81. pred_ptr += pred_stride;
  82. }
  83. }
  84. void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr,
  85. int pred_stride, unsigned char *dst_ptr,
  86. int dst_stride) {
  87. int a1 = ((input_dc + 4) >> 3);
  88. int r, c;
  89. for (r = 0; r < 4; ++r) {
  90. for (c = 0; c < 4; ++c) {
  91. int a = a1 + pred_ptr[c];
  92. if (a < 0) a = 0;
  93. if (a > 255) a = 255;
  94. dst_ptr[c] = (unsigned char)a;
  95. }
  96. dst_ptr += dst_stride;
  97. pred_ptr += pred_stride;
  98. }
  99. }
  100. void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff) {
  101. short output[16];
  102. int i;
  103. int a1, b1, c1, d1;
  104. int a2, b2, c2, d2;
  105. short *ip = input;
  106. short *op = output;
  107. for (i = 0; i < 4; ++i) {
  108. a1 = ip[0] + ip[12];
  109. b1 = ip[4] + ip[8];
  110. c1 = ip[4] - ip[8];
  111. d1 = ip[0] - ip[12];
  112. op[0] = a1 + b1;
  113. op[4] = c1 + d1;
  114. op[8] = a1 - b1;
  115. op[12] = d1 - c1;
  116. ip++;
  117. op++;
  118. }
  119. ip = output;
  120. op = output;
  121. for (i = 0; i < 4; ++i) {
  122. a1 = ip[0] + ip[3];
  123. b1 = ip[1] + ip[2];
  124. c1 = ip[1] - ip[2];
  125. d1 = ip[0] - ip[3];
  126. a2 = a1 + b1;
  127. b2 = c1 + d1;
  128. c2 = a1 - b1;
  129. d2 = d1 - c1;
  130. op[0] = (a2 + 3) >> 3;
  131. op[1] = (b2 + 3) >> 3;
  132. op[2] = (c2 + 3) >> 3;
  133. op[3] = (d2 + 3) >> 3;
  134. ip += 4;
  135. op += 4;
  136. }
  137. for (i = 0; i < 16; ++i) {
  138. mb_dqcoeff[i * 16] = output[i];
  139. }
  140. }
  141. void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff) {
  142. int i;
  143. int a1;
  144. a1 = ((input[0] + 3) >> 3);
  145. for (i = 0; i < 16; ++i) {
  146. mb_dqcoeff[i * 16] = a1;
  147. }
  148. }