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.

1619 lines
58KB

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