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.

1524 lines
56KB

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