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.

172 lines
5.9KB

  1. /*
  2. * Copyright (c) 2000, 2001 Fabrice Bellard
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <assert.h>
  22. #include "bit_depth_template.c"
  23. #define H264_CHROMA_MC(OPNAME, OP)\
  24. static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
  25. pixel *dst = (pixel*)_dst;\
  26. pixel *src = (pixel*)_src;\
  27. const int A=(8-x)*(8-y);\
  28. const int B=( x)*(8-y);\
  29. const int C=(8-x)*( y);\
  30. const int D=( x)*( y);\
  31. int i;\
  32. stride /= sizeof(pixel);\
  33. \
  34. assert(x<8 && y<8 && x>=0 && y>=0);\
  35. \
  36. if(D){\
  37. for(i=0; i<h; i++){\
  38. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  39. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  40. dst+= stride;\
  41. src+= stride;\
  42. }\
  43. } else if (B + C) {\
  44. const int E= B+C;\
  45. const int step= C ? stride : 1;\
  46. for(i=0; i<h; i++){\
  47. OP(dst[0], (A*src[0] + E*src[step+0]));\
  48. OP(dst[1], (A*src[1] + E*src[step+1]));\
  49. dst+= stride;\
  50. src+= stride;\
  51. }\
  52. } else {\
  53. for ( i = 0; i < h; i++){\
  54. OP(dst[0], A * src[0]);\
  55. OP(dst[1], A * src[1]);\
  56. dst += stride;\
  57. src += stride;\
  58. }\
  59. }\
  60. }\
  61. \
  62. static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
  63. pixel *dst = (pixel*)_dst;\
  64. pixel *src = (pixel*)_src;\
  65. const int A=(8-x)*(8-y);\
  66. const int B=( x)*(8-y);\
  67. const int C=(8-x)*( y);\
  68. const int D=( x)*( y);\
  69. int i;\
  70. stride /= sizeof(pixel);\
  71. \
  72. assert(x<8 && y<8 && x>=0 && y>=0);\
  73. \
  74. if(D){\
  75. for(i=0; i<h; i++){\
  76. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  77. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  78. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  79. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  80. dst+= stride;\
  81. src+= stride;\
  82. }\
  83. } else if (B + C) {\
  84. const int E= B+C;\
  85. const int step= C ? stride : 1;\
  86. for(i=0; i<h; i++){\
  87. OP(dst[0], (A*src[0] + E*src[step+0]));\
  88. OP(dst[1], (A*src[1] + E*src[step+1]));\
  89. OP(dst[2], (A*src[2] + E*src[step+2]));\
  90. OP(dst[3], (A*src[3] + E*src[step+3]));\
  91. dst+= stride;\
  92. src+= stride;\
  93. }\
  94. } else {\
  95. for ( i = 0; i < h; i++){\
  96. OP(dst[0], A * src[0]);\
  97. OP(dst[1], A * src[1]);\
  98. OP(dst[2], A * src[2]);\
  99. OP(dst[3], A * src[3]);\
  100. dst += stride;\
  101. src += stride;\
  102. }\
  103. }\
  104. }\
  105. \
  106. static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
  107. pixel *dst = (pixel*)_dst;\
  108. pixel *src = (pixel*)_src;\
  109. const int A=(8-x)*(8-y);\
  110. const int B=( x)*(8-y);\
  111. const int C=(8-x)*( y);\
  112. const int D=( x)*( y);\
  113. int i;\
  114. stride /= sizeof(pixel);\
  115. \
  116. assert(x<8 && y<8 && x>=0 && y>=0);\
  117. \
  118. if(D){\
  119. for(i=0; i<h; i++){\
  120. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  121. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  122. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  123. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  124. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  125. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  126. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  127. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  128. dst+= stride;\
  129. src+= stride;\
  130. }\
  131. } else if (B + C) {\
  132. const int E= B+C;\
  133. const int step= C ? stride : 1;\
  134. for(i=0; i<h; i++){\
  135. OP(dst[0], (A*src[0] + E*src[step+0]));\
  136. OP(dst[1], (A*src[1] + E*src[step+1]));\
  137. OP(dst[2], (A*src[2] + E*src[step+2]));\
  138. OP(dst[3], (A*src[3] + E*src[step+3]));\
  139. OP(dst[4], (A*src[4] + E*src[step+4]));\
  140. OP(dst[5], (A*src[5] + E*src[step+5]));\
  141. OP(dst[6], (A*src[6] + E*src[step+6]));\
  142. OP(dst[7], (A*src[7] + E*src[step+7]));\
  143. dst+= stride;\
  144. src+= stride;\
  145. }\
  146. } else {\
  147. for ( i = 0; i < h; i++){\
  148. OP(dst[0], A * src[0]);\
  149. OP(dst[1], A * src[1]);\
  150. OP(dst[2], A * src[2]);\
  151. OP(dst[3], A * src[3]);\
  152. OP(dst[4], A * src[4]);\
  153. OP(dst[5], A * src[5]);\
  154. OP(dst[6], A * src[6]);\
  155. OP(dst[7], A * src[7]);\
  156. dst += stride;\
  157. src += stride;\
  158. }\
  159. }\
  160. }
  161. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  162. #define op_put(a, b) a = (((b) + 32)>>6)
  163. H264_CHROMA_MC(put_ , op_put)
  164. H264_CHROMA_MC(avg_ , op_avg)
  165. #undef op_avg
  166. #undef op_put