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.

553 lines
24KB

  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
  3. * Copyright (c) 2003-2010 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 "libavutil/common.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "bit_depth_template.c"
  24. #include "hpel_template.c"
  25. #include "pel_template.c"
  26. static inline void FUNC(copy_block2)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  27. {
  28. int i;
  29. for(i=0; i<h; i++)
  30. {
  31. AV_WN2P(dst , AV_RN2P(src ));
  32. dst+=dstStride;
  33. src+=srcStride;
  34. }
  35. }
  36. static inline void FUNC(copy_block4)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  37. {
  38. int i;
  39. for(i=0; i<h; i++)
  40. {
  41. AV_WN4P(dst , AV_RN4P(src ));
  42. dst+=dstStride;
  43. src+=srcStride;
  44. }
  45. }
  46. static inline void FUNC(copy_block8)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  47. {
  48. int i;
  49. for(i=0; i<h; i++)
  50. {
  51. AV_WN4P(dst , AV_RN4P(src ));
  52. AV_WN4P(dst+4*sizeof(pixel), AV_RN4P(src+4*sizeof(pixel)));
  53. dst+=dstStride;
  54. src+=srcStride;
  55. }
  56. }
  57. static inline void FUNC(copy_block16)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
  58. {
  59. int i;
  60. for(i=0; i<h; i++)
  61. {
  62. AV_WN4P(dst , AV_RN4P(src ));
  63. AV_WN4P(dst+ 4*sizeof(pixel), AV_RN4P(src+ 4*sizeof(pixel)));
  64. AV_WN4P(dst+ 8*sizeof(pixel), AV_RN4P(src+ 8*sizeof(pixel)));
  65. AV_WN4P(dst+12*sizeof(pixel), AV_RN4P(src+12*sizeof(pixel)));
  66. dst+=dstStride;
  67. src+=srcStride;
  68. }
  69. }
  70. #define H264_LOWPASS(OPNAME, OP, OP2) \
  71. static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *_dst, const uint8_t *_src, int dstStride, int srcStride){\
  72. const int h=2;\
  73. INIT_CLIP\
  74. int i;\
  75. pixel *dst = (pixel*)_dst;\
  76. const pixel *src = (const pixel*)_src;\
  77. dstStride /= sizeof(pixel);\
  78. srcStride /= sizeof(pixel);\
  79. for(i=0; i<h; i++)\
  80. {\
  81. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  82. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  83. dst+=dstStride;\
  84. src+=srcStride;\
  85. }\
  86. }\
  87. \
  88. static av_unused void FUNC(OPNAME ## h264_qpel2_v_lowpass)(uint8_t *_dst, const uint8_t *_src, int dstStride, int srcStride){\
  89. const int w=2;\
  90. INIT_CLIP\
  91. int i;\
  92. pixel *dst = (pixel*)_dst;\
  93. const pixel *src = (const pixel*)_src;\
  94. dstStride /= sizeof(pixel);\
  95. srcStride /= sizeof(pixel);\
  96. for(i=0; i<w; i++)\
  97. {\
  98. const int srcB= src[-2*srcStride];\
  99. const int srcA= src[-1*srcStride];\
  100. const int src0= src[0 *srcStride];\
  101. const int src1= src[1 *srcStride];\
  102. const int src2= src[2 *srcStride];\
  103. const int src3= src[3 *srcStride];\
  104. const int src4= src[4 *srcStride];\
  105. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  106. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  107. dst++;\
  108. src++;\
  109. }\
  110. }\
  111. \
  112. static av_unused void FUNC(OPNAME ## h264_qpel2_hv_lowpass)(uint8_t *_dst, int16_t *tmp, const uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
  113. const int h=2;\
  114. const int w=2;\
  115. const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
  116. INIT_CLIP\
  117. int i;\
  118. pixel *dst = (pixel*)_dst;\
  119. const pixel *src = (const pixel*)_src;\
  120. dstStride /= sizeof(pixel);\
  121. srcStride /= sizeof(pixel);\
  122. src -= 2*srcStride;\
  123. for(i=0; i<h+5; i++)\
  124. {\
  125. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + pad;\
  126. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + pad;\
  127. tmp+=tmpStride;\
  128. src+=srcStride;\
  129. }\
  130. tmp -= tmpStride*(h+5-2);\
  131. for(i=0; i<w; i++)\
  132. {\
  133. const int tmpB= tmp[-2*tmpStride] - pad;\
  134. const int tmpA= tmp[-1*tmpStride] - pad;\
  135. const int tmp0= tmp[0 *tmpStride] - pad;\
  136. const int tmp1= tmp[1 *tmpStride] - pad;\
  137. const int tmp2= tmp[2 *tmpStride] - pad;\
  138. const int tmp3= tmp[3 *tmpStride] - pad;\
  139. const int tmp4= tmp[4 *tmpStride] - pad;\
  140. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  141. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  142. dst++;\
  143. tmp++;\
  144. }\
  145. }\
  146. static void FUNC(OPNAME ## h264_qpel4_h_lowpass)(uint8_t *_dst, const uint8_t *_src, int dstStride, int srcStride){\
  147. const int h=4;\
  148. INIT_CLIP\
  149. int i;\
  150. pixel *dst = (pixel*)_dst;\
  151. const pixel *src = (const pixel*)_src;\
  152. dstStride /= sizeof(pixel);\
  153. srcStride /= sizeof(pixel);\
  154. for(i=0; i<h; i++)\
  155. {\
  156. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  157. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  158. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  159. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  160. dst+=dstStride;\
  161. src+=srcStride;\
  162. }\
  163. }\
  164. \
  165. static void FUNC(OPNAME ## h264_qpel4_v_lowpass)(uint8_t *_dst, const uint8_t *_src, int dstStride, int srcStride){\
  166. const int w=4;\
  167. INIT_CLIP\
  168. int i;\
  169. pixel *dst = (pixel*)_dst;\
  170. const pixel *src = (const pixel*)_src;\
  171. dstStride /= sizeof(pixel);\
  172. srcStride /= sizeof(pixel);\
  173. for(i=0; i<w; i++)\
  174. {\
  175. const int srcB= src[-2*srcStride];\
  176. const int srcA= src[-1*srcStride];\
  177. const int src0= src[0 *srcStride];\
  178. const int src1= src[1 *srcStride];\
  179. const int src2= src[2 *srcStride];\
  180. const int src3= src[3 *srcStride];\
  181. const int src4= src[4 *srcStride];\
  182. const int src5= src[5 *srcStride];\
  183. const int src6= src[6 *srcStride];\
  184. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  185. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  186. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  187. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  188. dst++;\
  189. src++;\
  190. }\
  191. }\
  192. \
  193. static void FUNC(OPNAME ## h264_qpel4_hv_lowpass)(uint8_t *_dst, int16_t *tmp, const uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
  194. const int h=4;\
  195. const int w=4;\
  196. const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
  197. INIT_CLIP\
  198. int i;\
  199. pixel *dst = (pixel*)_dst;\
  200. const pixel *src = (const pixel*)_src;\
  201. dstStride /= sizeof(pixel);\
  202. srcStride /= sizeof(pixel);\
  203. src -= 2*srcStride;\
  204. for(i=0; i<h+5; i++)\
  205. {\
  206. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + pad;\
  207. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + pad;\
  208. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]) + pad;\
  209. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]) + pad;\
  210. tmp+=tmpStride;\
  211. src+=srcStride;\
  212. }\
  213. tmp -= tmpStride*(h+5-2);\
  214. for(i=0; i<w; i++)\
  215. {\
  216. const int tmpB= tmp[-2*tmpStride] - pad;\
  217. const int tmpA= tmp[-1*tmpStride] - pad;\
  218. const int tmp0= tmp[0 *tmpStride] - pad;\
  219. const int tmp1= tmp[1 *tmpStride] - pad;\
  220. const int tmp2= tmp[2 *tmpStride] - pad;\
  221. const int tmp3= tmp[3 *tmpStride] - pad;\
  222. const int tmp4= tmp[4 *tmpStride] - pad;\
  223. const int tmp5= tmp[5 *tmpStride] - pad;\
  224. const int tmp6= tmp[6 *tmpStride] - pad;\
  225. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  226. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  227. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  228. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  229. dst++;\
  230. tmp++;\
  231. }\
  232. }\
  233. \
  234. static void FUNC(OPNAME ## h264_qpel8_h_lowpass)(uint8_t *_dst, const uint8_t *_src, int dstStride, int srcStride){\
  235. const int h=8;\
  236. INIT_CLIP\
  237. int i;\
  238. pixel *dst = (pixel*)_dst;\
  239. const pixel *src = (const pixel*)_src;\
  240. dstStride /= sizeof(pixel);\
  241. srcStride /= sizeof(pixel);\
  242. for(i=0; i<h; i++)\
  243. {\
  244. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  245. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  246. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  247. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  248. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  249. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  250. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  251. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  252. dst+=dstStride;\
  253. src+=srcStride;\
  254. }\
  255. }\
  256. \
  257. static void FUNC(OPNAME ## h264_qpel8_v_lowpass)(uint8_t *_dst, const uint8_t *_src, int dstStride, int srcStride){\
  258. const int w=8;\
  259. INIT_CLIP\
  260. int i;\
  261. pixel *dst = (pixel*)_dst;\
  262. const pixel *src = (const pixel*)_src;\
  263. dstStride /= sizeof(pixel);\
  264. srcStride /= sizeof(pixel);\
  265. for(i=0; i<w; i++)\
  266. {\
  267. const int srcB= src[-2*srcStride];\
  268. const int srcA= src[-1*srcStride];\
  269. const int src0= src[0 *srcStride];\
  270. const int src1= src[1 *srcStride];\
  271. const int src2= src[2 *srcStride];\
  272. const int src3= src[3 *srcStride];\
  273. const int src4= src[4 *srcStride];\
  274. const int src5= src[5 *srcStride];\
  275. const int src6= src[6 *srcStride];\
  276. const int src7= src[7 *srcStride];\
  277. const int src8= src[8 *srcStride];\
  278. const int src9= src[9 *srcStride];\
  279. const int src10=src[10*srcStride];\
  280. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  281. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  282. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  283. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  284. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  285. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  286. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  287. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  288. dst++;\
  289. src++;\
  290. }\
  291. }\
  292. \
  293. static void FUNC(OPNAME ## h264_qpel8_hv_lowpass)(uint8_t *_dst, int16_t *tmp, const uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
  294. const int h=8;\
  295. const int w=8;\
  296. const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
  297. INIT_CLIP\
  298. int i;\
  299. pixel *dst = (pixel*)_dst;\
  300. const pixel *src = (const pixel*)_src;\
  301. dstStride /= sizeof(pixel);\
  302. srcStride /= sizeof(pixel);\
  303. src -= 2*srcStride;\
  304. for(i=0; i<h+5; i++)\
  305. {\
  306. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]) + pad;\
  307. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]) + pad;\
  308. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]) + pad;\
  309. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]) + pad;\
  310. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]) + pad;\
  311. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]) + pad;\
  312. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]) + pad;\
  313. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]) + pad;\
  314. tmp+=tmpStride;\
  315. src+=srcStride;\
  316. }\
  317. tmp -= tmpStride*(h+5-2);\
  318. for(i=0; i<w; i++)\
  319. {\
  320. const int tmpB= tmp[-2*tmpStride] - pad;\
  321. const int tmpA= tmp[-1*tmpStride] - pad;\
  322. const int tmp0= tmp[0 *tmpStride] - pad;\
  323. const int tmp1= tmp[1 *tmpStride] - pad;\
  324. const int tmp2= tmp[2 *tmpStride] - pad;\
  325. const int tmp3= tmp[3 *tmpStride] - pad;\
  326. const int tmp4= tmp[4 *tmpStride] - pad;\
  327. const int tmp5= tmp[5 *tmpStride] - pad;\
  328. const int tmp6= tmp[6 *tmpStride] - pad;\
  329. const int tmp7= tmp[7 *tmpStride] - pad;\
  330. const int tmp8= tmp[8 *tmpStride] - pad;\
  331. const int tmp9= tmp[9 *tmpStride] - pad;\
  332. const int tmp10=tmp[10*tmpStride] - pad;\
  333. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  334. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  335. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  336. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  337. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  338. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  339. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  340. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  341. dst++;\
  342. tmp++;\
  343. }\
  344. }\
  345. \
  346. static void FUNC(OPNAME ## h264_qpel16_v_lowpass)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  347. FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst , src , dstStride, srcStride);\
  348. FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
  349. src += 8*srcStride;\
  350. dst += 8*dstStride;\
  351. FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst , src , dstStride, srcStride);\
  352. FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
  353. }\
  354. \
  355. static void FUNC(OPNAME ## h264_qpel16_h_lowpass)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  356. FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst , src , dstStride, srcStride);\
  357. FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
  358. src += 8*srcStride;\
  359. dst += 8*dstStride;\
  360. FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst , src , dstStride, srcStride);\
  361. FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
  362. }\
  363. \
  364. static void FUNC(OPNAME ## h264_qpel16_hv_lowpass)(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  365. FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst , tmp , src , dstStride, tmpStride, srcStride);\
  366. FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\
  367. src += 8*srcStride;\
  368. dst += 8*dstStride;\
  369. FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst , tmp , src , dstStride, tmpStride, srcStride);\
  370. FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\
  371. }\
  372. #define H264_MC(OPNAME, SIZE) \
  373. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc00)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  374. {\
  375. FUNCC(OPNAME ## pixels ## SIZE)(dst, src, stride, SIZE);\
  376. }\
  377. \
  378. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc10)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  379. {\
  380. uint8_t half[SIZE*SIZE*sizeof(pixel)];\
  381. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(half, src, SIZE*sizeof(pixel), stride);\
  382. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, src, half, stride, stride, SIZE*sizeof(pixel), SIZE);\
  383. }\
  384. \
  385. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc20)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  386. {\
  387. FUNC(OPNAME ## h264_qpel ## SIZE ## _h_lowpass)(dst, src, stride, stride);\
  388. }\
  389. \
  390. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc30)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  391. {\
  392. uint8_t half[SIZE*SIZE*sizeof(pixel)];\
  393. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(half, src, SIZE*sizeof(pixel), stride);\
  394. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, src+sizeof(pixel), half, stride, stride, SIZE*sizeof(pixel), SIZE);\
  395. }\
  396. \
  397. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc01)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  398. {\
  399. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  400. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  401. uint8_t half[SIZE*SIZE*sizeof(pixel)];\
  402. FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
  403. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(half, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  404. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, full_mid, half, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  405. }\
  406. \
  407. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc02)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  408. {\
  409. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  410. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  411. FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
  412. FUNC(OPNAME ## h264_qpel ## SIZE ## _v_lowpass)(dst, full_mid, stride, SIZE*sizeof(pixel));\
  413. }\
  414. \
  415. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc03)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  416. {\
  417. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  418. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  419. uint8_t half[SIZE*SIZE*sizeof(pixel)];\
  420. FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
  421. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(half, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  422. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, full_mid+SIZE*sizeof(pixel), half, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  423. }\
  424. \
  425. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc11)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  426. {\
  427. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  428. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  429. uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
  430. uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
  431. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
  432. FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
  433. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  434. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  435. }\
  436. \
  437. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc31)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  438. {\
  439. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  440. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  441. uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
  442. uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
  443. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
  444. FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel), stride, SIZE + 5);\
  445. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  446. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  447. }\
  448. \
  449. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc13)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  450. {\
  451. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  452. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  453. uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
  454. uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
  455. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
  456. FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
  457. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  458. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  459. }\
  460. \
  461. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc33)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  462. {\
  463. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  464. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  465. uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
  466. uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
  467. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
  468. FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel), stride, SIZE + 5);\
  469. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  470. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  471. }\
  472. \
  473. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc22)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  474. {\
  475. int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
  476. FUNC(OPNAME ## h264_qpel ## SIZE ## _hv_lowpass)(dst, tmp, src, stride, SIZE*sizeof(pixel), stride);\
  477. }\
  478. \
  479. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc21)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  480. {\
  481. int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
  482. uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
  483. uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
  484. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
  485. FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
  486. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  487. }\
  488. \
  489. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc23)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  490. {\
  491. int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
  492. uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
  493. uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
  494. FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
  495. FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
  496. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  497. }\
  498. \
  499. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc12)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  500. {\
  501. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  502. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  503. int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
  504. uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
  505. uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
  506. FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
  507. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  508. FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
  509. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfV, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  510. }\
  511. \
  512. static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc32)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  513. {\
  514. uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
  515. uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
  516. int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
  517. uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
  518. uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
  519. FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel), stride, SIZE + 5);\
  520. FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
  521. FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
  522. FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfV, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
  523. }\
  524. #define op_avg(a, b) a = (((a)+CLIP(((b) + 16)>>5)+1)>>1)
  525. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  526. #define op_put(a, b) a = CLIP(((b) + 16)>>5)
  527. #define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1)
  528. #define op2_put(a, b) a = CLIP(((b) + 512)>>10)
  529. H264_LOWPASS(put_ , op_put, op2_put)
  530. H264_LOWPASS(avg_ , op_avg, op2_avg)
  531. H264_MC(put_, 2)
  532. H264_MC(put_, 4)
  533. H264_MC(put_, 8)
  534. H264_MC(put_, 16)
  535. H264_MC(avg_, 4)
  536. H264_MC(avg_, 8)
  537. H264_MC(avg_, 16)
  538. #undef op_avg
  539. #undef op_put
  540. #undef op2_avg
  541. #undef op2_put