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.

1451 lines
53KB

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