swscale.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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/mem_internal.h"
  30. #include "libavutil/pixdesc.h"
  31. const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = {
  32. 0x0103010301030103LL,
  33. 0x0200020002000200LL,};
  34. const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = {
  35. 0x0602060206020602LL,
  36. 0x0004000400040004LL,};
  37. #if HAVE_INLINE_ASM
  38. #define DITHER1XBPP
  39. DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL;
  40. DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL;
  41. DECLARE_ASM_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL;
  42. DECLARE_ASM_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL;
  43. DECLARE_ASM_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL;
  44. DECLARE_ASM_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL;
  45. DECLARE_ASM_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL;
  46. DECLARE_ASM_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL;
  47. // MMXEXT versions
  48. #if HAVE_MMXEXT_INLINE
  49. #undef RENAME
  50. #undef COMPILE_TEMPLATE_MMXEXT
  51. #define COMPILE_TEMPLATE_MMXEXT 1
  52. #define RENAME(a) a ## _mmxext
  53. #include "swscale_template.c"
  54. #endif
  55. void ff_updateMMXDitherTables(SwsContext *c, int dstY)
  56. {
  57. const int dstH= c->dstH;
  58. const int flags= c->flags;
  59. SwsPlane *lumPlane = &c->slice[c->numSlice-2].plane[0];
  60. SwsPlane *chrUPlane = &c->slice[c->numSlice-2].plane[1];
  61. SwsPlane *alpPlane = &c->slice[c->numSlice-2].plane[3];
  62. int hasAlpha = c->needAlpha;
  63. int32_t *vLumFilterPos= c->vLumFilterPos;
  64. int32_t *vChrFilterPos= c->vChrFilterPos;
  65. int16_t *vLumFilter= c->vLumFilter;
  66. int16_t *vChrFilter= c->vChrFilter;
  67. int32_t *lumMmxFilter= c->lumMmxFilter;
  68. int32_t *chrMmxFilter= c->chrMmxFilter;
  69. int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
  70. const int vLumFilterSize= c->vLumFilterSize;
  71. const int vChrFilterSize= c->vChrFilterSize;
  72. const int chrDstY= dstY>>c->chrDstVSubSample;
  73. const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
  74. const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
  75. c->blueDither= ff_dither8[dstY&1];
  76. if (c->dstFormat == AV_PIX_FMT_RGB555 || c->dstFormat == AV_PIX_FMT_BGR555)
  77. c->greenDither= ff_dither8[dstY&1];
  78. else
  79. c->greenDither= ff_dither4[dstY&1];
  80. c->redDither= ff_dither8[(dstY+1)&1];
  81. if (dstY < dstH - 2) {
  82. const int16_t **lumSrcPtr = (const int16_t **)(void*) lumPlane->line + firstLumSrcY - lumPlane->sliceY;
  83. const int16_t **chrUSrcPtr = (const int16_t **)(void*) chrUPlane->line + firstChrSrcY - chrUPlane->sliceY;
  84. const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && hasAlpha) ? (const int16_t **)(void*) alpPlane->line + firstLumSrcY - alpPlane->sliceY : NULL;
  85. int i;
  86. if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {
  87. const int16_t **tmpY = (const int16_t **) lumPlane->tmp;
  88. int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);
  89. for (i = 0; i < neg; i++)
  90. tmpY[i] = lumSrcPtr[neg];
  91. for ( ; i < end; i++)
  92. tmpY[i] = lumSrcPtr[i];
  93. for ( ; i < vLumFilterSize; i++)
  94. tmpY[i] = tmpY[i-1];
  95. lumSrcPtr = tmpY;
  96. if (alpSrcPtr) {
  97. const int16_t **tmpA = (const int16_t **) alpPlane->tmp;
  98. for (i = 0; i < neg; i++)
  99. tmpA[i] = alpSrcPtr[neg];
  100. for ( ; i < end; i++)
  101. tmpA[i] = alpSrcPtr[i];
  102. for ( ; i < vLumFilterSize; i++)
  103. tmpA[i] = tmpA[i - 1];
  104. alpSrcPtr = tmpA;
  105. }
  106. }
  107. if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {
  108. const int16_t **tmpU = (const int16_t **) chrUPlane->tmp;
  109. int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);
  110. for (i = 0; i < neg; i++) {
  111. tmpU[i] = chrUSrcPtr[neg];
  112. }
  113. for ( ; i < end; i++) {
  114. tmpU[i] = chrUSrcPtr[i];
  115. }
  116. for ( ; i < vChrFilterSize; i++) {
  117. tmpU[i] = tmpU[i - 1];
  118. }
  119. chrUSrcPtr = tmpU;
  120. }
  121. if (flags & SWS_ACCURATE_RND) {
  122. int s= APCK_SIZE / 8;
  123. for (i=0; i<vLumFilterSize; i+=2) {
  124. *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
  125. *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
  126. lumMmxFilter[s*i+APCK_COEF/4 ]=
  127. lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ]
  128. + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1] * (1 << 16) : 0);
  129. if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
  130. *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ];
  131. *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)];
  132. alpMmxFilter[s*i+APCK_COEF/4 ]=
  133. alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ];
  134. }
  135. }
  136. for (i=0; i<vChrFilterSize; i+=2) {
  137. *(const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
  138. *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
  139. chrMmxFilter[s*i+APCK_COEF/4 ]=
  140. chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
  141. + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1] * (1 << 16) : 0);
  142. }
  143. } else {
  144. for (i=0; i<vLumFilterSize; i++) {
  145. *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
  146. lumMmxFilter[4*i+2]=
  147. lumMmxFilter[4*i+3]=
  148. ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001U;
  149. if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
  150. *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
  151. alpMmxFilter[4*i+2]=
  152. alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
  153. }
  154. }
  155. for (i=0; i<vChrFilterSize; i++) {
  156. *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
  157. chrMmxFilter[4*i+2]=
  158. chrMmxFilter[4*i+3]=
  159. ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001U;
  160. }
  161. }
  162. }
  163. }
  164. #endif /* HAVE_INLINE_ASM */
  165. #define YUV2YUVX_FUNC_MMX(opt, step) \
  166. void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
  167. uint8_t *dest, int dstW, \
  168. const uint8_t *dither, int offset); \
  169. static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
  170. const int16_t **src, uint8_t *dest, int dstW, \
  171. const uint8_t *dither, int offset) \
  172. { \
  173. if(dstW > 0) \
  174. ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, dstW + offset, dither, offset); \
  175. return; \
  176. }
  177. #define YUV2YUVX_FUNC(opt, step) \
  178. void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
  179. uint8_t *dest, int dstW, \
  180. const uint8_t *dither, int offset); \
  181. static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
  182. const int16_t **src, uint8_t *dest, int dstW, \
  183. const uint8_t *dither, int offset) \
  184. { \
  185. int remainder = (dstW % step); \
  186. int pixelsProcessed = dstW - remainder; \
  187. if(((uintptr_t)dest) & 15){ \
  188. yuv2yuvX_mmxext(filter, filterSize, src, dest, dstW, dither, offset); \
  189. return; \
  190. } \
  191. if(pixelsProcessed > 0) \
  192. ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, pixelsProcessed + offset, dither, offset); \
  193. if(remainder > 0){ \
  194. ff_yuv2yuvX_mmxext(filter, filterSize - 1, pixelsProcessed, dest - offset, pixelsProcessed + remainder + offset, dither, offset); \
  195. } \
  196. return; \
  197. }
  198. #if HAVE_MMXEXT_EXTERNAL
  199. YUV2YUVX_FUNC_MMX(mmxext, 16)
  200. #endif
  201. #if HAVE_SSE3_EXTERNAL
  202. YUV2YUVX_FUNC(sse3, 32)
  203. #endif
  204. #if HAVE_AVX2_EXTERNAL
  205. YUV2YUVX_FUNC(avx2, 64)
  206. #endif
  207. #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
  208. void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
  209. SwsContext *c, int16_t *data, \
  210. int dstW, const uint8_t *src, \
  211. const int16_t *filter, \
  212. const int32_t *filterPos, int filterSize)
  213. #define SCALE_FUNCS(filter_n, opt) \
  214. SCALE_FUNC(filter_n, 8, 15, opt); \
  215. SCALE_FUNC(filter_n, 9, 15, opt); \
  216. SCALE_FUNC(filter_n, 10, 15, opt); \
  217. SCALE_FUNC(filter_n, 12, 15, opt); \
  218. SCALE_FUNC(filter_n, 14, 15, opt); \
  219. SCALE_FUNC(filter_n, 16, 15, opt); \
  220. SCALE_FUNC(filter_n, 8, 19, opt); \
  221. SCALE_FUNC(filter_n, 9, 19, opt); \
  222. SCALE_FUNC(filter_n, 10, 19, opt); \
  223. SCALE_FUNC(filter_n, 12, 19, opt); \
  224. SCALE_FUNC(filter_n, 14, 19, opt); \
  225. SCALE_FUNC(filter_n, 16, 19, opt)
  226. #define SCALE_FUNCS_MMX(opt) \
  227. SCALE_FUNCS(4, opt); \
  228. SCALE_FUNCS(8, opt); \
  229. SCALE_FUNCS(X, opt)
  230. #define SCALE_FUNCS_SSE(opt) \
  231. SCALE_FUNCS(4, opt); \
  232. SCALE_FUNCS(8, opt); \
  233. SCALE_FUNCS(X4, opt); \
  234. SCALE_FUNCS(X8, opt)
  235. SCALE_FUNCS_SSE(sse2);
  236. SCALE_FUNCS_SSE(ssse3);
  237. SCALE_FUNCS_SSE(sse4);
  238. SCALE_FUNC(4, 8, 15, avx2);
  239. SCALE_FUNC(X4, 8, 15, avx2);
  240. #define VSCALEX_FUNC(size, opt) \
  241. void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
  242. const int16_t **src, uint8_t *dest, int dstW, \
  243. const uint8_t *dither, int offset)
  244. #define VSCALEX_FUNCS(opt) \
  245. VSCALEX_FUNC(8, opt); \
  246. VSCALEX_FUNC(9, opt); \
  247. VSCALEX_FUNC(10, opt)
  248. VSCALEX_FUNC(8, mmxext);
  249. VSCALEX_FUNCS(sse2);
  250. VSCALEX_FUNCS(sse4);
  251. VSCALEX_FUNC(16, sse4);
  252. VSCALEX_FUNCS(avx);
  253. #define VSCALE_FUNC(size, opt) \
  254. void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
  255. const uint8_t *dither, int offset)
  256. #define VSCALE_FUNCS(opt1, opt2) \
  257. VSCALE_FUNC(8, opt1); \
  258. VSCALE_FUNC(9, opt2); \
  259. VSCALE_FUNC(10, opt2); \
  260. VSCALE_FUNC(16, opt1)
  261. VSCALE_FUNCS(sse2, sse2);
  262. VSCALE_FUNC(16, sse4);
  263. VSCALE_FUNCS(avx, avx);
  264. #define INPUT_Y_FUNC(fmt, opt) \
  265. void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
  266. const uint8_t *unused1, const uint8_t *unused2, \
  267. int w, uint32_t *unused, void *opq)
  268. #define INPUT_UV_FUNC(fmt, opt) \
  269. void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
  270. const uint8_t *unused0, \
  271. const uint8_t *src1, \
  272. const uint8_t *src2, \
  273. int w, uint32_t *unused, void *opq)
  274. #define INPUT_FUNC(fmt, opt) \
  275. INPUT_Y_FUNC(fmt, opt); \
  276. INPUT_UV_FUNC(fmt, opt)
  277. #define INPUT_FUNCS(opt) \
  278. INPUT_FUNC(uyvy, opt); \
  279. INPUT_FUNC(yuyv, opt); \
  280. INPUT_UV_FUNC(nv12, opt); \
  281. INPUT_UV_FUNC(nv21, opt); \
  282. INPUT_FUNC(rgba, opt); \
  283. INPUT_FUNC(bgra, opt); \
  284. INPUT_FUNC(argb, opt); \
  285. INPUT_FUNC(abgr, opt); \
  286. INPUT_FUNC(rgb24, opt); \
  287. INPUT_FUNC(bgr24, opt)
  288. INPUT_FUNCS(sse2);
  289. INPUT_FUNCS(ssse3);
  290. INPUT_FUNCS(avx);
  291. INPUT_FUNC(rgba, avx2);
  292. INPUT_FUNC(bgra, avx2);
  293. INPUT_FUNC(argb, avx2);
  294. INPUT_FUNC(abgr, avx2);
  295. INPUT_FUNC(rgb24, avx2);
  296. INPUT_FUNC(bgr24, avx2);
  297. #if ARCH_X86_64
  298. #define YUV2NV_DECL(fmt, opt) \
  299. void ff_yuv2 ## fmt ## cX_ ## opt(enum AVPixelFormat format, const uint8_t *dither, \
  300. const int16_t *filter, int filterSize, \
  301. const int16_t **u, const int16_t **v, \
  302. uint8_t *dst, int dstWidth)
  303. YUV2NV_DECL(nv12, avx2);
  304. YUV2NV_DECL(nv21, avx2);
  305. #define YUV2GBRP_FN_DECL(fmt, opt) \
  306. void ff_yuv2##fmt##_full_X_ ##opt(SwsContext *c, const int16_t *lumFilter, \
  307. const int16_t **lumSrcx, int lumFilterSize, \
  308. const int16_t *chrFilter, const int16_t **chrUSrcx, \
  309. const int16_t **chrVSrcx, int chrFilterSize, \
  310. const int16_t **alpSrcx, uint8_t **dest, \
  311. int dstW, int y)
  312. #define YUV2GBRP_DECL(opt) \
  313. YUV2GBRP_FN_DECL(gbrp, opt); \
  314. YUV2GBRP_FN_DECL(gbrap, opt); \
  315. YUV2GBRP_FN_DECL(gbrp9le, opt); \
  316. YUV2GBRP_FN_DECL(gbrp10le, opt); \
  317. YUV2GBRP_FN_DECL(gbrap10le, opt); \
  318. YUV2GBRP_FN_DECL(gbrp12le, opt); \
  319. YUV2GBRP_FN_DECL(gbrap12le, opt); \
  320. YUV2GBRP_FN_DECL(gbrp14le, opt); \
  321. YUV2GBRP_FN_DECL(gbrp16le, opt); \
  322. YUV2GBRP_FN_DECL(gbrap16le, opt); \
  323. YUV2GBRP_FN_DECL(gbrpf32le, opt); \
  324. YUV2GBRP_FN_DECL(gbrapf32le, opt); \
  325. YUV2GBRP_FN_DECL(gbrp9be, opt); \
  326. YUV2GBRP_FN_DECL(gbrp10be, opt); \
  327. YUV2GBRP_FN_DECL(gbrap10be, opt); \
  328. YUV2GBRP_FN_DECL(gbrp12be, opt); \
  329. YUV2GBRP_FN_DECL(gbrap12be, opt); \
  330. YUV2GBRP_FN_DECL(gbrp14be, opt); \
  331. YUV2GBRP_FN_DECL(gbrp16be, opt); \
  332. YUV2GBRP_FN_DECL(gbrap16be, opt); \
  333. YUV2GBRP_FN_DECL(gbrpf32be, opt); \
  334. YUV2GBRP_FN_DECL(gbrapf32be, opt)
  335. YUV2GBRP_DECL(sse2);
  336. YUV2GBRP_DECL(sse4);
  337. YUV2GBRP_DECL(avx2);
  338. #define INPUT_PLANAR_RGB_Y_FN_DECL(fmt, opt) \
  339. void ff_planar_##fmt##_to_y_##opt(uint8_t *dst, \
  340. const uint8_t *src[4], int w, int32_t *rgb2yuv, \
  341. void *opq)
  342. #define INPUT_PLANAR_RGB_UV_FN_DECL(fmt, opt) \
  343. void ff_planar_##fmt##_to_uv_##opt(uint8_t *dstU, uint8_t *dstV, \
  344. const uint8_t *src[4], int w, int32_t *rgb2yuv, \
  345. void *opq)
  346. #define INPUT_PLANAR_RGB_A_FN_DECL(fmt, opt) \
  347. void ff_planar_##fmt##_to_a_##opt(uint8_t *dst, \
  348. const uint8_t *src[4], int w, int32_t *rgb2yuv, \
  349. void *opq)
  350. #define INPUT_PLANAR_RGBXX_A_DECL(fmt, opt) \
  351. INPUT_PLANAR_RGB_A_FN_DECL(fmt##le, opt); \
  352. INPUT_PLANAR_RGB_A_FN_DECL(fmt##be, opt)
  353. #define INPUT_PLANAR_RGBXX_Y_DECL(fmt, opt) \
  354. INPUT_PLANAR_RGB_Y_FN_DECL(fmt##le, opt); \
  355. INPUT_PLANAR_RGB_Y_FN_DECL(fmt##be, opt)
  356. #define INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt) \
  357. INPUT_PLANAR_RGB_UV_FN_DECL(fmt##le, opt); \
  358. INPUT_PLANAR_RGB_UV_FN_DECL(fmt##be, opt)
  359. #define INPUT_PLANAR_RGBXX_YUVA_DECL(fmt, opt) \
  360. INPUT_PLANAR_RGBXX_Y_DECL(fmt, opt); \
  361. INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt); \
  362. INPUT_PLANAR_RGBXX_A_DECL(fmt, opt)
  363. #define INPUT_PLANAR_RGBXX_YUV_DECL(fmt, opt) \
  364. INPUT_PLANAR_RGBXX_Y_DECL(fmt, opt); \
  365. INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt)
  366. #define INPUT_PLANAR_RGBXX_UVA_DECL(fmt, opt) \
  367. INPUT_PLANAR_RGBXX_UV_DECL(fmt, opt); \
  368. INPUT_PLANAR_RGBXX_A_DECL(fmt, opt)
  369. #define INPUT_PLANAR_RGB_A_ALL_DECL(opt) \
  370. INPUT_PLANAR_RGB_A_FN_DECL(rgb, opt); \
  371. INPUT_PLANAR_RGBXX_A_DECL(rgb10, opt); \
  372. INPUT_PLANAR_RGBXX_A_DECL(rgb12, opt); \
  373. INPUT_PLANAR_RGBXX_A_DECL(rgb16, opt); \
  374. INPUT_PLANAR_RGBXX_A_DECL(rgbf32, opt)
  375. #define INPUT_PLANAR_RGB_Y_ALL_DECL(opt) \
  376. INPUT_PLANAR_RGB_Y_FN_DECL(rgb, opt); \
  377. INPUT_PLANAR_RGBXX_Y_DECL(rgb9, opt); \
  378. INPUT_PLANAR_RGBXX_Y_DECL(rgb10, opt); \
  379. INPUT_PLANAR_RGBXX_Y_DECL(rgb12, opt); \
  380. INPUT_PLANAR_RGBXX_Y_DECL(rgb14, opt); \
  381. INPUT_PLANAR_RGBXX_Y_DECL(rgb16, opt); \
  382. INPUT_PLANAR_RGBXX_Y_DECL(rgbf32, opt)
  383. #define INPUT_PLANAR_RGB_UV_ALL_DECL(opt) \
  384. INPUT_PLANAR_RGB_UV_FN_DECL(rgb, opt); \
  385. INPUT_PLANAR_RGBXX_UV_DECL(rgb9, opt); \
  386. INPUT_PLANAR_RGBXX_UV_DECL(rgb10, opt); \
  387. INPUT_PLANAR_RGBXX_UV_DECL(rgb12, opt); \
  388. INPUT_PLANAR_RGBXX_UV_DECL(rgb14, opt); \
  389. INPUT_PLANAR_RGBXX_UV_DECL(rgb16, opt); \
  390. INPUT_PLANAR_RGBXX_UV_DECL(rgbf32, opt)
  391. INPUT_PLANAR_RGBXX_Y_DECL(rgbf32, sse2);
  392. INPUT_PLANAR_RGB_UV_ALL_DECL(sse2);
  393. INPUT_PLANAR_RGB_A_ALL_DECL(sse2);
  394. INPUT_PLANAR_RGB_Y_ALL_DECL(sse4);
  395. INPUT_PLANAR_RGB_UV_ALL_DECL(sse4);
  396. INPUT_PLANAR_RGBXX_A_DECL(rgbf32, sse4);
  397. INPUT_PLANAR_RGB_Y_ALL_DECL(avx2);
  398. INPUT_PLANAR_RGB_UV_ALL_DECL(avx2);
  399. INPUT_PLANAR_RGB_A_ALL_DECL(avx2);
  400. #endif
  401. #define RANGE_CONVERT_FUNCS(opt) do { \
  402. if (c->dstBpc <= 14) { \
  403. if (c->srcRange) { \
  404. c->lumConvertRange = ff_lumRangeFromJpeg_ ##opt; \
  405. c->chrConvertRange = ff_chrRangeFromJpeg_ ##opt; \
  406. } else { \
  407. c->lumConvertRange = ff_lumRangeToJpeg_ ##opt; \
  408. c->chrConvertRange = ff_chrRangeToJpeg_ ##opt; \
  409. } \
  410. } \
  411. } while (0)
  412. #define RANGE_CONVERT_FUNCS_DECL(opt) \
  413. void ff_lumRangeFromJpeg_ ##opt(int16_t *dst, int width); \
  414. void ff_chrRangeFromJpeg_ ##opt(int16_t *dstU, int16_t *dstV, int width); \
  415. void ff_lumRangeToJpeg_ ##opt(int16_t *dst, int width); \
  416. void ff_chrRangeToJpeg_ ##opt(int16_t *dstU, int16_t *dstV, int width); \
  417. RANGE_CONVERT_FUNCS_DECL(sse2);
  418. RANGE_CONVERT_FUNCS_DECL(avx2);
  419. av_cold void ff_sws_init_range_convert_x86(SwsContext *c)
  420. {
  421. if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
  422. int cpu_flags = av_get_cpu_flags();
  423. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  424. RANGE_CONVERT_FUNCS(avx2);
  425. } else if (EXTERNAL_SSE2(cpu_flags)) {
  426. RANGE_CONVERT_FUNCS(sse2);
  427. }
  428. }
  429. }
  430. av_cold void ff_sws_init_swscale_x86(SwsContext *c)
  431. {
  432. int cpu_flags = av_get_cpu_flags();
  433. #if HAVE_MMXEXT_INLINE
  434. if (INLINE_MMXEXT(cpu_flags))
  435. sws_init_swscale_mmxext(c);
  436. #endif
  437. if(c->use_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND)) {
  438. #if HAVE_MMXEXT_EXTERNAL
  439. if (EXTERNAL_MMXEXT(cpu_flags))
  440. c->yuv2planeX = yuv2yuvX_mmxext;
  441. #endif
  442. #if HAVE_SSE3_EXTERNAL
  443. if (EXTERNAL_SSE3(cpu_flags))
  444. c->yuv2planeX = yuv2yuvX_sse3;
  445. #endif
  446. #if HAVE_AVX2_EXTERNAL
  447. if (EXTERNAL_AVX2_FAST(cpu_flags))
  448. c->yuv2planeX = yuv2yuvX_avx2;
  449. #endif
  450. }
  451. #if ARCH_X86_32 && !HAVE_ALIGNED_STACK
  452. // The better yuv2planeX_8 functions need aligned stack on x86-32,
  453. // so we use MMXEXT in this case if they are not available.
  454. if (EXTERNAL_MMXEXT(cpu_flags)) {
  455. if (c->dstBpc == 8 && !c->use_mmx_vfilter)
  456. c->yuv2planeX = ff_yuv2planeX_8_mmxext;
  457. }
  458. #endif /* ARCH_X86_32 && !HAVE_ALIGNED_STACK */
  459. #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
  460. if (c->srcBpc == 8) { \
  461. hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
  462. ff_hscale8to19_ ## filtersize ## _ ## opt1; \
  463. } else if (c->srcBpc == 9) { \
  464. hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
  465. ff_hscale9to19_ ## filtersize ## _ ## opt1; \
  466. } else if (c->srcBpc == 10) { \
  467. hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
  468. ff_hscale10to19_ ## filtersize ## _ ## opt1; \
  469. } else if (c->srcBpc == 12) { \
  470. hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
  471. ff_hscale12to19_ ## filtersize ## _ ## opt1; \
  472. } 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)) { \
  473. hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
  474. ff_hscale14to19_ ## filtersize ## _ ## opt1; \
  475. } else { /* c->srcBpc == 16 */ \
  476. av_assert0(c->srcBpc == 16);\
  477. hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
  478. ff_hscale16to19_ ## filtersize ## _ ## opt1; \
  479. } \
  480. } while (0)
  481. #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
  482. switch(c->dstBpc){ \
  483. case 16: do_16_case; break; \
  484. case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
  485. case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
  486. case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
  487. }
  488. #define ASSIGN_VSCALE_FUNC(vscalefn, opt) \
  489. switch(c->dstBpc){ \
  490. case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt; break; \
  491. case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2plane1_10_ ## opt; break; \
  492. case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_9_ ## opt; break; \
  493. case 8: vscalefn = ff_yuv2plane1_8_ ## opt; break; \
  494. default: av_assert0(c->dstBpc>8); \
  495. }
  496. #define case_rgb(x, X, opt) \
  497. case AV_PIX_FMT_ ## X: \
  498. c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
  499. if (!c->chrSrcHSubSample) \
  500. c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
  501. break
  502. #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  503. switch (filtersize) { \
  504. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  505. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  506. default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
  507. else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
  508. break; \
  509. }
  510. if (EXTERNAL_SSE2(cpu_flags)) {
  511. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
  512. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
  513. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, ,
  514. HAVE_ALIGNED_STACK || ARCH_X86_64);
  515. if (!(c->flags & SWS_ACCURATE_RND))
  516. ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2);
  517. switch (c->srcFormat) {
  518. case AV_PIX_FMT_YA8:
  519. c->lumToYV12 = ff_yuyvToY_sse2;
  520. if (c->needAlpha)
  521. c->alpToYV12 = ff_uyvyToY_sse2;
  522. break;
  523. case AV_PIX_FMT_YUYV422:
  524. c->lumToYV12 = ff_yuyvToY_sse2;
  525. c->chrToYV12 = ff_yuyvToUV_sse2;
  526. break;
  527. case AV_PIX_FMT_UYVY422:
  528. c->lumToYV12 = ff_uyvyToY_sse2;
  529. c->chrToYV12 = ff_uyvyToUV_sse2;
  530. break;
  531. case AV_PIX_FMT_NV12:
  532. c->chrToYV12 = ff_nv12ToUV_sse2;
  533. break;
  534. case AV_PIX_FMT_NV21:
  535. c->chrToYV12 = ff_nv21ToUV_sse2;
  536. break;
  537. case_rgb(rgb24, RGB24, sse2);
  538. case_rgb(bgr24, BGR24, sse2);
  539. case_rgb(bgra, BGRA, sse2);
  540. case_rgb(rgba, RGBA, sse2);
  541. case_rgb(abgr, ABGR, sse2);
  542. case_rgb(argb, ARGB, sse2);
  543. default:
  544. break;
  545. }
  546. }
  547. if (EXTERNAL_SSSE3(cpu_flags)) {
  548. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
  549. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
  550. switch (c->srcFormat) {
  551. case_rgb(rgb24, RGB24, ssse3);
  552. case_rgb(bgr24, BGR24, ssse3);
  553. default:
  554. break;
  555. }
  556. }
  557. if (EXTERNAL_SSE4(cpu_flags)) {
  558. /* Xto15 don't need special sse4 functions */
  559. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
  560. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
  561. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4,
  562. if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4,
  563. HAVE_ALIGNED_STACK || ARCH_X86_64);
  564. if (c->dstBpc == 16 && !isBE(c->dstFormat) && !(c->flags & SWS_ACCURATE_RND))
  565. c->yuv2plane1 = ff_yuv2plane1_16_sse4;
  566. }
  567. if (EXTERNAL_AVX(cpu_flags)) {
  568. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, ,
  569. HAVE_ALIGNED_STACK || ARCH_X86_64);
  570. if (!(c->flags & SWS_ACCURATE_RND))
  571. ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx);
  572. switch (c->srcFormat) {
  573. case AV_PIX_FMT_YUYV422:
  574. c->chrToYV12 = ff_yuyvToUV_avx;
  575. break;
  576. case AV_PIX_FMT_UYVY422:
  577. c->chrToYV12 = ff_uyvyToUV_avx;
  578. break;
  579. case AV_PIX_FMT_NV12:
  580. c->chrToYV12 = ff_nv12ToUV_avx;
  581. break;
  582. case AV_PIX_FMT_NV21:
  583. c->chrToYV12 = ff_nv21ToUV_avx;
  584. break;
  585. case_rgb(rgb24, RGB24, avx);
  586. case_rgb(bgr24, BGR24, avx);
  587. case_rgb(bgra, BGRA, avx);
  588. case_rgb(rgba, RGBA, avx);
  589. case_rgb(abgr, ABGR, avx);
  590. case_rgb(argb, ARGB, avx);
  591. default:
  592. break;
  593. }
  594. }
  595. #if ARCH_X86_64
  596. #define ASSIGN_AVX2_SCALE_FUNC(hscalefn, filtersize) \
  597. switch (filtersize) { \
  598. case 4: hscalefn = ff_hscale8to15_4_avx2; break; \
  599. default: hscalefn = ff_hscale8to15_X4_avx2; break; \
  600. break; \
  601. }
  602. if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & AV_CPU_FLAG_SLOW_GATHER)) {
  603. if ((c->srcBpc == 8) && (c->dstBpc <= 14)) {
  604. ASSIGN_AVX2_SCALE_FUNC(c->hcScale, c->hChrFilterSize);
  605. ASSIGN_AVX2_SCALE_FUNC(c->hyScale, c->hLumFilterSize);
  606. }
  607. }
  608. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  609. if (ARCH_X86_64)
  610. switch (c->srcFormat) {
  611. case_rgb(rgb24, RGB24, avx2);
  612. case_rgb(bgr24, BGR24, avx2);
  613. case_rgb(bgra, BGRA, avx2);
  614. case_rgb(rgba, RGBA, avx2);
  615. case_rgb(abgr, ABGR, avx2);
  616. case_rgb(argb, ARGB, avx2);
  617. }
  618. switch (c->dstFormat) {
  619. case AV_PIX_FMT_NV12:
  620. case AV_PIX_FMT_NV24:
  621. c->yuv2nv12cX = ff_yuv2nv12cX_avx2;
  622. break;
  623. case AV_PIX_FMT_NV21:
  624. case AV_PIX_FMT_NV42:
  625. c->yuv2nv12cX = ff_yuv2nv21cX_avx2;
  626. break;
  627. default:
  628. break;
  629. }
  630. }
  631. #define INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(fmt, name, opt) \
  632. case fmt: \
  633. c->readAlpPlanar = ff_planar_##name##_to_a_##opt;
  634. #define INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  635. case rgba_fmt: \
  636. case rgb_fmt: \
  637. c->readLumPlanar = ff_planar_##name##_to_y_##opt; \
  638. c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \
  639. break;
  640. #define INPUT_PLANER_RGB_YUV_FUNC_CASE(fmt, name, opt) \
  641. case fmt: \
  642. c->readLumPlanar = ff_planar_##name##_to_y_##opt; \
  643. c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \
  644. break;
  645. #define INPUT_PLANER_RGB_UV_FUNC_CASE(fmt, name, opt) \
  646. case fmt: \
  647. c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \
  648. break;
  649. #define INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  650. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt) \
  651. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  652. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt) \
  653. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  654. #define INPUT_PLANER_RGBAXX_UVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  655. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt) \
  656. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  657. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt) \
  658. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  659. #define INPUT_PLANER_RGBAXX_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  660. INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt##LE, rgba_fmt##LE, name##le, opt) \
  661. INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt##BE, rgba_fmt##BE, name##be, opt)
  662. #define INPUT_PLANER_RGBXX_YUV_FUNC_CASE(rgb_fmt, name, opt) \
  663. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  664. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  665. #define INPUT_PLANER_RGBXX_UV_FUNC_CASE(rgb_fmt, name, opt) \
  666. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  667. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  668. #define INPUT_PLANER_RGB_YUVA_ALL_CASES(opt) \
  669. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, opt) \
  670. INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, opt) \
  671. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, opt) \
  672. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, opt) \
  673. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, opt) \
  674. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, opt) \
  675. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, opt) \
  676. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, opt)
  677. if (EXTERNAL_SSE2(cpu_flags)) {
  678. switch (c->srcFormat) {
  679. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, sse2);
  680. INPUT_PLANER_RGB_UV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse2);
  681. INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse2);
  682. INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse2);
  683. INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, sse2);
  684. INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, sse2);
  685. INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, sse2);
  686. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, sse2);
  687. default:
  688. break;
  689. }
  690. }
  691. if (EXTERNAL_SSE4(cpu_flags)) {
  692. switch (c->srcFormat) {
  693. case AV_PIX_FMT_GBRAP:
  694. INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse4);
  695. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse4);
  696. INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse4);
  697. INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, sse4);
  698. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, sse4);
  699. INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, sse4);
  700. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, sse4);
  701. default:
  702. break;
  703. }
  704. }
  705. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  706. switch (c->srcFormat) {
  707. INPUT_PLANER_RGB_YUVA_ALL_CASES(avx2)
  708. default:
  709. break;
  710. }
  711. }
  712. if(c->flags & SWS_FULL_CHR_H_INT) {
  713. /* yuv2gbrp uses the SwsContext for yuv coefficients
  714. if struct offsets change the asm needs to be updated too */
  715. av_assert0(offsetof(SwsContext, yuv2rgb_y_offset) == 40292);
  716. #define YUV2ANYX_FUNC_CASE(fmt, name, opt) \
  717. case fmt: \
  718. c->yuv2anyX = ff_yuv2##name##_full_X_##opt; \
  719. break;
  720. #define YUV2ANYX_GBRAP_CASES(opt) \
  721. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP, gbrp, opt) \
  722. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP, gbrap, opt) \
  723. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP9LE, gbrp9le, opt) \
  724. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP10LE, gbrp10le, opt) \
  725. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP10LE, gbrap10le, opt) \
  726. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP12LE, gbrp12le, opt) \
  727. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP12LE, gbrap12le, opt) \
  728. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP14LE, gbrp14le, opt) \
  729. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP16LE, gbrp16le, opt) \
  730. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP16LE, gbrap16le, opt) \
  731. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRPF32LE, gbrpf32le, opt) \
  732. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32LE, gbrapf32le, opt) \
  733. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP9BE, gbrp9be, opt) \
  734. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP10BE, gbrp10be, opt) \
  735. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP10BE, gbrap10be, opt) \
  736. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP12BE, gbrp12be, opt) \
  737. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP12BE, gbrap12be, opt) \
  738. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP14BE, gbrp14be, opt) \
  739. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP16BE, gbrp16be, opt) \
  740. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP16BE, gbrap16be, opt) \
  741. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRPF32BE, gbrpf32be, opt) \
  742. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32BE, gbrapf32be, opt)
  743. if (EXTERNAL_SSE2(cpu_flags)) {
  744. switch (c->dstFormat) {
  745. YUV2ANYX_GBRAP_CASES(sse2)
  746. default:
  747. break;
  748. }
  749. }
  750. if (EXTERNAL_SSE4(cpu_flags)) {
  751. switch (c->dstFormat) {
  752. YUV2ANYX_GBRAP_CASES(sse4)
  753. default:
  754. break;
  755. }
  756. }
  757. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  758. switch (c->dstFormat) {
  759. YUV2ANYX_GBRAP_CASES(avx2)
  760. default:
  761. break;
  762. }
  763. }
  764. }
  765. #endif
  766. ff_sws_init_range_convert_x86(c);
  767. }