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.

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