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.

239 lines
7.0KB

  1. /*
  2. * Floating point AAN DCT
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * this implementation is based upon the IJG integer AAN DCT (see jfdctfst.c)
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * The AAN DCT in this file except ff_faandct248() can also be used under the
  24. * new (3 clause) BSD license.
  25. */
  26. /**
  27. * @file faandct.c
  28. * @brief
  29. * Floating point AAN DCT
  30. * @author Michael Niedermayer <michaelni@gmx.at>
  31. */
  32. #include "dsputil.h"
  33. #include "faandct.h"
  34. #define FLOAT float
  35. #ifdef FAAN_POSTSCALE
  36. # define SCALE(x) postscale[x]
  37. #else
  38. # define SCALE(x) 1
  39. #endif
  40. //numbers generated by simple c code (not as accurate as they could be)
  41. /*
  42. for(i=0; i<8; i++){
  43. printf("#define B%d %1.20llf\n", i, (long double)1.0/(cosl(i*acosl(-1.0)/(long double)16.0)*sqrtl(2)));
  44. }
  45. */
  46. #define B0 1.00000000000000000000
  47. #define B1 0.72095982200694791383 // (cos(pi*1/16)sqrt(2))^-1
  48. #define B2 0.76536686473017954350 // (cos(pi*2/16)sqrt(2))^-1
  49. #define B3 0.85043009476725644878 // (cos(pi*3/16)sqrt(2))^-1
  50. #define B4 1.00000000000000000000 // (cos(pi*4/16)sqrt(2))^-1
  51. #define B5 1.27275858057283393842 // (cos(pi*5/16)sqrt(2))^-1
  52. #define B6 1.84775906502257351242 // (cos(pi*6/16)sqrt(2))^-1
  53. #define B7 3.62450978541155137218 // (cos(pi*7/16)sqrt(2))^-1
  54. #define A1 0.70710678118654752438 // cos(pi*4/16)
  55. #define A2 0.54119610014619698435 // cos(pi*6/16)sqrt(2)
  56. #define A5 0.38268343236508977170 // cos(pi*6/16)
  57. #define A4 1.30656296487637652774 // cos(pi*2/16)sqrt(2)
  58. static FLOAT postscale[64]={
  59. B0*B0, B0*B1, B0*B2, B0*B3, B0*B4, B0*B5, B0*B6, B0*B7,
  60. B1*B0, B1*B1, B1*B2, B1*B3, B1*B4, B1*B5, B1*B6, B1*B7,
  61. B2*B0, B2*B1, B2*B2, B2*B3, B2*B4, B2*B5, B2*B6, B2*B7,
  62. B3*B0, B3*B1, B3*B2, B3*B3, B3*B4, B3*B5, B3*B6, B3*B7,
  63. B4*B0, B4*B1, B4*B2, B4*B3, B4*B4, B4*B5, B4*B6, B4*B7,
  64. B5*B0, B5*B1, B5*B2, B5*B3, B5*B4, B5*B5, B5*B6, B5*B7,
  65. B6*B0, B6*B1, B6*B2, B6*B3, B6*B4, B6*B5, B6*B6, B6*B7,
  66. B7*B0, B7*B1, B7*B2, B7*B3, B7*B4, B7*B5, B7*B6, B7*B7,
  67. };
  68. static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data)
  69. {
  70. FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  71. FLOAT tmp10, tmp11, tmp12, tmp13;
  72. FLOAT z2, z4, z11, z13;
  73. FLOAT av_unused z5;
  74. int i;
  75. for (i=0; i<8*8; i+=8) {
  76. tmp0= data[0 + i] + data[7 + i];
  77. tmp7= data[0 + i] - data[7 + i];
  78. tmp1= data[1 + i] + data[6 + i];
  79. tmp6= data[1 + i] - data[6 + i];
  80. tmp2= data[2 + i] + data[5 + i];
  81. tmp5= data[2 + i] - data[5 + i];
  82. tmp3= data[3 + i] + data[4 + i];
  83. tmp4= data[3 + i] - data[4 + i];
  84. tmp10= tmp0 + tmp3;
  85. tmp13= tmp0 - tmp3;
  86. tmp11= tmp1 + tmp2;
  87. tmp12= tmp1 - tmp2;
  88. temp[0 + i]= tmp10 + tmp11;
  89. temp[4 + i]= tmp10 - tmp11;
  90. tmp12 += tmp13;
  91. tmp12 *= A1;
  92. temp[2 + i]= tmp13 + tmp12;
  93. temp[6 + i]= tmp13 - tmp12;
  94. tmp4 += tmp5;
  95. tmp5 += tmp6;
  96. tmp6 += tmp7;
  97. #if 0
  98. z5= (tmp4 - tmp6) * A5;
  99. z2= tmp4*A2 + z5;
  100. z4= tmp6*A4 + z5;
  101. #else
  102. z2= tmp4*(A2+A5) - tmp6*A5;
  103. z4= tmp6*(A4-A5) + tmp4*A5;
  104. #endif
  105. tmp5*=A1;
  106. z11= tmp7 + tmp5;
  107. z13= tmp7 - tmp5;
  108. temp[5 + i]= z13 + z2;
  109. temp[3 + i]= z13 - z2;
  110. temp[1 + i]= z11 + z4;
  111. temp[7 + i]= z11 - z4;
  112. }
  113. }
  114. void ff_faandct(DCTELEM * data)
  115. {
  116. FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  117. FLOAT tmp10, tmp11, tmp12, tmp13;
  118. FLOAT z2, z4, z11, z13;
  119. FLOAT av_unused z5;
  120. FLOAT temp[64];
  121. int i;
  122. emms_c();
  123. row_fdct(temp, data);
  124. for (i=0; i<8; i++) {
  125. tmp0= temp[8*0 + i] + temp[8*7 + i];
  126. tmp7= temp[8*0 + i] - temp[8*7 + i];
  127. tmp1= temp[8*1 + i] + temp[8*6 + i];
  128. tmp6= temp[8*1 + i] - temp[8*6 + i];
  129. tmp2= temp[8*2 + i] + temp[8*5 + i];
  130. tmp5= temp[8*2 + i] - temp[8*5 + i];
  131. tmp3= temp[8*3 + i] + temp[8*4 + i];
  132. tmp4= temp[8*3 + i] - temp[8*4 + i];
  133. tmp10= tmp0 + tmp3;
  134. tmp13= tmp0 - tmp3;
  135. tmp11= tmp1 + tmp2;
  136. tmp12= tmp1 - tmp2;
  137. data[8*0 + i]= lrintf(SCALE(8*0 + i) * (tmp10 + tmp11));
  138. data[8*4 + i]= lrintf(SCALE(8*4 + i) * (tmp10 - tmp11));
  139. tmp12 += tmp13;
  140. tmp12 *= A1;
  141. data[8*2 + i]= lrintf(SCALE(8*2 + i) * (tmp13 + tmp12));
  142. data[8*6 + i]= lrintf(SCALE(8*6 + i) * (tmp13 - tmp12));
  143. tmp4 += tmp5;
  144. tmp5 += tmp6;
  145. tmp6 += tmp7;
  146. #if 0
  147. z5= (tmp4 - tmp6) * A5;
  148. z2= tmp4*A2 + z5;
  149. z4= tmp6*A4 + z5;
  150. #else
  151. z2= tmp4*(A2+A5) - tmp6*A5;
  152. z4= tmp6*(A4-A5) + tmp4*A5;
  153. #endif
  154. tmp5*=A1;
  155. z11= tmp7 + tmp5;
  156. z13= tmp7 - tmp5;
  157. data[8*5 + i]= lrintf(SCALE(8*5 + i) * (z13 + z2));
  158. data[8*3 + i]= lrintf(SCALE(8*3 + i) * (z13 - z2));
  159. data[8*1 + i]= lrintf(SCALE(8*1 + i) * (z11 + z4));
  160. data[8*7 + i]= lrintf(SCALE(8*7 + i) * (z11 - z4));
  161. }
  162. }
  163. void ff_faandct248(DCTELEM * data)
  164. {
  165. FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  166. FLOAT tmp10, tmp11, tmp12, tmp13;
  167. FLOAT temp[64];
  168. int i;
  169. emms_c();
  170. row_fdct(temp, data);
  171. for (i=0; i<8; i++) {
  172. tmp0 = temp[8*0 + i] + temp[8*1 + i];
  173. tmp1 = temp[8*2 + i] + temp[8*3 + i];
  174. tmp2 = temp[8*4 + i] + temp[8*5 + i];
  175. tmp3 = temp[8*6 + i] + temp[8*7 + i];
  176. tmp4 = temp[8*0 + i] - temp[8*1 + i];
  177. tmp5 = temp[8*2 + i] - temp[8*3 + i];
  178. tmp6 = temp[8*4 + i] - temp[8*5 + i];
  179. tmp7 = temp[8*6 + i] - temp[8*7 + i];
  180. tmp10 = tmp0 + tmp3;
  181. tmp11 = tmp1 + tmp2;
  182. tmp12 = tmp1 - tmp2;
  183. tmp13 = tmp0 - tmp3;
  184. data[8*0 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11));
  185. data[8*4 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11));
  186. tmp12 += tmp13;
  187. tmp12 *= A1;
  188. data[8*2 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12));
  189. data[8*6 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12));
  190. tmp10 = tmp4 + tmp7;
  191. tmp11 = tmp5 + tmp6;
  192. tmp12 = tmp5 - tmp6;
  193. tmp13 = tmp4 - tmp7;
  194. data[8*1 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11));
  195. data[8*5 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11));
  196. tmp12 += tmp13;
  197. tmp12 *= A1;
  198. data[8*3 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12));
  199. data[8*7 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12));
  200. }
  201. }