swscale.c 24 KB

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