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.

1525 lines
55KB

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