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.

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