swscale.c 35 KB

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