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.

230 lines
7.0KB

  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 "dsputil.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. #define M(a,b) (((a) * (b))>>16)
  35. static always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type)
  36. {
  37. int16_t *ip = input;
  38. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  39. int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;
  40. int Ed, Gd, Add, Bdd, Fd, Hd;
  41. int i;
  42. /* Inverse DCT on the rows now */
  43. for (i = 0; i < 8; i++) {
  44. /* Check for non-zero values */
  45. if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
  46. A = M(xC1S7, ip[1]) + M(xC7S1, ip[7]);
  47. B = M(xC7S1, ip[1]) - M(xC1S7, ip[7]);
  48. C = M(xC3S5, ip[3]) + M(xC5S3, ip[5]);
  49. D = M(xC3S5, ip[5]) - M(xC5S3, ip[3]);
  50. Ad = M(xC4S4, (A - C));
  51. Bd = M(xC4S4, (B - D));
  52. Cd = A + C;
  53. Dd = B + D;
  54. E = M(xC4S4, (ip[0] + ip[4]));
  55. F = M(xC4S4, (ip[0] - ip[4]));
  56. G = M(xC2S6, ip[2]) + M(xC6S2, ip[6]);
  57. H = M(xC6S2, ip[2]) - M(xC2S6, ip[6]);
  58. Ed = E - G;
  59. Gd = E + G;
  60. Add = F + Ad;
  61. Bdd = Bd - H;
  62. Fd = F - Ad;
  63. Hd = Bd + H;
  64. /* Final sequence of operations over-write original inputs. */
  65. ip[0] = Gd + Cd ;
  66. ip[7] = Gd - Cd ;
  67. ip[1] = Add + Hd;
  68. ip[2] = Add - Hd;
  69. ip[3] = Ed + Dd ;
  70. ip[4] = Ed - Dd ;
  71. ip[5] = Fd + Bdd;
  72. ip[6] = Fd - Bdd;
  73. }
  74. ip += 8; /* next row */
  75. }
  76. ip = input;
  77. for ( i = 0; i < 8; i++) {
  78. /* Check for non-zero values (bitwise or faster than ||) */
  79. if ( ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
  80. ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
  81. A = M(xC1S7, ip[1*8]) + M(xC7S1, ip[7*8]);
  82. B = M(xC7S1, ip[1*8]) - M(xC1S7, ip[7*8]);
  83. C = M(xC3S5, ip[3*8]) + M(xC5S3, ip[5*8]);
  84. D = M(xC3S5, ip[5*8]) - M(xC5S3, ip[3*8]);
  85. Ad = M(xC4S4, (A - C));
  86. Bd = M(xC4S4, (B - D));
  87. Cd = A + C;
  88. Dd = B + D;
  89. E = M(xC4S4, (ip[0*8] + ip[4*8]));
  90. F = M(xC4S4, (ip[0*8] - ip[4*8]));
  91. G = M(xC2S6, ip[2*8]) + M(xC6S2, ip[6*8]);
  92. H = M(xC6S2, ip[2*8]) - M(xC2S6, ip[6*8]);
  93. Ed = E - G;
  94. Gd = E + G;
  95. Add = F + Ad;
  96. Bdd = Bd - H;
  97. Fd = F - Ad;
  98. Hd = Bd + H;
  99. if(type==1){ //HACK
  100. Gd += 16*128;
  101. Add+= 16*128;
  102. Ed += 16*128;
  103. Fd += 16*128;
  104. }
  105. Gd += IdctAdjustBeforeShift;
  106. Add += IdctAdjustBeforeShift;
  107. Ed += IdctAdjustBeforeShift;
  108. Fd += IdctAdjustBeforeShift;
  109. /* Final sequence of operations over-write original inputs. */
  110. if(type==0){
  111. ip[0*8] = (Gd + Cd ) >> 4;
  112. ip[7*8] = (Gd - Cd ) >> 4;
  113. ip[1*8] = (Add + Hd ) >> 4;
  114. ip[2*8] = (Add - Hd ) >> 4;
  115. ip[3*8] = (Ed + Dd ) >> 4;
  116. ip[4*8] = (Ed - Dd ) >> 4;
  117. ip[5*8] = (Fd + Bdd ) >> 4;
  118. ip[6*8] = (Fd - Bdd ) >> 4;
  119. }else if(type==1){
  120. dst[0*stride] = cm[(Gd + Cd ) >> 4];
  121. dst[7*stride] = cm[(Gd - Cd ) >> 4];
  122. dst[1*stride] = cm[(Add + Hd ) >> 4];
  123. dst[2*stride] = cm[(Add - Hd ) >> 4];
  124. dst[3*stride] = cm[(Ed + Dd ) >> 4];
  125. dst[4*stride] = cm[(Ed - Dd ) >> 4];
  126. dst[5*stride] = cm[(Fd + Bdd ) >> 4];
  127. dst[6*stride] = cm[(Fd - Bdd ) >> 4];
  128. }else{
  129. dst[0*stride] = cm[dst[0*stride] + ((Gd + Cd ) >> 4)];
  130. dst[7*stride] = cm[dst[7*stride] + ((Gd - Cd ) >> 4)];
  131. dst[1*stride] = cm[dst[1*stride] + ((Add + Hd ) >> 4)];
  132. dst[2*stride] = cm[dst[2*stride] + ((Add - Hd ) >> 4)];
  133. dst[3*stride] = cm[dst[3*stride] + ((Ed + Dd ) >> 4)];
  134. dst[4*stride] = cm[dst[4*stride] + ((Ed - Dd ) >> 4)];
  135. dst[5*stride] = cm[dst[5*stride] + ((Fd + Bdd ) >> 4)];
  136. dst[6*stride] = cm[dst[6*stride] + ((Fd - Bdd ) >> 4)];
  137. }
  138. } else {
  139. if(type==0){
  140. ip[0*8] =
  141. ip[1*8] =
  142. ip[2*8] =
  143. ip[3*8] =
  144. ip[4*8] =
  145. ip[5*8] =
  146. ip[6*8] =
  147. ip[7*8] = ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
  148. }else if(type==1){
  149. dst[0*stride]=
  150. dst[1*stride]=
  151. dst[2*stride]=
  152. dst[3*stride]=
  153. dst[4*stride]=
  154. dst[5*stride]=
  155. dst[6*stride]=
  156. dst[7*stride]= 128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
  157. }else{
  158. if(ip[0*8]){
  159. int v= ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
  160. dst[0*stride] = cm[dst[0*stride] + v];
  161. dst[1*stride] = cm[dst[1*stride] + v];
  162. dst[2*stride] = cm[dst[2*stride] + v];
  163. dst[3*stride] = cm[dst[3*stride] + v];
  164. dst[4*stride] = cm[dst[4*stride] + v];
  165. dst[5*stride] = cm[dst[5*stride] + v];
  166. dst[6*stride] = cm[dst[6*stride] + v];
  167. dst[7*stride] = cm[dst[7*stride] + v];
  168. }
  169. }
  170. }
  171. ip++; /* next column */
  172. dst++;
  173. }
  174. }
  175. void ff_vp3_idct_c(DCTELEM *block/* align 16*/){
  176. idct(NULL, 0, block, 0);
  177. }
  178. void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
  179. idct(dest, line_size, block, 1);
  180. }
  181. void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
  182. idct(dest, line_size, block, 2);
  183. }