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.

518 lines
21KB

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