swscale.c 24 KB

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