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.

586 lines
24KB

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