You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
6.7KB

  1. /*
  2. * Copyright (C) 2004 the ffmpeg project
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /**
  19. * @file vp3dsp.c
  20. * Standard C DSP-oriented functions cribbed from the original VP3
  21. * source code.
  22. */
  23. #include "common.h"
  24. #include "avcodec.h"
  25. #include "vp3data.h"
  26. #define IdctAdjustBeforeShift 8
  27. #define xC1S7 64277
  28. #define xC2S6 60547
  29. #define xC3S5 54491
  30. #define xC4S4 46341
  31. #define xC5S3 36410
  32. #define xC6S2 25080
  33. #define xC7S1 12785
  34. void vp3_dsp_init_c(void)
  35. {
  36. /* nop */
  37. }
  38. void vp3_idct_c(int16_t *input_data, int16_t *dequant_matrix,
  39. int coeff_count, int16_t *output_data)
  40. {
  41. int32_t dequantized_data[64];
  42. int32_t *ip = dequantized_data;
  43. int16_t *op = output_data;
  44. int32_t A_, B_, C_, D_, _Ad, _Bd, _Cd, _Dd, E_, F_, G_, H_;
  45. int32_t _Ed, _Gd, _Add, _Bdd, _Fd, _Hd;
  46. int32_t t1, t2;
  47. int i, j;
  48. /* de-zigzag and dequantize */
  49. for (i = 0; i < coeff_count; i++) {
  50. j = dezigzag_index[i];
  51. dequantized_data[j] = dequant_matrix[i] * input_data[i];
  52. }
  53. /* Inverse DCT on the rows now */
  54. for (i = 0; i < 8; i++) {
  55. /* Check for non-zero values */
  56. if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
  57. t1 = (int32_t)(xC1S7 * ip[1]);
  58. t2 = (int32_t)(xC7S1 * ip[7]);
  59. t1 >>= 16;
  60. t2 >>= 16;
  61. A_ = t1 + t2;
  62. t1 = (int32_t)(xC7S1 * ip[1]);
  63. t2 = (int32_t)(xC1S7 * ip[7]);
  64. t1 >>= 16;
  65. t2 >>= 16;
  66. B_ = t1 - t2;
  67. t1 = (int32_t)(xC3S5 * ip[3]);
  68. t2 = (int32_t)(xC5S3 * ip[5]);
  69. t1 >>= 16;
  70. t2 >>= 16;
  71. C_ = t1 + t2;
  72. t1 = (int32_t)(xC3S5 * ip[5]);
  73. t2 = (int32_t)(xC5S3 * ip[3]);
  74. t1 >>= 16;
  75. t2 >>= 16;
  76. D_ = t1 - t2;
  77. t1 = (int32_t)(xC4S4 * (A_ - C_));
  78. t1 >>= 16;
  79. _Ad = t1;
  80. t1 = (int32_t)(xC4S4 * (B_ - D_));
  81. t1 >>= 16;
  82. _Bd = t1;
  83. _Cd = A_ + C_;
  84. _Dd = B_ + D_;
  85. t1 = (int32_t)(xC4S4 * (ip[0] + ip[4]));
  86. t1 >>= 16;
  87. E_ = t1;
  88. t1 = (int32_t)(xC4S4 * (ip[0] - ip[4]));
  89. t1 >>= 16;
  90. F_ = t1;
  91. t1 = (int32_t)(xC2S6 * ip[2]);
  92. t2 = (int32_t)(xC6S2 * ip[6]);
  93. t1 >>= 16;
  94. t2 >>= 16;
  95. G_ = t1 + t2;
  96. t1 = (int32_t)(xC6S2 * ip[2]);
  97. t2 = (int32_t)(xC2S6 * ip[6]);
  98. t1 >>= 16;
  99. t2 >>= 16;
  100. H_ = t1 - t2;
  101. _Ed = E_ - G_;
  102. _Gd = E_ + G_;
  103. _Add = F_ + _Ad;
  104. _Bdd = _Bd - H_;
  105. _Fd = F_ - _Ad;
  106. _Hd = _Bd + H_;
  107. /* Final sequence of operations over-write original inputs. */
  108. ip[0] = (int16_t)((_Gd + _Cd ) >> 0);
  109. ip[7] = (int16_t)((_Gd - _Cd ) >> 0);
  110. ip[1] = (int16_t)((_Add + _Hd ) >> 0);
  111. ip[2] = (int16_t)((_Add - _Hd ) >> 0);
  112. ip[3] = (int16_t)((_Ed + _Dd ) >> 0);
  113. ip[4] = (int16_t)((_Ed - _Dd ) >> 0);
  114. ip[5] = (int16_t)((_Fd + _Bdd ) >> 0);
  115. ip[6] = (int16_t)((_Fd - _Bdd ) >> 0);
  116. }
  117. ip += 8; /* next row */
  118. }
  119. ip = dequantized_data;
  120. for ( i = 0; i < 8; i++) {
  121. /* Check for non-zero values (bitwise or faster than ||) */
  122. if ( ip[0 * 8] | ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
  123. ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
  124. t1 = (int32_t)(xC1S7 * ip[1*8]);
  125. t2 = (int32_t)(xC7S1 * ip[7*8]);
  126. t1 >>= 16;
  127. t2 >>= 16;
  128. A_ = t1 + t2;
  129. t1 = (int32_t)(xC7S1 * ip[1*8]);
  130. t2 = (int32_t)(xC1S7 * ip[7*8]);
  131. t1 >>= 16;
  132. t2 >>= 16;
  133. B_ = t1 - t2;
  134. t1 = (int32_t)(xC3S5 * ip[3*8]);
  135. t2 = (int32_t)(xC5S3 * ip[5*8]);
  136. t1 >>= 16;
  137. t2 >>= 16;
  138. C_ = t1 + t2;
  139. t1 = (int32_t)(xC3S5 * ip[5*8]);
  140. t2 = (int32_t)(xC5S3 * ip[3*8]);
  141. t1 >>= 16;
  142. t2 >>= 16;
  143. D_ = t1 - t2;
  144. t1 = (int32_t)(xC4S4 * (A_ - C_));
  145. t1 >>= 16;
  146. _Ad = t1;
  147. t1 = (int32_t)(xC4S4 * (B_ - D_));
  148. t1 >>= 16;
  149. _Bd = t1;
  150. _Cd = A_ + C_;
  151. _Dd = B_ + D_;
  152. t1 = (int32_t)(xC4S4 * (ip[0*8] + ip[4*8]));
  153. t1 >>= 16;
  154. E_ = t1;
  155. t1 = (int32_t)(xC4S4 * (ip[0*8] - ip[4*8]));
  156. t1 >>= 16;
  157. F_ = t1;
  158. t1 = (int32_t)(xC2S6 * ip[2*8]);
  159. t2 = (int32_t)(xC6S2 * ip[6*8]);
  160. t1 >>= 16;
  161. t2 >>= 16;
  162. G_ = t1 + t2;
  163. t1 = (int32_t)(xC6S2 * ip[2*8]);
  164. t2 = (int32_t)(xC2S6 * ip[6*8]);
  165. t1 >>= 16;
  166. t2 >>= 16;
  167. H_ = t1 - t2;
  168. _Ed = E_ - G_;
  169. _Gd = E_ + G_;
  170. _Add = F_ + _Ad;
  171. _Bdd = _Bd - H_;
  172. _Fd = F_ - _Ad;
  173. _Hd = _Bd + H_;
  174. _Gd += IdctAdjustBeforeShift;
  175. _Add += IdctAdjustBeforeShift;
  176. _Ed += IdctAdjustBeforeShift;
  177. _Fd += IdctAdjustBeforeShift;
  178. /* Final sequence of operations over-write original inputs. */
  179. op[0*8] = (int16_t)((_Gd + _Cd ) >> 4);
  180. op[7*8] = (int16_t)((_Gd - _Cd ) >> 4);
  181. op[1*8] = (int16_t)((_Add + _Hd ) >> 4);
  182. op[2*8] = (int16_t)((_Add - _Hd ) >> 4);
  183. op[3*8] = (int16_t)((_Ed + _Dd ) >> 4);
  184. op[4*8] = (int16_t)((_Ed - _Dd ) >> 4);
  185. op[5*8] = (int16_t)((_Fd + _Bdd ) >> 4);
  186. op[6*8] = (int16_t)((_Fd - _Bdd ) >> 4);
  187. } else {
  188. op[0*8] = 0;
  189. op[7*8] = 0;
  190. op[1*8] = 0;
  191. op[2*8] = 0;
  192. op[3*8] = 0;
  193. op[4*8] = 0;
  194. op[5*8] = 0;
  195. op[6*8] = 0;
  196. }
  197. ip++; /* next column */
  198. op++;
  199. }
  200. }