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.

561 lines
23KB

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