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.

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