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.

1456 lines
54KB

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