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.

143 lines
5.1KB

  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{\
  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. }\
  53. }\
  54. \
  55. 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){\
  56. pixel *dst = (pixel*)_dst;\
  57. pixel *src = (pixel*)_src;\
  58. const int A=(8-x)*(8-y);\
  59. const int B=( x)*(8-y);\
  60. const int C=(8-x)*( y);\
  61. const int D=( x)*( y);\
  62. int i;\
  63. stride /= sizeof(pixel);\
  64. \
  65. assert(x<8 && y<8 && x>=0 && y>=0);\
  66. \
  67. if(D){\
  68. for(i=0; i<h; i++){\
  69. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  70. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  71. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  72. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  73. dst+= stride;\
  74. src+= stride;\
  75. }\
  76. }else{\
  77. const int E= B+C;\
  78. const int step= C ? stride : 1;\
  79. for(i=0; i<h; i++){\
  80. OP(dst[0], (A*src[0] + E*src[step+0]));\
  81. OP(dst[1], (A*src[1] + E*src[step+1]));\
  82. OP(dst[2], (A*src[2] + E*src[step+2]));\
  83. OP(dst[3], (A*src[3] + E*src[step+3]));\
  84. dst+= stride;\
  85. src+= stride;\
  86. }\
  87. }\
  88. }\
  89. \
  90. 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){\
  91. pixel *dst = (pixel*)_dst;\
  92. pixel *src = (pixel*)_src;\
  93. const int A=(8-x)*(8-y);\
  94. const int B=( x)*(8-y);\
  95. const int C=(8-x)*( y);\
  96. const int D=( x)*( y);\
  97. int i;\
  98. stride /= sizeof(pixel);\
  99. \
  100. assert(x<8 && y<8 && x>=0 && y>=0);\
  101. \
  102. if(D){\
  103. for(i=0; i<h; i++){\
  104. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  105. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  106. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  107. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  108. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  109. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  110. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  111. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  112. dst+= stride;\
  113. src+= stride;\
  114. }\
  115. }else{\
  116. const int E= B+C;\
  117. const int step= C ? stride : 1;\
  118. for(i=0; i<h; i++){\
  119. OP(dst[0], (A*src[0] + E*src[step+0]));\
  120. OP(dst[1], (A*src[1] + E*src[step+1]));\
  121. OP(dst[2], (A*src[2] + E*src[step+2]));\
  122. OP(dst[3], (A*src[3] + E*src[step+3]));\
  123. OP(dst[4], (A*src[4] + E*src[step+4]));\
  124. OP(dst[5], (A*src[5] + E*src[step+5]));\
  125. OP(dst[6], (A*src[6] + E*src[step+6]));\
  126. OP(dst[7], (A*src[7] + E*src[step+7]));\
  127. dst+= stride;\
  128. src+= stride;\
  129. }\
  130. }\
  131. }
  132. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  133. #define op_put(a, b) a = (((b) + 32)>>6)
  134. H264_CHROMA_MC(put_ , op_put)
  135. H264_CHROMA_MC(avg_ , op_avg)
  136. #undef op_avg
  137. #undef op_put