You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2843 lines
102KB

  1. /*
  2. * Copyright (C) 2001-2012 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 <math.h>
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/avutil.h"
  26. #include "libavutil/avassert.h"
  27. #include "libavutil/bswap.h"
  28. #include "libavutil/cpu.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "libavutil/mathematics.h"
  31. #include "libavutil/pixdesc.h"
  32. #include "config.h"
  33. #include "rgb2rgb.h"
  34. #include "swscale.h"
  35. #include "swscale_internal.h"
  36. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
  37. { 1, 3, 1, 3, 1, 3, 1, 3, },
  38. { 2, 0, 2, 0, 2, 0, 2, 0, },
  39. { 1, 3, 1, 3, 1, 3, 1, 3, },
  40. };
  41. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
  42. { 6, 2, 6, 2, 6, 2, 6, 2, },
  43. { 0, 4, 0, 4, 0, 4, 0, 4, },
  44. { 6, 2, 6, 2, 6, 2, 6, 2, },
  45. };
  46. DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
  47. { 8, 4, 11, 7, 8, 4, 11, 7, },
  48. { 2, 14, 1, 13, 2, 14, 1, 13, },
  49. { 10, 6, 9, 5, 10, 6, 9, 5, },
  50. { 0, 12, 3, 15, 0, 12, 3, 15, },
  51. { 8, 4, 11, 7, 8, 4, 11, 7, },
  52. };
  53. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
  54. { 17, 9, 23, 15, 16, 8, 22, 14, },
  55. { 5, 29, 3, 27, 4, 28, 2, 26, },
  56. { 21, 13, 19, 11, 20, 12, 18, 10, },
  57. { 0, 24, 6, 30, 1, 25, 7, 31, },
  58. { 16, 8, 22, 14, 17, 9, 23, 15, },
  59. { 4, 28, 2, 26, 5, 29, 3, 27, },
  60. { 20, 12, 18, 10, 21, 13, 19, 11, },
  61. { 1, 25, 7, 31, 0, 24, 6, 30, },
  62. { 17, 9, 23, 15, 16, 8, 22, 14, },
  63. };
  64. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
  65. { 0, 55, 14, 68, 3, 58, 17, 72, },
  66. { 37, 18, 50, 32, 40, 22, 54, 35, },
  67. { 9, 64, 5, 59, 13, 67, 8, 63, },
  68. { 46, 27, 41, 23, 49, 31, 44, 26, },
  69. { 2, 57, 16, 71, 1, 56, 15, 70, },
  70. { 39, 21, 52, 34, 38, 19, 51, 33, },
  71. { 11, 66, 7, 62, 10, 65, 6, 60, },
  72. { 48, 30, 43, 25, 47, 29, 42, 24, },
  73. { 0, 55, 14, 68, 3, 58, 17, 72, },
  74. };
  75. #if 1
  76. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  77. {117, 62, 158, 103, 113, 58, 155, 100, },
  78. { 34, 199, 21, 186, 31, 196, 17, 182, },
  79. {144, 89, 131, 76, 141, 86, 127, 72, },
  80. { 0, 165, 41, 206, 10, 175, 52, 217, },
  81. {110, 55, 151, 96, 120, 65, 162, 107, },
  82. { 28, 193, 14, 179, 38, 203, 24, 189, },
  83. {138, 83, 124, 69, 148, 93, 134, 79, },
  84. { 7, 172, 48, 213, 3, 168, 45, 210, },
  85. {117, 62, 158, 103, 113, 58, 155, 100, },
  86. };
  87. #elif 1
  88. // tries to correct a gamma of 1.5
  89. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  90. { 0, 143, 18, 200, 2, 156, 25, 215, },
  91. { 78, 28, 125, 64, 89, 36, 138, 74, },
  92. { 10, 180, 3, 161, 16, 195, 8, 175, },
  93. {109, 51, 93, 38, 121, 60, 105, 47, },
  94. { 1, 152, 23, 210, 0, 147, 20, 205, },
  95. { 85, 33, 134, 71, 81, 30, 130, 67, },
  96. { 14, 190, 6, 171, 12, 185, 5, 166, },
  97. {117, 57, 101, 44, 113, 54, 97, 41, },
  98. { 0, 143, 18, 200, 2, 156, 25, 215, },
  99. };
  100. #elif 1
  101. // tries to correct a gamma of 2.0
  102. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  103. { 0, 124, 8, 193, 0, 140, 12, 213, },
  104. { 55, 14, 104, 42, 66, 19, 119, 52, },
  105. { 3, 168, 1, 145, 6, 187, 3, 162, },
  106. { 86, 31, 70, 21, 99, 39, 82, 28, },
  107. { 0, 134, 11, 206, 0, 129, 9, 200, },
  108. { 62, 17, 114, 48, 58, 16, 109, 45, },
  109. { 5, 181, 2, 157, 4, 175, 1, 151, },
  110. { 95, 36, 78, 26, 90, 34, 74, 24, },
  111. { 0, 124, 8, 193, 0, 140, 12, 213, },
  112. };
  113. #else
  114. // tries to correct a gamma of 2.5
  115. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  116. { 0, 107, 3, 187, 0, 125, 6, 212, },
  117. { 39, 7, 86, 28, 49, 11, 102, 36, },
  118. { 1, 158, 0, 131, 3, 180, 1, 151, },
  119. { 68, 19, 52, 12, 81, 25, 64, 17, },
  120. { 0, 119, 5, 203, 0, 113, 4, 195, },
  121. { 45, 9, 96, 33, 42, 8, 91, 30, },
  122. { 2, 172, 1, 144, 2, 165, 0, 137, },
  123. { 77, 23, 60, 15, 72, 21, 56, 14, },
  124. { 0, 107, 3, 187, 0, 125, 6, 212, },
  125. };
  126. #endif
  127. #define output_pixel(pos, val, bias, signedness) \
  128. if (big_endian) { \
  129. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  130. } else { \
  131. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  132. }
  133. static av_always_inline void
  134. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  135. int big_endian, int output_bits)
  136. {
  137. int i;
  138. int shift = 3;
  139. av_assert0(output_bits == 16);
  140. for (i = 0; i < dstW; i++) {
  141. int val = src[i] + (1 << (shift - 1));
  142. output_pixel(&dest[i], val, 0, uint);
  143. }
  144. }
  145. static av_always_inline void
  146. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  147. const int32_t **src, uint16_t *dest, int dstW,
  148. int big_endian, int output_bits)
  149. {
  150. int i;
  151. int shift = 15;
  152. av_assert0(output_bits == 16);
  153. for (i = 0; i < dstW; i++) {
  154. int val = 1 << (shift - 1);
  155. int j;
  156. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  157. * filters (or anything with negative coeffs, the range can be slightly
  158. * wider in both directions. To account for this overflow, we subtract
  159. * a constant so it always fits in the signed range (assuming a
  160. * reasonable filterSize), and re-add that at the end. */
  161. val -= 0x40000000;
  162. for (j = 0; j < filterSize; j++)
  163. val += src[j][i] * (unsigned)filter[j];
  164. output_pixel(&dest[i], val, 0x8000, int);
  165. }
  166. }
  167. static void yuv2p016cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  168. const int16_t **chrUSrc, const int16_t **chrVSrc,
  169. uint8_t *dest8, int chrDstW)
  170. {
  171. uint16_t *dest = (uint16_t*)dest8;
  172. const int32_t **uSrc = (const int32_t **)chrUSrc;
  173. const int32_t **vSrc = (const int32_t **)chrVSrc;
  174. int shift = 15;
  175. int big_endian = c->dstFormat == AV_PIX_FMT_P016BE;
  176. int i, j;
  177. for (i = 0; i < chrDstW; i++) {
  178. int u = 1 << (shift - 1);
  179. int v = 1 << (shift - 1);
  180. /* See yuv2planeX_16_c_template for details. */
  181. u -= 0x40000000;
  182. v -= 0x40000000;
  183. for (j = 0; j < chrFilterSize; j++) {
  184. u += uSrc[j][i] * (unsigned)chrFilter[j];
  185. v += vSrc[j][i] * (unsigned)chrFilter[j];
  186. }
  187. output_pixel(&dest[2*i] , u, 0x8000, int);
  188. output_pixel(&dest[2*i+1], v, 0x8000, int);
  189. }
  190. }
  191. static av_always_inline void
  192. yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
  193. {
  194. static const int big_endian = HAVE_BIGENDIAN;
  195. static const int shift = 3;
  196. static const float float_mult = 1.0f / 65535.0f;
  197. int i, val;
  198. uint16_t val_uint;
  199. for (i = 0; i < dstW; ++i){
  200. val = src[i] + (1 << (shift - 1));
  201. output_pixel(&val_uint, val, 0, uint);
  202. dest[i] = float_mult * (float)val_uint;
  203. }
  204. }
  205. static av_always_inline void
  206. yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
  207. {
  208. static const int big_endian = HAVE_BIGENDIAN;
  209. static const int shift = 3;
  210. static const float float_mult = 1.0f / 65535.0f;
  211. int i, val;
  212. uint16_t val_uint;
  213. for (i = 0; i < dstW; ++i){
  214. val = src[i] + (1 << (shift - 1));
  215. output_pixel(&val_uint, val, 0, uint);
  216. dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
  217. }
  218. }
  219. static av_always_inline void
  220. yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
  221. float *dest, int dstW)
  222. {
  223. static const int big_endian = HAVE_BIGENDIAN;
  224. static const int shift = 15;
  225. static const float float_mult = 1.0f / 65535.0f;
  226. int i, j, val;
  227. uint16_t val_uint;
  228. for (i = 0; i < dstW; ++i){
  229. val = (1 << (shift - 1)) - 0x40000000;
  230. for (j = 0; j < filterSize; ++j){
  231. val += src[j][i] * (unsigned)filter[j];
  232. }
  233. output_pixel(&val_uint, val, 0x8000, int);
  234. dest[i] = float_mult * (float)val_uint;
  235. }
  236. }
  237. static av_always_inline void
  238. yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
  239. uint32_t *dest, int dstW)
  240. {
  241. static const int big_endian = HAVE_BIGENDIAN;
  242. static const int shift = 15;
  243. static const float float_mult = 1.0f / 65535.0f;
  244. int i, j, val;
  245. uint16_t val_uint;
  246. for (i = 0; i < dstW; ++i){
  247. val = (1 << (shift - 1)) - 0x40000000;
  248. for (j = 0; j < filterSize; ++j){
  249. val += src[j][i] * (unsigned)filter[j];
  250. }
  251. output_pixel(&val_uint, val, 0x8000, int);
  252. dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
  253. }
  254. }
  255. #define yuv2plane1_float(template, dest_type, BE_LE) \
  256. static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
  257. const uint8_t *dither, int offset) \
  258. { \
  259. template((const int32_t *)src, (dest_type *)dest, dstW); \
  260. }
  261. #define yuv2planeX_float(template, dest_type, BE_LE) \
  262. static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  263. const int16_t **src, uint8_t *dest, int dstW, \
  264. const uint8_t *dither, int offset) \
  265. { \
  266. template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
  267. }
  268. #if HAVE_BIGENDIAN
  269. yuv2plane1_float(yuv2plane1_float_c_template, float, BE)
  270. yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, LE)
  271. yuv2planeX_float(yuv2planeX_float_c_template, float, BE)
  272. yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, LE)
  273. #else
  274. yuv2plane1_float(yuv2plane1_float_c_template, float, LE)
  275. yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, BE)
  276. yuv2planeX_float(yuv2planeX_float_c_template, float, LE)
  277. yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, BE)
  278. #endif
  279. #undef output_pixel
  280. #define output_pixel(pos, val) \
  281. if (big_endian) { \
  282. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  283. } else { \
  284. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  285. }
  286. static av_always_inline void
  287. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  288. int big_endian, int output_bits)
  289. {
  290. int i;
  291. int shift = 15 - output_bits;
  292. for (i = 0; i < dstW; i++) {
  293. int val = src[i] + (1 << (shift - 1));
  294. output_pixel(&dest[i], val);
  295. }
  296. }
  297. static av_always_inline void
  298. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  299. const int16_t **src, uint16_t *dest, int dstW,
  300. int big_endian, int output_bits)
  301. {
  302. int i;
  303. int shift = 11 + 16 - output_bits;
  304. for (i = 0; i < dstW; i++) {
  305. int val = 1 << (shift - 1);
  306. int j;
  307. for (j = 0; j < filterSize; j++)
  308. val += src[j][i] * filter[j];
  309. output_pixel(&dest[i], val);
  310. }
  311. }
  312. #undef output_pixel
  313. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  314. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  315. uint8_t *dest, int dstW, \
  316. const uint8_t *dither, int offset)\
  317. { \
  318. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  319. (uint16_t *) dest, dstW, is_be, bits); \
  320. }\
  321. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  322. const int16_t **src, uint8_t *dest, int dstW, \
  323. const uint8_t *dither, int offset)\
  324. { \
  325. yuv2planeX_## template_size ## _c_template(filter, \
  326. filterSize, (const typeX_t **) src, \
  327. (uint16_t *) dest, dstW, is_be, bits); \
  328. }
  329. yuv2NBPS( 9, BE, 1, 10, int16_t)
  330. yuv2NBPS( 9, LE, 0, 10, int16_t)
  331. yuv2NBPS(10, BE, 1, 10, int16_t)
  332. yuv2NBPS(10, LE, 0, 10, int16_t)
  333. yuv2NBPS(12, BE, 1, 10, int16_t)
  334. yuv2NBPS(12, LE, 0, 10, int16_t)
  335. yuv2NBPS(14, BE, 1, 10, int16_t)
  336. yuv2NBPS(14, LE, 0, 10, int16_t)
  337. yuv2NBPS(16, BE, 1, 16, int32_t)
  338. yuv2NBPS(16, LE, 0, 16, int32_t)
  339. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  340. const int16_t **src, uint8_t *dest, int dstW,
  341. const uint8_t *dither, int offset)
  342. {
  343. int i;
  344. for (i=0; i<dstW; i++) {
  345. int val = dither[(i + offset) & 7] << 12;
  346. int j;
  347. for (j=0; j<filterSize; j++)
  348. val += src[j][i] * filter[j];
  349. dest[i]= av_clip_uint8(val>>19);
  350. }
  351. }
  352. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  353. const uint8_t *dither, int offset)
  354. {
  355. int i;
  356. for (i=0; i<dstW; i++) {
  357. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  358. dest[i]= av_clip_uint8(val);
  359. }
  360. }
  361. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  362. const int16_t **chrUSrc, const int16_t **chrVSrc,
  363. uint8_t *dest, int chrDstW)
  364. {
  365. enum AVPixelFormat dstFormat = c->dstFormat;
  366. const uint8_t *chrDither = c->chrDither8;
  367. int i;
  368. if (dstFormat == AV_PIX_FMT_NV12)
  369. for (i=0; i<chrDstW; i++) {
  370. int u = chrDither[i & 7] << 12;
  371. int v = chrDither[(i + 3) & 7] << 12;
  372. int j;
  373. for (j=0; j<chrFilterSize; j++) {
  374. u += chrUSrc[j][i] * chrFilter[j];
  375. v += chrVSrc[j][i] * chrFilter[j];
  376. }
  377. dest[2*i]= av_clip_uint8(u>>19);
  378. dest[2*i+1]= av_clip_uint8(v>>19);
  379. }
  380. else
  381. for (i=0; i<chrDstW; i++) {
  382. int u = chrDither[i & 7] << 12;
  383. int v = chrDither[(i + 3) & 7] << 12;
  384. int j;
  385. for (j=0; j<chrFilterSize; j++) {
  386. u += chrUSrc[j][i] * chrFilter[j];
  387. v += chrVSrc[j][i] * chrFilter[j];
  388. }
  389. dest[2*i]= av_clip_uint8(v>>19);
  390. dest[2*i+1]= av_clip_uint8(u>>19);
  391. }
  392. }
  393. #define output_pixel(pos, val) \
  394. if (big_endian) { \
  395. AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
  396. } else { \
  397. AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
  398. }
  399. static void yuv2p010l1_c(const int16_t *src,
  400. uint16_t *dest, int dstW,
  401. int big_endian)
  402. {
  403. int i;
  404. int shift = 5;
  405. for (i = 0; i < dstW; i++) {
  406. int val = src[i] + (1 << (shift - 1));
  407. output_pixel(&dest[i], val);
  408. }
  409. }
  410. static void yuv2p010lX_c(const int16_t *filter, int filterSize,
  411. const int16_t **src, uint16_t *dest, int dstW,
  412. int big_endian)
  413. {
  414. int i, j;
  415. int shift = 17;
  416. for (i = 0; i < dstW; i++) {
  417. int val = 1 << (shift - 1);
  418. for (j = 0; j < filterSize; j++)
  419. val += src[j][i] * filter[j];
  420. output_pixel(&dest[i], val);
  421. }
  422. }
  423. static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  424. const int16_t **chrUSrc, const int16_t **chrVSrc,
  425. uint8_t *dest8, int chrDstW)
  426. {
  427. uint16_t *dest = (uint16_t*)dest8;
  428. int shift = 17;
  429. int big_endian = c->dstFormat == AV_PIX_FMT_P010BE;
  430. int i, j;
  431. for (i = 0; i < chrDstW; i++) {
  432. int u = 1 << (shift - 1);
  433. int v = 1 << (shift - 1);
  434. for (j = 0; j < chrFilterSize; j++) {
  435. u += chrUSrc[j][i] * chrFilter[j];
  436. v += chrVSrc[j][i] * chrFilter[j];
  437. }
  438. output_pixel(&dest[2*i] , u);
  439. output_pixel(&dest[2*i+1], v);
  440. }
  441. }
  442. static void yuv2p010l1_LE_c(const int16_t *src,
  443. uint8_t *dest, int dstW,
  444. const uint8_t *dither, int offset)
  445. {
  446. yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
  447. }
  448. static void yuv2p010l1_BE_c(const int16_t *src,
  449. uint8_t *dest, int dstW,
  450. const uint8_t *dither, int offset)
  451. {
  452. yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
  453. }
  454. static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
  455. const int16_t **src, uint8_t *dest, int dstW,
  456. const uint8_t *dither, int offset)
  457. {
  458. yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
  459. }
  460. static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
  461. const int16_t **src, uint8_t *dest, int dstW,
  462. const uint8_t *dither, int offset)
  463. {
  464. yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
  465. }
  466. #undef output_pixel
  467. #define accumulate_bit(acc, val) \
  468. acc <<= 1; \
  469. acc |= (val) >= 234
  470. #define output_pixel(pos, acc) \
  471. if (target == AV_PIX_FMT_MONOBLACK) { \
  472. pos = acc; \
  473. } else { \
  474. pos = ~acc; \
  475. }
  476. static av_always_inline void
  477. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  478. const int16_t **lumSrc, int lumFilterSize,
  479. const int16_t *chrFilter, const int16_t **chrUSrc,
  480. const int16_t **chrVSrc, int chrFilterSize,
  481. const int16_t **alpSrc, uint8_t *dest, int dstW,
  482. int y, enum AVPixelFormat target)
  483. {
  484. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  485. int i;
  486. unsigned acc = 0;
  487. int err = 0;
  488. for (i = 0; i < dstW; i += 2) {
  489. int j;
  490. int Y1 = 1 << 18;
  491. int Y2 = 1 << 18;
  492. for (j = 0; j < lumFilterSize; j++) {
  493. Y1 += lumSrc[j][i] * lumFilter[j];
  494. Y2 += lumSrc[j][i+1] * lumFilter[j];
  495. }
  496. Y1 >>= 19;
  497. Y2 >>= 19;
  498. if ((Y1 | Y2) & 0x100) {
  499. Y1 = av_clip_uint8(Y1);
  500. Y2 = av_clip_uint8(Y2);
  501. }
  502. if (c->dither == SWS_DITHER_ED) {
  503. Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  504. c->dither_error[0][i] = err;
  505. acc = 2*acc + (Y1 >= 128);
  506. Y1 -= 220*(acc&1);
  507. err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
  508. c->dither_error[0][i+1] = Y1;
  509. acc = 2*acc + (err >= 128);
  510. err -= 220*(acc&1);
  511. } else {
  512. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  513. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  514. }
  515. if ((i & 7) == 6) {
  516. output_pixel(*dest++, acc);
  517. }
  518. }
  519. c->dither_error[0][i] = err;
  520. if (i & 6) {
  521. output_pixel(*dest, acc);
  522. }
  523. }
  524. static av_always_inline void
  525. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  526. const int16_t *ubuf[2], const int16_t *vbuf[2],
  527. const int16_t *abuf[2], uint8_t *dest, int dstW,
  528. int yalpha, int uvalpha, int y,
  529. enum AVPixelFormat target)
  530. {
  531. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  532. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  533. int yalpha1 = 4096 - yalpha;
  534. int i;
  535. av_assert2(yalpha <= 4096U);
  536. if (c->dither == SWS_DITHER_ED) {
  537. int err = 0;
  538. int acc = 0;
  539. for (i = 0; i < dstW; i +=2) {
  540. int Y;
  541. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  542. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  543. c->dither_error[0][i] = err;
  544. acc = 2*acc + (Y >= 128);
  545. Y -= 220*(acc&1);
  546. err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  547. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  548. c->dither_error[0][i+1] = Y;
  549. acc = 2*acc + (err >= 128);
  550. err -= 220*(acc&1);
  551. if ((i & 7) == 6)
  552. output_pixel(*dest++, acc);
  553. }
  554. c->dither_error[0][i] = err;
  555. } else {
  556. for (i = 0; i < dstW; i += 8) {
  557. int Y, acc = 0;
  558. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  559. accumulate_bit(acc, Y + d128[0]);
  560. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  561. accumulate_bit(acc, Y + d128[1]);
  562. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  563. accumulate_bit(acc, Y + d128[2]);
  564. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  565. accumulate_bit(acc, Y + d128[3]);
  566. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  567. accumulate_bit(acc, Y + d128[4]);
  568. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  569. accumulate_bit(acc, Y + d128[5]);
  570. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  571. accumulate_bit(acc, Y + d128[6]);
  572. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  573. accumulate_bit(acc, Y + d128[7]);
  574. output_pixel(*dest++, acc);
  575. }
  576. }
  577. }
  578. static av_always_inline void
  579. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  580. const int16_t *ubuf[2], const int16_t *vbuf[2],
  581. const int16_t *abuf0, uint8_t *dest, int dstW,
  582. int uvalpha, int y, enum AVPixelFormat target)
  583. {
  584. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  585. int i;
  586. if (c->dither == SWS_DITHER_ED) {
  587. int err = 0;
  588. int acc = 0;
  589. for (i = 0; i < dstW; i +=2) {
  590. int Y;
  591. Y = ((buf0[i + 0] + 64) >> 7);
  592. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  593. c->dither_error[0][i] = err;
  594. acc = 2*acc + (Y >= 128);
  595. Y -= 220*(acc&1);
  596. err = ((buf0[i + 1] + 64) >> 7);
  597. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  598. c->dither_error[0][i+1] = Y;
  599. acc = 2*acc + (err >= 128);
  600. err -= 220*(acc&1);
  601. if ((i & 7) == 6)
  602. output_pixel(*dest++, acc);
  603. }
  604. c->dither_error[0][i] = err;
  605. } else {
  606. for (i = 0; i < dstW; i += 8) {
  607. int acc = 0;
  608. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  609. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  610. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  611. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  612. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  613. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  614. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  615. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  616. output_pixel(*dest++, acc);
  617. }
  618. }
  619. }
  620. #undef output_pixel
  621. #undef accumulate_bit
  622. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  623. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  624. const int16_t **lumSrc, int lumFilterSize, \
  625. const int16_t *chrFilter, const int16_t **chrUSrc, \
  626. const int16_t **chrVSrc, int chrFilterSize, \
  627. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  628. int y) \
  629. { \
  630. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  631. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  632. alpSrc, dest, dstW, y, fmt); \
  633. } \
  634. \
  635. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  636. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  637. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  638. int yalpha, int uvalpha, int y) \
  639. { \
  640. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  641. dest, dstW, yalpha, uvalpha, y, fmt); \
  642. } \
  643. \
  644. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  645. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  646. const int16_t *abuf0, uint8_t *dest, int dstW, \
  647. int uvalpha, int y) \
  648. { \
  649. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  650. abuf0, dest, dstW, uvalpha, \
  651. y, fmt); \
  652. }
  653. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  654. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  655. #define output_pixels(pos, Y1, U, Y2, V) \
  656. if (target == AV_PIX_FMT_YUYV422) { \
  657. dest[pos + 0] = Y1; \
  658. dest[pos + 1] = U; \
  659. dest[pos + 2] = Y2; \
  660. dest[pos + 3] = V; \
  661. } else if (target == AV_PIX_FMT_YVYU422) { \
  662. dest[pos + 0] = Y1; \
  663. dest[pos + 1] = V; \
  664. dest[pos + 2] = Y2; \
  665. dest[pos + 3] = U; \
  666. } else { /* AV_PIX_FMT_UYVY422 */ \
  667. dest[pos + 0] = U; \
  668. dest[pos + 1] = Y1; \
  669. dest[pos + 2] = V; \
  670. dest[pos + 3] = Y2; \
  671. }
  672. static av_always_inline void
  673. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  674. const int16_t **lumSrc, int lumFilterSize,
  675. const int16_t *chrFilter, const int16_t **chrUSrc,
  676. const int16_t **chrVSrc, int chrFilterSize,
  677. const int16_t **alpSrc, uint8_t *dest, int dstW,
  678. int y, enum AVPixelFormat target)
  679. {
  680. int i;
  681. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  682. int j;
  683. int Y1 = 1 << 18;
  684. int Y2 = 1 << 18;
  685. int U = 1 << 18;
  686. int V = 1 << 18;
  687. for (j = 0; j < lumFilterSize; j++) {
  688. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  689. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  690. }
  691. for (j = 0; j < chrFilterSize; j++) {
  692. U += chrUSrc[j][i] * chrFilter[j];
  693. V += chrVSrc[j][i] * chrFilter[j];
  694. }
  695. Y1 >>= 19;
  696. Y2 >>= 19;
  697. U >>= 19;
  698. V >>= 19;
  699. if ((Y1 | Y2 | U | V) & 0x100) {
  700. Y1 = av_clip_uint8(Y1);
  701. Y2 = av_clip_uint8(Y2);
  702. U = av_clip_uint8(U);
  703. V = av_clip_uint8(V);
  704. }
  705. output_pixels(4*i, Y1, U, Y2, V);
  706. }
  707. }
  708. static av_always_inline void
  709. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  710. const int16_t *ubuf[2], const int16_t *vbuf[2],
  711. const int16_t *abuf[2], uint8_t *dest, int dstW,
  712. int yalpha, int uvalpha, int y,
  713. enum AVPixelFormat target)
  714. {
  715. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  716. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  717. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  718. int yalpha1 = 4096 - yalpha;
  719. int uvalpha1 = 4096 - uvalpha;
  720. int i;
  721. av_assert2(yalpha <= 4096U);
  722. av_assert2(uvalpha <= 4096U);
  723. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  724. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  725. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  726. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  727. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  728. if ((Y1 | Y2 | U | V) & 0x100) {
  729. Y1 = av_clip_uint8(Y1);
  730. Y2 = av_clip_uint8(Y2);
  731. U = av_clip_uint8(U);
  732. V = av_clip_uint8(V);
  733. }
  734. output_pixels(i * 4, Y1, U, Y2, V);
  735. }
  736. }
  737. static av_always_inline void
  738. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  739. const int16_t *ubuf[2], const int16_t *vbuf[2],
  740. const int16_t *abuf0, uint8_t *dest, int dstW,
  741. int uvalpha, int y, enum AVPixelFormat target)
  742. {
  743. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  744. int i;
  745. if (uvalpha < 2048) {
  746. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  747. int Y1 = (buf0[i * 2 ]+64) >> 7;
  748. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  749. int U = (ubuf0[i] +64) >> 7;
  750. int V = (vbuf0[i] +64) >> 7;
  751. if ((Y1 | Y2 | U | V) & 0x100) {
  752. Y1 = av_clip_uint8(Y1);
  753. Y2 = av_clip_uint8(Y2);
  754. U = av_clip_uint8(U);
  755. V = av_clip_uint8(V);
  756. }
  757. Y1 = av_clip_uint8(Y1);
  758. Y2 = av_clip_uint8(Y2);
  759. U = av_clip_uint8(U);
  760. V = av_clip_uint8(V);
  761. output_pixels(i * 4, Y1, U, Y2, V);
  762. }
  763. } else {
  764. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  765. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  766. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  767. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  768. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  769. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  770. if ((Y1 | Y2 | U | V) & 0x100) {
  771. Y1 = av_clip_uint8(Y1);
  772. Y2 = av_clip_uint8(Y2);
  773. U = av_clip_uint8(U);
  774. V = av_clip_uint8(V);
  775. }
  776. Y1 = av_clip_uint8(Y1);
  777. Y2 = av_clip_uint8(Y2);
  778. U = av_clip_uint8(U);
  779. V = av_clip_uint8(V);
  780. output_pixels(i * 4, Y1, U, Y2, V);
  781. }
  782. }
  783. }
  784. #undef output_pixels
  785. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  786. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  787. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  788. #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
  789. #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
  790. #define output_pixel(pos, val) \
  791. if (isBE(target)) { \
  792. AV_WB16(pos, val); \
  793. } else { \
  794. AV_WL16(pos, val); \
  795. }
  796. static av_always_inline void
  797. yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
  798. const int32_t **lumSrc, int lumFilterSize,
  799. const int16_t *chrFilter, const int32_t **chrUSrc,
  800. const int32_t **chrVSrc, int chrFilterSize,
  801. const int32_t **alpSrc, uint16_t *dest, int dstW,
  802. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  803. {
  804. int i;
  805. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  806. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  807. int j;
  808. int Y1 = -0x40000000;
  809. int Y2 = -0x40000000;
  810. int U = -(128 << 23); // 19
  811. int V = -(128 << 23);
  812. int R, G, B;
  813. for (j = 0; j < lumFilterSize; j++) {
  814. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  815. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  816. }
  817. for (j = 0; j < chrFilterSize; j++) {;
  818. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  819. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  820. }
  821. if (hasAlpha) {
  822. A1 = -0x40000000;
  823. A2 = -0x40000000;
  824. for (j = 0; j < lumFilterSize; j++) {
  825. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  826. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  827. }
  828. A1 >>= 1;
  829. A1 += 0x20002000;
  830. A2 >>= 1;
  831. A2 += 0x20002000;
  832. }
  833. // 8 bits: 12+15=27; 16 bits: 12+19=31
  834. Y1 >>= 14; // 10
  835. Y1 += 0x10000;
  836. Y2 >>= 14;
  837. Y2 += 0x10000;
  838. U >>= 14;
  839. V >>= 14;
  840. // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
  841. Y1 -= c->yuv2rgb_y_offset;
  842. Y2 -= c->yuv2rgb_y_offset;
  843. Y1 *= c->yuv2rgb_y_coeff;
  844. Y2 *= c->yuv2rgb_y_coeff;
  845. Y1 += 1 << 13; // 21
  846. Y2 += 1 << 13;
  847. // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
  848. R = V * c->yuv2rgb_v2r_coeff;
  849. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  850. B = U * c->yuv2rgb_u2b_coeff;
  851. // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
  852. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  853. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  854. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  855. if (eightbytes) {
  856. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  857. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  858. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  859. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  860. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  861. dest += 8;
  862. } else {
  863. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  864. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  865. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  866. dest += 6;
  867. }
  868. }
  869. }
  870. static av_always_inline void
  871. yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
  872. const int32_t *ubuf[2], const int32_t *vbuf[2],
  873. const int32_t *abuf[2], uint16_t *dest, int dstW,
  874. int yalpha, int uvalpha, int y,
  875. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  876. {
  877. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  878. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  879. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  880. *abuf0 = hasAlpha ? abuf[0] : NULL,
  881. *abuf1 = hasAlpha ? abuf[1] : NULL;
  882. int yalpha1 = 4096 - yalpha;
  883. int uvalpha1 = 4096 - uvalpha;
  884. int i;
  885. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  886. av_assert2(yalpha <= 4096U);
  887. av_assert2(uvalpha <= 4096U);
  888. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  889. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  890. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  891. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  892. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  893. int R, G, B;
  894. Y1 -= c->yuv2rgb_y_offset;
  895. Y2 -= c->yuv2rgb_y_offset;
  896. Y1 *= c->yuv2rgb_y_coeff;
  897. Y2 *= c->yuv2rgb_y_coeff;
  898. Y1 += 1 << 13;
  899. Y2 += 1 << 13;
  900. R = V * c->yuv2rgb_v2r_coeff;
  901. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  902. B = U * c->yuv2rgb_u2b_coeff;
  903. if (hasAlpha) {
  904. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  905. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  906. A1 += 1 << 13;
  907. A2 += 1 << 13;
  908. }
  909. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  910. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  911. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  912. if (eightbytes) {
  913. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  914. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  915. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  916. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  917. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  918. dest += 8;
  919. } else {
  920. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  921. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  922. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  923. dest += 6;
  924. }
  925. }
  926. }
  927. static av_always_inline void
  928. yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
  929. const int32_t *ubuf[2], const int32_t *vbuf[2],
  930. const int32_t *abuf0, uint16_t *dest, int dstW,
  931. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  932. {
  933. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  934. int i;
  935. int A1 = 0xffff<<14, A2= 0xffff<<14;
  936. if (uvalpha < 2048) {
  937. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  938. int Y1 = (buf0[i * 2] ) >> 2;
  939. int Y2 = (buf0[i * 2 + 1]) >> 2;
  940. int U = (ubuf0[i] - (128 << 11)) >> 2;
  941. int V = (vbuf0[i] - (128 << 11)) >> 2;
  942. int R, G, B;
  943. Y1 -= c->yuv2rgb_y_offset;
  944. Y2 -= c->yuv2rgb_y_offset;
  945. Y1 *= c->yuv2rgb_y_coeff;
  946. Y2 *= c->yuv2rgb_y_coeff;
  947. Y1 += 1 << 13;
  948. Y2 += 1 << 13;
  949. if (hasAlpha) {
  950. A1 = abuf0[i * 2 ] << 11;
  951. A2 = abuf0[i * 2 + 1] << 11;
  952. A1 += 1 << 13;
  953. A2 += 1 << 13;
  954. }
  955. R = V * c->yuv2rgb_v2r_coeff;
  956. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  957. B = U * c->yuv2rgb_u2b_coeff;
  958. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  959. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  960. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  961. if (eightbytes) {
  962. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  963. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  964. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  965. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  966. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  967. dest += 8;
  968. } else {
  969. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  970. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  971. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  972. dest += 6;
  973. }
  974. }
  975. } else {
  976. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  977. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  978. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  979. int Y1 = (buf0[i * 2] ) >> 2;
  980. int Y2 = (buf0[i * 2 + 1]) >> 2;
  981. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  982. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  983. int R, G, B;
  984. Y1 -= c->yuv2rgb_y_offset;
  985. Y2 -= c->yuv2rgb_y_offset;
  986. Y1 *= c->yuv2rgb_y_coeff;
  987. Y2 *= c->yuv2rgb_y_coeff;
  988. Y1 += 1 << 13;
  989. Y2 += 1 << 13;
  990. if (hasAlpha) {
  991. A1 = abuf0[i * 2 ] << 11;
  992. A2 = abuf0[i * 2 + 1] << 11;
  993. A1 += 1 << 13;
  994. A2 += 1 << 13;
  995. }
  996. R = V * c->yuv2rgb_v2r_coeff;
  997. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  998. B = U * c->yuv2rgb_u2b_coeff;
  999. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  1000. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  1001. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  1002. if (eightbytes) {
  1003. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1004. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  1005. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  1006. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  1007. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1008. dest += 8;
  1009. } else {
  1010. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  1011. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  1012. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  1013. dest += 6;
  1014. }
  1015. }
  1016. }
  1017. }
  1018. static av_always_inline void
  1019. yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1020. const int32_t **lumSrc, int lumFilterSize,
  1021. const int16_t *chrFilter, const int32_t **chrUSrc,
  1022. const int32_t **chrVSrc, int chrFilterSize,
  1023. const int32_t **alpSrc, uint16_t *dest, int dstW,
  1024. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1025. {
  1026. int i;
  1027. int A = 0xffff<<14;
  1028. for (i = 0; i < dstW; i++) {
  1029. int j;
  1030. int Y = -0x40000000;
  1031. int U = -(128 << 23); // 19
  1032. int V = -(128 << 23);
  1033. int R, G, B;
  1034. for (j = 0; j < lumFilterSize; j++) {
  1035. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1036. }
  1037. for (j = 0; j < chrFilterSize; j++) {;
  1038. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1039. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1040. }
  1041. if (hasAlpha) {
  1042. A = -0x40000000;
  1043. for (j = 0; j < lumFilterSize; j++) {
  1044. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1045. }
  1046. A >>= 1;
  1047. A += 0x20002000;
  1048. }
  1049. // 8bit: 12+15=27; 16-bit: 12+19=31
  1050. Y >>= 14; // 10
  1051. Y += 0x10000;
  1052. U >>= 14;
  1053. V >>= 14;
  1054. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  1055. Y -= c->yuv2rgb_y_offset;
  1056. Y *= c->yuv2rgb_y_coeff;
  1057. Y += 1 << 13; // 21
  1058. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  1059. R = V * c->yuv2rgb_v2r_coeff;
  1060. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1061. B = U * c->yuv2rgb_u2b_coeff;
  1062. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  1063. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1064. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1065. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1066. if (eightbytes) {
  1067. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1068. dest += 4;
  1069. } else {
  1070. dest += 3;
  1071. }
  1072. }
  1073. }
  1074. static av_always_inline void
  1075. yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
  1076. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1077. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1078. int yalpha, int uvalpha, int y,
  1079. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1080. {
  1081. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1082. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1083. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1084. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1085. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1086. int yalpha1 = 4096 - yalpha;
  1087. int uvalpha1 = 4096 - uvalpha;
  1088. int i;
  1089. int A = 0xffff<<14;
  1090. av_assert2(yalpha <= 4096U);
  1091. av_assert2(uvalpha <= 4096U);
  1092. for (i = 0; i < dstW; i++) {
  1093. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  1094. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1095. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1096. int R, G, B;
  1097. Y -= c->yuv2rgb_y_offset;
  1098. Y *= c->yuv2rgb_y_coeff;
  1099. Y += 1 << 13;
  1100. R = V * c->yuv2rgb_v2r_coeff;
  1101. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1102. B = U * c->yuv2rgb_u2b_coeff;
  1103. if (hasAlpha) {
  1104. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  1105. A += 1 << 13;
  1106. }
  1107. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1108. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1109. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1110. if (eightbytes) {
  1111. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1112. dest += 4;
  1113. } else {
  1114. dest += 3;
  1115. }
  1116. }
  1117. }
  1118. static av_always_inline void
  1119. yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
  1120. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1121. const int32_t *abuf0, uint16_t *dest, int dstW,
  1122. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1123. {
  1124. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1125. int i;
  1126. int A = 0xffff<<14;
  1127. if (uvalpha < 2048) {
  1128. for (i = 0; i < dstW; i++) {
  1129. int Y = (buf0[i]) >> 2;
  1130. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1131. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1132. int R, G, B;
  1133. Y -= c->yuv2rgb_y_offset;
  1134. Y *= c->yuv2rgb_y_coeff;
  1135. Y += 1 << 13;
  1136. if (hasAlpha) {
  1137. A = abuf0[i] << 11;
  1138. A += 1 << 13;
  1139. }
  1140. R = V * c->yuv2rgb_v2r_coeff;
  1141. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1142. B = U * c->yuv2rgb_u2b_coeff;
  1143. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1144. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1145. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1146. if (eightbytes) {
  1147. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1148. dest += 4;
  1149. } else {
  1150. dest += 3;
  1151. }
  1152. }
  1153. } else {
  1154. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1155. int A = 0xffff<<14;
  1156. for (i = 0; i < dstW; i++) {
  1157. int Y = (buf0[i] ) >> 2;
  1158. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1159. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1160. int R, G, B;
  1161. Y -= c->yuv2rgb_y_offset;
  1162. Y *= c->yuv2rgb_y_coeff;
  1163. Y += 1 << 13;
  1164. if (hasAlpha) {
  1165. A = abuf0[i] << 11;
  1166. A += 1 << 13;
  1167. }
  1168. R = V * c->yuv2rgb_v2r_coeff;
  1169. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1170. B = U * c->yuv2rgb_u2b_coeff;
  1171. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1172. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1173. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1174. if (eightbytes) {
  1175. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1176. dest += 4;
  1177. } else {
  1178. dest += 3;
  1179. }
  1180. }
  1181. }
  1182. }
  1183. #undef output_pixel
  1184. #undef r_b
  1185. #undef b_r
  1186. #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
  1187. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1188. const int16_t **_lumSrc, int lumFilterSize, \
  1189. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  1190. const int16_t **_chrVSrc, int chrFilterSize, \
  1191. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  1192. int y) \
  1193. { \
  1194. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1195. **chrUSrc = (const int32_t **) _chrUSrc, \
  1196. **chrVSrc = (const int32_t **) _chrVSrc, \
  1197. **alpSrc = (const int32_t **) _alpSrc; \
  1198. uint16_t *dest = (uint16_t *) _dest; \
  1199. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1200. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1201. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
  1202. } \
  1203. \
  1204. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  1205. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1206. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1207. int yalpha, int uvalpha, int y) \
  1208. { \
  1209. const int32_t **buf = (const int32_t **) _buf, \
  1210. **ubuf = (const int32_t **) _ubuf, \
  1211. **vbuf = (const int32_t **) _vbuf, \
  1212. **abuf = (const int32_t **) _abuf; \
  1213. uint16_t *dest = (uint16_t *) _dest; \
  1214. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1215. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1216. } \
  1217. \
  1218. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  1219. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1220. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1221. int uvalpha, int y) \
  1222. { \
  1223. const int32_t *buf0 = (const int32_t *) _buf0, \
  1224. **ubuf = (const int32_t **) _ubuf, \
  1225. **vbuf = (const int32_t **) _vbuf, \
  1226. *abuf0 = (const int32_t *) _abuf0; \
  1227. uint16_t *dest = (uint16_t *) _dest; \
  1228. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1229. dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1230. }
  1231. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
  1232. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
  1233. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
  1234. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
  1235. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
  1236. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
  1237. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
  1238. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
  1239. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
  1240. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
  1241. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
  1242. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
  1243. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
  1244. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
  1245. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
  1246. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
  1247. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
  1248. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
  1249. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
  1250. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
  1251. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
  1252. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
  1253. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
  1254. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
  1255. /*
  1256. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1257. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1258. * things like endianness conversion and shifting. The caller takes care of
  1259. * setting the correct offset in these tables from the chroma (U/V) values.
  1260. * This function then uses the luminance (Y1/Y2) values to write out the
  1261. * correct RGB values into the destination buffer.
  1262. */
  1263. static av_always_inline void
  1264. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1265. unsigned A1, unsigned A2,
  1266. const void *_r, const void *_g, const void *_b, int y,
  1267. enum AVPixelFormat target, int hasAlpha)
  1268. {
  1269. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1270. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1271. uint32_t *dest = (uint32_t *) _dest;
  1272. const uint32_t *r = (const uint32_t *) _r;
  1273. const uint32_t *g = (const uint32_t *) _g;
  1274. const uint32_t *b = (const uint32_t *) _b;
  1275. #if CONFIG_SMALL
  1276. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1277. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1278. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1279. #else
  1280. if (hasAlpha) {
  1281. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1282. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1283. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1284. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1285. } else {
  1286. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1287. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1288. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1289. #endif
  1290. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1291. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1292. }
  1293. #endif
  1294. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1295. uint8_t *dest = (uint8_t *) _dest;
  1296. const uint8_t *r = (const uint8_t *) _r;
  1297. const uint8_t *g = (const uint8_t *) _g;
  1298. const uint8_t *b = (const uint8_t *) _b;
  1299. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1300. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1301. dest[i * 6 + 0] = r_b[Y1];
  1302. dest[i * 6 + 1] = g[Y1];
  1303. dest[i * 6 + 2] = b_r[Y1];
  1304. dest[i * 6 + 3] = r_b[Y2];
  1305. dest[i * 6 + 4] = g[Y2];
  1306. dest[i * 6 + 5] = b_r[Y2];
  1307. #undef r_b
  1308. #undef b_r
  1309. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1310. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1311. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1312. uint16_t *dest = (uint16_t *) _dest;
  1313. const uint16_t *r = (const uint16_t *) _r;
  1314. const uint16_t *g = (const uint16_t *) _g;
  1315. const uint16_t *b = (const uint16_t *) _b;
  1316. int dr1, dg1, db1, dr2, dg2, db2;
  1317. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1318. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1319. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1320. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1321. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1322. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1323. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1324. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1325. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1326. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1327. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1328. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1329. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1330. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1331. } else {
  1332. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1333. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1334. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1335. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1336. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1337. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1338. }
  1339. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1340. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1341. } else /* 8/4 bits */ {
  1342. uint8_t *dest = (uint8_t *) _dest;
  1343. const uint8_t *r = (const uint8_t *) _r;
  1344. const uint8_t *g = (const uint8_t *) _g;
  1345. const uint8_t *b = (const uint8_t *) _b;
  1346. int dr1, dg1, db1, dr2, dg2, db2;
  1347. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1348. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1349. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1350. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1351. db1 = d64[(i * 2 + 0) & 7];
  1352. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1353. db2 = d64[(i * 2 + 1) & 7];
  1354. } else {
  1355. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1356. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1357. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1358. dg1 = d64[(i * 2 + 0) & 7];
  1359. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1360. dg2 = d64[(i * 2 + 1) & 7];
  1361. }
  1362. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1363. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1364. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1365. } else {
  1366. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1367. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1368. }
  1369. }
  1370. }
  1371. static av_always_inline void
  1372. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1373. const int16_t **lumSrc, int lumFilterSize,
  1374. const int16_t *chrFilter, const int16_t **chrUSrc,
  1375. const int16_t **chrVSrc, int chrFilterSize,
  1376. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1377. int y, enum AVPixelFormat target, int hasAlpha)
  1378. {
  1379. int i;
  1380. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1381. int j, A1, A2;
  1382. int Y1 = 1 << 18;
  1383. int Y2 = 1 << 18;
  1384. int U = 1 << 18;
  1385. int V = 1 << 18;
  1386. const void *r, *g, *b;
  1387. for (j = 0; j < lumFilterSize; j++) {
  1388. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1389. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1390. }
  1391. for (j = 0; j < chrFilterSize; j++) {
  1392. U += chrUSrc[j][i] * chrFilter[j];
  1393. V += chrVSrc[j][i] * chrFilter[j];
  1394. }
  1395. Y1 >>= 19;
  1396. Y2 >>= 19;
  1397. U >>= 19;
  1398. V >>= 19;
  1399. if (hasAlpha) {
  1400. A1 = 1 << 18;
  1401. A2 = 1 << 18;
  1402. for (j = 0; j < lumFilterSize; j++) {
  1403. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1404. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1405. }
  1406. A1 >>= 19;
  1407. A2 >>= 19;
  1408. if ((A1 | A2) & 0x100) {
  1409. A1 = av_clip_uint8(A1);
  1410. A2 = av_clip_uint8(A2);
  1411. }
  1412. }
  1413. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1414. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1415. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1416. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1417. r, g, b, y, target, hasAlpha);
  1418. }
  1419. }
  1420. static av_always_inline void
  1421. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  1422. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1423. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1424. int yalpha, int uvalpha, int y,
  1425. enum AVPixelFormat target, int hasAlpha)
  1426. {
  1427. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1428. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1429. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1430. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1431. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1432. int yalpha1 = 4096 - yalpha;
  1433. int uvalpha1 = 4096 - uvalpha;
  1434. int i;
  1435. av_assert2(yalpha <= 4096U);
  1436. av_assert2(uvalpha <= 4096U);
  1437. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1438. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1439. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1440. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1441. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1442. int A1, A2;
  1443. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1444. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1445. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1446. if (hasAlpha) {
  1447. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1448. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1449. A1 = av_clip_uint8(A1);
  1450. A2 = av_clip_uint8(A2);
  1451. }
  1452. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1453. r, g, b, y, target, hasAlpha);
  1454. }
  1455. }
  1456. static av_always_inline void
  1457. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  1458. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1459. const int16_t *abuf0, uint8_t *dest, int dstW,
  1460. int uvalpha, int y, enum AVPixelFormat target,
  1461. int hasAlpha)
  1462. {
  1463. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1464. int i;
  1465. if (uvalpha < 2048) {
  1466. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1467. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1468. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1469. int U = (ubuf0[i] + 64) >> 7;
  1470. int V = (vbuf0[i] + 64) >> 7;
  1471. int A1, A2;
  1472. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1473. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1474. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1475. if (hasAlpha) {
  1476. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1477. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1478. A1 = av_clip_uint8(A1);
  1479. A2 = av_clip_uint8(A2);
  1480. }
  1481. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1482. r, g, b, y, target, hasAlpha);
  1483. }
  1484. } else {
  1485. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1486. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1487. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1488. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1489. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1490. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1491. int A1, A2;
  1492. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1493. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1494. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1495. if (hasAlpha) {
  1496. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1497. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1498. A1 = av_clip_uint8(A1);
  1499. A2 = av_clip_uint8(A2);
  1500. }
  1501. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1502. r, g, b, y, target, hasAlpha);
  1503. }
  1504. }
  1505. }
  1506. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1507. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1508. const int16_t **lumSrc, int lumFilterSize, \
  1509. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1510. const int16_t **chrVSrc, int chrFilterSize, \
  1511. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1512. int y) \
  1513. { \
  1514. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1515. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1516. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1517. }
  1518. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1519. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1520. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1521. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1522. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1523. int yalpha, int uvalpha, int y) \
  1524. { \
  1525. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1526. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1527. }
  1528. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1529. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1530. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1531. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1532. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1533. int uvalpha, int y) \
  1534. { \
  1535. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1536. dstW, uvalpha, y, fmt, hasAlpha); \
  1537. }
  1538. #if CONFIG_SMALL
  1539. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1540. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1541. #else
  1542. #if CONFIG_SWSCALE_ALPHA
  1543. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1544. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1545. #endif
  1546. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1547. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1548. #endif
  1549. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1550. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1551. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1552. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1553. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1554. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1555. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1556. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1557. static av_always_inline void yuv2rgb_write_full(SwsContext *c,
  1558. uint8_t *dest, int i, int Y, int A, int U, int V,
  1559. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1560. {
  1561. int R, G, B;
  1562. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1563. Y -= c->yuv2rgb_y_offset;
  1564. Y *= c->yuv2rgb_y_coeff;
  1565. Y += 1 << 21;
  1566. R = Y + V*c->yuv2rgb_v2r_coeff;
  1567. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1568. B = Y + U*c->yuv2rgb_u2b_coeff;
  1569. if ((R | G | B) & 0xC0000000) {
  1570. R = av_clip_uintp2(R, 30);
  1571. G = av_clip_uintp2(G, 30);
  1572. B = av_clip_uintp2(B, 30);
  1573. }
  1574. switch(target) {
  1575. case AV_PIX_FMT_ARGB:
  1576. dest[0] = hasAlpha ? A : 255;
  1577. dest[1] = R >> 22;
  1578. dest[2] = G >> 22;
  1579. dest[3] = B >> 22;
  1580. break;
  1581. case AV_PIX_FMT_RGB24:
  1582. dest[0] = R >> 22;
  1583. dest[1] = G >> 22;
  1584. dest[2] = B >> 22;
  1585. break;
  1586. case AV_PIX_FMT_RGBA:
  1587. dest[0] = R >> 22;
  1588. dest[1] = G >> 22;
  1589. dest[2] = B >> 22;
  1590. dest[3] = hasAlpha ? A : 255;
  1591. break;
  1592. case AV_PIX_FMT_ABGR:
  1593. dest[0] = hasAlpha ? A : 255;
  1594. dest[1] = B >> 22;
  1595. dest[2] = G >> 22;
  1596. dest[3] = R >> 22;
  1597. break;
  1598. case AV_PIX_FMT_BGR24:
  1599. dest[0] = B >> 22;
  1600. dest[1] = G >> 22;
  1601. dest[2] = R >> 22;
  1602. break;
  1603. case AV_PIX_FMT_BGRA:
  1604. dest[0] = B >> 22;
  1605. dest[1] = G >> 22;
  1606. dest[2] = R >> 22;
  1607. dest[3] = hasAlpha ? A : 255;
  1608. break;
  1609. case AV_PIX_FMT_BGR4_BYTE:
  1610. case AV_PIX_FMT_RGB4_BYTE:
  1611. case AV_PIX_FMT_BGR8:
  1612. case AV_PIX_FMT_RGB8:
  1613. {
  1614. int r,g,b;
  1615. switch (c->dither) {
  1616. default:
  1617. case SWS_DITHER_AUTO:
  1618. case SWS_DITHER_ED:
  1619. R >>= 22;
  1620. G >>= 22;
  1621. B >>= 22;
  1622. R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
  1623. G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
  1624. B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
  1625. c->dither_error[0][i] = err[0];
  1626. c->dither_error[1][i] = err[1];
  1627. c->dither_error[2][i] = err[2];
  1628. r = R >> (isrgb8 ? 5 : 7);
  1629. g = G >> (isrgb8 ? 5 : 6);
  1630. b = B >> (isrgb8 ? 6 : 7);
  1631. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1632. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1633. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1634. err[0] = R - r*(isrgb8 ? 36 : 255);
  1635. err[1] = G - g*(isrgb8 ? 36 : 85);
  1636. err[2] = B - b*(isrgb8 ? 85 : 255);
  1637. break;
  1638. case SWS_DITHER_A_DITHER:
  1639. if (isrgb8) {
  1640. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1641. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1642. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1643. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1644. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1645. r = av_clip_uintp2(r, 3);
  1646. g = av_clip_uintp2(g, 3);
  1647. b = av_clip_uintp2(b, 2);
  1648. } else {
  1649. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1650. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1651. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1652. r = av_clip_uintp2(r, 1);
  1653. g = av_clip_uintp2(g, 2);
  1654. b = av_clip_uintp2(b, 1);
  1655. }
  1656. break;
  1657. case SWS_DITHER_X_DITHER:
  1658. if (isrgb8) {
  1659. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1660. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1661. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1662. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1663. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1664. r = av_clip_uintp2(r, 3);
  1665. g = av_clip_uintp2(g, 3);
  1666. b = av_clip_uintp2(b, 2);
  1667. } else {
  1668. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1669. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1670. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1671. r = av_clip_uintp2(r, 1);
  1672. g = av_clip_uintp2(g, 2);
  1673. b = av_clip_uintp2(b, 1);
  1674. }
  1675. break;
  1676. }
  1677. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1678. dest[0] = r + 2*g + 8*b;
  1679. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1680. dest[0] = b + 2*g + 8*r;
  1681. } else if(target == AV_PIX_FMT_BGR8) {
  1682. dest[0] = r + 8*g + 64*b;
  1683. } else if(target == AV_PIX_FMT_RGB8) {
  1684. dest[0] = b + 4*g + 32*r;
  1685. } else
  1686. av_assert2(0);
  1687. break;}
  1688. }
  1689. }
  1690. static av_always_inline void
  1691. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1692. const int16_t **lumSrc, int lumFilterSize,
  1693. const int16_t *chrFilter, const int16_t **chrUSrc,
  1694. const int16_t **chrVSrc, int chrFilterSize,
  1695. const int16_t **alpSrc, uint8_t *dest,
  1696. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1697. {
  1698. int i;
  1699. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1700. int err[4] = {0};
  1701. int A = 0; //init to silence warning
  1702. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1703. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1704. step = 1;
  1705. for (i = 0; i < dstW; i++) {
  1706. int j;
  1707. int Y = 1<<9;
  1708. int U = (1<<9)-(128 << 19);
  1709. int V = (1<<9)-(128 << 19);
  1710. for (j = 0; j < lumFilterSize; j++) {
  1711. Y += lumSrc[j][i] * lumFilter[j];
  1712. }
  1713. for (j = 0; j < chrFilterSize; j++) {
  1714. U += chrUSrc[j][i] * chrFilter[j];
  1715. V += chrVSrc[j][i] * chrFilter[j];
  1716. }
  1717. Y >>= 10;
  1718. U >>= 10;
  1719. V >>= 10;
  1720. if (hasAlpha) {
  1721. A = 1 << 18;
  1722. for (j = 0; j < lumFilterSize; j++) {
  1723. A += alpSrc[j][i] * lumFilter[j];
  1724. }
  1725. A >>= 19;
  1726. if (A & 0x100)
  1727. A = av_clip_uint8(A);
  1728. }
  1729. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1730. dest += step;
  1731. }
  1732. c->dither_error[0][i] = err[0];
  1733. c->dither_error[1][i] = err[1];
  1734. c->dither_error[2][i] = err[2];
  1735. }
  1736. static av_always_inline void
  1737. yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
  1738. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1739. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1740. int yalpha, int uvalpha, int y,
  1741. enum AVPixelFormat target, int hasAlpha)
  1742. {
  1743. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1744. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1745. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1746. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1747. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1748. int yalpha1 = 4096 - yalpha;
  1749. int uvalpha1 = 4096 - uvalpha;
  1750. int i;
  1751. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1752. int err[4] = {0};
  1753. int A = 0; // init to silcene warning
  1754. av_assert2(yalpha <= 4096U);
  1755. av_assert2(uvalpha <= 4096U);
  1756. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1757. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1758. step = 1;
  1759. for (i = 0; i < dstW; i++) {
  1760. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1761. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1762. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1763. if (hasAlpha) {
  1764. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1765. if (A & 0x100)
  1766. A = av_clip_uint8(A);
  1767. }
  1768. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1769. dest += step;
  1770. }
  1771. c->dither_error[0][i] = err[0];
  1772. c->dither_error[1][i] = err[1];
  1773. c->dither_error[2][i] = err[2];
  1774. }
  1775. static av_always_inline void
  1776. yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
  1777. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1778. const int16_t *abuf0, uint8_t *dest, int dstW,
  1779. int uvalpha, int y, enum AVPixelFormat target,
  1780. int hasAlpha)
  1781. {
  1782. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1783. int i;
  1784. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1785. int err[4] = {0};
  1786. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1787. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1788. step = 1;
  1789. if (uvalpha < 2048) {
  1790. int A = 0; //init to silence warning
  1791. for (i = 0; i < dstW; i++) {
  1792. int Y = buf0[i] << 2;
  1793. int U = (ubuf0[i] - (128<<7)) * 4;
  1794. int V = (vbuf0[i] - (128<<7)) * 4;
  1795. if (hasAlpha) {
  1796. A = (abuf0[i] + 64) >> 7;
  1797. if (A & 0x100)
  1798. A = av_clip_uint8(A);
  1799. }
  1800. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1801. dest += step;
  1802. }
  1803. } else {
  1804. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1805. int A = 0; //init to silence warning
  1806. for (i = 0; i < dstW; i++) {
  1807. int Y = buf0[i] << 2;
  1808. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
  1809. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
  1810. if (hasAlpha) {
  1811. A = (abuf0[i] + 64) >> 7;
  1812. if (A & 0x100)
  1813. A = av_clip_uint8(A);
  1814. }
  1815. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1816. dest += step;
  1817. }
  1818. }
  1819. c->dither_error[0][i] = err[0];
  1820. c->dither_error[1][i] = err[1];
  1821. c->dither_error[2][i] = err[2];
  1822. }
  1823. #if CONFIG_SMALL
  1824. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1825. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1826. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1827. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1828. #else
  1829. #if CONFIG_SWSCALE_ALPHA
  1830. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1831. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1832. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1833. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1834. #endif
  1835. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1836. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1837. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1838. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1839. #endif
  1840. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1841. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1842. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  1843. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  1844. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  1845. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  1846. static void
  1847. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1848. const int16_t **lumSrc, int lumFilterSize,
  1849. const int16_t *chrFilter, const int16_t **chrUSrc,
  1850. const int16_t **chrVSrc, int chrFilterSize,
  1851. const int16_t **alpSrc, uint8_t **dest,
  1852. int dstW, int y)
  1853. {
  1854. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1855. int i;
  1856. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  1857. uint16_t **dest16 = (uint16_t**)dest;
  1858. int SH = 22 + 8 - desc->comp[0].depth;
  1859. int A = 0; // init to silence warning
  1860. for (i = 0; i < dstW; i++) {
  1861. int j;
  1862. int Y = 1 << 9;
  1863. int U = (1 << 9) - (128 << 19);
  1864. int V = (1 << 9) - (128 << 19);
  1865. int R, G, B;
  1866. for (j = 0; j < lumFilterSize; j++)
  1867. Y += lumSrc[j][i] * lumFilter[j];
  1868. for (j = 0; j < chrFilterSize; j++) {
  1869. U += chrUSrc[j][i] * chrFilter[j];
  1870. V += chrVSrc[j][i] * chrFilter[j];
  1871. }
  1872. Y >>= 10;
  1873. U >>= 10;
  1874. V >>= 10;
  1875. if (hasAlpha) {
  1876. A = 1 << 18;
  1877. for (j = 0; j < lumFilterSize; j++)
  1878. A += alpSrc[j][i] * lumFilter[j];
  1879. if (A & 0xF8000000)
  1880. A = av_clip_uintp2(A, 27);
  1881. }
  1882. Y -= c->yuv2rgb_y_offset;
  1883. Y *= c->yuv2rgb_y_coeff;
  1884. Y += 1 << (SH-1);
  1885. R = Y + V * c->yuv2rgb_v2r_coeff;
  1886. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1887. B = Y + U * c->yuv2rgb_u2b_coeff;
  1888. if ((R | G | B) & 0xC0000000) {
  1889. R = av_clip_uintp2(R, 30);
  1890. G = av_clip_uintp2(G, 30);
  1891. B = av_clip_uintp2(B, 30);
  1892. }
  1893. if (SH != 22) {
  1894. dest16[0][i] = G >> SH;
  1895. dest16[1][i] = B >> SH;
  1896. dest16[2][i] = R >> SH;
  1897. if (hasAlpha)
  1898. dest16[3][i] = A >> (SH - 3);
  1899. } else {
  1900. dest[0][i] = G >> 22;
  1901. dest[1][i] = B >> 22;
  1902. dest[2][i] = R >> 22;
  1903. if (hasAlpha)
  1904. dest[3][i] = A >> 19;
  1905. }
  1906. }
  1907. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1908. for (i = 0; i < dstW; i++) {
  1909. dest16[0][i] = av_bswap16(dest16[0][i]);
  1910. dest16[1][i] = av_bswap16(dest16[1][i]);
  1911. dest16[2][i] = av_bswap16(dest16[2][i]);
  1912. if (hasAlpha)
  1913. dest16[3][i] = av_bswap16(dest16[3][i]);
  1914. }
  1915. }
  1916. }
  1917. static void
  1918. yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1919. const int16_t **lumSrcx, int lumFilterSize,
  1920. const int16_t *chrFilter, const int16_t **chrUSrcx,
  1921. const int16_t **chrVSrcx, int chrFilterSize,
  1922. const int16_t **alpSrcx, uint8_t **dest,
  1923. int dstW, int y)
  1924. {
  1925. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1926. int i;
  1927. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  1928. uint16_t **dest16 = (uint16_t**)dest;
  1929. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  1930. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  1931. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  1932. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  1933. for (i = 0; i < dstW; i++) {
  1934. int j;
  1935. int Y = -0x40000000;
  1936. int U = -(128 << 23);
  1937. int V = -(128 << 23);
  1938. int R, G, B, A;
  1939. for (j = 0; j < lumFilterSize; j++)
  1940. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1941. for (j = 0; j < chrFilterSize; j++) {
  1942. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1943. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1944. }
  1945. Y >>= 14;
  1946. Y += 0x10000;
  1947. U >>= 14;
  1948. V >>= 14;
  1949. if (hasAlpha) {
  1950. A = -0x40000000;
  1951. for (j = 0; j < lumFilterSize; j++)
  1952. A += alpSrc[j][i] * lumFilter[j];
  1953. A >>= 1;
  1954. A += 0x20002000;
  1955. }
  1956. Y -= c->yuv2rgb_y_offset;
  1957. Y *= c->yuv2rgb_y_coeff;
  1958. Y += 1 << 13;
  1959. R = V * c->yuv2rgb_v2r_coeff;
  1960. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1961. B = U * c->yuv2rgb_u2b_coeff;
  1962. R = av_clip_uintp2(Y + R, 30);
  1963. G = av_clip_uintp2(Y + G, 30);
  1964. B = av_clip_uintp2(Y + B, 30);
  1965. dest16[0][i] = G >> 14;
  1966. dest16[1][i] = B >> 14;
  1967. dest16[2][i] = R >> 14;
  1968. if (hasAlpha)
  1969. dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
  1970. }
  1971. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1972. for (i = 0; i < dstW; i++) {
  1973. dest16[0][i] = av_bswap16(dest16[0][i]);
  1974. dest16[1][i] = av_bswap16(dest16[1][i]);
  1975. dest16[2][i] = av_bswap16(dest16[2][i]);
  1976. if (hasAlpha)
  1977. dest16[3][i] = av_bswap16(dest16[3][i]);
  1978. }
  1979. }
  1980. }
  1981. static void
  1982. yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
  1983. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1984. const int16_t *abuf0, uint8_t *dest, int dstW,
  1985. int uvalpha, int y)
  1986. {
  1987. int hasAlpha = !!abuf0;
  1988. int i;
  1989. for (i = 0; i < dstW; i++) {
  1990. int Y = (buf0[i] + 64) >> 7;
  1991. int A;
  1992. Y = av_clip_uint8(Y);
  1993. if (hasAlpha) {
  1994. A = (abuf0[i] + 64) >> 7;
  1995. if (A & 0x100)
  1996. A = av_clip_uint8(A);
  1997. }
  1998. dest[i * 2 ] = Y;
  1999. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2000. }
  2001. }
  2002. static void
  2003. yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
  2004. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2005. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2006. int yalpha, int uvalpha, int y)
  2007. {
  2008. int hasAlpha = abuf && abuf[0] && abuf[1];
  2009. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2010. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2011. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2012. int yalpha1 = 4096 - yalpha;
  2013. int i;
  2014. av_assert2(yalpha <= 4096U);
  2015. for (i = 0; i < dstW; i++) {
  2016. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2017. int A;
  2018. Y = av_clip_uint8(Y);
  2019. if (hasAlpha) {
  2020. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2021. A = av_clip_uint8(A);
  2022. }
  2023. dest[i * 2 ] = Y;
  2024. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2025. }
  2026. }
  2027. static void
  2028. yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
  2029. const int16_t **lumSrc, int lumFilterSize,
  2030. const int16_t *chrFilter, const int16_t **chrUSrc,
  2031. const int16_t **chrVSrc, int chrFilterSize,
  2032. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2033. {
  2034. int hasAlpha = !!alpSrc;
  2035. int i;
  2036. for (i = 0; i < dstW; i++) {
  2037. int j;
  2038. int Y = 1 << 18, A = 1 << 18;
  2039. for (j = 0; j < lumFilterSize; j++)
  2040. Y += lumSrc[j][i] * lumFilter[j];
  2041. Y >>= 19;
  2042. if (Y & 0x100)
  2043. Y = av_clip_uint8(Y);
  2044. if (hasAlpha) {
  2045. for (j = 0; j < lumFilterSize; j++)
  2046. A += alpSrc[j][i] * lumFilter[j];
  2047. A >>= 19;
  2048. if (A & 0x100)
  2049. A = av_clip_uint8(A);
  2050. }
  2051. dest[2 * i ] = Y;
  2052. dest[2 * i + 1] = hasAlpha ? A : 255;
  2053. }
  2054. }
  2055. static void
  2056. yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
  2057. const int16_t **_lumSrc, int lumFilterSize,
  2058. const int16_t *chrFilter, const int16_t **_chrUSrc,
  2059. const int16_t **_chrVSrc, int chrFilterSize,
  2060. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
  2061. {
  2062. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  2063. **chrUSrc = (const int32_t **) _chrUSrc,
  2064. **chrVSrc = (const int32_t **) _chrVSrc,
  2065. **alpSrc = (const int32_t **) _alpSrc;
  2066. int hasAlpha = !!alpSrc;
  2067. int i;
  2068. for (i = 0; i < dstW; i++) {
  2069. int Y = 1 << 14, U = 1 << 14;
  2070. int V = 1 << 14, A = 1 << 14;
  2071. int j;
  2072. Y -= 0x40000000;
  2073. U -= 0x40000000;
  2074. V -= 0x40000000;
  2075. A -= 0x40000000;
  2076. for (j = 0; j < lumFilterSize; j++)
  2077. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2078. for (j = 0; j < chrFilterSize; j++)
  2079. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2080. for (j = 0; j < chrFilterSize; j++)
  2081. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2082. if (hasAlpha)
  2083. for (j = 0; j < lumFilterSize; j++)
  2084. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2085. Y = 0x8000 + av_clip_int16(Y >> 15);
  2086. U = 0x8000 + av_clip_int16(U >> 15);
  2087. V = 0x8000 + av_clip_int16(V >> 15);
  2088. A = 0x8000 + av_clip_int16(A >> 15);
  2089. AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
  2090. AV_WL16(dest + 8 * i + 2, Y);
  2091. AV_WL16(dest + 8 * i + 4, U);
  2092. AV_WL16(dest + 8 * i + 6, V);
  2093. }
  2094. }
  2095. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  2096. yuv2planar1_fn *yuv2plane1,
  2097. yuv2planarX_fn *yuv2planeX,
  2098. yuv2interleavedX_fn *yuv2nv12cX,
  2099. yuv2packed1_fn *yuv2packed1,
  2100. yuv2packed2_fn *yuv2packed2,
  2101. yuv2packedX_fn *yuv2packedX,
  2102. yuv2anyX_fn *yuv2anyX)
  2103. {
  2104. enum AVPixelFormat dstFormat = c->dstFormat;
  2105. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  2106. if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
  2107. *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
  2108. *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
  2109. *yuv2nv12cX = yuv2p010cX_c;
  2110. } else if (is16BPS(dstFormat)) {
  2111. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  2112. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  2113. if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) {
  2114. *yuv2nv12cX = yuv2p016cX_c;
  2115. }
  2116. } else if (isNBPS(dstFormat)) {
  2117. if (desc->comp[0].depth == 9) {
  2118. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  2119. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  2120. } else if (desc->comp[0].depth == 10) {
  2121. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  2122. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  2123. } else if (desc->comp[0].depth == 12) {
  2124. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  2125. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  2126. } else if (desc->comp[0].depth == 14) {
  2127. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  2128. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  2129. } else
  2130. av_assert0(0);
  2131. } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
  2132. *yuv2planeX = yuv2planeX_floatBE_c;
  2133. *yuv2plane1 = yuv2plane1_floatBE_c;
  2134. } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
  2135. *yuv2planeX = yuv2planeX_floatLE_c;
  2136. *yuv2plane1 = yuv2plane1_floatLE_c;
  2137. } else {
  2138. *yuv2plane1 = yuv2plane1_8_c;
  2139. *yuv2planeX = yuv2planeX_8_c;
  2140. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  2141. *yuv2nv12cX = yuv2nv12cX_c;
  2142. }
  2143. if(c->flags & SWS_FULL_CHR_H_INT) {
  2144. switch (dstFormat) {
  2145. case AV_PIX_FMT_RGBA:
  2146. #if CONFIG_SMALL
  2147. *yuv2packedX = yuv2rgba32_full_X_c;
  2148. *yuv2packed2 = yuv2rgba32_full_2_c;
  2149. *yuv2packed1 = yuv2rgba32_full_1_c;
  2150. #else
  2151. #if CONFIG_SWSCALE_ALPHA
  2152. if (c->needAlpha) {
  2153. *yuv2packedX = yuv2rgba32_full_X_c;
  2154. *yuv2packed2 = yuv2rgba32_full_2_c;
  2155. *yuv2packed1 = yuv2rgba32_full_1_c;
  2156. } else
  2157. #endif /* CONFIG_SWSCALE_ALPHA */
  2158. {
  2159. *yuv2packedX = yuv2rgbx32_full_X_c;
  2160. *yuv2packed2 = yuv2rgbx32_full_2_c;
  2161. *yuv2packed1 = yuv2rgbx32_full_1_c;
  2162. }
  2163. #endif /* !CONFIG_SMALL */
  2164. break;
  2165. case AV_PIX_FMT_ARGB:
  2166. #if CONFIG_SMALL
  2167. *yuv2packedX = yuv2argb32_full_X_c;
  2168. *yuv2packed2 = yuv2argb32_full_2_c;
  2169. *yuv2packed1 = yuv2argb32_full_1_c;
  2170. #else
  2171. #if CONFIG_SWSCALE_ALPHA
  2172. if (c->needAlpha) {
  2173. *yuv2packedX = yuv2argb32_full_X_c;
  2174. *yuv2packed2 = yuv2argb32_full_2_c;
  2175. *yuv2packed1 = yuv2argb32_full_1_c;
  2176. } else
  2177. #endif /* CONFIG_SWSCALE_ALPHA */
  2178. {
  2179. *yuv2packedX = yuv2xrgb32_full_X_c;
  2180. *yuv2packed2 = yuv2xrgb32_full_2_c;
  2181. *yuv2packed1 = yuv2xrgb32_full_1_c;
  2182. }
  2183. #endif /* !CONFIG_SMALL */
  2184. break;
  2185. case AV_PIX_FMT_BGRA:
  2186. #if CONFIG_SMALL
  2187. *yuv2packedX = yuv2bgra32_full_X_c;
  2188. *yuv2packed2 = yuv2bgra32_full_2_c;
  2189. *yuv2packed1 = yuv2bgra32_full_1_c;
  2190. #else
  2191. #if CONFIG_SWSCALE_ALPHA
  2192. if (c->needAlpha) {
  2193. *yuv2packedX = yuv2bgra32_full_X_c;
  2194. *yuv2packed2 = yuv2bgra32_full_2_c;
  2195. *yuv2packed1 = yuv2bgra32_full_1_c;
  2196. } else
  2197. #endif /* CONFIG_SWSCALE_ALPHA */
  2198. {
  2199. *yuv2packedX = yuv2bgrx32_full_X_c;
  2200. *yuv2packed2 = yuv2bgrx32_full_2_c;
  2201. *yuv2packed1 = yuv2bgrx32_full_1_c;
  2202. }
  2203. #endif /* !CONFIG_SMALL */
  2204. break;
  2205. case AV_PIX_FMT_ABGR:
  2206. #if CONFIG_SMALL
  2207. *yuv2packedX = yuv2abgr32_full_X_c;
  2208. *yuv2packed2 = yuv2abgr32_full_2_c;
  2209. *yuv2packed1 = yuv2abgr32_full_1_c;
  2210. #else
  2211. #if CONFIG_SWSCALE_ALPHA
  2212. if (c->needAlpha) {
  2213. *yuv2packedX = yuv2abgr32_full_X_c;
  2214. *yuv2packed2 = yuv2abgr32_full_2_c;
  2215. *yuv2packed1 = yuv2abgr32_full_1_c;
  2216. } else
  2217. #endif /* CONFIG_SWSCALE_ALPHA */
  2218. {
  2219. *yuv2packedX = yuv2xbgr32_full_X_c;
  2220. *yuv2packed2 = yuv2xbgr32_full_2_c;
  2221. *yuv2packed1 = yuv2xbgr32_full_1_c;
  2222. }
  2223. #endif /* !CONFIG_SMALL */
  2224. break;
  2225. case AV_PIX_FMT_RGBA64LE:
  2226. #if CONFIG_SWSCALE_ALPHA
  2227. if (c->needAlpha) {
  2228. *yuv2packedX = yuv2rgba64le_full_X_c;
  2229. *yuv2packed2 = yuv2rgba64le_full_2_c;
  2230. *yuv2packed1 = yuv2rgba64le_full_1_c;
  2231. } else
  2232. #endif /* CONFIG_SWSCALE_ALPHA */
  2233. {
  2234. *yuv2packedX = yuv2rgbx64le_full_X_c;
  2235. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  2236. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  2237. }
  2238. break;
  2239. case AV_PIX_FMT_RGBA64BE:
  2240. #if CONFIG_SWSCALE_ALPHA
  2241. if (c->needAlpha) {
  2242. *yuv2packedX = yuv2rgba64be_full_X_c;
  2243. *yuv2packed2 = yuv2rgba64be_full_2_c;
  2244. *yuv2packed1 = yuv2rgba64be_full_1_c;
  2245. } else
  2246. #endif /* CONFIG_SWSCALE_ALPHA */
  2247. {
  2248. *yuv2packedX = yuv2rgbx64be_full_X_c;
  2249. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  2250. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  2251. }
  2252. break;
  2253. case AV_PIX_FMT_BGRA64LE:
  2254. #if CONFIG_SWSCALE_ALPHA
  2255. if (c->needAlpha) {
  2256. *yuv2packedX = yuv2bgra64le_full_X_c;
  2257. *yuv2packed2 = yuv2bgra64le_full_2_c;
  2258. *yuv2packed1 = yuv2bgra64le_full_1_c;
  2259. } else
  2260. #endif /* CONFIG_SWSCALE_ALPHA */
  2261. {
  2262. *yuv2packedX = yuv2bgrx64le_full_X_c;
  2263. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  2264. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  2265. }
  2266. break;
  2267. case AV_PIX_FMT_BGRA64BE:
  2268. #if CONFIG_SWSCALE_ALPHA
  2269. if (c->needAlpha) {
  2270. *yuv2packedX = yuv2bgra64be_full_X_c;
  2271. *yuv2packed2 = yuv2bgra64be_full_2_c;
  2272. *yuv2packed1 = yuv2bgra64be_full_1_c;
  2273. } else
  2274. #endif /* CONFIG_SWSCALE_ALPHA */
  2275. {
  2276. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2277. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2278. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2279. }
  2280. break;
  2281. case AV_PIX_FMT_RGB24:
  2282. *yuv2packedX = yuv2rgb24_full_X_c;
  2283. *yuv2packed2 = yuv2rgb24_full_2_c;
  2284. *yuv2packed1 = yuv2rgb24_full_1_c;
  2285. break;
  2286. case AV_PIX_FMT_BGR24:
  2287. *yuv2packedX = yuv2bgr24_full_X_c;
  2288. *yuv2packed2 = yuv2bgr24_full_2_c;
  2289. *yuv2packed1 = yuv2bgr24_full_1_c;
  2290. break;
  2291. case AV_PIX_FMT_RGB48LE:
  2292. *yuv2packedX = yuv2rgb48le_full_X_c;
  2293. *yuv2packed2 = yuv2rgb48le_full_2_c;
  2294. *yuv2packed1 = yuv2rgb48le_full_1_c;
  2295. break;
  2296. case AV_PIX_FMT_BGR48LE:
  2297. *yuv2packedX = yuv2bgr48le_full_X_c;
  2298. *yuv2packed2 = yuv2bgr48le_full_2_c;
  2299. *yuv2packed1 = yuv2bgr48le_full_1_c;
  2300. break;
  2301. case AV_PIX_FMT_RGB48BE:
  2302. *yuv2packedX = yuv2rgb48be_full_X_c;
  2303. *yuv2packed2 = yuv2rgb48be_full_2_c;
  2304. *yuv2packed1 = yuv2rgb48be_full_1_c;
  2305. break;
  2306. case AV_PIX_FMT_BGR48BE:
  2307. *yuv2packedX = yuv2bgr48be_full_X_c;
  2308. *yuv2packed2 = yuv2bgr48be_full_2_c;
  2309. *yuv2packed1 = yuv2bgr48be_full_1_c;
  2310. break;
  2311. case AV_PIX_FMT_BGR4_BYTE:
  2312. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  2313. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  2314. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  2315. break;
  2316. case AV_PIX_FMT_RGB4_BYTE:
  2317. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  2318. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  2319. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  2320. break;
  2321. case AV_PIX_FMT_BGR8:
  2322. *yuv2packedX = yuv2bgr8_full_X_c;
  2323. *yuv2packed2 = yuv2bgr8_full_2_c;
  2324. *yuv2packed1 = yuv2bgr8_full_1_c;
  2325. break;
  2326. case AV_PIX_FMT_RGB8:
  2327. *yuv2packedX = yuv2rgb8_full_X_c;
  2328. *yuv2packed2 = yuv2rgb8_full_2_c;
  2329. *yuv2packed1 = yuv2rgb8_full_1_c;
  2330. break;
  2331. case AV_PIX_FMT_GBRP:
  2332. case AV_PIX_FMT_GBRP9BE:
  2333. case AV_PIX_FMT_GBRP9LE:
  2334. case AV_PIX_FMT_GBRP10BE:
  2335. case AV_PIX_FMT_GBRP10LE:
  2336. case AV_PIX_FMT_GBRP12BE:
  2337. case AV_PIX_FMT_GBRP12LE:
  2338. case AV_PIX_FMT_GBRP14BE:
  2339. case AV_PIX_FMT_GBRP14LE:
  2340. case AV_PIX_FMT_GBRAP:
  2341. case AV_PIX_FMT_GBRAP10BE:
  2342. case AV_PIX_FMT_GBRAP10LE:
  2343. case AV_PIX_FMT_GBRAP12BE:
  2344. case AV_PIX_FMT_GBRAP12LE:
  2345. *yuv2anyX = yuv2gbrp_full_X_c;
  2346. break;
  2347. case AV_PIX_FMT_GBRP16BE:
  2348. case AV_PIX_FMT_GBRP16LE:
  2349. case AV_PIX_FMT_GBRAP16BE:
  2350. case AV_PIX_FMT_GBRAP16LE:
  2351. *yuv2anyX = yuv2gbrp16_full_X_c;
  2352. break;
  2353. }
  2354. if (!*yuv2packedX && !*yuv2anyX)
  2355. goto YUV_PACKED;
  2356. } else {
  2357. YUV_PACKED:
  2358. switch (dstFormat) {
  2359. case AV_PIX_FMT_RGBA64LE:
  2360. #if CONFIG_SWSCALE_ALPHA
  2361. if (c->needAlpha) {
  2362. *yuv2packed1 = yuv2rgba64le_1_c;
  2363. *yuv2packed2 = yuv2rgba64le_2_c;
  2364. *yuv2packedX = yuv2rgba64le_X_c;
  2365. } else
  2366. #endif /* CONFIG_SWSCALE_ALPHA */
  2367. {
  2368. *yuv2packed1 = yuv2rgbx64le_1_c;
  2369. *yuv2packed2 = yuv2rgbx64le_2_c;
  2370. *yuv2packedX = yuv2rgbx64le_X_c;
  2371. }
  2372. break;
  2373. case AV_PIX_FMT_RGBA64BE:
  2374. #if CONFIG_SWSCALE_ALPHA
  2375. if (c->needAlpha) {
  2376. *yuv2packed1 = yuv2rgba64be_1_c;
  2377. *yuv2packed2 = yuv2rgba64be_2_c;
  2378. *yuv2packedX = yuv2rgba64be_X_c;
  2379. } else
  2380. #endif /* CONFIG_SWSCALE_ALPHA */
  2381. {
  2382. *yuv2packed1 = yuv2rgbx64be_1_c;
  2383. *yuv2packed2 = yuv2rgbx64be_2_c;
  2384. *yuv2packedX = yuv2rgbx64be_X_c;
  2385. }
  2386. break;
  2387. case AV_PIX_FMT_BGRA64LE:
  2388. #if CONFIG_SWSCALE_ALPHA
  2389. if (c->needAlpha) {
  2390. *yuv2packed1 = yuv2bgra64le_1_c;
  2391. *yuv2packed2 = yuv2bgra64le_2_c;
  2392. *yuv2packedX = yuv2bgra64le_X_c;
  2393. } else
  2394. #endif /* CONFIG_SWSCALE_ALPHA */
  2395. {
  2396. *yuv2packed1 = yuv2bgrx64le_1_c;
  2397. *yuv2packed2 = yuv2bgrx64le_2_c;
  2398. *yuv2packedX = yuv2bgrx64le_X_c;
  2399. }
  2400. break;
  2401. case AV_PIX_FMT_BGRA64BE:
  2402. #if CONFIG_SWSCALE_ALPHA
  2403. if (c->needAlpha) {
  2404. *yuv2packed1 = yuv2bgra64be_1_c;
  2405. *yuv2packed2 = yuv2bgra64be_2_c;
  2406. *yuv2packedX = yuv2bgra64be_X_c;
  2407. } else
  2408. #endif /* CONFIG_SWSCALE_ALPHA */
  2409. {
  2410. *yuv2packed1 = yuv2bgrx64be_1_c;
  2411. *yuv2packed2 = yuv2bgrx64be_2_c;
  2412. *yuv2packedX = yuv2bgrx64be_X_c;
  2413. }
  2414. break;
  2415. case AV_PIX_FMT_RGB48LE:
  2416. *yuv2packed1 = yuv2rgb48le_1_c;
  2417. *yuv2packed2 = yuv2rgb48le_2_c;
  2418. *yuv2packedX = yuv2rgb48le_X_c;
  2419. break;
  2420. case AV_PIX_FMT_RGB48BE:
  2421. *yuv2packed1 = yuv2rgb48be_1_c;
  2422. *yuv2packed2 = yuv2rgb48be_2_c;
  2423. *yuv2packedX = yuv2rgb48be_X_c;
  2424. break;
  2425. case AV_PIX_FMT_BGR48LE:
  2426. *yuv2packed1 = yuv2bgr48le_1_c;
  2427. *yuv2packed2 = yuv2bgr48le_2_c;
  2428. *yuv2packedX = yuv2bgr48le_X_c;
  2429. break;
  2430. case AV_PIX_FMT_BGR48BE:
  2431. *yuv2packed1 = yuv2bgr48be_1_c;
  2432. *yuv2packed2 = yuv2bgr48be_2_c;
  2433. *yuv2packedX = yuv2bgr48be_X_c;
  2434. break;
  2435. case AV_PIX_FMT_RGB32:
  2436. case AV_PIX_FMT_BGR32:
  2437. #if CONFIG_SMALL
  2438. *yuv2packed1 = yuv2rgb32_1_c;
  2439. *yuv2packed2 = yuv2rgb32_2_c;
  2440. *yuv2packedX = yuv2rgb32_X_c;
  2441. #else
  2442. #if CONFIG_SWSCALE_ALPHA
  2443. if (c->needAlpha) {
  2444. *yuv2packed1 = yuv2rgba32_1_c;
  2445. *yuv2packed2 = yuv2rgba32_2_c;
  2446. *yuv2packedX = yuv2rgba32_X_c;
  2447. } else
  2448. #endif /* CONFIG_SWSCALE_ALPHA */
  2449. {
  2450. *yuv2packed1 = yuv2rgbx32_1_c;
  2451. *yuv2packed2 = yuv2rgbx32_2_c;
  2452. *yuv2packedX = yuv2rgbx32_X_c;
  2453. }
  2454. #endif /* !CONFIG_SMALL */
  2455. break;
  2456. case AV_PIX_FMT_RGB32_1:
  2457. case AV_PIX_FMT_BGR32_1:
  2458. #if CONFIG_SMALL
  2459. *yuv2packed1 = yuv2rgb32_1_1_c;
  2460. *yuv2packed2 = yuv2rgb32_1_2_c;
  2461. *yuv2packedX = yuv2rgb32_1_X_c;
  2462. #else
  2463. #if CONFIG_SWSCALE_ALPHA
  2464. if (c->needAlpha) {
  2465. *yuv2packed1 = yuv2rgba32_1_1_c;
  2466. *yuv2packed2 = yuv2rgba32_1_2_c;
  2467. *yuv2packedX = yuv2rgba32_1_X_c;
  2468. } else
  2469. #endif /* CONFIG_SWSCALE_ALPHA */
  2470. {
  2471. *yuv2packed1 = yuv2rgbx32_1_1_c;
  2472. *yuv2packed2 = yuv2rgbx32_1_2_c;
  2473. *yuv2packedX = yuv2rgbx32_1_X_c;
  2474. }
  2475. #endif /* !CONFIG_SMALL */
  2476. break;
  2477. case AV_PIX_FMT_RGB24:
  2478. *yuv2packed1 = yuv2rgb24_1_c;
  2479. *yuv2packed2 = yuv2rgb24_2_c;
  2480. *yuv2packedX = yuv2rgb24_X_c;
  2481. break;
  2482. case AV_PIX_FMT_BGR24:
  2483. *yuv2packed1 = yuv2bgr24_1_c;
  2484. *yuv2packed2 = yuv2bgr24_2_c;
  2485. *yuv2packedX = yuv2bgr24_X_c;
  2486. break;
  2487. case AV_PIX_FMT_RGB565LE:
  2488. case AV_PIX_FMT_RGB565BE:
  2489. case AV_PIX_FMT_BGR565LE:
  2490. case AV_PIX_FMT_BGR565BE:
  2491. *yuv2packed1 = yuv2rgb16_1_c;
  2492. *yuv2packed2 = yuv2rgb16_2_c;
  2493. *yuv2packedX = yuv2rgb16_X_c;
  2494. break;
  2495. case AV_PIX_FMT_RGB555LE:
  2496. case AV_PIX_FMT_RGB555BE:
  2497. case AV_PIX_FMT_BGR555LE:
  2498. case AV_PIX_FMT_BGR555BE:
  2499. *yuv2packed1 = yuv2rgb15_1_c;
  2500. *yuv2packed2 = yuv2rgb15_2_c;
  2501. *yuv2packedX = yuv2rgb15_X_c;
  2502. break;
  2503. case AV_PIX_FMT_RGB444LE:
  2504. case AV_PIX_FMT_RGB444BE:
  2505. case AV_PIX_FMT_BGR444LE:
  2506. case AV_PIX_FMT_BGR444BE:
  2507. *yuv2packed1 = yuv2rgb12_1_c;
  2508. *yuv2packed2 = yuv2rgb12_2_c;
  2509. *yuv2packedX = yuv2rgb12_X_c;
  2510. break;
  2511. case AV_PIX_FMT_RGB8:
  2512. case AV_PIX_FMT_BGR8:
  2513. *yuv2packed1 = yuv2rgb8_1_c;
  2514. *yuv2packed2 = yuv2rgb8_2_c;
  2515. *yuv2packedX = yuv2rgb8_X_c;
  2516. break;
  2517. case AV_PIX_FMT_RGB4:
  2518. case AV_PIX_FMT_BGR4:
  2519. *yuv2packed1 = yuv2rgb4_1_c;
  2520. *yuv2packed2 = yuv2rgb4_2_c;
  2521. *yuv2packedX = yuv2rgb4_X_c;
  2522. break;
  2523. case AV_PIX_FMT_RGB4_BYTE:
  2524. case AV_PIX_FMT_BGR4_BYTE:
  2525. *yuv2packed1 = yuv2rgb4b_1_c;
  2526. *yuv2packed2 = yuv2rgb4b_2_c;
  2527. *yuv2packedX = yuv2rgb4b_X_c;
  2528. break;
  2529. }
  2530. }
  2531. switch (dstFormat) {
  2532. case AV_PIX_FMT_MONOWHITE:
  2533. *yuv2packed1 = yuv2monowhite_1_c;
  2534. *yuv2packed2 = yuv2monowhite_2_c;
  2535. *yuv2packedX = yuv2monowhite_X_c;
  2536. break;
  2537. case AV_PIX_FMT_MONOBLACK:
  2538. *yuv2packed1 = yuv2monoblack_1_c;
  2539. *yuv2packed2 = yuv2monoblack_2_c;
  2540. *yuv2packedX = yuv2monoblack_X_c;
  2541. break;
  2542. case AV_PIX_FMT_YUYV422:
  2543. *yuv2packed1 = yuv2yuyv422_1_c;
  2544. *yuv2packed2 = yuv2yuyv422_2_c;
  2545. *yuv2packedX = yuv2yuyv422_X_c;
  2546. break;
  2547. case AV_PIX_FMT_YVYU422:
  2548. *yuv2packed1 = yuv2yvyu422_1_c;
  2549. *yuv2packed2 = yuv2yvyu422_2_c;
  2550. *yuv2packedX = yuv2yvyu422_X_c;
  2551. break;
  2552. case AV_PIX_FMT_UYVY422:
  2553. *yuv2packed1 = yuv2uyvy422_1_c;
  2554. *yuv2packed2 = yuv2uyvy422_2_c;
  2555. *yuv2packedX = yuv2uyvy422_X_c;
  2556. break;
  2557. case AV_PIX_FMT_YA8:
  2558. *yuv2packed1 = yuv2ya8_1_c;
  2559. *yuv2packed2 = yuv2ya8_2_c;
  2560. *yuv2packedX = yuv2ya8_X_c;
  2561. break;
  2562. case AV_PIX_FMT_AYUV64LE:
  2563. *yuv2packedX = yuv2ayuv64le_X_c;
  2564. break;
  2565. }
  2566. }