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.

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