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.

494 lines
19KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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/attributes.h"
  25. #include "libavutil/intreadwrite.h"
  26. #include "libavutil/x86/asm.h"
  27. #include "libavutil/x86/cpu.h"
  28. #include "libavutil/cpu.h"
  29. #include "libavutil/pixdesc.h"
  30. #if HAVE_INLINE_ASM
  31. #define DITHER1XBPP
  32. DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL;
  33. DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL;
  34. DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL;
  35. DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL;
  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. //MMX versions
  64. #if HAVE_MMX_INLINE
  65. #undef RENAME
  66. #define COMPILE_TEMPLATE_MMXEXT 0
  67. #define RENAME(a) a ## _MMX
  68. #include "swscale_template.c"
  69. #endif
  70. // MMXEXT versions
  71. #if HAVE_MMXEXT_INLINE
  72. #undef RENAME
  73. #undef COMPILE_TEMPLATE_MMXEXT
  74. #define COMPILE_TEMPLATE_MMXEXT 1
  75. #define RENAME(a) a ## _MMXEXT
  76. #include "swscale_template.c"
  77. #endif
  78. void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
  79. int lastInLumBuf, int lastInChrBuf)
  80. {
  81. const int dstH= c->dstH;
  82. const int flags= c->flags;
  83. int16_t **lumPixBuf= c->lumPixBuf;
  84. int16_t **chrUPixBuf= c->chrUPixBuf;
  85. int16_t **alpPixBuf= c->alpPixBuf;
  86. const int vLumBufSize= c->vLumBufSize;
  87. const int vChrBufSize= c->vChrBufSize;
  88. int32_t *vLumFilterPos= c->vLumFilterPos;
  89. int32_t *vChrFilterPos= c->vChrFilterPos;
  90. int16_t *vLumFilter= c->vLumFilter;
  91. int16_t *vChrFilter= c->vChrFilter;
  92. int32_t *lumMmxFilter= c->lumMmxFilter;
  93. int32_t *chrMmxFilter= c->chrMmxFilter;
  94. int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
  95. const int vLumFilterSize= c->vLumFilterSize;
  96. const int vChrFilterSize= c->vChrFilterSize;
  97. const int chrDstY= dstY>>c->chrDstVSubSample;
  98. const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
  99. const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
  100. c->blueDither= ff_dither8[dstY&1];
  101. if (c->dstFormat == AV_PIX_FMT_RGB555 || c->dstFormat == AV_PIX_FMT_BGR555)
  102. c->greenDither= ff_dither8[dstY&1];
  103. else
  104. c->greenDither= ff_dither4[dstY&1];
  105. c->redDither= ff_dither8[(dstY+1)&1];
  106. if (dstY < dstH - 2) {
  107. const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
  108. const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
  109. const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
  110. int i;
  111. if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {
  112. const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize;
  113. int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);
  114. for (i = 0; i < neg; i++)
  115. tmpY[i] = lumSrcPtr[neg];
  116. for ( ; i < end; i++)
  117. tmpY[i] = lumSrcPtr[i];
  118. for ( ; i < vLumFilterSize; i++)
  119. tmpY[i] = tmpY[i-1];
  120. lumSrcPtr = tmpY;
  121. if (alpSrcPtr) {
  122. const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize;
  123. for (i = 0; i < neg; i++)
  124. tmpA[i] = alpSrcPtr[neg];
  125. for ( ; i < end; i++)
  126. tmpA[i] = alpSrcPtr[i];
  127. for ( ; i < vLumFilterSize; i++)
  128. tmpA[i] = tmpA[i - 1];
  129. alpSrcPtr = tmpA;
  130. }
  131. }
  132. if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {
  133. const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize;
  134. int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);
  135. for (i = 0; i < neg; i++) {
  136. tmpU[i] = chrUSrcPtr[neg];
  137. }
  138. for ( ; i < end; i++) {
  139. tmpU[i] = chrUSrcPtr[i];
  140. }
  141. for ( ; i < vChrFilterSize; i++) {
  142. tmpU[i] = tmpU[i - 1];
  143. }
  144. chrUSrcPtr = tmpU;
  145. }
  146. if (flags & SWS_ACCURATE_RND) {
  147. int s= APCK_SIZE / 8;
  148. for (i=0; i<vLumFilterSize; i+=2) {
  149. *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
  150. *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
  151. lumMmxFilter[s*i+APCK_COEF/4 ]=
  152. lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ]
  153. + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
  154. if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
  155. *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ];
  156. *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)];
  157. alpMmxFilter[s*i+APCK_COEF/4 ]=
  158. alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ];
  159. }
  160. }
  161. for (i=0; i<vChrFilterSize; i+=2) {
  162. *(const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
  163. *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
  164. chrMmxFilter[s*i+APCK_COEF/4 ]=
  165. chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
  166. + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
  167. }
  168. } else {
  169. for (i=0; i<vLumFilterSize; i++) {
  170. *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
  171. lumMmxFilter[4*i+2]=
  172. lumMmxFilter[4*i+3]=
  173. ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001;
  174. if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
  175. *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
  176. alpMmxFilter[4*i+2]=
  177. alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
  178. }
  179. }
  180. for (i=0; i<vChrFilterSize; i++) {
  181. *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
  182. chrMmxFilter[4*i+2]=
  183. chrMmxFilter[4*i+3]=
  184. ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001;
  185. }
  186. }
  187. }
  188. }
  189. #endif /* HAVE_INLINE_ASM */
  190. #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
  191. void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
  192. SwsContext *c, int16_t *data, \
  193. int dstW, const uint8_t *src, \
  194. const int16_t *filter, \
  195. const int32_t *filterPos, int filterSize)
  196. #define SCALE_FUNCS(filter_n, opt) \
  197. SCALE_FUNC(filter_n, 8, 15, opt); \
  198. SCALE_FUNC(filter_n, 9, 15, opt); \
  199. SCALE_FUNC(filter_n, 10, 15, opt); \
  200. SCALE_FUNC(filter_n, 16, 15, opt); \
  201. SCALE_FUNC(filter_n, 8, 19, opt); \
  202. SCALE_FUNC(filter_n, 9, 19, opt); \
  203. SCALE_FUNC(filter_n, 10, 19, opt); \
  204. SCALE_FUNC(filter_n, 16, 19, opt)
  205. #define SCALE_FUNCS_MMX(opt) \
  206. SCALE_FUNCS(4, opt); \
  207. SCALE_FUNCS(8, opt); \
  208. SCALE_FUNCS(X, opt)
  209. #define SCALE_FUNCS_SSE(opt) \
  210. SCALE_FUNCS(4, opt); \
  211. SCALE_FUNCS(8, opt); \
  212. SCALE_FUNCS(X4, opt); \
  213. SCALE_FUNCS(X8, opt)
  214. #if ARCH_X86_32
  215. SCALE_FUNCS_MMX(mmx);
  216. #endif
  217. SCALE_FUNCS_SSE(sse2);
  218. SCALE_FUNCS_SSE(ssse3);
  219. SCALE_FUNCS_SSE(sse4);
  220. #define VSCALEX_FUNC(size, opt) \
  221. void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
  222. const int16_t **src, uint8_t *dest, int dstW, \
  223. const uint8_t *dither, int offset)
  224. #define VSCALEX_FUNCS(opt) \
  225. VSCALEX_FUNC(8, opt); \
  226. VSCALEX_FUNC(9, opt); \
  227. VSCALEX_FUNC(10, opt)
  228. #if ARCH_X86_32
  229. VSCALEX_FUNCS(mmxext);
  230. #endif
  231. VSCALEX_FUNCS(sse2);
  232. VSCALEX_FUNCS(sse4);
  233. VSCALEX_FUNC(16, sse4);
  234. VSCALEX_FUNCS(avx);
  235. #define VSCALE_FUNC(size, opt) \
  236. void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
  237. const uint8_t *dither, int offset)
  238. #define VSCALE_FUNCS(opt1, opt2) \
  239. VSCALE_FUNC(8, opt1); \
  240. VSCALE_FUNC(9, opt2); \
  241. VSCALE_FUNC(10, opt2); \
  242. VSCALE_FUNC(16, opt1)
  243. #if ARCH_X86_32
  244. VSCALE_FUNCS(mmx, mmxext);
  245. #endif
  246. VSCALE_FUNCS(sse2, sse2);
  247. VSCALE_FUNC(16, sse4);
  248. VSCALE_FUNCS(avx, avx);
  249. #define INPUT_Y_FUNC(fmt, opt) \
  250. void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
  251. int w, uint32_t *unused)
  252. #define INPUT_UV_FUNC(fmt, opt) \
  253. void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
  254. const uint8_t *src, const uint8_t *unused1, \
  255. int w, uint32_t *unused2)
  256. #define INPUT_FUNC(fmt, opt) \
  257. INPUT_Y_FUNC(fmt, opt); \
  258. INPUT_UV_FUNC(fmt, opt)
  259. #define INPUT_FUNCS(opt) \
  260. INPUT_FUNC(uyvy, opt); \
  261. INPUT_FUNC(yuyv, opt); \
  262. INPUT_UV_FUNC(nv12, opt); \
  263. INPUT_UV_FUNC(nv21, opt); \
  264. INPUT_FUNC(rgba, opt); \
  265. INPUT_FUNC(bgra, opt); \
  266. INPUT_FUNC(argb, opt); \
  267. INPUT_FUNC(abgr, opt); \
  268. INPUT_FUNC(rgb24, opt); \
  269. INPUT_FUNC(bgr24, opt)
  270. #if ARCH_X86_32
  271. INPUT_FUNCS(mmx);
  272. #endif
  273. INPUT_FUNCS(sse2);
  274. INPUT_FUNCS(ssse3);
  275. INPUT_FUNCS(avx);
  276. av_cold void ff_sws_init_swscale_x86(SwsContext *c)
  277. {
  278. int cpu_flags = av_get_cpu_flags();
  279. #if HAVE_MMX_INLINE
  280. if (cpu_flags & AV_CPU_FLAG_MMX)
  281. sws_init_swscale_MMX(c);
  282. #endif
  283. #if HAVE_MMXEXT_INLINE
  284. if (cpu_flags & AV_CPU_FLAG_MMXEXT)
  285. sws_init_swscale_MMXEXT(c);
  286. #endif
  287. #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
  288. if (c->srcBpc == 8) { \
  289. hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
  290. ff_hscale8to19_ ## filtersize ## _ ## opt1; \
  291. } else if (c->srcBpc == 9) { \
  292. hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
  293. ff_hscale9to19_ ## filtersize ## _ ## opt1; \
  294. } else if (c->srcBpc == 10) { \
  295. hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
  296. ff_hscale10to19_ ## filtersize ## _ ## opt1; \
  297. } else /* c->srcBpc == 16 */ { \
  298. hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
  299. ff_hscale16to19_ ## filtersize ## _ ## opt1; \
  300. } \
  301. } while (0)
  302. #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  303. switch (filtersize) { \
  304. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  305. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  306. default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
  307. }
  308. #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
  309. switch(c->dstBpc){ \
  310. case 16: do_16_case; break; \
  311. case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
  312. case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
  313. default: if (condition_8bit) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
  314. }
  315. #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
  316. switch(c->dstBpc){ \
  317. case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
  318. case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
  319. case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
  320. default: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
  321. }
  322. #define case_rgb(x, X, opt) \
  323. case AV_PIX_FMT_ ## X: \
  324. c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
  325. if (!c->chrSrcHSubSample) \
  326. c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
  327. break
  328. #if ARCH_X86_32
  329. if (EXTERNAL_MMX(cpu_flags)) {
  330. ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
  331. ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
  332. ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmxext, cpu_flags & AV_CPU_FLAG_MMXEXT);
  333. switch (c->srcFormat) {
  334. case AV_PIX_FMT_Y400A:
  335. c->lumToYV12 = ff_yuyvToY_mmx;
  336. if (c->alpPixBuf)
  337. c->alpToYV12 = ff_uyvyToY_mmx;
  338. break;
  339. case AV_PIX_FMT_YUYV422:
  340. c->lumToYV12 = ff_yuyvToY_mmx;
  341. c->chrToYV12 = ff_yuyvToUV_mmx;
  342. break;
  343. case AV_PIX_FMT_UYVY422:
  344. c->lumToYV12 = ff_uyvyToY_mmx;
  345. c->chrToYV12 = ff_uyvyToUV_mmx;
  346. break;
  347. case AV_PIX_FMT_NV12:
  348. c->chrToYV12 = ff_nv12ToUV_mmx;
  349. break;
  350. case AV_PIX_FMT_NV21:
  351. c->chrToYV12 = ff_nv21ToUV_mmx;
  352. break;
  353. case_rgb(rgb24, RGB24, mmx);
  354. case_rgb(bgr24, BGR24, mmx);
  355. case_rgb(bgra, BGRA, mmx);
  356. case_rgb(rgba, RGBA, mmx);
  357. case_rgb(abgr, ABGR, mmx);
  358. case_rgb(argb, ARGB, mmx);
  359. default:
  360. break;
  361. }
  362. }
  363. if (EXTERNAL_MMXEXT(cpu_flags)) {
  364. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmxext, , 1);
  365. }
  366. #endif /* ARCH_X86_32 */
  367. #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  368. switch (filtersize) { \
  369. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  370. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  371. default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
  372. else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
  373. break; \
  374. }
  375. if (EXTERNAL_SSE2(cpu_flags)) {
  376. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
  377. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
  378. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, ,
  379. HAVE_ALIGNED_STACK || ARCH_X86_64);
  380. ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1);
  381. switch (c->srcFormat) {
  382. case AV_PIX_FMT_Y400A:
  383. c->lumToYV12 = ff_yuyvToY_sse2;
  384. if (c->alpPixBuf)
  385. c->alpToYV12 = ff_uyvyToY_sse2;
  386. break;
  387. case AV_PIX_FMT_YUYV422:
  388. c->lumToYV12 = ff_yuyvToY_sse2;
  389. c->chrToYV12 = ff_yuyvToUV_sse2;
  390. break;
  391. case AV_PIX_FMT_UYVY422:
  392. c->lumToYV12 = ff_uyvyToY_sse2;
  393. c->chrToYV12 = ff_uyvyToUV_sse2;
  394. break;
  395. case AV_PIX_FMT_NV12:
  396. c->chrToYV12 = ff_nv12ToUV_sse2;
  397. break;
  398. case AV_PIX_FMT_NV21:
  399. c->chrToYV12 = ff_nv21ToUV_sse2;
  400. break;
  401. case_rgb(rgb24, RGB24, sse2);
  402. case_rgb(bgr24, BGR24, sse2);
  403. case_rgb(bgra, BGRA, sse2);
  404. case_rgb(rgba, RGBA, sse2);
  405. case_rgb(abgr, ABGR, sse2);
  406. case_rgb(argb, ARGB, sse2);
  407. default:
  408. break;
  409. }
  410. }
  411. if (EXTERNAL_SSSE3(cpu_flags)) {
  412. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
  413. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
  414. switch (c->srcFormat) {
  415. case_rgb(rgb24, RGB24, ssse3);
  416. case_rgb(bgr24, BGR24, ssse3);
  417. default:
  418. break;
  419. }
  420. }
  421. if (EXTERNAL_SSE4(cpu_flags)) {
  422. /* Xto15 don't need special sse4 functions */
  423. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
  424. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
  425. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4,
  426. if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4,
  427. HAVE_ALIGNED_STACK || ARCH_X86_64);
  428. if (c->dstBpc == 16 && !isBE(c->dstFormat))
  429. c->yuv2plane1 = ff_yuv2plane1_16_sse4;
  430. }
  431. if (EXTERNAL_AVX(cpu_flags)) {
  432. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, ,
  433. HAVE_ALIGNED_STACK || ARCH_X86_64);
  434. ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1);
  435. switch (c->srcFormat) {
  436. case AV_PIX_FMT_YUYV422:
  437. c->chrToYV12 = ff_yuyvToUV_avx;
  438. break;
  439. case AV_PIX_FMT_UYVY422:
  440. c->chrToYV12 = ff_uyvyToUV_avx;
  441. break;
  442. case AV_PIX_FMT_NV12:
  443. c->chrToYV12 = ff_nv12ToUV_avx;
  444. break;
  445. case AV_PIX_FMT_NV21:
  446. c->chrToYV12 = ff_nv21ToUV_avx;
  447. break;
  448. case_rgb(rgb24, RGB24, avx);
  449. case_rgb(bgr24, BGR24, avx);
  450. case_rgb(bgra, BGRA, avx);
  451. case_rgb(rgba, RGBA, avx);
  452. case_rgb(abgr, ABGR, avx);
  453. case_rgb(argb, ARGB, avx);
  454. default:
  455. break;
  456. }
  457. }
  458. }