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.

1604 lines
57KB

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