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.

1435 lines
53KB

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