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.

491 lines
20KB

  1. /*
  2. * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <inttypes.h>
  21. #include "config.h"
  22. #include "libswscale/swscale.h"
  23. #include "libswscale/swscale_internal.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "libavutil/x86_cpu.h"
  26. #include "libavutil/cpu.h"
  27. #include "libavutil/pixdesc.h"
  28. DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL;
  29. DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL;
  30. DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL;
  31. DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL;
  32. DECLARE_ASM_CONST(8, uint64_t, bm00001111)=0x00000000FFFFFFFFLL;
  33. DECLARE_ASM_CONST(8, uint64_t, bm00000111)=0x0000000000FFFFFFLL;
  34. DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL;
  35. DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL;
  36. const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = {
  37. 0x0103010301030103LL,
  38. 0x0200020002000200LL,};
  39. const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = {
  40. 0x0602060206020602LL,
  41. 0x0004000400040004LL,};
  42. DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL;
  43. DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL;
  44. DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL;
  45. DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL;
  46. DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL;
  47. DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL;
  48. DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL;
  49. DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL;
  50. DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL;
  51. #ifdef FAST_BGR2YV12
  52. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL;
  53. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL;
  54. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL;
  55. #else
  56. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL;
  57. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL;
  58. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL;
  59. #endif /* FAST_BGR2YV12 */
  60. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL;
  61. DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL;
  62. DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL;
  63. DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY1Coeff) = 0x0C88000040870C88ULL;
  64. DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY2Coeff) = 0x20DE4087000020DEULL;
  65. DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY1Coeff) = 0x20DE0000408720DEULL;
  66. DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY2Coeff) = 0x0C88408700000C88ULL;
  67. DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toYOffset) = 0x0008010000080100ULL;
  68. DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV)[2][4] = {
  69. {0x38380000DAC83838ULL, 0xECFFDAC80000ECFFULL, 0xF6E40000D0E3F6E4ULL, 0x3838D0E300003838ULL},
  70. {0xECFF0000DAC8ECFFULL, 0x3838DAC800003838ULL, 0x38380000D0E33838ULL, 0xF6E4D0E30000F6E4ULL},
  71. };
  72. DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUVOffset)= 0x0040010000400100ULL;
  73. //MMX versions
  74. #if HAVE_MMX
  75. #undef RENAME
  76. #define COMPILE_TEMPLATE_MMX2 0
  77. #define RENAME(a) a ## _MMX
  78. #include "swscale_template.c"
  79. #endif
  80. //MMX2 versions
  81. #if HAVE_MMX2
  82. #undef RENAME
  83. #undef COMPILE_TEMPLATE_MMX2
  84. #define COMPILE_TEMPLATE_MMX2 1
  85. #define RENAME(a) a ## _MMX2
  86. #include "swscale_template.c"
  87. #endif
  88. void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
  89. int lastInLumBuf, int lastInChrBuf)
  90. {
  91. const int dstH= c->dstH;
  92. const int flags= c->flags;
  93. int16_t **lumPixBuf= c->lumPixBuf;
  94. int16_t **chrUPixBuf= c->chrUPixBuf;
  95. int16_t **alpPixBuf= c->alpPixBuf;
  96. const int vLumBufSize= c->vLumBufSize;
  97. const int vChrBufSize= c->vChrBufSize;
  98. int16_t *vLumFilterPos= c->vLumFilterPos;
  99. int16_t *vChrFilterPos= c->vChrFilterPos;
  100. int16_t *vLumFilter= c->vLumFilter;
  101. int16_t *vChrFilter= c->vChrFilter;
  102. int32_t *lumMmxFilter= c->lumMmxFilter;
  103. int32_t *chrMmxFilter= c->chrMmxFilter;
  104. int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
  105. const int vLumFilterSize= c->vLumFilterSize;
  106. const int vChrFilterSize= c->vChrFilterSize;
  107. const int chrDstY= dstY>>c->chrDstVSubSample;
  108. const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
  109. const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
  110. c->blueDither= ff_dither8[dstY&1];
  111. if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555)
  112. c->greenDither= ff_dither8[dstY&1];
  113. else
  114. c->greenDither= ff_dither4[dstY&1];
  115. c->redDither= ff_dither8[(dstY+1)&1];
  116. if (dstY < dstH - 2) {
  117. const int16_t **lumSrcPtr= (const int16_t **)(void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  118. const int16_t **chrUSrcPtr= (const int16_t **)(void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  119. const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
  120. int i;
  121. if (flags & SWS_ACCURATE_RND) {
  122. int s= APCK_SIZE / 8;
  123. for (i=0; i<vLumFilterSize; i+=2) {
  124. *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
  125. *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
  126. lumMmxFilter[s*i+APCK_COEF/4 ]=
  127. lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ]
  128. + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
  129. if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
  130. *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ];
  131. *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)];
  132. alpMmxFilter[s*i+APCK_COEF/4 ]=
  133. alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ];
  134. }
  135. }
  136. for (i=0; i<vChrFilterSize; i+=2) {
  137. *(const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
  138. *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
  139. chrMmxFilter[s*i+APCK_COEF/4 ]=
  140. chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
  141. + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
  142. }
  143. } else {
  144. for (i=0; i<vLumFilterSize; i++) {
  145. *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
  146. lumMmxFilter[4*i+2]=
  147. lumMmxFilter[4*i+3]=
  148. ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001;
  149. if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
  150. *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
  151. alpMmxFilter[4*i+2]=
  152. alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
  153. }
  154. }
  155. for (i=0; i<vChrFilterSize; i++) {
  156. *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
  157. chrMmxFilter[4*i+2]=
  158. chrMmxFilter[4*i+3]=
  159. ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001;
  160. }
  161. }
  162. }
  163. }
  164. #if HAVE_MMX2
  165. static void yuv2yuvX_sse3(const int16_t *filter, int filterSize,
  166. const int16_t **src, uint8_t *dest, int dstW,
  167. const uint8_t *dither, int offset)
  168. {
  169. if(((int)dest) & 15){
  170. return yuv2yuvX_MMX2(filter, filterSize, src, dest, dstW, dither, offset);
  171. }
  172. if (offset) {
  173. __asm__ volatile("movq (%0), %%xmm3\n\t"
  174. "movdqa %%xmm3, %%xmm4\n\t"
  175. "psrlq $24, %%xmm3\n\t"
  176. "psllq $40, %%xmm4\n\t"
  177. "por %%xmm4, %%xmm3\n\t"
  178. :: "r"(dither)
  179. );
  180. } else {
  181. __asm__ volatile("movq (%0), %%xmm3\n\t"
  182. :: "r"(dither)
  183. );
  184. }
  185. __asm__ volatile(
  186. "pxor %%xmm0, %%xmm0\n\t"
  187. "punpcklbw %%xmm0, %%xmm3\n\t"
  188. "psraw $4, %%xmm3\n\t"
  189. "movdqa %%xmm3, %%xmm4\n\t"
  190. "movdqa %%xmm3, %%xmm7\n\t"
  191. "movl %3, %%ecx\n\t"
  192. "mov %0, %%"REG_d" \n\t"\
  193. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  194. ".p2align 4 \n\t" /* FIXME Unroll? */\
  195. "1: \n\t"\
  196. "movddup 8(%%"REG_d"), %%xmm0 \n\t" /* filterCoeff */\
  197. "movdqa (%%"REG_S", %%"REG_c", 2), %%xmm2 \n\t" /* srcData */\
  198. "movdqa 16(%%"REG_S", %%"REG_c", 2), %%xmm5 \n\t" /* srcData */\
  199. "add $16, %%"REG_d" \n\t"\
  200. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  201. "test %%"REG_S", %%"REG_S" \n\t"\
  202. "pmulhw %%xmm0, %%xmm2 \n\t"\
  203. "pmulhw %%xmm0, %%xmm5 \n\t"\
  204. "paddw %%xmm2, %%xmm3 \n\t"\
  205. "paddw %%xmm5, %%xmm4 \n\t"\
  206. " jnz 1b \n\t"\
  207. "psraw $3, %%xmm3 \n\t"\
  208. "psraw $3, %%xmm4 \n\t"\
  209. "packuswb %%xmm4, %%xmm3 \n\t"
  210. "movntdq %%xmm3, (%1, %%"REG_c")\n\t"
  211. "add $16, %%"REG_c" \n\t"\
  212. "cmp %2, %%"REG_c" \n\t"\
  213. "movdqa %%xmm7, %%xmm3\n\t"
  214. "movdqa %%xmm7, %%xmm4\n\t"
  215. "mov %0, %%"REG_d" \n\t"\
  216. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  217. "jb 1b \n\t"\
  218. :: "g" (filter),
  219. "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset)
  220. : "%"REG_d, "%"REG_S, "%"REG_c
  221. );
  222. }
  223. #endif
  224. #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
  225. extern void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
  226. SwsContext *c, int16_t *data, \
  227. int dstW, const uint8_t *src, \
  228. const int16_t *filter, \
  229. const int16_t *filterPos, int filterSize)
  230. #define SCALE_FUNCS(filter_n, opt) \
  231. SCALE_FUNC(filter_n, 8, 15, opt); \
  232. SCALE_FUNC(filter_n, 9, 15, opt); \
  233. SCALE_FUNC(filter_n, 10, 15, opt); \
  234. SCALE_FUNC(filter_n, 14, 15, opt); \
  235. SCALE_FUNC(filter_n, 16, 15, opt); \
  236. SCALE_FUNC(filter_n, 8, 19, opt); \
  237. SCALE_FUNC(filter_n, 9, 19, opt); \
  238. SCALE_FUNC(filter_n, 10, 19, opt); \
  239. SCALE_FUNC(filter_n, 14, 19, opt); \
  240. SCALE_FUNC(filter_n, 16, 19, opt)
  241. #define SCALE_FUNCS_MMX(opt) \
  242. SCALE_FUNCS(4, opt); \
  243. SCALE_FUNCS(8, opt); \
  244. SCALE_FUNCS(X, opt)
  245. #define SCALE_FUNCS_SSE(opt) \
  246. SCALE_FUNCS(4, opt); \
  247. SCALE_FUNCS(8, opt); \
  248. SCALE_FUNCS(X4, opt); \
  249. SCALE_FUNCS(X8, opt)
  250. #if ARCH_X86_32
  251. SCALE_FUNCS_MMX(mmx);
  252. #endif
  253. SCALE_FUNCS_SSE(sse2);
  254. SCALE_FUNCS_SSE(ssse3);
  255. SCALE_FUNCS_SSE(sse4);
  256. #define VSCALEX_FUNC(size, opt) \
  257. extern void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
  258. const int16_t **src, uint8_t *dest, int dstW, \
  259. const uint8_t *dither, int offset)
  260. #define VSCALEX_FUNCS(opt) \
  261. VSCALEX_FUNC(8, opt); \
  262. VSCALEX_FUNC(9, opt); \
  263. VSCALEX_FUNC(10, opt)
  264. #if ARCH_X86_32
  265. VSCALEX_FUNCS(mmx2);
  266. #endif
  267. VSCALEX_FUNCS(sse2);
  268. VSCALEX_FUNCS(sse4);
  269. VSCALEX_FUNC(16, sse4);
  270. VSCALEX_FUNCS(avx);
  271. #define VSCALE_FUNC(size, opt) \
  272. extern void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
  273. const uint8_t *dither, int offset)
  274. #define VSCALE_FUNCS(opt1, opt2) \
  275. VSCALE_FUNC(8, opt1); \
  276. VSCALE_FUNC(9, opt2); \
  277. VSCALE_FUNC(10, opt2); \
  278. VSCALE_FUNC(16, opt1)
  279. #if ARCH_X86_32
  280. VSCALE_FUNCS(mmx, mmx2);
  281. #endif
  282. VSCALE_FUNCS(sse2, sse2);
  283. VSCALE_FUNC(16, sse4);
  284. VSCALE_FUNCS(avx, avx);
  285. #define INPUT_UV_FUNC(fmt, opt) \
  286. extern void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
  287. const uint8_t *src, const uint8_t *unused1, \
  288. int w, uint32_t *unused2)
  289. #define INPUT_FUNC(fmt, opt) \
  290. extern void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
  291. int w, uint32_t *unused); \
  292. INPUT_UV_FUNC(fmt, opt)
  293. #define INPUT_FUNCS(opt) \
  294. INPUT_FUNC(uyvy, opt); \
  295. INPUT_FUNC(yuyv, opt); \
  296. INPUT_UV_FUNC(nv12, opt); \
  297. INPUT_UV_FUNC(nv21, opt)
  298. #if ARCH_X86_32
  299. INPUT_FUNCS(mmx);
  300. #endif
  301. INPUT_FUNCS(sse2);
  302. INPUT_FUNCS(avx);
  303. void ff_sws_init_swScale_mmx(SwsContext *c)
  304. {
  305. int cpu_flags = av_get_cpu_flags();
  306. if (cpu_flags & AV_CPU_FLAG_MMX)
  307. sws_init_swScale_MMX(c);
  308. #if HAVE_MMX2
  309. if (cpu_flags & AV_CPU_FLAG_MMX2)
  310. sws_init_swScale_MMX2(c);
  311. if (cpu_flags & AV_CPU_FLAG_SSE3){
  312. if(c->use_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND))
  313. c->yuv2planeX = yuv2yuvX_sse3;
  314. }
  315. #endif
  316. #if HAVE_YASM
  317. #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
  318. if (c->srcBpc == 8) { \
  319. hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
  320. ff_hscale8to19_ ## filtersize ## _ ## opt1; \
  321. } else if (c->srcBpc == 9) { \
  322. hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
  323. ff_hscale9to19_ ## filtersize ## _ ## opt1; \
  324. } else if (c->srcBpc == 10) { \
  325. hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
  326. ff_hscale10to19_ ## filtersize ## _ ## opt1; \
  327. } else if (c->srcBpc == 14 || ((c->srcFormat==PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15)) { \
  328. hscalefn = c->dstBpc <= 10 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
  329. ff_hscale14to19_ ## filtersize ## _ ## opt1; \
  330. } else { /* c->srcBpc == 16 */ \
  331. hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
  332. ff_hscale16to19_ ## filtersize ## _ ## opt1; \
  333. } \
  334. } while (0)
  335. #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  336. switch (filtersize) { \
  337. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  338. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  339. default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
  340. }
  341. #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case) \
  342. switch(c->dstBpc){ \
  343. case 16: /*do_16_case;*/ break; \
  344. case 10: if (!isBE(c->dstFormat)) /*vscalefn = ff_yuv2planeX_10_ ## opt;*/ break; \
  345. case 9: if (!isBE(c->dstFormat)) /*vscalefn = ff_yuv2planeX_9_ ## opt;*/ break; \
  346. default: /*vscalefn = ff_yuv2planeX_8_ ## opt;*/ break; \
  347. }
  348. #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
  349. switch(c->dstBpc){ \
  350. case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
  351. case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
  352. case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
  353. default: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
  354. }
  355. #if ARCH_X86_32
  356. if (cpu_flags & AV_CPU_FLAG_MMX) {
  357. ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
  358. ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
  359. ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmx2, cpu_flags & AV_CPU_FLAG_MMX2);
  360. switch (c->srcFormat) {
  361. case PIX_FMT_Y400A:
  362. c->lumToYV12 = ff_yuyvToY_mmx;
  363. if (c->alpPixBuf)
  364. c->alpToYV12 = ff_uyvyToY_mmx;
  365. break;
  366. case PIX_FMT_YUYV422:
  367. c->lumToYV12 = ff_yuyvToY_mmx;
  368. c->chrToYV12 = ff_yuyvToUV_mmx;
  369. break;
  370. case PIX_FMT_UYVY422:
  371. c->lumToYV12 = ff_uyvyToY_mmx;
  372. c->chrToYV12 = ff_uyvyToUV_mmx;
  373. break;
  374. case PIX_FMT_NV12:
  375. c->chrToYV12 = ff_nv12ToUV_mmx;
  376. break;
  377. case PIX_FMT_NV21:
  378. c->chrToYV12 = ff_nv21ToUV_mmx;
  379. break;
  380. default:
  381. break;
  382. }
  383. }
  384. if (cpu_flags & AV_CPU_FLAG_MMX2) {
  385. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmx2,);
  386. }
  387. #endif
  388. #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  389. switch (filtersize) { \
  390. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  391. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  392. default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
  393. else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
  394. break; \
  395. }
  396. if (cpu_flags & AV_CPU_FLAG_SSE2) {
  397. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
  398. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
  399. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2,);
  400. ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1);
  401. switch (c->srcFormat) {
  402. case PIX_FMT_Y400A:
  403. c->lumToYV12 = ff_yuyvToY_sse2;
  404. if (c->alpPixBuf)
  405. c->alpToYV12 = ff_uyvyToY_sse2;
  406. break;
  407. case PIX_FMT_YUYV422:
  408. c->lumToYV12 = ff_yuyvToY_sse2;
  409. c->chrToYV12 = ff_yuyvToUV_sse2;
  410. break;
  411. case PIX_FMT_UYVY422:
  412. c->lumToYV12 = ff_uyvyToY_sse2;
  413. c->chrToYV12 = ff_uyvyToUV_sse2;
  414. break;
  415. case PIX_FMT_NV12:
  416. c->chrToYV12 = ff_nv12ToUV_sse2;
  417. break;
  418. case PIX_FMT_NV21:
  419. c->chrToYV12 = ff_nv21ToUV_sse2;
  420. break;
  421. }
  422. }
  423. if (cpu_flags & AV_CPU_FLAG_SSSE3) {
  424. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
  425. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
  426. }
  427. if (cpu_flags & AV_CPU_FLAG_SSE4) {
  428. /* Xto15 don't need special sse4 functions */
  429. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
  430. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
  431. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4,
  432. if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4);
  433. if (c->dstBpc == 16 && !isBE(c->dstFormat))
  434. c->yuv2plane1 = ff_yuv2plane1_16_sse4;
  435. }
  436. if (HAVE_AVX && cpu_flags & AV_CPU_FLAG_AVX) {
  437. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx,);
  438. ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1);
  439. switch (c->srcFormat) {
  440. case PIX_FMT_YUYV422:
  441. c->chrToYV12 = ff_yuyvToUV_avx;
  442. break;
  443. case PIX_FMT_UYVY422:
  444. c->chrToYV12 = ff_uyvyToUV_avx;
  445. break;
  446. case PIX_FMT_NV12:
  447. c->chrToYV12 = ff_nv12ToUV_avx;
  448. break;
  449. case PIX_FMT_NV21:
  450. c->chrToYV12 = ff_nv21ToUV_avx;
  451. break;
  452. default:
  453. break;
  454. }
  455. }
  456. #endif
  457. }