swscale_mmx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. int32_t *vLumFilterPos= c->vLumFilterPos;
  86. int32_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 (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {
  109. const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize;
  110. int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);
  111. for (i = 0; i < neg; i++)
  112. tmpY[i] = lumSrcPtr[neg];
  113. for ( ; i < end; i++)
  114. tmpY[i] = lumSrcPtr[i];
  115. for ( ; i < vLumFilterSize; i++)
  116. tmpY[i] = tmpY[i-1];
  117. lumSrcPtr = tmpY;
  118. if (alpSrcPtr) {
  119. const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize;
  120. for (i = 0; i < neg; i++)
  121. tmpA[i] = alpSrcPtr[neg];
  122. for ( ; i < end; i++)
  123. tmpA[i] = alpSrcPtr[i];
  124. for ( ; i < vLumFilterSize; i++)
  125. tmpA[i] = tmpA[i - 1];
  126. alpSrcPtr = tmpA;
  127. }
  128. }
  129. if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {
  130. const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize;
  131. int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);
  132. for (i = 0; i < neg; i++) {
  133. tmpU[i] = chrUSrcPtr[neg];
  134. }
  135. for ( ; i < end; i++) {
  136. tmpU[i] = chrUSrcPtr[i];
  137. }
  138. for ( ; i < vChrFilterSize; i++) {
  139. tmpU[i] = tmpU[i - 1];
  140. }
  141. chrUSrcPtr = tmpU;
  142. }
  143. if (flags & SWS_ACCURATE_RND) {
  144. int s= APCK_SIZE / 8;
  145. for (i=0; i<vLumFilterSize; i+=2) {
  146. *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
  147. *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
  148. lumMmxFilter[s*i+APCK_COEF/4 ]=
  149. lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ]
  150. + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
  151. if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
  152. *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ];
  153. *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)];
  154. alpMmxFilter[s*i+APCK_COEF/4 ]=
  155. alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ];
  156. }
  157. }
  158. for (i=0; i<vChrFilterSize; i+=2) {
  159. *(const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
  160. *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
  161. chrMmxFilter[s*i+APCK_COEF/4 ]=
  162. chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
  163. + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
  164. }
  165. } else {
  166. for (i=0; i<vLumFilterSize; i++) {
  167. *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
  168. lumMmxFilter[4*i+2]=
  169. lumMmxFilter[4*i+3]=
  170. ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001;
  171. if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
  172. *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
  173. alpMmxFilter[4*i+2]=
  174. alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
  175. }
  176. }
  177. for (i=0; i<vChrFilterSize; i++) {
  178. *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
  179. chrMmxFilter[4*i+2]=
  180. chrMmxFilter[4*i+3]=
  181. ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001;
  182. }
  183. }
  184. }
  185. }
  186. #if HAVE_MMX2
  187. static void yuv2yuvX_sse3(const int16_t *filter, int filterSize,
  188. const int16_t **src, uint8_t *dest, int dstW,
  189. const uint8_t *dither, int offset)
  190. {
  191. if(((int)dest) & 15){
  192. return yuv2yuvX_MMX2(filter, filterSize, src, dest, dstW, dither, offset);
  193. }
  194. if (offset) {
  195. __asm__ volatile("movq (%0), %%xmm3\n\t"
  196. "movdqa %%xmm3, %%xmm4\n\t"
  197. "psrlq $24, %%xmm3\n\t"
  198. "psllq $40, %%xmm4\n\t"
  199. "por %%xmm4, %%xmm3\n\t"
  200. :: "r"(dither)
  201. );
  202. } else {
  203. __asm__ volatile("movq (%0), %%xmm3\n\t"
  204. :: "r"(dither)
  205. );
  206. }
  207. __asm__ volatile(
  208. "pxor %%xmm0, %%xmm0\n\t"
  209. "punpcklbw %%xmm0, %%xmm3\n\t"
  210. "psraw $4, %%xmm3\n\t"
  211. "movdqa %%xmm3, %%xmm4\n\t"
  212. "movdqa %%xmm3, %%xmm7\n\t"
  213. "movl %3, %%ecx\n\t"
  214. "mov %0, %%"REG_d" \n\t"\
  215. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  216. ".p2align 4 \n\t" /* FIXME Unroll? */\
  217. "1: \n\t"\
  218. "movddup 8(%%"REG_d"), %%xmm0 \n\t" /* filterCoeff */\
  219. "movdqa (%%"REG_S", %%"REG_c", 2), %%xmm2 \n\t" /* srcData */\
  220. "movdqa 16(%%"REG_S", %%"REG_c", 2), %%xmm5 \n\t" /* srcData */\
  221. "add $16, %%"REG_d" \n\t"\
  222. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  223. "test %%"REG_S", %%"REG_S" \n\t"\
  224. "pmulhw %%xmm0, %%xmm2 \n\t"\
  225. "pmulhw %%xmm0, %%xmm5 \n\t"\
  226. "paddw %%xmm2, %%xmm3 \n\t"\
  227. "paddw %%xmm5, %%xmm4 \n\t"\
  228. " jnz 1b \n\t"\
  229. "psraw $3, %%xmm3 \n\t"\
  230. "psraw $3, %%xmm4 \n\t"\
  231. "packuswb %%xmm4, %%xmm3 \n\t"
  232. "movntdq %%xmm3, (%1, %%"REG_c")\n\t"
  233. "add $16, %%"REG_c" \n\t"\
  234. "cmp %2, %%"REG_c" \n\t"\
  235. "movdqa %%xmm7, %%xmm3\n\t"
  236. "movdqa %%xmm7, %%xmm4\n\t"
  237. "mov %0, %%"REG_d" \n\t"\
  238. "mov (%%"REG_d"), %%"REG_S" \n\t"\
  239. "jb 1b \n\t"\
  240. :: "g" (filter),
  241. "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset)
  242. : "%"REG_d, "%"REG_S, "%"REG_c
  243. );
  244. }
  245. #endif
  246. #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
  247. extern void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
  248. SwsContext *c, int16_t *data, \
  249. int dstW, const uint8_t *src, \
  250. const int16_t *filter, \
  251. const int32_t *filterPos, int filterSize)
  252. #define SCALE_FUNCS(filter_n, opt) \
  253. SCALE_FUNC(filter_n, 8, 15, opt); \
  254. SCALE_FUNC(filter_n, 9, 15, opt); \
  255. SCALE_FUNC(filter_n, 10, 15, opt); \
  256. SCALE_FUNC(filter_n, 14, 15, opt); \
  257. SCALE_FUNC(filter_n, 16, 15, opt); \
  258. SCALE_FUNC(filter_n, 8, 19, opt); \
  259. SCALE_FUNC(filter_n, 9, 19, opt); \
  260. SCALE_FUNC(filter_n, 10, 19, opt); \
  261. SCALE_FUNC(filter_n, 14, 19, opt); \
  262. SCALE_FUNC(filter_n, 16, 19, opt)
  263. #define SCALE_FUNCS_MMX(opt) \
  264. SCALE_FUNCS(4, opt); \
  265. SCALE_FUNCS(8, opt); \
  266. SCALE_FUNCS(X, opt)
  267. #define SCALE_FUNCS_SSE(opt) \
  268. SCALE_FUNCS(4, opt); \
  269. SCALE_FUNCS(8, opt); \
  270. SCALE_FUNCS(X4, opt); \
  271. SCALE_FUNCS(X8, opt)
  272. #if ARCH_X86_32
  273. SCALE_FUNCS_MMX(mmx);
  274. #endif
  275. SCALE_FUNCS_SSE(sse2);
  276. SCALE_FUNCS_SSE(ssse3);
  277. SCALE_FUNCS_SSE(sse4);
  278. #define VSCALEX_FUNC(size, opt) \
  279. extern void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
  280. const int16_t **src, uint8_t *dest, int dstW, \
  281. const uint8_t *dither, int offset)
  282. #define VSCALEX_FUNCS(opt) \
  283. VSCALEX_FUNC(8, opt); \
  284. VSCALEX_FUNC(9, opt); \
  285. VSCALEX_FUNC(10, opt)
  286. #if ARCH_X86_32
  287. VSCALEX_FUNCS(mmx2);
  288. #endif
  289. VSCALEX_FUNCS(sse2);
  290. VSCALEX_FUNCS(sse4);
  291. VSCALEX_FUNC(16, sse4);
  292. VSCALEX_FUNCS(avx);
  293. #define VSCALE_FUNC(size, opt) \
  294. extern void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
  295. const uint8_t *dither, int offset)
  296. #define VSCALE_FUNCS(opt1, opt2) \
  297. VSCALE_FUNC(8, opt1); \
  298. VSCALE_FUNC(9, opt2); \
  299. VSCALE_FUNC(10, opt2); \
  300. VSCALE_FUNC(16, opt1)
  301. #if ARCH_X86_32
  302. VSCALE_FUNCS(mmx, mmx2);
  303. #endif
  304. VSCALE_FUNCS(sse2, sse2);
  305. VSCALE_FUNC(16, sse4);
  306. VSCALE_FUNCS(avx, avx);
  307. #define INPUT_Y_FUNC(fmt, opt) \
  308. extern void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
  309. int w, uint32_t *unused)
  310. #define INPUT_UV_FUNC(fmt, opt) \
  311. extern void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
  312. const uint8_t *src, const uint8_t *unused1, \
  313. int w, uint32_t *unused2)
  314. #define INPUT_FUNC(fmt, opt) \
  315. INPUT_Y_FUNC(fmt, opt); \
  316. INPUT_UV_FUNC(fmt, opt)
  317. #define INPUT_FUNCS(opt) \
  318. INPUT_FUNC(uyvy, opt); \
  319. INPUT_FUNC(yuyv, opt); \
  320. INPUT_UV_FUNC(nv12, opt); \
  321. INPUT_UV_FUNC(nv21, opt); \
  322. INPUT_FUNC(rgba, opt); \
  323. INPUT_FUNC(bgra, opt); \
  324. INPUT_FUNC(argb, opt); \
  325. INPUT_FUNC(abgr, opt); \
  326. INPUT_FUNC(rgb24, opt); \
  327. INPUT_FUNC(bgr24, opt)
  328. #if ARCH_X86_32
  329. INPUT_FUNCS(mmx);
  330. #endif
  331. INPUT_FUNCS(sse2);
  332. INPUT_FUNCS(ssse3);
  333. INPUT_FUNCS(avx);
  334. void ff_sws_init_swScale_mmx(SwsContext *c)
  335. {
  336. int cpu_flags = av_get_cpu_flags();
  337. if (cpu_flags & AV_CPU_FLAG_MMX)
  338. sws_init_swScale_MMX(c);
  339. #if HAVE_MMX2
  340. if (cpu_flags & AV_CPU_FLAG_MMX2)
  341. sws_init_swScale_MMX2(c);
  342. if (cpu_flags & AV_CPU_FLAG_SSE3){
  343. if(c->use_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND))
  344. c->yuv2planeX = yuv2yuvX_sse3;
  345. }
  346. #endif
  347. #if HAVE_YASM
  348. #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
  349. if (c->srcBpc == 8) { \
  350. hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
  351. ff_hscale8to19_ ## filtersize ## _ ## opt1; \
  352. } else if (c->srcBpc == 9) { \
  353. hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
  354. ff_hscale9to19_ ## filtersize ## _ ## opt1; \
  355. } else if (c->srcBpc == 10) { \
  356. hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
  357. ff_hscale10to19_ ## filtersize ## _ ## opt1; \
  358. } else if (c->srcBpc == 14 || ((c->srcFormat==PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15)) { \
  359. hscalefn = c->dstBpc <= 10 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
  360. ff_hscale14to19_ ## filtersize ## _ ## opt1; \
  361. } else { /* c->srcBpc == 16 */ \
  362. hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
  363. ff_hscale16to19_ ## filtersize ## _ ## opt1; \
  364. } \
  365. } while (0)
  366. #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  367. switch (filtersize) { \
  368. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  369. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  370. default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
  371. }
  372. #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case) \
  373. switch(c->dstBpc){ \
  374. case 16: do_16_case; break; \
  375. case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
  376. case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
  377. default: /*vscalefn = ff_yuv2planeX_8_ ## opt;*/ break; \
  378. }
  379. #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
  380. switch(c->dstBpc){ \
  381. case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
  382. case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
  383. case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
  384. default: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
  385. }
  386. #define case_rgb(x, X, opt) \
  387. case PIX_FMT_ ## X: \
  388. c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
  389. if (!c->chrSrcHSubSample) \
  390. c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
  391. break
  392. #if ARCH_X86_32
  393. if (cpu_flags & AV_CPU_FLAG_MMX) {
  394. ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
  395. ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
  396. ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmx2, cpu_flags & AV_CPU_FLAG_MMX2);
  397. switch (c->srcFormat) {
  398. case PIX_FMT_Y400A:
  399. c->lumToYV12 = ff_yuyvToY_mmx;
  400. if (c->alpPixBuf)
  401. c->alpToYV12 = ff_uyvyToY_mmx;
  402. break;
  403. case PIX_FMT_YUYV422:
  404. c->lumToYV12 = ff_yuyvToY_mmx;
  405. c->chrToYV12 = ff_yuyvToUV_mmx;
  406. break;
  407. case PIX_FMT_UYVY422:
  408. c->lumToYV12 = ff_uyvyToY_mmx;
  409. c->chrToYV12 = ff_uyvyToUV_mmx;
  410. break;
  411. case PIX_FMT_NV12:
  412. c->chrToYV12 = ff_nv12ToUV_mmx;
  413. break;
  414. case PIX_FMT_NV21:
  415. c->chrToYV12 = ff_nv21ToUV_mmx;
  416. break;
  417. case_rgb(rgb24, RGB24, mmx);
  418. case_rgb(bgr24, BGR24, mmx);
  419. case_rgb(bgra, BGRA, mmx);
  420. case_rgb(rgba, RGBA, mmx);
  421. case_rgb(abgr, ABGR, mmx);
  422. case_rgb(argb, ARGB, mmx);
  423. default:
  424. break;
  425. }
  426. }
  427. if (cpu_flags & AV_CPU_FLAG_MMX2) {
  428. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmx2,);
  429. }
  430. #endif
  431. #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  432. switch (filtersize) { \
  433. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  434. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  435. default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
  436. else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
  437. break; \
  438. }
  439. if (cpu_flags & AV_CPU_FLAG_SSE2) {
  440. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
  441. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
  442. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2,);
  443. ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1);
  444. switch (c->srcFormat) {
  445. case PIX_FMT_Y400A:
  446. c->lumToYV12 = ff_yuyvToY_sse2;
  447. if (c->alpPixBuf)
  448. c->alpToYV12 = ff_uyvyToY_sse2;
  449. break;
  450. case PIX_FMT_YUYV422:
  451. c->lumToYV12 = ff_yuyvToY_sse2;
  452. c->chrToYV12 = ff_yuyvToUV_sse2;
  453. break;
  454. case PIX_FMT_UYVY422:
  455. c->lumToYV12 = ff_uyvyToY_sse2;
  456. c->chrToYV12 = ff_uyvyToUV_sse2;
  457. break;
  458. case PIX_FMT_NV12:
  459. c->chrToYV12 = ff_nv12ToUV_sse2;
  460. break;
  461. case PIX_FMT_NV21:
  462. c->chrToYV12 = ff_nv21ToUV_sse2;
  463. break;
  464. case_rgb(rgb24, RGB24, sse2);
  465. case_rgb(bgr24, BGR24, sse2);
  466. case_rgb(bgra, BGRA, sse2);
  467. case_rgb(rgba, RGBA, sse2);
  468. case_rgb(abgr, ABGR, sse2);
  469. case_rgb(argb, ARGB, sse2);
  470. default:
  471. break;
  472. }
  473. }
  474. if (cpu_flags & AV_CPU_FLAG_SSSE3) {
  475. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
  476. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
  477. switch (c->srcFormat) {
  478. case_rgb(rgb24, RGB24, ssse3);
  479. case_rgb(bgr24, BGR24, ssse3);
  480. default:
  481. break;
  482. }
  483. }
  484. if (cpu_flags & AV_CPU_FLAG_SSE4) {
  485. /* Xto15 don't need special sse4 functions */
  486. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
  487. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
  488. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4,
  489. if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4);
  490. if (c->dstBpc == 16 && !isBE(c->dstFormat))
  491. c->yuv2plane1 = ff_yuv2plane1_16_sse4;
  492. }
  493. if (HAVE_AVX && cpu_flags & AV_CPU_FLAG_AVX) {
  494. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx,);
  495. ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1);
  496. switch (c->srcFormat) {
  497. case PIX_FMT_YUYV422:
  498. c->chrToYV12 = ff_yuyvToUV_avx;
  499. break;
  500. case PIX_FMT_UYVY422:
  501. c->chrToYV12 = ff_uyvyToUV_avx;
  502. break;
  503. case PIX_FMT_NV12:
  504. c->chrToYV12 = ff_nv12ToUV_avx;
  505. break;
  506. case PIX_FMT_NV21:
  507. c->chrToYV12 = ff_nv21ToUV_avx;
  508. break;
  509. case_rgb(rgb24, RGB24, avx);
  510. case_rgb(bgr24, BGR24, avx);
  511. case_rgb(bgra, BGRA, avx);
  512. case_rgb(rgba, RGBA, avx);
  513. case_rgb(abgr, ABGR, avx);
  514. case_rgb(argb, ARGB, avx);
  515. default:
  516. break;
  517. }
  518. }
  519. #endif
  520. }