swscale.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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(SwsInternal *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. SwsInternal *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(SwsInternal *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(SwsInternal *c)
  419. {
  420. int cpu_flags = av_get_cpu_flags();
  421. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  422. RANGE_CONVERT_FUNCS(avx2);
  423. } else if (EXTERNAL_SSE2(cpu_flags)) {
  424. RANGE_CONVERT_FUNCS(sse2);
  425. }
  426. }
  427. av_cold void ff_sws_init_swscale_x86(SwsInternal *c)
  428. {
  429. int cpu_flags = av_get_cpu_flags();
  430. #if HAVE_MMXEXT_INLINE
  431. if (INLINE_MMXEXT(cpu_flags))
  432. sws_init_swscale_mmxext(c);
  433. #endif
  434. if(c->use_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND)) {
  435. #if HAVE_MMXEXT_EXTERNAL
  436. if (EXTERNAL_MMXEXT(cpu_flags))
  437. c->yuv2planeX = yuv2yuvX_mmxext;
  438. #endif
  439. #if HAVE_SSE3_EXTERNAL
  440. if (EXTERNAL_SSE3(cpu_flags))
  441. c->yuv2planeX = yuv2yuvX_sse3;
  442. #endif
  443. #if HAVE_AVX2_EXTERNAL
  444. if (EXTERNAL_AVX2_FAST(cpu_flags))
  445. c->yuv2planeX = yuv2yuvX_avx2;
  446. #endif
  447. }
  448. #if ARCH_X86_32 && !HAVE_ALIGNED_STACK
  449. // The better yuv2planeX_8 functions need aligned stack on x86-32,
  450. // so we use MMXEXT in this case if they are not available.
  451. if (EXTERNAL_MMXEXT(cpu_flags)) {
  452. if (c->dstBpc == 8 && !c->use_mmx_vfilter)
  453. c->yuv2planeX = ff_yuv2planeX_8_mmxext;
  454. }
  455. #endif /* ARCH_X86_32 && !HAVE_ALIGNED_STACK */
  456. #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
  457. if (c->srcBpc == 8) { \
  458. hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
  459. ff_hscale8to19_ ## filtersize ## _ ## opt1; \
  460. } else if (c->srcBpc == 9) { \
  461. hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
  462. ff_hscale9to19_ ## filtersize ## _ ## opt1; \
  463. } else if (c->srcBpc == 10) { \
  464. hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
  465. ff_hscale10to19_ ## filtersize ## _ ## opt1; \
  466. } else if (c->srcBpc == 12) { \
  467. hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
  468. ff_hscale12to19_ ## filtersize ## _ ## opt1; \
  469. } 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)) { \
  470. hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
  471. ff_hscale14to19_ ## filtersize ## _ ## opt1; \
  472. } else { /* c->srcBpc == 16 */ \
  473. av_assert0(c->srcBpc == 16);\
  474. hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
  475. ff_hscale16to19_ ## filtersize ## _ ## opt1; \
  476. } \
  477. } while (0)
  478. #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
  479. switch(c->dstBpc){ \
  480. case 16: do_16_case; break; \
  481. case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
  482. case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
  483. case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
  484. }
  485. #define ASSIGN_VSCALE_FUNC(vscalefn, opt) \
  486. switch(c->dstBpc){ \
  487. case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt; break; \
  488. case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2plane1_10_ ## opt; break; \
  489. case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_9_ ## opt; break; \
  490. case 8: vscalefn = ff_yuv2plane1_8_ ## opt; break; \
  491. default: av_assert0(c->dstBpc>8); \
  492. }
  493. #define case_rgb(x, X, opt) \
  494. case AV_PIX_FMT_ ## X: \
  495. c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
  496. if (!c->chrSrcHSubSample) \
  497. c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
  498. break
  499. #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
  500. switch (filtersize) { \
  501. case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
  502. case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
  503. default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
  504. else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
  505. break; \
  506. }
  507. if (EXTERNAL_SSE2(cpu_flags)) {
  508. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
  509. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
  510. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, ,
  511. HAVE_ALIGNED_STACK || ARCH_X86_64);
  512. if (!(c->flags & SWS_ACCURATE_RND))
  513. ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2);
  514. switch (c->srcFormat) {
  515. case AV_PIX_FMT_YA8:
  516. c->lumToYV12 = ff_yuyvToY_sse2;
  517. if (c->needAlpha)
  518. c->alpToYV12 = ff_uyvyToY_sse2;
  519. break;
  520. case AV_PIX_FMT_YUYV422:
  521. c->lumToYV12 = ff_yuyvToY_sse2;
  522. c->chrToYV12 = ff_yuyvToUV_sse2;
  523. break;
  524. case AV_PIX_FMT_UYVY422:
  525. c->lumToYV12 = ff_uyvyToY_sse2;
  526. c->chrToYV12 = ff_uyvyToUV_sse2;
  527. break;
  528. case AV_PIX_FMT_NV12:
  529. c->chrToYV12 = ff_nv12ToUV_sse2;
  530. break;
  531. case AV_PIX_FMT_NV21:
  532. c->chrToYV12 = ff_nv21ToUV_sse2;
  533. break;
  534. case_rgb(rgb24, RGB24, sse2);
  535. case_rgb(bgr24, BGR24, sse2);
  536. case_rgb(bgra, BGRA, sse2);
  537. case_rgb(rgba, RGBA, sse2);
  538. case_rgb(abgr, ABGR, sse2);
  539. case_rgb(argb, ARGB, sse2);
  540. default:
  541. break;
  542. }
  543. }
  544. if (EXTERNAL_SSSE3(cpu_flags)) {
  545. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
  546. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
  547. switch (c->srcFormat) {
  548. case_rgb(rgb24, RGB24, ssse3);
  549. case_rgb(bgr24, BGR24, ssse3);
  550. default:
  551. break;
  552. }
  553. }
  554. if (EXTERNAL_SSE4(cpu_flags)) {
  555. /* Xto15 don't need special sse4 functions */
  556. ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
  557. ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
  558. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4,
  559. if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4,
  560. HAVE_ALIGNED_STACK || ARCH_X86_64);
  561. if (c->dstBpc == 16 && !isBE(c->dstFormat) && !(c->flags & SWS_ACCURATE_RND))
  562. c->yuv2plane1 = ff_yuv2plane1_16_sse4;
  563. }
  564. if (EXTERNAL_AVX(cpu_flags)) {
  565. ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, ,
  566. HAVE_ALIGNED_STACK || ARCH_X86_64);
  567. if (!(c->flags & SWS_ACCURATE_RND))
  568. ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx);
  569. switch (c->srcFormat) {
  570. case AV_PIX_FMT_YUYV422:
  571. c->chrToYV12 = ff_yuyvToUV_avx;
  572. break;
  573. case AV_PIX_FMT_UYVY422:
  574. c->chrToYV12 = ff_uyvyToUV_avx;
  575. break;
  576. case AV_PIX_FMT_NV12:
  577. c->chrToYV12 = ff_nv12ToUV_avx;
  578. break;
  579. case AV_PIX_FMT_NV21:
  580. c->chrToYV12 = ff_nv21ToUV_avx;
  581. break;
  582. case_rgb(rgb24, RGB24, avx);
  583. case_rgb(bgr24, BGR24, avx);
  584. case_rgb(bgra, BGRA, avx);
  585. case_rgb(rgba, RGBA, avx);
  586. case_rgb(abgr, ABGR, avx);
  587. case_rgb(argb, ARGB, avx);
  588. default:
  589. break;
  590. }
  591. }
  592. #if ARCH_X86_64
  593. #define ASSIGN_AVX2_SCALE_FUNC(hscalefn, filtersize) \
  594. switch (filtersize) { \
  595. case 4: hscalefn = ff_hscale8to15_4_avx2; break; \
  596. default: hscalefn = ff_hscale8to15_X4_avx2; break; \
  597. break; \
  598. }
  599. if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & AV_CPU_FLAG_SLOW_GATHER)) {
  600. if ((c->srcBpc == 8) && (c->dstBpc <= 14)) {
  601. ASSIGN_AVX2_SCALE_FUNC(c->hcScale, c->hChrFilterSize);
  602. ASSIGN_AVX2_SCALE_FUNC(c->hyScale, c->hLumFilterSize);
  603. }
  604. }
  605. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  606. if (ARCH_X86_64)
  607. switch (c->srcFormat) {
  608. case_rgb(rgb24, RGB24, avx2);
  609. case_rgb(bgr24, BGR24, avx2);
  610. case_rgb(bgra, BGRA, avx2);
  611. case_rgb(rgba, RGBA, avx2);
  612. case_rgb(abgr, ABGR, avx2);
  613. case_rgb(argb, ARGB, avx2);
  614. }
  615. if (!(c->flags & SWS_ACCURATE_RND)) // FIXME
  616. switch (c->dstFormat) {
  617. case AV_PIX_FMT_NV12:
  618. case AV_PIX_FMT_NV24:
  619. c->yuv2nv12cX = ff_yuv2nv12cX_avx2;
  620. break;
  621. case AV_PIX_FMT_NV21:
  622. case AV_PIX_FMT_NV42:
  623. c->yuv2nv12cX = ff_yuv2nv21cX_avx2;
  624. break;
  625. default:
  626. break;
  627. }
  628. }
  629. #define INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(fmt, name, opt) \
  630. case fmt: \
  631. c->readAlpPlanar = ff_planar_##name##_to_a_##opt;
  632. #define INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  633. case rgba_fmt: \
  634. case rgb_fmt: \
  635. c->readLumPlanar = ff_planar_##name##_to_y_##opt; \
  636. c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \
  637. break;
  638. #define INPUT_PLANER_RGB_YUV_FUNC_CASE(fmt, name, opt) \
  639. case fmt: \
  640. c->readLumPlanar = ff_planar_##name##_to_y_##opt; \
  641. c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \
  642. break;
  643. #define INPUT_PLANER_RGB_UV_FUNC_CASE(fmt, name, opt) \
  644. case fmt: \
  645. c->readChrPlanar = ff_planar_##name##_to_uv_##opt; \
  646. break;
  647. #define INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  648. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt) \
  649. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  650. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt) \
  651. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  652. #define INPUT_PLANER_RGBAXX_UVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  653. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt) \
  654. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  655. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt) \
  656. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  657. #define INPUT_PLANER_RGBAXX_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
  658. INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt##LE, rgba_fmt##LE, name##le, opt) \
  659. INPUT_PLANER_RGBA_YUV_FUNC_CASE(rgb_fmt##BE, rgba_fmt##BE, name##be, opt)
  660. #define INPUT_PLANER_RGBXX_YUV_FUNC_CASE(rgb_fmt, name, opt) \
  661. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  662. INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  663. #define INPUT_PLANER_RGBXX_UV_FUNC_CASE(rgb_fmt, name, opt) \
  664. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt) \
  665. INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
  666. #define INPUT_PLANER_RGB_YUVA_ALL_CASES(opt) \
  667. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, opt) \
  668. INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, opt) \
  669. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, opt) \
  670. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, opt) \
  671. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, opt) \
  672. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, opt) \
  673. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, opt) \
  674. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, opt)
  675. if (EXTERNAL_SSE2(cpu_flags)) {
  676. switch (c->srcFormat) {
  677. INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, sse2);
  678. INPUT_PLANER_RGB_UV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse2);
  679. INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse2);
  680. INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse2);
  681. INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, sse2);
  682. INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, sse2);
  683. INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, sse2);
  684. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, sse2);
  685. default:
  686. break;
  687. }
  688. }
  689. if (EXTERNAL_SSE4(cpu_flags)) {
  690. switch (c->srcFormat) {
  691. case AV_PIX_FMT_GBRAP:
  692. INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse4);
  693. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse4);
  694. INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, rgb10, sse4);
  695. INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, rgb12, sse4);
  696. INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP14, rgb14, sse4);
  697. INPUT_PLANER_RGBAXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, rgb16, sse4);
  698. INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, rgbf32, sse4);
  699. default:
  700. break;
  701. }
  702. }
  703. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  704. switch (c->srcFormat) {
  705. INPUT_PLANER_RGB_YUVA_ALL_CASES(avx2)
  706. default:
  707. break;
  708. }
  709. }
  710. if(c->flags & SWS_FULL_CHR_H_INT) {
  711. /* yuv2gbrp uses the SwsInternal for yuv coefficients
  712. if struct offsets change the asm needs to be updated too */
  713. av_assert0(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292);
  714. #define YUV2ANYX_FUNC_CASE(fmt, name, opt) \
  715. case fmt: \
  716. c->yuv2anyX = ff_yuv2##name##_full_X_##opt; \
  717. break;
  718. #define YUV2ANYX_GBRAP_CASES(opt) \
  719. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP, gbrp, opt) \
  720. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP, gbrap, opt) \
  721. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP9LE, gbrp9le, opt) \
  722. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP10LE, gbrp10le, opt) \
  723. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP10LE, gbrap10le, opt) \
  724. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP12LE, gbrp12le, opt) \
  725. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP12LE, gbrap12le, opt) \
  726. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP14LE, gbrp14le, opt) \
  727. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP16LE, gbrp16le, opt) \
  728. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP16LE, gbrap16le, opt) \
  729. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRPF32LE, gbrpf32le, opt) \
  730. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32LE, gbrapf32le, opt) \
  731. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP9BE, gbrp9be, opt) \
  732. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP10BE, gbrp10be, opt) \
  733. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP10BE, gbrap10be, opt) \
  734. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP12BE, gbrp12be, opt) \
  735. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP12BE, gbrap12be, opt) \
  736. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP14BE, gbrp14be, opt) \
  737. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRP16BE, gbrp16be, opt) \
  738. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAP16BE, gbrap16be, opt) \
  739. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRPF32BE, gbrpf32be, opt) \
  740. YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32BE, gbrapf32be, opt)
  741. if (EXTERNAL_SSE2(cpu_flags)) {
  742. switch (c->dstFormat) {
  743. YUV2ANYX_GBRAP_CASES(sse2)
  744. default:
  745. break;
  746. }
  747. }
  748. if (EXTERNAL_SSE4(cpu_flags)) {
  749. switch (c->dstFormat) {
  750. YUV2ANYX_GBRAP_CASES(sse4)
  751. default:
  752. break;
  753. }
  754. }
  755. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  756. switch (c->dstFormat) {
  757. YUV2ANYX_GBRAP_CASES(avx2)
  758. default:
  759. break;
  760. }
  761. }
  762. }
  763. #endif
  764. }