idctllm.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. {
  30. int i;
  31. int r, c;
  32. int a1, b1, c1, d1;
  33. short output[16];
  34. short *ip = input;
  35. short *op = output;
  36. int temp1, temp2;
  37. int shortpitch = 4;
  38. for (i = 0; i < 4; i++)
  39. {
  40. a1 = ip[0] + ip[8];
  41. b1 = ip[0] - ip[8];
  42. temp1 = (ip[4] * sinpi8sqrt2) >> 16;
  43. temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
  44. c1 = temp1 - temp2;
  45. temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
  46. temp2 = (ip[12] * sinpi8sqrt2) >> 16;
  47. d1 = temp1 + temp2;
  48. op[shortpitch*0] = a1 + d1;
  49. op[shortpitch*3] = a1 - d1;
  50. op[shortpitch*1] = b1 + c1;
  51. op[shortpitch*2] = b1 - c1;
  52. ip++;
  53. op++;
  54. }
  55. ip = output;
  56. op = output;
  57. for (i = 0; i < 4; i++)
  58. {
  59. a1 = ip[0] + ip[2];
  60. b1 = ip[0] - ip[2];
  61. temp1 = (ip[1] * sinpi8sqrt2) >> 16;
  62. temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
  63. c1 = temp1 - temp2;
  64. temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
  65. temp2 = (ip[3] * sinpi8sqrt2) >> 16;
  66. d1 = temp1 + temp2;
  67. op[0] = (a1 + d1 + 4) >> 3;
  68. op[3] = (a1 - d1 + 4) >> 3;
  69. op[1] = (b1 + c1 + 4) >> 3;
  70. op[2] = (b1 - c1 + 4) >> 3;
  71. ip += shortpitch;
  72. op += shortpitch;
  73. }
  74. ip = output;
  75. for (r = 0; r < 4; r++)
  76. {
  77. for (c = 0; c < 4; c++)
  78. {
  79. int a = ip[c] + pred_ptr[c] ;
  80. if (a < 0)
  81. a = 0;
  82. if (a > 255)
  83. a = 255;
  84. dst_ptr[c] = (unsigned char) a ;
  85. }
  86. ip += 4;
  87. dst_ptr += dst_stride;
  88. pred_ptr += pred_stride;
  89. }
  90. }
  91. void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr,
  92. int pred_stride, unsigned char *dst_ptr,
  93. int dst_stride)
  94. {
  95. int a1 = ((input_dc + 4) >> 3);
  96. int r, c;
  97. for (r = 0; r < 4; r++)
  98. {
  99. for (c = 0; c < 4; c++)
  100. {
  101. int a = a1 + pred_ptr[c] ;
  102. if (a < 0)
  103. a = 0;
  104. if (a > 255)
  105. a = 255;
  106. dst_ptr[c] = (unsigned char) a ;
  107. }
  108. dst_ptr += dst_stride;
  109. pred_ptr += pred_stride;
  110. }
  111. }
  112. void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff)
  113. {
  114. short output[16];
  115. int i;
  116. int a1, b1, c1, d1;
  117. int a2, b2, c2, d2;
  118. short *ip = input;
  119. short *op = output;
  120. for (i = 0; i < 4; i++)
  121. {
  122. a1 = ip[0] + ip[12];
  123. b1 = ip[4] + ip[8];
  124. c1 = ip[4] - ip[8];
  125. d1 = ip[0] - ip[12];
  126. op[0] = a1 + b1;
  127. op[4] = c1 + d1;
  128. op[8] = a1 - b1;
  129. op[12] = d1 - c1;
  130. ip++;
  131. op++;
  132. }
  133. ip = output;
  134. op = output;
  135. for (i = 0; i < 4; i++)
  136. {
  137. a1 = ip[0] + ip[3];
  138. b1 = ip[1] + ip[2];
  139. c1 = ip[1] - ip[2];
  140. d1 = ip[0] - ip[3];
  141. a2 = a1 + b1;
  142. b2 = c1 + d1;
  143. c2 = a1 - b1;
  144. d2 = d1 - c1;
  145. op[0] = (a2 + 3) >> 3;
  146. op[1] = (b2 + 3) >> 3;
  147. op[2] = (c2 + 3) >> 3;
  148. op[3] = (d2 + 3) >> 3;
  149. ip += 4;
  150. op += 4;
  151. }
  152. for(i = 0; i < 16; i++)
  153. {
  154. mb_dqcoeff[i * 16] = output[i];
  155. }
  156. }
  157. void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff)
  158. {
  159. int i;
  160. int a1;
  161. a1 = ((input[0] + 3) >> 3);
  162. for(i = 0; i < 16; i++)
  163. {
  164. mb_dqcoeff[i * 16] = a1;
  165. }
  166. }