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.

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