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.

1497 lines
54KB

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