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.

1436 lines
52KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <assert.h>
  21. #include <math.h>
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "libavutil/avutil.h"
  26. #include "libavutil/bswap.h"
  27. #include "libavutil/cpu.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/mathematics.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "config.h"
  32. #include "rgb2rgb.h"
  33. #include "swscale.h"
  34. #include "swscale_internal.h"
  35. DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4)[2][8]={
  36. { 1, 3, 1, 3, 1, 3, 1, 3, },
  37. { 2, 0, 2, 0, 2, 0, 2, 0, },
  38. };
  39. DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8)[2][8]={
  40. { 6, 2, 6, 2, 6, 2, 6, 2, },
  41. { 0, 4, 0, 4, 0, 4, 0, 4, },
  42. };
  43. DECLARE_ALIGNED(8, const uint8_t, dither_4x4_16)[4][8]={
  44. { 8, 4, 11, 7, 8, 4, 11, 7, },
  45. { 2, 14, 1, 13, 2, 14, 1, 13, },
  46. { 10, 6, 9, 5, 10, 6, 9, 5, },
  47. { 0, 12, 3, 15, 0, 12, 3, 15, },
  48. };
  49. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32)[8][8]={
  50. { 17, 9, 23, 15, 16, 8, 22, 14, },
  51. { 5, 29, 3, 27, 4, 28, 2, 26, },
  52. { 21, 13, 19, 11, 20, 12, 18, 10, },
  53. { 0, 24, 6, 30, 1, 25, 7, 31, },
  54. { 16, 8, 22, 14, 17, 9, 23, 15, },
  55. { 4, 28, 2, 26, 5, 29, 3, 27, },
  56. { 20, 12, 18, 10, 21, 13, 19, 11, },
  57. { 1, 25, 7, 31, 0, 24, 6, 30, },
  58. };
  59. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73)[8][8]={
  60. { 0, 55, 14, 68, 3, 58, 17, 72, },
  61. { 37, 18, 50, 32, 40, 22, 54, 35, },
  62. { 9, 64, 5, 59, 13, 67, 8, 63, },
  63. { 46, 27, 41, 23, 49, 31, 44, 26, },
  64. { 2, 57, 16, 71, 1, 56, 15, 70, },
  65. { 39, 21, 52, 34, 38, 19, 51, 33, },
  66. { 11, 66, 7, 62, 10, 65, 6, 60, },
  67. { 48, 30, 43, 25, 47, 29, 42, 24, },
  68. };
  69. #if 1
  70. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  71. {117, 62, 158, 103, 113, 58, 155, 100, },
  72. { 34, 199, 21, 186, 31, 196, 17, 182, },
  73. {144, 89, 131, 76, 141, 86, 127, 72, },
  74. { 0, 165, 41, 206, 10, 175, 52, 217, },
  75. {110, 55, 151, 96, 120, 65, 162, 107, },
  76. { 28, 193, 14, 179, 38, 203, 24, 189, },
  77. {138, 83, 124, 69, 148, 93, 134, 79, },
  78. { 7, 172, 48, 213, 3, 168, 45, 210, },
  79. };
  80. #elif 1
  81. // tries to correct a gamma of 1.5
  82. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  83. { 0, 143, 18, 200, 2, 156, 25, 215, },
  84. { 78, 28, 125, 64, 89, 36, 138, 74, },
  85. { 10, 180, 3, 161, 16, 195, 8, 175, },
  86. {109, 51, 93, 38, 121, 60, 105, 47, },
  87. { 1, 152, 23, 210, 0, 147, 20, 205, },
  88. { 85, 33, 134, 71, 81, 30, 130, 67, },
  89. { 14, 190, 6, 171, 12, 185, 5, 166, },
  90. {117, 57, 101, 44, 113, 54, 97, 41, },
  91. };
  92. #elif 1
  93. // tries to correct a gamma of 2.0
  94. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  95. { 0, 124, 8, 193, 0, 140, 12, 213, },
  96. { 55, 14, 104, 42, 66, 19, 119, 52, },
  97. { 3, 168, 1, 145, 6, 187, 3, 162, },
  98. { 86, 31, 70, 21, 99, 39, 82, 28, },
  99. { 0, 134, 11, 206, 0, 129, 9, 200, },
  100. { 62, 17, 114, 48, 58, 16, 109, 45, },
  101. { 5, 181, 2, 157, 4, 175, 1, 151, },
  102. { 95, 36, 78, 26, 90, 34, 74, 24, },
  103. };
  104. #else
  105. // tries to correct a gamma of 2.5
  106. DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
  107. { 0, 107, 3, 187, 0, 125, 6, 212, },
  108. { 39, 7, 86, 28, 49, 11, 102, 36, },
  109. { 1, 158, 0, 131, 3, 180, 1, 151, },
  110. { 68, 19, 52, 12, 81, 25, 64, 17, },
  111. { 0, 119, 5, 203, 0, 113, 4, 195, },
  112. { 45, 9, 96, 33, 42, 8, 91, 30, },
  113. { 2, 172, 1, 144, 2, 165, 0, 137, },
  114. { 77, 23, 60, 15, 72, 21, 56, 14, },
  115. };
  116. #endif
  117. #define output_pixel(pos, val, bias, signedness) \
  118. if (big_endian) { \
  119. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  120. } else { \
  121. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  122. }
  123. static av_always_inline void
  124. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  125. int big_endian, int output_bits)
  126. {
  127. int i;
  128. int shift = 19 - output_bits;
  129. for (i = 0; i < dstW; i++) {
  130. int val = src[i] + (1 << (shift - 1));
  131. output_pixel(&dest[i], val, 0, uint);
  132. }
  133. }
  134. static av_always_inline void
  135. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  136. const int32_t **src, uint16_t *dest, int dstW,
  137. int big_endian, int output_bits)
  138. {
  139. int i;
  140. int shift = 15 + 16 - output_bits;
  141. for (i = 0; i < dstW; i++) {
  142. int val = 1 << (30-output_bits);
  143. int j;
  144. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  145. * filters (or anything with negative coeffs, the range can be slightly
  146. * wider in both directions. To account for this overflow, we subtract
  147. * a constant so it always fits in the signed range (assuming a
  148. * reasonable filterSize), and re-add that at the end. */
  149. val -= 0x40000000;
  150. for (j = 0; j < filterSize; j++)
  151. val += src[j][i] * filter[j];
  152. output_pixel(&dest[i], val, 0x8000, int);
  153. }
  154. }
  155. #undef output_pixel
  156. #define output_pixel(pos, val) \
  157. if (big_endian) { \
  158. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  159. } else { \
  160. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  161. }
  162. static av_always_inline void
  163. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  164. int big_endian, int output_bits)
  165. {
  166. int i;
  167. int shift = 15 - output_bits;
  168. for (i = 0; i < dstW; i++) {
  169. int val = src[i] + (1 << (shift - 1));
  170. output_pixel(&dest[i], val);
  171. }
  172. }
  173. static av_always_inline void
  174. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  175. const int16_t **src, uint16_t *dest, int dstW,
  176. int big_endian, int output_bits)
  177. {
  178. int i;
  179. int shift = 11 + 16 - output_bits;
  180. for (i = 0; i < dstW; i++) {
  181. int val = 1 << (26-output_bits);
  182. int j;
  183. for (j = 0; j < filterSize; j++)
  184. val += src[j][i] * filter[j];
  185. output_pixel(&dest[i], val);
  186. }
  187. }
  188. #undef output_pixel
  189. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  190. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  191. uint8_t *dest, int dstW, \
  192. const uint8_t *dither, int offset)\
  193. { \
  194. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  195. (uint16_t *) dest, dstW, is_be, bits); \
  196. }\
  197. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  198. const int16_t **src, uint8_t *dest, int dstW, \
  199. const uint8_t *dither, int offset)\
  200. { \
  201. yuv2planeX_## template_size ## _c_template(filter, \
  202. filterSize, (const typeX_t **) src, \
  203. (uint16_t *) dest, dstW, is_be, bits); \
  204. }
  205. yuv2NBPS( 9, BE, 1, 10, int16_t)
  206. yuv2NBPS( 9, LE, 0, 10, int16_t)
  207. yuv2NBPS(10, BE, 1, 10, int16_t)
  208. yuv2NBPS(10, LE, 0, 10, int16_t)
  209. yuv2NBPS(16, BE, 1, 16, int32_t)
  210. yuv2NBPS(16, LE, 0, 16, int32_t)
  211. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  212. const int16_t **src, uint8_t *dest, int dstW,
  213. const uint8_t *dither, int offset)
  214. {
  215. int i;
  216. for (i=0; i<dstW; i++) {
  217. int val = dither[(i + offset) & 7] << 12;
  218. int j;
  219. for (j=0; j<filterSize; j++)
  220. val += src[j][i] * filter[j];
  221. dest[i]= av_clip_uint8(val>>19);
  222. }
  223. }
  224. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  225. const uint8_t *dither, int offset)
  226. {
  227. int i;
  228. for (i=0; i<dstW; i++) {
  229. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  230. dest[i]= av_clip_uint8(val);
  231. }
  232. }
  233. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  234. const int16_t **chrUSrc, const int16_t **chrVSrc,
  235. uint8_t *dest, int chrDstW)
  236. {
  237. enum PixelFormat dstFormat = c->dstFormat;
  238. const uint8_t *chrDither = c->chrDither8;
  239. int i;
  240. if (dstFormat == PIX_FMT_NV12)
  241. for (i=0; i<chrDstW; i++) {
  242. int u = chrDither[i & 7] << 12;
  243. int v = chrDither[(i + 3) & 7] << 12;
  244. int j;
  245. for (j=0; j<chrFilterSize; j++) {
  246. u += chrUSrc[j][i] * chrFilter[j];
  247. v += chrVSrc[j][i] * chrFilter[j];
  248. }
  249. dest[2*i]= av_clip_uint8(u>>19);
  250. dest[2*i+1]= av_clip_uint8(v>>19);
  251. }
  252. else
  253. for (i=0; i<chrDstW; i++) {
  254. int u = chrDither[i & 7] << 12;
  255. int v = chrDither[(i + 3) & 7] << 12;
  256. int j;
  257. for (j=0; j<chrFilterSize; j++) {
  258. u += chrUSrc[j][i] * chrFilter[j];
  259. v += chrVSrc[j][i] * chrFilter[j];
  260. }
  261. dest[2*i]= av_clip_uint8(v>>19);
  262. dest[2*i+1]= av_clip_uint8(u>>19);
  263. }
  264. }
  265. #define output_pixel(pos, acc) \
  266. if (target == PIX_FMT_MONOBLACK) { \
  267. pos = acc; \
  268. } else { \
  269. pos = ~acc; \
  270. }
  271. static av_always_inline void
  272. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  273. const int16_t **lumSrc, int lumFilterSize,
  274. const int16_t *chrFilter, const int16_t **chrUSrc,
  275. const int16_t **chrVSrc, int chrFilterSize,
  276. const int16_t **alpSrc, uint8_t *dest, int dstW,
  277. int y, enum PixelFormat target)
  278. {
  279. const uint8_t * const d128=dither_8x8_220[y&7];
  280. uint8_t *g = c->table_gU[128] + c->table_gV[128];
  281. int i;
  282. unsigned acc = 0;
  283. for (i = 0; i < dstW - 1; i += 2) {
  284. int j;
  285. int Y1 = 1 << 18;
  286. int Y2 = 1 << 18;
  287. for (j = 0; j < lumFilterSize; j++) {
  288. Y1 += lumSrc[j][i] * lumFilter[j];
  289. Y2 += lumSrc[j][i+1] * lumFilter[j];
  290. }
  291. Y1 >>= 19;
  292. Y2 >>= 19;
  293. if ((Y1 | Y2) & 0x100) {
  294. Y1 = av_clip_uint8(Y1);
  295. Y2 = av_clip_uint8(Y2);
  296. }
  297. acc += acc + g[Y1 + d128[(i + 0) & 7]];
  298. acc += acc + g[Y2 + d128[(i + 1) & 7]];
  299. if ((i & 7) == 6) {
  300. output_pixel(*dest++, acc);
  301. }
  302. }
  303. }
  304. static av_always_inline void
  305. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  306. const int16_t *ubuf[2], const int16_t *vbuf[2],
  307. const int16_t *abuf[2], uint8_t *dest, int dstW,
  308. int yalpha, int uvalpha, int y,
  309. enum PixelFormat target)
  310. {
  311. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  312. const uint8_t * const d128 = dither_8x8_220[y & 7];
  313. uint8_t *g = c->table_gU[128] + c->table_gV[128];
  314. int yalpha1 = 4095 - yalpha;
  315. int i;
  316. for (i = 0; i < dstW - 7; i += 8) {
  317. int acc = g[((buf0[i ] * yalpha1 + buf1[i ] * yalpha) >> 19) + d128[0]];
  318. acc += acc + g[((buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19) + d128[1]];
  319. acc += acc + g[((buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19) + d128[2]];
  320. acc += acc + g[((buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19) + d128[3]];
  321. acc += acc + g[((buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19) + d128[4]];
  322. acc += acc + g[((buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19) + d128[5]];
  323. acc += acc + g[((buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19) + d128[6]];
  324. acc += acc + g[((buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19) + d128[7]];
  325. output_pixel(*dest++, acc);
  326. }
  327. }
  328. static av_always_inline void
  329. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  330. const int16_t *ubuf[2], const int16_t *vbuf[2],
  331. const int16_t *abuf0, uint8_t *dest, int dstW,
  332. int uvalpha, int y, enum PixelFormat target)
  333. {
  334. const uint8_t * const d128 = dither_8x8_220[y & 7];
  335. uint8_t *g = c->table_gU[128] + c->table_gV[128];
  336. int i;
  337. for (i = 0; i < dstW - 7; i += 8) {
  338. int acc = g[(buf0[i ] >> 7) + d128[0]];
  339. acc += acc + g[(buf0[i + 1] >> 7) + d128[1]];
  340. acc += acc + g[(buf0[i + 2] >> 7) + d128[2]];
  341. acc += acc + g[(buf0[i + 3] >> 7) + d128[3]];
  342. acc += acc + g[(buf0[i + 4] >> 7) + d128[4]];
  343. acc += acc + g[(buf0[i + 5] >> 7) + d128[5]];
  344. acc += acc + g[(buf0[i + 6] >> 7) + d128[6]];
  345. acc += acc + g[(buf0[i + 7] >> 7) + d128[7]];
  346. output_pixel(*dest++, acc);
  347. }
  348. }
  349. #undef output_pixel
  350. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  351. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  352. const int16_t **lumSrc, int lumFilterSize, \
  353. const int16_t *chrFilter, const int16_t **chrUSrc, \
  354. const int16_t **chrVSrc, int chrFilterSize, \
  355. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  356. int y) \
  357. { \
  358. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  359. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  360. alpSrc, dest, dstW, y, fmt); \
  361. } \
  362. \
  363. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  364. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  365. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  366. int yalpha, int uvalpha, int y) \
  367. { \
  368. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  369. dest, dstW, yalpha, uvalpha, y, fmt); \
  370. } \
  371. \
  372. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  373. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  374. const int16_t *abuf0, uint8_t *dest, int dstW, \
  375. int uvalpha, int y) \
  376. { \
  377. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  378. abuf0, dest, dstW, uvalpha, \
  379. y, fmt); \
  380. }
  381. YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE)
  382. YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK)
  383. #define output_pixels(pos, Y1, U, Y2, V) \
  384. if (target == PIX_FMT_YUYV422) { \
  385. dest[pos + 0] = Y1; \
  386. dest[pos + 1] = U; \
  387. dest[pos + 2] = Y2; \
  388. dest[pos + 3] = V; \
  389. } else { \
  390. dest[pos + 0] = U; \
  391. dest[pos + 1] = Y1; \
  392. dest[pos + 2] = V; \
  393. dest[pos + 3] = Y2; \
  394. }
  395. static av_always_inline void
  396. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  397. const int16_t **lumSrc, int lumFilterSize,
  398. const int16_t *chrFilter, const int16_t **chrUSrc,
  399. const int16_t **chrVSrc, int chrFilterSize,
  400. const int16_t **alpSrc, uint8_t *dest, int dstW,
  401. int y, enum PixelFormat target)
  402. {
  403. int i;
  404. for (i = 0; i < (dstW >> 1); i++) {
  405. int j;
  406. int Y1 = 1 << 18;
  407. int Y2 = 1 << 18;
  408. int U = 1 << 18;
  409. int V = 1 << 18;
  410. for (j = 0; j < lumFilterSize; j++) {
  411. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  412. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  413. }
  414. for (j = 0; j < chrFilterSize; j++) {
  415. U += chrUSrc[j][i] * chrFilter[j];
  416. V += chrVSrc[j][i] * chrFilter[j];
  417. }
  418. Y1 >>= 19;
  419. Y2 >>= 19;
  420. U >>= 19;
  421. V >>= 19;
  422. if ((Y1 | Y2 | U | V) & 0x100) {
  423. Y1 = av_clip_uint8(Y1);
  424. Y2 = av_clip_uint8(Y2);
  425. U = av_clip_uint8(U);
  426. V = av_clip_uint8(V);
  427. }
  428. output_pixels(4*i, Y1, U, Y2, V);
  429. }
  430. }
  431. static av_always_inline void
  432. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  433. const int16_t *ubuf[2], const int16_t *vbuf[2],
  434. const int16_t *abuf[2], uint8_t *dest, int dstW,
  435. int yalpha, int uvalpha, int y,
  436. enum PixelFormat target)
  437. {
  438. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  439. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  440. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  441. int yalpha1 = 4095 - yalpha;
  442. int uvalpha1 = 4095 - uvalpha;
  443. int i;
  444. for (i = 0; i < (dstW >> 1); i++) {
  445. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  446. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  447. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  448. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  449. output_pixels(i * 4, Y1, U, Y2, V);
  450. }
  451. }
  452. static av_always_inline void
  453. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  454. const int16_t *ubuf[2], const int16_t *vbuf[2],
  455. const int16_t *abuf0, uint8_t *dest, int dstW,
  456. int uvalpha, int y, enum PixelFormat target)
  457. {
  458. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  459. int i;
  460. if (uvalpha < 2048) {
  461. for (i = 0; i < (dstW >> 1); i++) {
  462. int Y1 = buf0[i * 2] >> 7;
  463. int Y2 = buf0[i * 2 + 1] >> 7;
  464. int U = ubuf0[i] >> 7;
  465. int V = vbuf0[i] >> 7;
  466. output_pixels(i * 4, Y1, U, Y2, V);
  467. }
  468. } else {
  469. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  470. for (i = 0; i < (dstW >> 1); i++) {
  471. int Y1 = buf0[i * 2] >> 7;
  472. int Y2 = buf0[i * 2 + 1] >> 7;
  473. int U = (ubuf0[i] + ubuf1[i]) >> 8;
  474. int V = (vbuf0[i] + vbuf1[i]) >> 8;
  475. output_pixels(i * 4, Y1, U, Y2, V);
  476. }
  477. }
  478. }
  479. #undef output_pixels
  480. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, PIX_FMT_YUYV422)
  481. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, PIX_FMT_UYVY422)
  482. #define R_B ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? R : B)
  483. #define B_R ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? B : R)
  484. #define output_pixel(pos, val) \
  485. if (isBE(target)) { \
  486. AV_WB16(pos, val); \
  487. } else { \
  488. AV_WL16(pos, val); \
  489. }
  490. static av_always_inline void
  491. yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
  492. const int32_t **lumSrc, int lumFilterSize,
  493. const int16_t *chrFilter, const int32_t **chrUSrc,
  494. const int32_t **chrVSrc, int chrFilterSize,
  495. const int32_t **alpSrc, uint16_t *dest, int dstW,
  496. int y, enum PixelFormat target)
  497. {
  498. int i;
  499. for (i = 0; i < (dstW >> 1); i++) {
  500. int j;
  501. int Y1 = -0x40000000;
  502. int Y2 = -0x40000000;
  503. int U = -128 << 23; // 19
  504. int V = -128 << 23;
  505. int R, G, B;
  506. for (j = 0; j < lumFilterSize; j++) {
  507. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  508. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  509. }
  510. for (j = 0; j < chrFilterSize; j++) {
  511. U += chrUSrc[j][i] * chrFilter[j];
  512. V += chrVSrc[j][i] * chrFilter[j];
  513. }
  514. // 8bit: 12+15=27; 16-bit: 12+19=31
  515. Y1 >>= 14; // 10
  516. Y1 += 0x10000;
  517. Y2 >>= 14;
  518. Y2 += 0x10000;
  519. U >>= 14;
  520. V >>= 14;
  521. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  522. Y1 -= c->yuv2rgb_y_offset;
  523. Y2 -= c->yuv2rgb_y_offset;
  524. Y1 *= c->yuv2rgb_y_coeff;
  525. Y2 *= c->yuv2rgb_y_coeff;
  526. Y1 += 1 << 13; // 21
  527. Y2 += 1 << 13;
  528. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  529. R = V * c->yuv2rgb_v2r_coeff;
  530. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  531. B = U * c->yuv2rgb_u2b_coeff;
  532. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  533. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  534. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  535. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  536. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  537. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  538. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  539. dest += 6;
  540. }
  541. }
  542. static av_always_inline void
  543. yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
  544. const int32_t *ubuf[2], const int32_t *vbuf[2],
  545. const int32_t *abuf[2], uint16_t *dest, int dstW,
  546. int yalpha, int uvalpha, int y,
  547. enum PixelFormat target)
  548. {
  549. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  550. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  551. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  552. int yalpha1 = 4095 - yalpha;
  553. int uvalpha1 = 4095 - uvalpha;
  554. int i;
  555. for (i = 0; i < (dstW >> 1); i++) {
  556. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  557. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  558. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
  559. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
  560. int R, G, B;
  561. Y1 -= c->yuv2rgb_y_offset;
  562. Y2 -= c->yuv2rgb_y_offset;
  563. Y1 *= c->yuv2rgb_y_coeff;
  564. Y2 *= c->yuv2rgb_y_coeff;
  565. Y1 += 1 << 13;
  566. Y2 += 1 << 13;
  567. R = V * c->yuv2rgb_v2r_coeff;
  568. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  569. B = U * c->yuv2rgb_u2b_coeff;
  570. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  571. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  572. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  573. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  574. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  575. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  576. dest += 6;
  577. }
  578. }
  579. static av_always_inline void
  580. yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
  581. const int32_t *ubuf[2], const int32_t *vbuf[2],
  582. const int32_t *abuf0, uint16_t *dest, int dstW,
  583. int uvalpha, int y, enum PixelFormat target)
  584. {
  585. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  586. int i;
  587. if (uvalpha < 2048) {
  588. for (i = 0; i < (dstW >> 1); i++) {
  589. int Y1 = (buf0[i * 2] ) >> 2;
  590. int Y2 = (buf0[i * 2 + 1]) >> 2;
  591. int U = (ubuf0[i] + (-128 << 11)) >> 2;
  592. int V = (vbuf0[i] + (-128 << 11)) >> 2;
  593. int R, G, B;
  594. Y1 -= c->yuv2rgb_y_offset;
  595. Y2 -= c->yuv2rgb_y_offset;
  596. Y1 *= c->yuv2rgb_y_coeff;
  597. Y2 *= c->yuv2rgb_y_coeff;
  598. Y1 += 1 << 13;
  599. Y2 += 1 << 13;
  600. R = V * c->yuv2rgb_v2r_coeff;
  601. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  602. B = U * c->yuv2rgb_u2b_coeff;
  603. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  604. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  605. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  606. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  607. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  608. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  609. dest += 6;
  610. }
  611. } else {
  612. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  613. for (i = 0; i < (dstW >> 1); i++) {
  614. int Y1 = (buf0[i * 2] ) >> 2;
  615. int Y2 = (buf0[i * 2 + 1]) >> 2;
  616. int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
  617. int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
  618. int R, G, B;
  619. Y1 -= c->yuv2rgb_y_offset;
  620. Y2 -= c->yuv2rgb_y_offset;
  621. Y1 *= c->yuv2rgb_y_coeff;
  622. Y2 *= c->yuv2rgb_y_coeff;
  623. Y1 += 1 << 13;
  624. Y2 += 1 << 13;
  625. R = V * c->yuv2rgb_v2r_coeff;
  626. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  627. B = U * c->yuv2rgb_u2b_coeff;
  628. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  629. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  630. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  631. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  632. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  633. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  634. dest += 6;
  635. }
  636. }
  637. }
  638. #undef output_pixel
  639. #undef r_b
  640. #undef b_r
  641. #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
  642. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  643. const int16_t **_lumSrc, int lumFilterSize, \
  644. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  645. const int16_t **_chrVSrc, int chrFilterSize, \
  646. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  647. int y) \
  648. { \
  649. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  650. **chrUSrc = (const int32_t **) _chrUSrc, \
  651. **chrVSrc = (const int32_t **) _chrVSrc, \
  652. **alpSrc = (const int32_t **) _alpSrc; \
  653. uint16_t *dest = (uint16_t *) _dest; \
  654. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  655. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  656. alpSrc, dest, dstW, y, fmt); \
  657. } \
  658. \
  659. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  660. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  661. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  662. int yalpha, int uvalpha, int y) \
  663. { \
  664. const int32_t **buf = (const int32_t **) _buf, \
  665. **ubuf = (const int32_t **) _ubuf, \
  666. **vbuf = (const int32_t **) _vbuf, \
  667. **abuf = (const int32_t **) _abuf; \
  668. uint16_t *dest = (uint16_t *) _dest; \
  669. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  670. dest, dstW, yalpha, uvalpha, y, fmt); \
  671. } \
  672. \
  673. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  674. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  675. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  676. int uvalpha, int y) \
  677. { \
  678. const int32_t *buf0 = (const int32_t *) _buf0, \
  679. **ubuf = (const int32_t **) _ubuf, \
  680. **vbuf = (const int32_t **) _vbuf, \
  681. *abuf0 = (const int32_t *) _abuf0; \
  682. uint16_t *dest = (uint16_t *) _dest; \
  683. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  684. dstW, uvalpha, y, fmt); \
  685. }
  686. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE)
  687. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE)
  688. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE)
  689. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE)
  690. /*
  691. * Write out 2 RGB pixels in the target pixel format. This function takes a
  692. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  693. * things like endianness conversion and shifting. The caller takes care of
  694. * setting the correct offset in these tables from the chroma (U/V) values.
  695. * This function then uses the luminance (Y1/Y2) values to write out the
  696. * correct RGB values into the destination buffer.
  697. */
  698. static av_always_inline void
  699. yuv2rgb_write(uint8_t *_dest, int i, unsigned Y1, unsigned Y2,
  700. unsigned A1, unsigned A2,
  701. const void *_r, const void *_g, const void *_b, int y,
  702. enum PixelFormat target, int hasAlpha)
  703. {
  704. if (target == PIX_FMT_ARGB || target == PIX_FMT_RGBA ||
  705. target == PIX_FMT_ABGR || target == PIX_FMT_BGRA) {
  706. uint32_t *dest = (uint32_t *) _dest;
  707. const uint32_t *r = (const uint32_t *) _r;
  708. const uint32_t *g = (const uint32_t *) _g;
  709. const uint32_t *b = (const uint32_t *) _b;
  710. #if CONFIG_SMALL
  711. int sh = hasAlpha ? ((target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  712. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  713. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  714. #else
  715. if (hasAlpha) {
  716. int sh = (target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24;
  717. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  718. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  719. } else {
  720. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  721. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  722. }
  723. #endif
  724. } else if (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) {
  725. uint8_t *dest = (uint8_t *) _dest;
  726. const uint8_t *r = (const uint8_t *) _r;
  727. const uint8_t *g = (const uint8_t *) _g;
  728. const uint8_t *b = (const uint8_t *) _b;
  729. #define r_b ((target == PIX_FMT_RGB24) ? r : b)
  730. #define b_r ((target == PIX_FMT_RGB24) ? b : r)
  731. dest[i * 6 + 0] = r_b[Y1];
  732. dest[i * 6 + 1] = g[Y1];
  733. dest[i * 6 + 2] = b_r[Y1];
  734. dest[i * 6 + 3] = r_b[Y2];
  735. dest[i * 6 + 4] = g[Y2];
  736. dest[i * 6 + 5] = b_r[Y2];
  737. #undef r_b
  738. #undef b_r
  739. } else if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565 ||
  740. target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555 ||
  741. target == PIX_FMT_RGB444 || target == PIX_FMT_BGR444) {
  742. uint16_t *dest = (uint16_t *) _dest;
  743. const uint16_t *r = (const uint16_t *) _r;
  744. const uint16_t *g = (const uint16_t *) _g;
  745. const uint16_t *b = (const uint16_t *) _b;
  746. int dr1, dg1, db1, dr2, dg2, db2;
  747. if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565) {
  748. dr1 = dither_2x2_8[ y & 1 ][0];
  749. dg1 = dither_2x2_4[ y & 1 ][0];
  750. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  751. dr2 = dither_2x2_8[ y & 1 ][1];
  752. dg2 = dither_2x2_4[ y & 1 ][1];
  753. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  754. } else if (target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555) {
  755. dr1 = dither_2x2_8[ y & 1 ][0];
  756. dg1 = dither_2x2_8[ y & 1 ][1];
  757. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  758. dr2 = dither_2x2_8[ y & 1 ][1];
  759. dg2 = dither_2x2_8[ y & 1 ][0];
  760. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  761. } else {
  762. dr1 = dither_4x4_16[ y & 3 ][0];
  763. dg1 = dither_4x4_16[ y & 3 ][1];
  764. db1 = dither_4x4_16[(y & 3) ^ 3][0];
  765. dr2 = dither_4x4_16[ y & 3 ][1];
  766. dg2 = dither_4x4_16[ y & 3 ][0];
  767. db2 = dither_4x4_16[(y & 3) ^ 3][1];
  768. }
  769. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  770. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  771. } else /* 8/4-bit */ {
  772. uint8_t *dest = (uint8_t *) _dest;
  773. const uint8_t *r = (const uint8_t *) _r;
  774. const uint8_t *g = (const uint8_t *) _g;
  775. const uint8_t *b = (const uint8_t *) _b;
  776. int dr1, dg1, db1, dr2, dg2, db2;
  777. if (target == PIX_FMT_RGB8 || target == PIX_FMT_BGR8) {
  778. const uint8_t * const d64 = dither_8x8_73[y & 7];
  779. const uint8_t * const d32 = dither_8x8_32[y & 7];
  780. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  781. db1 = d64[(i * 2 + 0) & 7];
  782. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  783. db2 = d64[(i * 2 + 1) & 7];
  784. } else {
  785. const uint8_t * const d64 = dither_8x8_73 [y & 7];
  786. const uint8_t * const d128 = dither_8x8_220[y & 7];
  787. dr1 = db1 = d128[(i * 2 + 0) & 7];
  788. dg1 = d64[(i * 2 + 0) & 7];
  789. dr2 = db2 = d128[(i * 2 + 1) & 7];
  790. dg2 = d64[(i * 2 + 1) & 7];
  791. }
  792. if (target == PIX_FMT_RGB4 || target == PIX_FMT_BGR4) {
  793. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  794. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  795. } else {
  796. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  797. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  798. }
  799. }
  800. }
  801. static av_always_inline void
  802. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  803. const int16_t **lumSrc, int lumFilterSize,
  804. const int16_t *chrFilter, const int16_t **chrUSrc,
  805. const int16_t **chrVSrc, int chrFilterSize,
  806. const int16_t **alpSrc, uint8_t *dest, int dstW,
  807. int y, enum PixelFormat target, int hasAlpha)
  808. {
  809. int i;
  810. for (i = 0; i < (dstW >> 1); i++) {
  811. int j, A1, A2;
  812. int Y1 = 1 << 18;
  813. int Y2 = 1 << 18;
  814. int U = 1 << 18;
  815. int V = 1 << 18;
  816. const void *r, *g, *b;
  817. for (j = 0; j < lumFilterSize; j++) {
  818. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  819. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  820. }
  821. for (j = 0; j < chrFilterSize; j++) {
  822. U += chrUSrc[j][i] * chrFilter[j];
  823. V += chrVSrc[j][i] * chrFilter[j];
  824. }
  825. Y1 >>= 19;
  826. Y2 >>= 19;
  827. U >>= 19;
  828. V >>= 19;
  829. if ((Y1 | Y2 | U | V) & 0x100) {
  830. Y1 = av_clip_uint8(Y1);
  831. Y2 = av_clip_uint8(Y2);
  832. U = av_clip_uint8(U);
  833. V = av_clip_uint8(V);
  834. }
  835. if (hasAlpha) {
  836. A1 = 1 << 18;
  837. A2 = 1 << 18;
  838. for (j = 0; j < lumFilterSize; j++) {
  839. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  840. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  841. }
  842. A1 >>= 19;
  843. A2 >>= 19;
  844. if ((A1 | A2) & 0x100) {
  845. A1 = av_clip_uint8(A1);
  846. A2 = av_clip_uint8(A2);
  847. }
  848. }
  849. /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/
  850. r = c->table_rV[V];
  851. g = (c->table_gU[U] + c->table_gV[V]);
  852. b = c->table_bU[U];
  853. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  854. r, g, b, y, target, hasAlpha);
  855. }
  856. }
  857. static av_always_inline void
  858. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  859. const int16_t *ubuf[2], const int16_t *vbuf[2],
  860. const int16_t *abuf[2], uint8_t *dest, int dstW,
  861. int yalpha, int uvalpha, int y,
  862. enum PixelFormat target, int hasAlpha)
  863. {
  864. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  865. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  866. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  867. *abuf0 = hasAlpha ? abuf[0] : NULL,
  868. *abuf1 = hasAlpha ? abuf[1] : NULL;
  869. int yalpha1 = 4095 - yalpha;
  870. int uvalpha1 = 4095 - uvalpha;
  871. int i;
  872. for (i = 0; i < (dstW >> 1); i++) {
  873. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  874. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  875. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  876. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  877. int A1, A2;
  878. const void *r = c->table_rV[V],
  879. *g = (c->table_gU[U] + c->table_gV[V]),
  880. *b = c->table_bU[U];
  881. if (hasAlpha) {
  882. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  883. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  884. }
  885. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  886. r, g, b, y, target, hasAlpha);
  887. }
  888. }
  889. static av_always_inline void
  890. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  891. const int16_t *ubuf[2], const int16_t *vbuf[2],
  892. const int16_t *abuf0, uint8_t *dest, int dstW,
  893. int uvalpha, int y, enum PixelFormat target,
  894. int hasAlpha)
  895. {
  896. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  897. int i;
  898. if (uvalpha < 2048) {
  899. for (i = 0; i < (dstW >> 1); i++) {
  900. int Y1 = buf0[i * 2] >> 7;
  901. int Y2 = buf0[i * 2 + 1] >> 7;
  902. int U = ubuf0[i] >> 7;
  903. int V = vbuf0[i] >> 7;
  904. int A1, A2;
  905. const void *r = c->table_rV[V],
  906. *g = (c->table_gU[U] + c->table_gV[V]),
  907. *b = c->table_bU[U];
  908. if (hasAlpha) {
  909. A1 = abuf0[i * 2 ] >> 7;
  910. A2 = abuf0[i * 2 + 1] >> 7;
  911. }
  912. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  913. r, g, b, y, target, hasAlpha);
  914. }
  915. } else {
  916. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  917. for (i = 0; i < (dstW >> 1); i++) {
  918. int Y1 = buf0[i * 2] >> 7;
  919. int Y2 = buf0[i * 2 + 1] >> 7;
  920. int U = (ubuf0[i] + ubuf1[i]) >> 8;
  921. int V = (vbuf0[i] + vbuf1[i]) >> 8;
  922. int A1, A2;
  923. const void *r = c->table_rV[V],
  924. *g = (c->table_gU[U] + c->table_gV[V]),
  925. *b = c->table_bU[U];
  926. if (hasAlpha) {
  927. A1 = abuf0[i * 2 ] >> 7;
  928. A2 = abuf0[i * 2 + 1] >> 7;
  929. }
  930. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  931. r, g, b, y, target, hasAlpha);
  932. }
  933. }
  934. }
  935. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  936. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  937. const int16_t **lumSrc, int lumFilterSize, \
  938. const int16_t *chrFilter, const int16_t **chrUSrc, \
  939. const int16_t **chrVSrc, int chrFilterSize, \
  940. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  941. int y) \
  942. { \
  943. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  944. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  945. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  946. }
  947. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  948. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  949. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  950. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  951. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  952. int yalpha, int uvalpha, int y) \
  953. { \
  954. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  955. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  956. } \
  957. \
  958. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  959. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  960. const int16_t *abuf0, uint8_t *dest, int dstW, \
  961. int uvalpha, int y) \
  962. { \
  963. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  964. dstW, uvalpha, y, fmt, hasAlpha); \
  965. }
  966. #if CONFIG_SMALL
  967. YUV2RGBWRAPPER(yuv2rgb,, 32_1, PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  968. YUV2RGBWRAPPER(yuv2rgb,, 32, PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  969. #else
  970. #if CONFIG_SWSCALE_ALPHA
  971. YUV2RGBWRAPPER(yuv2rgb,, a32_1, PIX_FMT_RGB32_1, 1)
  972. YUV2RGBWRAPPER(yuv2rgb,, a32, PIX_FMT_RGB32, 1)
  973. #endif
  974. YUV2RGBWRAPPER(yuv2rgb,, x32_1, PIX_FMT_RGB32_1, 0)
  975. YUV2RGBWRAPPER(yuv2rgb,, x32, PIX_FMT_RGB32, 0)
  976. #endif
  977. YUV2RGBWRAPPER(yuv2, rgb, rgb24, PIX_FMT_RGB24, 0)
  978. YUV2RGBWRAPPER(yuv2, rgb, bgr24, PIX_FMT_BGR24, 0)
  979. YUV2RGBWRAPPER(yuv2rgb,, 16, PIX_FMT_RGB565, 0)
  980. YUV2RGBWRAPPER(yuv2rgb,, 15, PIX_FMT_RGB555, 0)
  981. YUV2RGBWRAPPER(yuv2rgb,, 12, PIX_FMT_RGB444, 0)
  982. YUV2RGBWRAPPER(yuv2rgb,, 8, PIX_FMT_RGB8, 0)
  983. YUV2RGBWRAPPER(yuv2rgb,, 4, PIX_FMT_RGB4, 0)
  984. YUV2RGBWRAPPER(yuv2rgb,, 4b, PIX_FMT_RGB4_BYTE, 0)
  985. static av_always_inline void
  986. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  987. const int16_t **lumSrc, int lumFilterSize,
  988. const int16_t *chrFilter, const int16_t **chrUSrc,
  989. const int16_t **chrVSrc, int chrFilterSize,
  990. const int16_t **alpSrc, uint8_t *dest,
  991. int dstW, int y, enum PixelFormat target, int hasAlpha)
  992. {
  993. int i;
  994. int step = (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) ? 3 : 4;
  995. for (i = 0; i < dstW; i++) {
  996. int j;
  997. int Y = 0;
  998. int U = -128 << 19;
  999. int V = -128 << 19;
  1000. int R, G, B, A;
  1001. for (j = 0; j < lumFilterSize; j++) {
  1002. Y += lumSrc[j][i] * lumFilter[j];
  1003. }
  1004. for (j = 0; j < chrFilterSize; j++) {
  1005. U += chrUSrc[j][i] * chrFilter[j];
  1006. V += chrVSrc[j][i] * chrFilter[j];
  1007. }
  1008. Y >>= 10;
  1009. U >>= 10;
  1010. V >>= 10;
  1011. if (hasAlpha) {
  1012. A = 1 << 21;
  1013. for (j = 0; j < lumFilterSize; j++) {
  1014. A += alpSrc[j][i] * lumFilter[j];
  1015. }
  1016. A >>= 19;
  1017. if (A & 0x100)
  1018. A = av_clip_uint8(A);
  1019. }
  1020. Y -= c->yuv2rgb_y_offset;
  1021. Y *= c->yuv2rgb_y_coeff;
  1022. Y += 1 << 21;
  1023. R = Y + V*c->yuv2rgb_v2r_coeff;
  1024. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1025. B = Y + U*c->yuv2rgb_u2b_coeff;
  1026. if ((R | G | B) & 0xC0000000) {
  1027. R = av_clip_uintp2(R, 30);
  1028. G = av_clip_uintp2(G, 30);
  1029. B = av_clip_uintp2(B, 30);
  1030. }
  1031. switch(target) {
  1032. case PIX_FMT_ARGB:
  1033. dest[0] = hasAlpha ? A : 255;
  1034. dest[1] = R >> 22;
  1035. dest[2] = G >> 22;
  1036. dest[3] = B >> 22;
  1037. break;
  1038. case PIX_FMT_RGB24:
  1039. dest[0] = R >> 22;
  1040. dest[1] = G >> 22;
  1041. dest[2] = B >> 22;
  1042. break;
  1043. case PIX_FMT_RGBA:
  1044. dest[0] = R >> 22;
  1045. dest[1] = G >> 22;
  1046. dest[2] = B >> 22;
  1047. dest[3] = hasAlpha ? A : 255;
  1048. break;
  1049. case PIX_FMT_ABGR:
  1050. dest[0] = hasAlpha ? A : 255;
  1051. dest[1] = B >> 22;
  1052. dest[2] = G >> 22;
  1053. dest[3] = R >> 22;
  1054. dest += 4;
  1055. break;
  1056. case PIX_FMT_BGR24:
  1057. dest[0] = B >> 22;
  1058. dest[1] = G >> 22;
  1059. dest[2] = R >> 22;
  1060. break;
  1061. case PIX_FMT_BGRA:
  1062. dest[0] = B >> 22;
  1063. dest[1] = G >> 22;
  1064. dest[2] = R >> 22;
  1065. dest[3] = hasAlpha ? A : 255;
  1066. break;
  1067. }
  1068. dest += step;
  1069. }
  1070. }
  1071. #if CONFIG_SMALL
  1072. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1073. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1074. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1075. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1076. #else
  1077. #if CONFIG_SWSCALE_ALPHA
  1078. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA, 1)
  1079. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR, 1)
  1080. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA, 1)
  1081. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB, 1)
  1082. #endif
  1083. YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, PIX_FMT_BGRA, 0)
  1084. YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, PIX_FMT_ABGR, 0)
  1085. YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, PIX_FMT_RGBA, 0)
  1086. YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, PIX_FMT_ARGB, 0)
  1087. #endif
  1088. YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, PIX_FMT_BGR24, 0)
  1089. YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, PIX_FMT_RGB24, 0)
  1090. void ff_sws_init_output_funcs(SwsContext *c,
  1091. yuv2planar1_fn *yuv2plane1,
  1092. yuv2planarX_fn *yuv2planeX,
  1093. yuv2interleavedX_fn *yuv2nv12cX,
  1094. yuv2packed1_fn *yuv2packed1,
  1095. yuv2packed2_fn *yuv2packed2,
  1096. yuv2packedX_fn *yuv2packedX)
  1097. {
  1098. enum PixelFormat dstFormat = c->dstFormat;
  1099. if (is16BPS(dstFormat)) {
  1100. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  1101. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  1102. } else if (is9_OR_10BPS(dstFormat)) {
  1103. if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) {
  1104. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  1105. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  1106. } else {
  1107. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  1108. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  1109. }
  1110. } else {
  1111. *yuv2plane1 = yuv2plane1_8_c;
  1112. *yuv2planeX = yuv2planeX_8_c;
  1113. if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)
  1114. *yuv2nv12cX = yuv2nv12cX_c;
  1115. }
  1116. if(c->flags & SWS_FULL_CHR_H_INT) {
  1117. switch (dstFormat) {
  1118. case PIX_FMT_RGBA:
  1119. #if CONFIG_SMALL
  1120. *yuv2packedX = yuv2rgba32_full_X_c;
  1121. #else
  1122. #if CONFIG_SWSCALE_ALPHA
  1123. if (c->alpPixBuf) {
  1124. *yuv2packedX = yuv2rgba32_full_X_c;
  1125. } else
  1126. #endif /* CONFIG_SWSCALE_ALPHA */
  1127. {
  1128. *yuv2packedX = yuv2rgbx32_full_X_c;
  1129. }
  1130. #endif /* !CONFIG_SMALL */
  1131. break;
  1132. case PIX_FMT_ARGB:
  1133. #if CONFIG_SMALL
  1134. *yuv2packedX = yuv2argb32_full_X_c;
  1135. #else
  1136. #if CONFIG_SWSCALE_ALPHA
  1137. if (c->alpPixBuf) {
  1138. *yuv2packedX = yuv2argb32_full_X_c;
  1139. } else
  1140. #endif /* CONFIG_SWSCALE_ALPHA */
  1141. {
  1142. *yuv2packedX = yuv2xrgb32_full_X_c;
  1143. }
  1144. #endif /* !CONFIG_SMALL */
  1145. break;
  1146. case PIX_FMT_BGRA:
  1147. #if CONFIG_SMALL
  1148. *yuv2packedX = yuv2bgra32_full_X_c;
  1149. #else
  1150. #if CONFIG_SWSCALE_ALPHA
  1151. if (c->alpPixBuf) {
  1152. *yuv2packedX = yuv2bgra32_full_X_c;
  1153. } else
  1154. #endif /* CONFIG_SWSCALE_ALPHA */
  1155. {
  1156. *yuv2packedX = yuv2bgrx32_full_X_c;
  1157. }
  1158. #endif /* !CONFIG_SMALL */
  1159. break;
  1160. case PIX_FMT_ABGR:
  1161. #if CONFIG_SMALL
  1162. *yuv2packedX = yuv2abgr32_full_X_c;
  1163. #else
  1164. #if CONFIG_SWSCALE_ALPHA
  1165. if (c->alpPixBuf) {
  1166. *yuv2packedX = yuv2abgr32_full_X_c;
  1167. } else
  1168. #endif /* CONFIG_SWSCALE_ALPHA */
  1169. {
  1170. *yuv2packedX = yuv2xbgr32_full_X_c;
  1171. }
  1172. #endif /* !CONFIG_SMALL */
  1173. break;
  1174. case PIX_FMT_RGB24:
  1175. *yuv2packedX = yuv2rgb24_full_X_c;
  1176. break;
  1177. case PIX_FMT_BGR24:
  1178. *yuv2packedX = yuv2bgr24_full_X_c;
  1179. break;
  1180. }
  1181. } else {
  1182. switch (dstFormat) {
  1183. case PIX_FMT_RGB48LE:
  1184. *yuv2packed1 = yuv2rgb48le_1_c;
  1185. *yuv2packed2 = yuv2rgb48le_2_c;
  1186. *yuv2packedX = yuv2rgb48le_X_c;
  1187. break;
  1188. case PIX_FMT_RGB48BE:
  1189. *yuv2packed1 = yuv2rgb48be_1_c;
  1190. *yuv2packed2 = yuv2rgb48be_2_c;
  1191. *yuv2packedX = yuv2rgb48be_X_c;
  1192. break;
  1193. case PIX_FMT_BGR48LE:
  1194. *yuv2packed1 = yuv2bgr48le_1_c;
  1195. *yuv2packed2 = yuv2bgr48le_2_c;
  1196. *yuv2packedX = yuv2bgr48le_X_c;
  1197. break;
  1198. case PIX_FMT_BGR48BE:
  1199. *yuv2packed1 = yuv2bgr48be_1_c;
  1200. *yuv2packed2 = yuv2bgr48be_2_c;
  1201. *yuv2packedX = yuv2bgr48be_X_c;
  1202. break;
  1203. case PIX_FMT_RGB32:
  1204. case PIX_FMT_BGR32:
  1205. #if CONFIG_SMALL
  1206. *yuv2packed1 = yuv2rgb32_1_c;
  1207. *yuv2packed2 = yuv2rgb32_2_c;
  1208. *yuv2packedX = yuv2rgb32_X_c;
  1209. #else
  1210. #if CONFIG_SWSCALE_ALPHA
  1211. if (c->alpPixBuf) {
  1212. *yuv2packed1 = yuv2rgba32_1_c;
  1213. *yuv2packed2 = yuv2rgba32_2_c;
  1214. *yuv2packedX = yuv2rgba32_X_c;
  1215. } else
  1216. #endif /* CONFIG_SWSCALE_ALPHA */
  1217. {
  1218. *yuv2packed1 = yuv2rgbx32_1_c;
  1219. *yuv2packed2 = yuv2rgbx32_2_c;
  1220. *yuv2packedX = yuv2rgbx32_X_c;
  1221. }
  1222. #endif /* !CONFIG_SMALL */
  1223. break;
  1224. case PIX_FMT_RGB32_1:
  1225. case PIX_FMT_BGR32_1:
  1226. #if CONFIG_SMALL
  1227. *yuv2packed1 = yuv2rgb32_1_1_c;
  1228. *yuv2packed2 = yuv2rgb32_1_2_c;
  1229. *yuv2packedX = yuv2rgb32_1_X_c;
  1230. #else
  1231. #if CONFIG_SWSCALE_ALPHA
  1232. if (c->alpPixBuf) {
  1233. *yuv2packed1 = yuv2rgba32_1_1_c;
  1234. *yuv2packed2 = yuv2rgba32_1_2_c;
  1235. *yuv2packedX = yuv2rgba32_1_X_c;
  1236. } else
  1237. #endif /* CONFIG_SWSCALE_ALPHA */
  1238. {
  1239. *yuv2packed1 = yuv2rgbx32_1_1_c;
  1240. *yuv2packed2 = yuv2rgbx32_1_2_c;
  1241. *yuv2packedX = yuv2rgbx32_1_X_c;
  1242. }
  1243. #endif /* !CONFIG_SMALL */
  1244. break;
  1245. case PIX_FMT_RGB24:
  1246. *yuv2packed1 = yuv2rgb24_1_c;
  1247. *yuv2packed2 = yuv2rgb24_2_c;
  1248. *yuv2packedX = yuv2rgb24_X_c;
  1249. break;
  1250. case PIX_FMT_BGR24:
  1251. *yuv2packed1 = yuv2bgr24_1_c;
  1252. *yuv2packed2 = yuv2bgr24_2_c;
  1253. *yuv2packedX = yuv2bgr24_X_c;
  1254. break;
  1255. case PIX_FMT_RGB565LE:
  1256. case PIX_FMT_RGB565BE:
  1257. case PIX_FMT_BGR565LE:
  1258. case PIX_FMT_BGR565BE:
  1259. *yuv2packed1 = yuv2rgb16_1_c;
  1260. *yuv2packed2 = yuv2rgb16_2_c;
  1261. *yuv2packedX = yuv2rgb16_X_c;
  1262. break;
  1263. case PIX_FMT_RGB555LE:
  1264. case PIX_FMT_RGB555BE:
  1265. case PIX_FMT_BGR555LE:
  1266. case PIX_FMT_BGR555BE:
  1267. *yuv2packed1 = yuv2rgb15_1_c;
  1268. *yuv2packed2 = yuv2rgb15_2_c;
  1269. *yuv2packedX = yuv2rgb15_X_c;
  1270. break;
  1271. case PIX_FMT_RGB444LE:
  1272. case PIX_FMT_RGB444BE:
  1273. case PIX_FMT_BGR444LE:
  1274. case PIX_FMT_BGR444BE:
  1275. *yuv2packed1 = yuv2rgb12_1_c;
  1276. *yuv2packed2 = yuv2rgb12_2_c;
  1277. *yuv2packedX = yuv2rgb12_X_c;
  1278. break;
  1279. case PIX_FMT_RGB8:
  1280. case PIX_FMT_BGR8:
  1281. *yuv2packed1 = yuv2rgb8_1_c;
  1282. *yuv2packed2 = yuv2rgb8_2_c;
  1283. *yuv2packedX = yuv2rgb8_X_c;
  1284. break;
  1285. case PIX_FMT_RGB4:
  1286. case PIX_FMT_BGR4:
  1287. *yuv2packed1 = yuv2rgb4_1_c;
  1288. *yuv2packed2 = yuv2rgb4_2_c;
  1289. *yuv2packedX = yuv2rgb4_X_c;
  1290. break;
  1291. case PIX_FMT_RGB4_BYTE:
  1292. case PIX_FMT_BGR4_BYTE:
  1293. *yuv2packed1 = yuv2rgb4b_1_c;
  1294. *yuv2packed2 = yuv2rgb4b_2_c;
  1295. *yuv2packedX = yuv2rgb4b_X_c;
  1296. break;
  1297. }
  1298. }
  1299. switch (dstFormat) {
  1300. case PIX_FMT_MONOWHITE:
  1301. *yuv2packed1 = yuv2monowhite_1_c;
  1302. *yuv2packed2 = yuv2monowhite_2_c;
  1303. *yuv2packedX = yuv2monowhite_X_c;
  1304. break;
  1305. case PIX_FMT_MONOBLACK:
  1306. *yuv2packed1 = yuv2monoblack_1_c;
  1307. *yuv2packed2 = yuv2monoblack_2_c;
  1308. *yuv2packedX = yuv2monoblack_X_c;
  1309. break;
  1310. case PIX_FMT_YUYV422:
  1311. *yuv2packed1 = yuv2yuyv422_1_c;
  1312. *yuv2packed2 = yuv2yuyv422_2_c;
  1313. *yuv2packedX = yuv2yuyv422_X_c;
  1314. break;
  1315. case PIX_FMT_UYVY422:
  1316. *yuv2packed1 = yuv2uyvy422_1_c;
  1317. *yuv2packed2 = yuv2uyvy422_2_c;
  1318. *yuv2packedX = yuv2uyvy422_X_c;
  1319. break;
  1320. }
  1321. }