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.

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