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.

237 lines
6.9KB

  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, z5, z11, z13;
  73. int i;
  74. for (i=0; i<8*8; i+=8) {
  75. tmp0= data[0 + i] + data[7 + i];
  76. tmp7= data[0 + i] - data[7 + i];
  77. tmp1= data[1 + i] + data[6 + i];
  78. tmp6= data[1 + i] - data[6 + i];
  79. tmp2= data[2 + i] + data[5 + i];
  80. tmp5= data[2 + i] - data[5 + i];
  81. tmp3= data[3 + i] + data[4 + i];
  82. tmp4= data[3 + i] - data[4 + i];
  83. tmp10= tmp0 + tmp3;
  84. tmp13= tmp0 - tmp3;
  85. tmp11= tmp1 + tmp2;
  86. tmp12= tmp1 - tmp2;
  87. temp[0 + i]= tmp10 + tmp11;
  88. temp[4 + i]= tmp10 - tmp11;
  89. tmp12 += tmp13;
  90. tmp12 *= A1;
  91. temp[2 + i]= tmp13 + tmp12;
  92. temp[6 + i]= tmp13 - tmp12;
  93. tmp4 += tmp5;
  94. tmp5 += tmp6;
  95. tmp6 += tmp7;
  96. #if 0
  97. z5= (tmp4 - tmp6) * A5;
  98. z2= tmp4*A2 + z5;
  99. z4= tmp6*A4 + z5;
  100. #else
  101. z2= tmp4*(A2+A5) - tmp6*A5;
  102. z4= tmp6*(A4-A5) + tmp4*A5;
  103. #endif
  104. tmp5*=A1;
  105. z11= tmp7 + tmp5;
  106. z13= tmp7 - tmp5;
  107. temp[5 + i]= z13 + z2;
  108. temp[3 + i]= z13 - z2;
  109. temp[1 + i]= z11 + z4;
  110. temp[7 + i]= z11 - z4;
  111. }
  112. }
  113. void ff_faandct(DCTELEM * data)
  114. {
  115. FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  116. FLOAT tmp10, tmp11, tmp12, tmp13;
  117. FLOAT z2, z4, z5, z11, z13;
  118. FLOAT temp[64];
  119. int i;
  120. emms_c();
  121. row_fdct(temp, data);
  122. for (i=0; i<8; i++) {
  123. tmp0= temp[8*0 + i] + temp[8*7 + i];
  124. tmp7= temp[8*0 + i] - temp[8*7 + i];
  125. tmp1= temp[8*1 + i] + temp[8*6 + i];
  126. tmp6= temp[8*1 + i] - temp[8*6 + i];
  127. tmp2= temp[8*2 + i] + temp[8*5 + i];
  128. tmp5= temp[8*2 + i] - temp[8*5 + i];
  129. tmp3= temp[8*3 + i] + temp[8*4 + i];
  130. tmp4= temp[8*3 + i] - temp[8*4 + i];
  131. tmp10= tmp0 + tmp3;
  132. tmp13= tmp0 - tmp3;
  133. tmp11= tmp1 + tmp2;
  134. tmp12= tmp1 - tmp2;
  135. data[8*0 + i]= lrintf(SCALE(8*0 + i) * (tmp10 + tmp11));
  136. data[8*4 + i]= lrintf(SCALE(8*4 + i) * (tmp10 - tmp11));
  137. tmp12 += tmp13;
  138. tmp12 *= A1;
  139. data[8*2 + i]= lrintf(SCALE(8*2 + i) * (tmp13 + tmp12));
  140. data[8*6 + i]= lrintf(SCALE(8*6 + i) * (tmp13 - tmp12));
  141. tmp4 += tmp5;
  142. tmp5 += tmp6;
  143. tmp6 += tmp7;
  144. #if 0
  145. z5= (tmp4 - tmp6) * A5;
  146. z2= tmp4*A2 + z5;
  147. z4= tmp6*A4 + z5;
  148. #else
  149. z2= tmp4*(A2+A5) - tmp6*A5;
  150. z4= tmp6*(A4-A5) + tmp4*A5;
  151. #endif
  152. tmp5*=A1;
  153. z11= tmp7 + tmp5;
  154. z13= tmp7 - tmp5;
  155. data[8*5 + i]= lrintf(SCALE(8*5 + i) * (z13 + z2));
  156. data[8*3 + i]= lrintf(SCALE(8*3 + i) * (z13 - z2));
  157. data[8*1 + i]= lrintf(SCALE(8*1 + i) * (z11 + z4));
  158. data[8*7 + i]= lrintf(SCALE(8*7 + i) * (z11 - z4));
  159. }
  160. }
  161. void ff_faandct248(DCTELEM * data)
  162. {
  163. FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  164. FLOAT tmp10, tmp11, tmp12, tmp13;
  165. FLOAT temp[64];
  166. int i;
  167. emms_c();
  168. row_fdct(temp, data);
  169. for (i=0; i<8; i++) {
  170. tmp0 = temp[8*0 + i] + temp[8*1 + i];
  171. tmp1 = temp[8*2 + i] + temp[8*3 + i];
  172. tmp2 = temp[8*4 + i] + temp[8*5 + i];
  173. tmp3 = temp[8*6 + i] + temp[8*7 + i];
  174. tmp4 = temp[8*0 + i] - temp[8*1 + i];
  175. tmp5 = temp[8*2 + i] - temp[8*3 + i];
  176. tmp6 = temp[8*4 + i] - temp[8*5 + i];
  177. tmp7 = temp[8*6 + i] - temp[8*7 + i];
  178. tmp10 = tmp0 + tmp3;
  179. tmp11 = tmp1 + tmp2;
  180. tmp12 = tmp1 - tmp2;
  181. tmp13 = tmp0 - tmp3;
  182. data[8*0 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11));
  183. data[8*4 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11));
  184. tmp12 += tmp13;
  185. tmp12 *= A1;
  186. data[8*2 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12));
  187. data[8*6 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12));
  188. tmp10 = tmp4 + tmp7;
  189. tmp11 = tmp5 + tmp6;
  190. tmp12 = tmp5 - tmp6;
  191. tmp13 = tmp4 - tmp7;
  192. data[8*1 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11));
  193. data[8*5 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11));
  194. tmp12 += tmp13;
  195. tmp12 *= A1;
  196. data[8*3 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12));
  197. data[8*7 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12));
  198. }
  199. }