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.

2514 lines
92KB

  1. /*
  2. * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <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/avassert.h"
  27. #include "libavutil/bswap.h"
  28. #include "libavutil/cpu.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "libavutil/mathematics.h"
  31. #include "libavutil/pixdesc.h"
  32. #include "config.h"
  33. #include "rgb2rgb.h"
  34. #include "swscale.h"
  35. #include "swscale_internal.h"
  36. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
  37. { 1, 3, 1, 3, 1, 3, 1, 3, },
  38. { 2, 0, 2, 0, 2, 0, 2, 0, },
  39. { 1, 3, 1, 3, 1, 3, 1, 3, },
  40. };
  41. DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
  42. { 6, 2, 6, 2, 6, 2, 6, 2, },
  43. { 0, 4, 0, 4, 0, 4, 0, 4, },
  44. { 6, 2, 6, 2, 6, 2, 6, 2, },
  45. };
  46. DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
  47. { 8, 4, 11, 7, 8, 4, 11, 7, },
  48. { 2, 14, 1, 13, 2, 14, 1, 13, },
  49. { 10, 6, 9, 5, 10, 6, 9, 5, },
  50. { 0, 12, 3, 15, 0, 12, 3, 15, },
  51. { 8, 4, 11, 7, 8, 4, 11, 7, },
  52. };
  53. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
  54. { 17, 9, 23, 15, 16, 8, 22, 14, },
  55. { 5, 29, 3, 27, 4, 28, 2, 26, },
  56. { 21, 13, 19, 11, 20, 12, 18, 10, },
  57. { 0, 24, 6, 30, 1, 25, 7, 31, },
  58. { 16, 8, 22, 14, 17, 9, 23, 15, },
  59. { 4, 28, 2, 26, 5, 29, 3, 27, },
  60. { 20, 12, 18, 10, 21, 13, 19, 11, },
  61. { 1, 25, 7, 31, 0, 24, 6, 30, },
  62. { 17, 9, 23, 15, 16, 8, 22, 14, },
  63. };
  64. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
  65. { 0, 55, 14, 68, 3, 58, 17, 72, },
  66. { 37, 18, 50, 32, 40, 22, 54, 35, },
  67. { 9, 64, 5, 59, 13, 67, 8, 63, },
  68. { 46, 27, 41, 23, 49, 31, 44, 26, },
  69. { 2, 57, 16, 71, 1, 56, 15, 70, },
  70. { 39, 21, 52, 34, 38, 19, 51, 33, },
  71. { 11, 66, 7, 62, 10, 65, 6, 60, },
  72. { 48, 30, 43, 25, 47, 29, 42, 24, },
  73. { 0, 55, 14, 68, 3, 58, 17, 72, },
  74. };
  75. #if 1
  76. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  77. {117, 62, 158, 103, 113, 58, 155, 100, },
  78. { 34, 199, 21, 186, 31, 196, 17, 182, },
  79. {144, 89, 131, 76, 141, 86, 127, 72, },
  80. { 0, 165, 41, 206, 10, 175, 52, 217, },
  81. {110, 55, 151, 96, 120, 65, 162, 107, },
  82. { 28, 193, 14, 179, 38, 203, 24, 189, },
  83. {138, 83, 124, 69, 148, 93, 134, 79, },
  84. { 7, 172, 48, 213, 3, 168, 45, 210, },
  85. {117, 62, 158, 103, 113, 58, 155, 100, },
  86. };
  87. #elif 1
  88. // tries to correct a gamma of 1.5
  89. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  90. { 0, 143, 18, 200, 2, 156, 25, 215, },
  91. { 78, 28, 125, 64, 89, 36, 138, 74, },
  92. { 10, 180, 3, 161, 16, 195, 8, 175, },
  93. {109, 51, 93, 38, 121, 60, 105, 47, },
  94. { 1, 152, 23, 210, 0, 147, 20, 205, },
  95. { 85, 33, 134, 71, 81, 30, 130, 67, },
  96. { 14, 190, 6, 171, 12, 185, 5, 166, },
  97. {117, 57, 101, 44, 113, 54, 97, 41, },
  98. { 0, 143, 18, 200, 2, 156, 25, 215, },
  99. };
  100. #elif 1
  101. // tries to correct a gamma of 2.0
  102. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  103. { 0, 124, 8, 193, 0, 140, 12, 213, },
  104. { 55, 14, 104, 42, 66, 19, 119, 52, },
  105. { 3, 168, 1, 145, 6, 187, 3, 162, },
  106. { 86, 31, 70, 21, 99, 39, 82, 28, },
  107. { 0, 134, 11, 206, 0, 129, 9, 200, },
  108. { 62, 17, 114, 48, 58, 16, 109, 45, },
  109. { 5, 181, 2, 157, 4, 175, 1, 151, },
  110. { 95, 36, 78, 26, 90, 34, 74, 24, },
  111. { 0, 124, 8, 193, 0, 140, 12, 213, },
  112. };
  113. #else
  114. // tries to correct a gamma of 2.5
  115. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
  116. { 0, 107, 3, 187, 0, 125, 6, 212, },
  117. { 39, 7, 86, 28, 49, 11, 102, 36, },
  118. { 1, 158, 0, 131, 3, 180, 1, 151, },
  119. { 68, 19, 52, 12, 81, 25, 64, 17, },
  120. { 0, 119, 5, 203, 0, 113, 4, 195, },
  121. { 45, 9, 96, 33, 42, 8, 91, 30, },
  122. { 2, 172, 1, 144, 2, 165, 0, 137, },
  123. { 77, 23, 60, 15, 72, 21, 56, 14, },
  124. { 0, 107, 3, 187, 0, 125, 6, 212, },
  125. };
  126. #endif
  127. #define output_pixel(pos, val, bias, signedness) \
  128. if (big_endian) { \
  129. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  130. } else { \
  131. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  132. }
  133. static av_always_inline void
  134. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  135. int big_endian, int output_bits)
  136. {
  137. int i;
  138. int shift = 3;
  139. av_assert0(output_bits == 16);
  140. for (i = 0; i < dstW; i++) {
  141. int val = src[i] + (1 << (shift - 1));
  142. output_pixel(&dest[i], val, 0, uint);
  143. }
  144. }
  145. static av_always_inline void
  146. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  147. const int32_t **src, uint16_t *dest, int dstW,
  148. int big_endian, int output_bits)
  149. {
  150. int i;
  151. int shift = 15;
  152. av_assert0(output_bits == 16);
  153. for (i = 0; i < dstW; i++) {
  154. int val = 1 << (shift - 1);
  155. int j;
  156. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  157. * filters (or anything with negative coeffs, the range can be slightly
  158. * wider in both directions. To account for this overflow, we subtract
  159. * a constant so it always fits in the signed range (assuming a
  160. * reasonable filterSize), and re-add that at the end. */
  161. val -= 0x40000000;
  162. for (j = 0; j < filterSize; j++)
  163. val += src[j][i] * (unsigned)filter[j];
  164. output_pixel(&dest[i], val, 0x8000, int);
  165. }
  166. }
  167. #undef output_pixel
  168. #define output_pixel(pos, val) \
  169. if (big_endian) { \
  170. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  171. } else { \
  172. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  173. }
  174. static av_always_inline void
  175. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  176. int big_endian, int output_bits)
  177. {
  178. int i;
  179. int shift = 15 - output_bits;
  180. for (i = 0; i < dstW; i++) {
  181. int val = src[i] + (1 << (shift - 1));
  182. output_pixel(&dest[i], val);
  183. }
  184. }
  185. static av_always_inline void
  186. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  187. const int16_t **src, uint16_t *dest, int dstW,
  188. int big_endian, int output_bits)
  189. {
  190. int i;
  191. int shift = 11 + 16 - output_bits;
  192. for (i = 0; i < dstW; i++) {
  193. int val = 1 << (shift - 1);
  194. int j;
  195. for (j = 0; j < filterSize; j++)
  196. val += src[j][i] * filter[j];
  197. output_pixel(&dest[i], val);
  198. }
  199. }
  200. #undef output_pixel
  201. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  202. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  203. uint8_t *dest, int dstW, \
  204. const uint8_t *dither, int offset)\
  205. { \
  206. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  207. (uint16_t *) dest, dstW, is_be, bits); \
  208. }\
  209. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  210. const int16_t **src, uint8_t *dest, int dstW, \
  211. const uint8_t *dither, int offset)\
  212. { \
  213. yuv2planeX_## template_size ## _c_template(filter, \
  214. filterSize, (const typeX_t **) src, \
  215. (uint16_t *) dest, dstW, is_be, bits); \
  216. }
  217. yuv2NBPS( 9, BE, 1, 10, int16_t)
  218. yuv2NBPS( 9, LE, 0, 10, int16_t)
  219. yuv2NBPS(10, BE, 1, 10, int16_t)
  220. yuv2NBPS(10, LE, 0, 10, int16_t)
  221. yuv2NBPS(12, BE, 1, 10, int16_t)
  222. yuv2NBPS(12, LE, 0, 10, int16_t)
  223. yuv2NBPS(14, BE, 1, 10, int16_t)
  224. yuv2NBPS(14, LE, 0, 10, int16_t)
  225. yuv2NBPS(16, BE, 1, 16, int32_t)
  226. yuv2NBPS(16, LE, 0, 16, int32_t)
  227. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  228. 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 = dither[(i + offset) & 7] << 12;
  234. int j;
  235. for (j=0; j<filterSize; j++)
  236. val += src[j][i] * filter[j];
  237. dest[i]= av_clip_uint8(val>>19);
  238. }
  239. }
  240. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  241. const uint8_t *dither, int offset)
  242. {
  243. int i;
  244. for (i=0; i<dstW; i++) {
  245. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  246. dest[i]= av_clip_uint8(val);
  247. }
  248. }
  249. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  250. const int16_t **chrUSrc, const int16_t **chrVSrc,
  251. uint8_t *dest, int chrDstW)
  252. {
  253. enum AVPixelFormat dstFormat = c->dstFormat;
  254. const uint8_t *chrDither = c->chrDither8;
  255. int i;
  256. if (dstFormat == AV_PIX_FMT_NV12)
  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(u>>19);
  266. dest[2*i+1]= av_clip_uint8(v>>19);
  267. }
  268. else
  269. for (i=0; i<chrDstW; i++) {
  270. int u = chrDither[i & 7] << 12;
  271. int v = chrDither[(i + 3) & 7] << 12;
  272. int j;
  273. for (j=0; j<chrFilterSize; j++) {
  274. u += chrUSrc[j][i] * chrFilter[j];
  275. v += chrVSrc[j][i] * chrFilter[j];
  276. }
  277. dest[2*i]= av_clip_uint8(v>>19);
  278. dest[2*i+1]= av_clip_uint8(u>>19);
  279. }
  280. }
  281. #define accumulate_bit(acc, val) \
  282. acc <<= 1; \
  283. acc |= (val) >= (128 + 110)
  284. #define output_pixel(pos, acc) \
  285. if (target == AV_PIX_FMT_MONOBLACK) { \
  286. pos = acc; \
  287. } else { \
  288. pos = ~acc; \
  289. }
  290. static av_always_inline void
  291. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  292. const int16_t **lumSrc, int lumFilterSize,
  293. const int16_t *chrFilter, const int16_t **chrUSrc,
  294. const int16_t **chrVSrc, int chrFilterSize,
  295. const int16_t **alpSrc, uint8_t *dest, int dstW,
  296. int y, enum AVPixelFormat target)
  297. {
  298. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  299. int i;
  300. unsigned acc = 0;
  301. int err = 0;
  302. for (i = 0; i < dstW; i += 2) {
  303. int j;
  304. int Y1 = 1 << 18;
  305. int Y2 = 1 << 18;
  306. for (j = 0; j < lumFilterSize; j++) {
  307. Y1 += lumSrc[j][i] * lumFilter[j];
  308. Y2 += lumSrc[j][i+1] * lumFilter[j];
  309. }
  310. Y1 >>= 19;
  311. Y2 >>= 19;
  312. if ((Y1 | Y2) & 0x100) {
  313. Y1 = av_clip_uint8(Y1);
  314. Y2 = av_clip_uint8(Y2);
  315. }
  316. if (c->dither == SWS_DITHER_ED) {
  317. Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  318. c->dither_error[0][i] = err;
  319. acc = 2*acc + (Y1 >= 128);
  320. Y1 -= 220*(acc&1);
  321. err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
  322. c->dither_error[0][i+1] = Y1;
  323. acc = 2*acc + (err >= 128);
  324. err -= 220*(acc&1);
  325. } else {
  326. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  327. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  328. }
  329. if ((i & 7) == 6) {
  330. output_pixel(*dest++, acc);
  331. }
  332. }
  333. c->dither_error[0][i] = err;
  334. if (i & 6) {
  335. output_pixel(*dest, acc);
  336. }
  337. }
  338. static av_always_inline void
  339. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  340. const int16_t *ubuf[2], const int16_t *vbuf[2],
  341. const int16_t *abuf[2], uint8_t *dest, int dstW,
  342. int yalpha, int uvalpha, int y,
  343. enum AVPixelFormat target)
  344. {
  345. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  346. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  347. int yalpha1 = 4096 - yalpha;
  348. int i;
  349. if (c->dither == SWS_DITHER_ED) {
  350. int err = 0;
  351. int acc = 0;
  352. for (i = 0; i < dstW; i +=2) {
  353. int Y;
  354. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  355. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  356. c->dither_error[0][i] = err;
  357. acc = 2*acc + (Y >= 128);
  358. Y -= 220*(acc&1);
  359. err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  360. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  361. c->dither_error[0][i+1] = Y;
  362. acc = 2*acc + (err >= 128);
  363. err -= 220*(acc&1);
  364. if ((i & 7) == 6)
  365. output_pixel(*dest++, acc);
  366. }
  367. c->dither_error[0][i] = err;
  368. } else {
  369. for (i = 0; i < dstW; i += 8) {
  370. int Y, acc = 0;
  371. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  372. accumulate_bit(acc, Y + d128[0]);
  373. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  374. accumulate_bit(acc, Y + d128[1]);
  375. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  376. accumulate_bit(acc, Y + d128[2]);
  377. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  378. accumulate_bit(acc, Y + d128[3]);
  379. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  380. accumulate_bit(acc, Y + d128[4]);
  381. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  382. accumulate_bit(acc, Y + d128[5]);
  383. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  384. accumulate_bit(acc, Y + d128[6]);
  385. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  386. accumulate_bit(acc, Y + d128[7]);
  387. output_pixel(*dest++, acc);
  388. }
  389. }
  390. }
  391. static av_always_inline void
  392. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  393. const int16_t *ubuf[2], const int16_t *vbuf[2],
  394. const int16_t *abuf0, uint8_t *dest, int dstW,
  395. int uvalpha, int y, enum AVPixelFormat target)
  396. {
  397. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  398. int i;
  399. if (c->dither == SWS_DITHER_ED) {
  400. int err = 0;
  401. int acc = 0;
  402. for (i = 0; i < dstW; i +=2) {
  403. int Y;
  404. Y = ((buf0[i + 0] + 64) >> 7);
  405. Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
  406. c->dither_error[0][i] = err;
  407. acc = 2*acc + (Y >= 128);
  408. Y -= 220*(acc&1);
  409. err = ((buf0[i + 1] + 64) >> 7);
  410. err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
  411. c->dither_error[0][i+1] = Y;
  412. acc = 2*acc + (err >= 128);
  413. err -= 220*(acc&1);
  414. if ((i & 7) == 6)
  415. output_pixel(*dest++, acc);
  416. }
  417. c->dither_error[0][i] = err;
  418. } else {
  419. for (i = 0; i < dstW; i += 8) {
  420. int acc = 0;
  421. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  422. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  423. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  424. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  425. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  426. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  427. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  428. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  429. output_pixel(*dest++, acc);
  430. }
  431. }
  432. }
  433. #undef output_pixel
  434. #undef accumulate_bit
  435. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  436. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  437. const int16_t **lumSrc, int lumFilterSize, \
  438. const int16_t *chrFilter, const int16_t **chrUSrc, \
  439. const int16_t **chrVSrc, int chrFilterSize, \
  440. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  441. int y) \
  442. { \
  443. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  444. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  445. alpSrc, dest, dstW, y, fmt); \
  446. } \
  447. \
  448. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  449. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  450. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  451. int yalpha, int uvalpha, int y) \
  452. { \
  453. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  454. dest, dstW, yalpha, uvalpha, y, fmt); \
  455. } \
  456. \
  457. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  458. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  459. const int16_t *abuf0, uint8_t *dest, int dstW, \
  460. int uvalpha, int y) \
  461. { \
  462. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  463. abuf0, dest, dstW, uvalpha, \
  464. y, fmt); \
  465. }
  466. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  467. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  468. #define output_pixels(pos, Y1, U, Y2, V) \
  469. if (target == AV_PIX_FMT_YUYV422) { \
  470. dest[pos + 0] = Y1; \
  471. dest[pos + 1] = U; \
  472. dest[pos + 2] = Y2; \
  473. dest[pos + 3] = V; \
  474. } else if (target == AV_PIX_FMT_YVYU422) { \
  475. dest[pos + 0] = Y1; \
  476. dest[pos + 1] = V; \
  477. dest[pos + 2] = Y2; \
  478. dest[pos + 3] = U; \
  479. } else { /* AV_PIX_FMT_UYVY422 */ \
  480. dest[pos + 0] = U; \
  481. dest[pos + 1] = Y1; \
  482. dest[pos + 2] = V; \
  483. dest[pos + 3] = Y2; \
  484. }
  485. static av_always_inline void
  486. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  487. const int16_t **lumSrc, int lumFilterSize,
  488. const int16_t *chrFilter, const int16_t **chrUSrc,
  489. const int16_t **chrVSrc, int chrFilterSize,
  490. const int16_t **alpSrc, uint8_t *dest, int dstW,
  491. int y, enum AVPixelFormat target)
  492. {
  493. int i;
  494. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  495. int j;
  496. int Y1 = 1 << 18;
  497. int Y2 = 1 << 18;
  498. int U = 1 << 18;
  499. int V = 1 << 18;
  500. for (j = 0; j < lumFilterSize; j++) {
  501. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  502. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  503. }
  504. for (j = 0; j < chrFilterSize; j++) {
  505. U += chrUSrc[j][i] * chrFilter[j];
  506. V += chrVSrc[j][i] * chrFilter[j];
  507. }
  508. Y1 >>= 19;
  509. Y2 >>= 19;
  510. U >>= 19;
  511. V >>= 19;
  512. if ((Y1 | Y2 | U | V) & 0x100) {
  513. Y1 = av_clip_uint8(Y1);
  514. Y2 = av_clip_uint8(Y2);
  515. U = av_clip_uint8(U);
  516. V = av_clip_uint8(V);
  517. }
  518. output_pixels(4*i, Y1, U, Y2, V);
  519. }
  520. }
  521. static av_always_inline void
  522. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  523. const int16_t *ubuf[2], const int16_t *vbuf[2],
  524. const int16_t *abuf[2], uint8_t *dest, int dstW,
  525. int yalpha, int uvalpha, int y,
  526. enum AVPixelFormat target)
  527. {
  528. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  529. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  530. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  531. int yalpha1 = 4096 - yalpha;
  532. int uvalpha1 = 4096 - uvalpha;
  533. int i;
  534. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  535. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  536. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  537. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  538. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  539. if ((Y1 | Y2 | U | V) & 0x100) {
  540. Y1 = av_clip_uint8(Y1);
  541. Y2 = av_clip_uint8(Y2);
  542. U = av_clip_uint8(U);
  543. V = av_clip_uint8(V);
  544. }
  545. output_pixels(i * 4, Y1, U, Y2, V);
  546. }
  547. }
  548. static av_always_inline void
  549. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  550. const int16_t *ubuf[2], const int16_t *vbuf[2],
  551. const int16_t *abuf0, uint8_t *dest, int dstW,
  552. int uvalpha, int y, enum AVPixelFormat target)
  553. {
  554. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  555. int i;
  556. if (uvalpha < 2048) {
  557. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  558. int Y1 = (buf0[i * 2 ]+64) >> 7;
  559. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  560. int U = (ubuf0[i] +64) >> 7;
  561. int V = (vbuf0[i] +64) >> 7;
  562. if ((Y1 | Y2 | U | V) & 0x100) {
  563. Y1 = av_clip_uint8(Y1);
  564. Y2 = av_clip_uint8(Y2);
  565. U = av_clip_uint8(U);
  566. V = av_clip_uint8(V);
  567. }
  568. Y1 = av_clip_uint8(Y1);
  569. Y2 = av_clip_uint8(Y2);
  570. U = av_clip_uint8(U);
  571. V = av_clip_uint8(V);
  572. output_pixels(i * 4, Y1, U, Y2, V);
  573. }
  574. } else {
  575. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  576. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  577. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  578. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  579. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  580. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  581. if ((Y1 | Y2 | U | V) & 0x100) {
  582. Y1 = av_clip_uint8(Y1);
  583. Y2 = av_clip_uint8(Y2);
  584. U = av_clip_uint8(U);
  585. V = av_clip_uint8(V);
  586. }
  587. Y1 = av_clip_uint8(Y1);
  588. Y2 = av_clip_uint8(Y2);
  589. U = av_clip_uint8(U);
  590. V = av_clip_uint8(V);
  591. output_pixels(i * 4, Y1, U, Y2, V);
  592. }
  593. }
  594. }
  595. #undef output_pixels
  596. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  597. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  598. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  599. #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
  600. #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
  601. #define output_pixel(pos, val) \
  602. if (isBE(target)) { \
  603. AV_WB16(pos, val); \
  604. } else { \
  605. AV_WL16(pos, val); \
  606. }
  607. static av_always_inline void
  608. yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
  609. const int32_t **lumSrc, int lumFilterSize,
  610. const int16_t *chrFilter, const int32_t **chrUSrc,
  611. const int32_t **chrVSrc, int chrFilterSize,
  612. const int32_t **alpSrc, uint16_t *dest, int dstW,
  613. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  614. {
  615. int i;
  616. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  617. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  618. int j;
  619. int Y1 = -0x40000000;
  620. int Y2 = -0x40000000;
  621. int U = -(128 << 23); // 19
  622. int V = -(128 << 23);
  623. int R, G, B;
  624. for (j = 0; j < lumFilterSize; j++) {
  625. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  626. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  627. }
  628. for (j = 0; j < chrFilterSize; j++) {;
  629. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  630. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  631. }
  632. if (hasAlpha) {
  633. A1 = -0x40000000;
  634. A2 = -0x40000000;
  635. for (j = 0; j < lumFilterSize; j++) {
  636. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  637. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  638. }
  639. A1 >>= 1;
  640. A1 += 0x20002000;
  641. A2 >>= 1;
  642. A2 += 0x20002000;
  643. }
  644. // 8bit: 12+15=27; 16-bit: 12+19=31
  645. Y1 >>= 14; // 10
  646. Y1 += 0x10000;
  647. Y2 >>= 14;
  648. Y2 += 0x10000;
  649. U >>= 14;
  650. V >>= 14;
  651. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  652. Y1 -= c->yuv2rgb_y_offset;
  653. Y2 -= c->yuv2rgb_y_offset;
  654. Y1 *= c->yuv2rgb_y_coeff;
  655. Y2 *= c->yuv2rgb_y_coeff;
  656. Y1 += 1 << 13; // 21
  657. Y2 += 1 << 13;
  658. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  659. R = V * c->yuv2rgb_v2r_coeff;
  660. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  661. B = U * c->yuv2rgb_u2b_coeff;
  662. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  663. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  664. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  665. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  666. if (eightbytes) {
  667. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  668. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  669. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  670. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  671. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  672. dest += 8;
  673. } else {
  674. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  675. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  676. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  677. dest += 6;
  678. }
  679. }
  680. }
  681. static av_always_inline void
  682. yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
  683. const int32_t *ubuf[2], const int32_t *vbuf[2],
  684. const int32_t *abuf[2], uint16_t *dest, int dstW,
  685. int yalpha, int uvalpha, int y,
  686. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  687. {
  688. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  689. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  690. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  691. *abuf0 = hasAlpha ? abuf[0] : NULL,
  692. *abuf1 = hasAlpha ? abuf[1] : NULL;
  693. int yalpha1 = 4096 - yalpha;
  694. int uvalpha1 = 4096 - uvalpha;
  695. int i;
  696. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  697. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  698. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  699. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  700. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  701. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  702. int R, G, B;
  703. Y1 -= c->yuv2rgb_y_offset;
  704. Y2 -= c->yuv2rgb_y_offset;
  705. Y1 *= c->yuv2rgb_y_coeff;
  706. Y2 *= c->yuv2rgb_y_coeff;
  707. Y1 += 1 << 13;
  708. Y2 += 1 << 13;
  709. R = V * c->yuv2rgb_v2r_coeff;
  710. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  711. B = U * c->yuv2rgb_u2b_coeff;
  712. if (hasAlpha) {
  713. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  714. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  715. A1 += 1 << 13;
  716. A2 += 1 << 13;
  717. }
  718. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  719. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  720. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  721. if (eightbytes) {
  722. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  723. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  724. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  725. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  726. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  727. dest += 8;
  728. } else {
  729. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  730. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  731. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  732. dest += 6;
  733. }
  734. }
  735. }
  736. static av_always_inline void
  737. yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
  738. const int32_t *ubuf[2], const int32_t *vbuf[2],
  739. const int32_t *abuf0, uint16_t *dest, int dstW,
  740. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  741. {
  742. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  743. int i;
  744. int A1 = 0xffff<<14, A2= 0xffff<<14;
  745. if (uvalpha < 2048) {
  746. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  747. int Y1 = (buf0[i * 2] ) >> 2;
  748. int Y2 = (buf0[i * 2 + 1]) >> 2;
  749. int U = (ubuf0[i] - (128 << 11)) >> 2;
  750. int V = (vbuf0[i] - (128 << 11)) >> 2;
  751. int R, G, B;
  752. Y1 -= c->yuv2rgb_y_offset;
  753. Y2 -= c->yuv2rgb_y_offset;
  754. Y1 *= c->yuv2rgb_y_coeff;
  755. Y2 *= c->yuv2rgb_y_coeff;
  756. Y1 += 1 << 13;
  757. Y2 += 1 << 13;
  758. if (hasAlpha) {
  759. A1 = abuf0[i * 2 ] << 11;
  760. A2 = abuf0[i * 2 + 1] << 11;
  761. A1 += 1 << 13;
  762. A2 += 1 << 13;
  763. }
  764. R = V * c->yuv2rgb_v2r_coeff;
  765. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  766. B = U * c->yuv2rgb_u2b_coeff;
  767. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  768. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  769. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  770. if (eightbytes) {
  771. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  772. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  773. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  774. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  775. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  776. dest += 8;
  777. } else {
  778. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  779. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  780. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  781. dest += 6;
  782. }
  783. }
  784. } else {
  785. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  786. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  787. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  788. int Y1 = (buf0[i * 2] ) >> 2;
  789. int Y2 = (buf0[i * 2 + 1]) >> 2;
  790. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  791. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  792. int R, G, B;
  793. Y1 -= c->yuv2rgb_y_offset;
  794. Y2 -= c->yuv2rgb_y_offset;
  795. Y1 *= c->yuv2rgb_y_coeff;
  796. Y2 *= c->yuv2rgb_y_coeff;
  797. Y1 += 1 << 13;
  798. Y2 += 1 << 13;
  799. if (hasAlpha) {
  800. A1 = abuf0[i * 2 ] << 11;
  801. A2 = abuf0[i * 2 + 1] << 11;
  802. A1 += 1 << 13;
  803. A2 += 1 << 13;
  804. }
  805. R = V * c->yuv2rgb_v2r_coeff;
  806. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  807. B = U * c->yuv2rgb_u2b_coeff;
  808. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  809. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  810. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  811. if (eightbytes) {
  812. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  813. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  814. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  815. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  816. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  817. dest += 8;
  818. } else {
  819. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  820. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  821. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  822. dest += 6;
  823. }
  824. }
  825. }
  826. }
  827. static av_always_inline void
  828. yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  829. const int32_t **lumSrc, int lumFilterSize,
  830. const int16_t *chrFilter, const int32_t **chrUSrc,
  831. const int32_t **chrVSrc, int chrFilterSize,
  832. const int32_t **alpSrc, uint16_t *dest, int dstW,
  833. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  834. {
  835. int i;
  836. int A = 0xffff<<14;
  837. for (i = 0; i < dstW; i++) {
  838. int j;
  839. int Y = -0x40000000;
  840. int U = -(128 << 23); // 19
  841. int V = -(128 << 23);
  842. int R, G, B;
  843. for (j = 0; j < lumFilterSize; j++) {
  844. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  845. }
  846. for (j = 0; j < chrFilterSize; j++) {;
  847. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  848. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  849. }
  850. if (hasAlpha) {
  851. A = -0x40000000;
  852. for (j = 0; j < lumFilterSize; j++) {
  853. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  854. }
  855. A >>= 1;
  856. A += 0x20002000;
  857. }
  858. // 8bit: 12+15=27; 16-bit: 12+19=31
  859. Y >>= 14; // 10
  860. Y += 0x10000;
  861. U >>= 14;
  862. V >>= 14;
  863. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  864. Y -= c->yuv2rgb_y_offset;
  865. Y *= c->yuv2rgb_y_coeff;
  866. Y += 1 << 13; // 21
  867. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  868. R = V * c->yuv2rgb_v2r_coeff;
  869. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  870. B = U * c->yuv2rgb_u2b_coeff;
  871. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  872. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  873. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  874. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  875. if (eightbytes) {
  876. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  877. dest += 4;
  878. } else {
  879. dest += 3;
  880. }
  881. }
  882. }
  883. static av_always_inline void
  884. yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
  885. const int32_t *ubuf[2], const int32_t *vbuf[2],
  886. const int32_t *abuf[2], uint16_t *dest, int dstW,
  887. int yalpha, int uvalpha, int y,
  888. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  889. {
  890. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  891. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  892. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  893. *abuf0 = hasAlpha ? abuf[0] : NULL,
  894. *abuf1 = hasAlpha ? abuf[1] : NULL;
  895. int yalpha1 = 4096 - yalpha;
  896. int uvalpha1 = 4096 - uvalpha;
  897. int i;
  898. int A = 0xffff<<14;
  899. for (i = 0; i < dstW; i++) {
  900. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  901. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  902. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  903. int R, G, B;
  904. Y -= c->yuv2rgb_y_offset;
  905. Y *= c->yuv2rgb_y_coeff;
  906. Y += 1 << 13;
  907. R = V * c->yuv2rgb_v2r_coeff;
  908. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  909. B = U * c->yuv2rgb_u2b_coeff;
  910. if (hasAlpha) {
  911. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  912. A += 1 << 13;
  913. }
  914. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  915. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  916. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  917. if (eightbytes) {
  918. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  919. dest += 4;
  920. } else {
  921. dest += 3;
  922. }
  923. }
  924. }
  925. static av_always_inline void
  926. yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
  927. const int32_t *ubuf[2], const int32_t *vbuf[2],
  928. const int32_t *abuf0, uint16_t *dest, int dstW,
  929. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  930. {
  931. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  932. int i;
  933. int A = 0xffff<<14;
  934. if (uvalpha < 2048) {
  935. for (i = 0; i < dstW; i++) {
  936. int Y = (buf0[i]) >> 2;
  937. int U = (ubuf0[i] - (128 << 11)) >> 2;
  938. int V = (vbuf0[i] - (128 << 11)) >> 2;
  939. int R, G, B;
  940. Y -= c->yuv2rgb_y_offset;
  941. Y *= c->yuv2rgb_y_coeff;
  942. Y += 1 << 13;
  943. if (hasAlpha) {
  944. A = abuf0[i] << 11;
  945. A += 1 << 13;
  946. }
  947. R = V * c->yuv2rgb_v2r_coeff;
  948. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  949. B = U * c->yuv2rgb_u2b_coeff;
  950. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  951. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  952. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  953. if (eightbytes) {
  954. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  955. dest += 4;
  956. } else {
  957. dest += 3;
  958. }
  959. }
  960. } else {
  961. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  962. int A = 0xffff<<14;
  963. for (i = 0; i < dstW; i++) {
  964. int Y = (buf0[i] ) >> 2;
  965. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  966. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  967. int R, G, B;
  968. Y -= c->yuv2rgb_y_offset;
  969. Y *= c->yuv2rgb_y_coeff;
  970. Y += 1 << 13;
  971. if (hasAlpha) {
  972. A = abuf0[i] << 11;
  973. A += 1 << 13;
  974. }
  975. R = V * c->yuv2rgb_v2r_coeff;
  976. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  977. B = U * c->yuv2rgb_u2b_coeff;
  978. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  979. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  980. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  981. if (eightbytes) {
  982. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  983. dest += 4;
  984. } else {
  985. dest += 3;
  986. }
  987. }
  988. }
  989. }
  990. #undef output_pixel
  991. #undef r_b
  992. #undef b_r
  993. #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
  994. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  995. const int16_t **_lumSrc, int lumFilterSize, \
  996. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  997. const int16_t **_chrVSrc, int chrFilterSize, \
  998. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  999. int y) \
  1000. { \
  1001. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1002. **chrUSrc = (const int32_t **) _chrUSrc, \
  1003. **chrVSrc = (const int32_t **) _chrVSrc, \
  1004. **alpSrc = (const int32_t **) _alpSrc; \
  1005. uint16_t *dest = (uint16_t *) _dest; \
  1006. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1007. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1008. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
  1009. } \
  1010. \
  1011. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  1012. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1013. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1014. int yalpha, int uvalpha, int y) \
  1015. { \
  1016. const int32_t **buf = (const int32_t **) _buf, \
  1017. **ubuf = (const int32_t **) _ubuf, \
  1018. **vbuf = (const int32_t **) _vbuf, \
  1019. **abuf = (const int32_t **) _abuf; \
  1020. uint16_t *dest = (uint16_t *) _dest; \
  1021. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1022. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1023. } \
  1024. \
  1025. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  1026. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1027. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1028. int uvalpha, int y) \
  1029. { \
  1030. const int32_t *buf0 = (const int32_t *) _buf0, \
  1031. **ubuf = (const int32_t **) _ubuf, \
  1032. **vbuf = (const int32_t **) _vbuf, \
  1033. *abuf0 = (const int32_t *) _abuf0; \
  1034. uint16_t *dest = (uint16_t *) _dest; \
  1035. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1036. dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1037. }
  1038. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
  1039. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
  1040. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
  1041. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
  1042. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
  1043. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
  1044. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
  1045. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
  1046. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
  1047. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
  1048. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
  1049. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
  1050. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
  1051. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
  1052. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
  1053. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
  1054. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
  1055. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
  1056. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
  1057. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
  1058. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
  1059. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
  1060. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
  1061. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
  1062. /*
  1063. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1064. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1065. * things like endianness conversion and shifting. The caller takes care of
  1066. * setting the correct offset in these tables from the chroma (U/V) values.
  1067. * This function then uses the luminance (Y1/Y2) values to write out the
  1068. * correct RGB values into the destination buffer.
  1069. */
  1070. static av_always_inline void
  1071. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1072. unsigned A1, unsigned A2,
  1073. const void *_r, const void *_g, const void *_b, int y,
  1074. enum AVPixelFormat target, int hasAlpha)
  1075. {
  1076. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1077. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1078. uint32_t *dest = (uint32_t *) _dest;
  1079. const uint32_t *r = (const uint32_t *) _r;
  1080. const uint32_t *g = (const uint32_t *) _g;
  1081. const uint32_t *b = (const uint32_t *) _b;
  1082. #if CONFIG_SMALL
  1083. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1084. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1085. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1086. #else
  1087. if (hasAlpha) {
  1088. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1089. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1090. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1091. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1092. } else {
  1093. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1094. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1095. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1096. #endif
  1097. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1098. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1099. }
  1100. #endif
  1101. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1102. uint8_t *dest = (uint8_t *) _dest;
  1103. const uint8_t *r = (const uint8_t *) _r;
  1104. const uint8_t *g = (const uint8_t *) _g;
  1105. const uint8_t *b = (const uint8_t *) _b;
  1106. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1107. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1108. dest[i * 6 + 0] = r_b[Y1];
  1109. dest[i * 6 + 1] = g[Y1];
  1110. dest[i * 6 + 2] = b_r[Y1];
  1111. dest[i * 6 + 3] = r_b[Y2];
  1112. dest[i * 6 + 4] = g[Y2];
  1113. dest[i * 6 + 5] = b_r[Y2];
  1114. #undef r_b
  1115. #undef b_r
  1116. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1117. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1118. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1119. uint16_t *dest = (uint16_t *) _dest;
  1120. const uint16_t *r = (const uint16_t *) _r;
  1121. const uint16_t *g = (const uint16_t *) _g;
  1122. const uint16_t *b = (const uint16_t *) _b;
  1123. int dr1, dg1, db1, dr2, dg2, db2;
  1124. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1125. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1126. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1127. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1128. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1129. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1130. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1131. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1132. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1133. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1134. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1135. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1136. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1137. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1138. } else {
  1139. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1140. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1141. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1142. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1143. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1144. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1145. }
  1146. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1147. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1148. } else /* 8/4-bit */ {
  1149. uint8_t *dest = (uint8_t *) _dest;
  1150. const uint8_t *r = (const uint8_t *) _r;
  1151. const uint8_t *g = (const uint8_t *) _g;
  1152. const uint8_t *b = (const uint8_t *) _b;
  1153. int dr1, dg1, db1, dr2, dg2, db2;
  1154. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1155. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1156. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1157. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1158. db1 = d64[(i * 2 + 0) & 7];
  1159. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1160. db2 = d64[(i * 2 + 1) & 7];
  1161. } else {
  1162. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1163. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1164. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1165. dg1 = d64[(i * 2 + 0) & 7];
  1166. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1167. dg2 = d64[(i * 2 + 1) & 7];
  1168. }
  1169. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1170. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1171. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1172. } else {
  1173. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1174. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1175. }
  1176. }
  1177. }
  1178. static av_always_inline void
  1179. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1180. const int16_t **lumSrc, int lumFilterSize,
  1181. const int16_t *chrFilter, const int16_t **chrUSrc,
  1182. const int16_t **chrVSrc, int chrFilterSize,
  1183. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1184. int y, enum AVPixelFormat target, int hasAlpha)
  1185. {
  1186. int i;
  1187. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1188. int j, A1, A2;
  1189. int Y1 = 1 << 18;
  1190. int Y2 = 1 << 18;
  1191. int U = 1 << 18;
  1192. int V = 1 << 18;
  1193. const void *r, *g, *b;
  1194. for (j = 0; j < lumFilterSize; j++) {
  1195. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1196. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1197. }
  1198. for (j = 0; j < chrFilterSize; j++) {
  1199. U += chrUSrc[j][i] * chrFilter[j];
  1200. V += chrVSrc[j][i] * chrFilter[j];
  1201. }
  1202. Y1 >>= 19;
  1203. Y2 >>= 19;
  1204. U >>= 19;
  1205. V >>= 19;
  1206. if (hasAlpha) {
  1207. A1 = 1 << 18;
  1208. A2 = 1 << 18;
  1209. for (j = 0; j < lumFilterSize; j++) {
  1210. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1211. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1212. }
  1213. A1 >>= 19;
  1214. A2 >>= 19;
  1215. if ((A1 | A2) & 0x100) {
  1216. A1 = av_clip_uint8(A1);
  1217. A2 = av_clip_uint8(A2);
  1218. }
  1219. }
  1220. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1221. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1222. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1223. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1224. r, g, b, y, target, hasAlpha);
  1225. }
  1226. }
  1227. static av_always_inline void
  1228. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  1229. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1230. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1231. int yalpha, int uvalpha, int y,
  1232. enum AVPixelFormat target, int hasAlpha)
  1233. {
  1234. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1235. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1236. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1237. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1238. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1239. int yalpha1 = 4096 - yalpha;
  1240. int uvalpha1 = 4096 - uvalpha;
  1241. int i;
  1242. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1243. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1244. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1245. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1246. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1247. int A1, A2;
  1248. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1249. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1250. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1251. if (hasAlpha) {
  1252. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1253. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1254. A1 = av_clip_uint8(A1);
  1255. A2 = av_clip_uint8(A2);
  1256. }
  1257. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1258. r, g, b, y, target, hasAlpha);
  1259. }
  1260. }
  1261. static av_always_inline void
  1262. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  1263. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1264. const int16_t *abuf0, uint8_t *dest, int dstW,
  1265. int uvalpha, int y, enum AVPixelFormat target,
  1266. int hasAlpha)
  1267. {
  1268. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1269. int i;
  1270. if (uvalpha < 2048) {
  1271. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1272. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1273. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1274. int U = (ubuf0[i] + 64) >> 7;
  1275. int V = (vbuf0[i] + 64) >> 7;
  1276. int A1, A2;
  1277. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1278. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1279. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1280. if (hasAlpha) {
  1281. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1282. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1283. A1 = av_clip_uint8(A1);
  1284. A2 = av_clip_uint8(A2);
  1285. }
  1286. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1287. r, g, b, y, target, hasAlpha);
  1288. }
  1289. } else {
  1290. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1291. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1292. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1293. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1294. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1295. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1296. int A1, A2;
  1297. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1298. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1299. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1300. if (hasAlpha) {
  1301. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1302. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1303. A1 = av_clip_uint8(A1);
  1304. A2 = av_clip_uint8(A2);
  1305. }
  1306. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1307. r, g, b, y, target, hasAlpha);
  1308. }
  1309. }
  1310. }
  1311. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1312. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1313. const int16_t **lumSrc, int lumFilterSize, \
  1314. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1315. const int16_t **chrVSrc, int chrFilterSize, \
  1316. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1317. int y) \
  1318. { \
  1319. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1320. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1321. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1322. }
  1323. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1324. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1325. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1326. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1327. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1328. int yalpha, int uvalpha, int y) \
  1329. { \
  1330. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1331. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1332. }
  1333. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1334. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1335. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1336. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1337. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1338. int uvalpha, int y) \
  1339. { \
  1340. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1341. dstW, uvalpha, y, fmt, hasAlpha); \
  1342. }
  1343. #if CONFIG_SMALL
  1344. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1345. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1346. #else
  1347. #if CONFIG_SWSCALE_ALPHA
  1348. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1349. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1350. #endif
  1351. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1352. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1353. #endif
  1354. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1355. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1356. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1357. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1358. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1359. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1360. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1361. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1362. static av_always_inline void yuv2rgb_write_full(SwsContext *c,
  1363. uint8_t *dest, int i, int Y, int A, int U, int V,
  1364. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1365. {
  1366. int R, G, B;
  1367. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1368. Y -= c->yuv2rgb_y_offset;
  1369. Y *= c->yuv2rgb_y_coeff;
  1370. Y += 1 << 21;
  1371. R = Y + V*c->yuv2rgb_v2r_coeff;
  1372. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1373. B = Y + U*c->yuv2rgb_u2b_coeff;
  1374. if ((R | G | B) & 0xC0000000) {
  1375. R = av_clip_uintp2(R, 30);
  1376. G = av_clip_uintp2(G, 30);
  1377. B = av_clip_uintp2(B, 30);
  1378. }
  1379. switch(target) {
  1380. case AV_PIX_FMT_ARGB:
  1381. dest[0] = hasAlpha ? A : 255;
  1382. dest[1] = R >> 22;
  1383. dest[2] = G >> 22;
  1384. dest[3] = B >> 22;
  1385. break;
  1386. case AV_PIX_FMT_RGB24:
  1387. dest[0] = R >> 22;
  1388. dest[1] = G >> 22;
  1389. dest[2] = B >> 22;
  1390. break;
  1391. case AV_PIX_FMT_RGBA:
  1392. dest[0] = R >> 22;
  1393. dest[1] = G >> 22;
  1394. dest[2] = B >> 22;
  1395. dest[3] = hasAlpha ? A : 255;
  1396. break;
  1397. case AV_PIX_FMT_ABGR:
  1398. dest[0] = hasAlpha ? A : 255;
  1399. dest[1] = B >> 22;
  1400. dest[2] = G >> 22;
  1401. dest[3] = R >> 22;
  1402. break;
  1403. case AV_PIX_FMT_BGR24:
  1404. dest[0] = B >> 22;
  1405. dest[1] = G >> 22;
  1406. dest[2] = R >> 22;
  1407. break;
  1408. case AV_PIX_FMT_BGRA:
  1409. dest[0] = B >> 22;
  1410. dest[1] = G >> 22;
  1411. dest[2] = R >> 22;
  1412. dest[3] = hasAlpha ? A : 255;
  1413. break;
  1414. case AV_PIX_FMT_BGR4_BYTE:
  1415. case AV_PIX_FMT_RGB4_BYTE:
  1416. case AV_PIX_FMT_BGR8:
  1417. case AV_PIX_FMT_RGB8:
  1418. {
  1419. int r,g,b;
  1420. switch (c->dither) {
  1421. default:
  1422. case SWS_DITHER_AUTO:
  1423. case SWS_DITHER_ED:
  1424. R >>= 22;
  1425. G >>= 22;
  1426. B >>= 22;
  1427. R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
  1428. G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
  1429. B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
  1430. c->dither_error[0][i] = err[0];
  1431. c->dither_error[1][i] = err[1];
  1432. c->dither_error[2][i] = err[2];
  1433. r = R >> (isrgb8 ? 5 : 7);
  1434. g = G >> (isrgb8 ? 5 : 6);
  1435. b = B >> (isrgb8 ? 6 : 7);
  1436. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1437. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1438. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1439. err[0] = R - r*(isrgb8 ? 36 : 255);
  1440. err[1] = G - g*(isrgb8 ? 36 : 85);
  1441. err[2] = B - b*(isrgb8 ? 85 : 255);
  1442. break;
  1443. case SWS_DITHER_A_DITHER:
  1444. if (isrgb8) {
  1445. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1446. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1447. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1448. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1449. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1450. r = av_clip_uintp2(r, 3);
  1451. g = av_clip_uintp2(g, 3);
  1452. b = av_clip_uintp2(b, 2);
  1453. } else {
  1454. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1455. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1456. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1457. r = av_clip_uintp2(r, 1);
  1458. g = av_clip_uintp2(g, 2);
  1459. b = av_clip_uintp2(b, 1);
  1460. }
  1461. break;
  1462. case SWS_DITHER_X_DITHER:
  1463. if (isrgb8) {
  1464. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1465. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1466. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1467. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1468. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1469. r = av_clip_uintp2(r, 3);
  1470. g = av_clip_uintp2(g, 3);
  1471. b = av_clip_uintp2(b, 2);
  1472. } else {
  1473. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1474. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1475. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1476. r = av_clip_uintp2(r, 1);
  1477. g = av_clip_uintp2(g, 2);
  1478. b = av_clip_uintp2(b, 1);
  1479. }
  1480. break;
  1481. }
  1482. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1483. dest[0] = r + 2*g + 8*b;
  1484. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1485. dest[0] = b + 2*g + 8*r;
  1486. } else if(target == AV_PIX_FMT_BGR8) {
  1487. dest[0] = r + 8*g + 64*b;
  1488. } else if(target == AV_PIX_FMT_RGB8) {
  1489. dest[0] = b + 4*g + 32*r;
  1490. } else
  1491. av_assert2(0);
  1492. break;}
  1493. }
  1494. }
  1495. static av_always_inline void
  1496. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1497. const int16_t **lumSrc, int lumFilterSize,
  1498. const int16_t *chrFilter, const int16_t **chrUSrc,
  1499. const int16_t **chrVSrc, int chrFilterSize,
  1500. const int16_t **alpSrc, uint8_t *dest,
  1501. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1502. {
  1503. int i;
  1504. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1505. int err[4] = {0};
  1506. int A = 0; //init to silence warning
  1507. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1508. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1509. step = 1;
  1510. for (i = 0; i < dstW; i++) {
  1511. int j;
  1512. int Y = 1<<9;
  1513. int U = (1<<9)-(128 << 19);
  1514. int V = (1<<9)-(128 << 19);
  1515. for (j = 0; j < lumFilterSize; j++) {
  1516. Y += lumSrc[j][i] * lumFilter[j];
  1517. }
  1518. for (j = 0; j < chrFilterSize; j++) {
  1519. U += chrUSrc[j][i] * chrFilter[j];
  1520. V += chrVSrc[j][i] * chrFilter[j];
  1521. }
  1522. Y >>= 10;
  1523. U >>= 10;
  1524. V >>= 10;
  1525. if (hasAlpha) {
  1526. A = 1 << 18;
  1527. for (j = 0; j < lumFilterSize; j++) {
  1528. A += alpSrc[j][i] * lumFilter[j];
  1529. }
  1530. A >>= 19;
  1531. if (A & 0x100)
  1532. A = av_clip_uint8(A);
  1533. }
  1534. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1535. dest += step;
  1536. }
  1537. c->dither_error[0][i] = err[0];
  1538. c->dither_error[1][i] = err[1];
  1539. c->dither_error[2][i] = err[2];
  1540. }
  1541. static av_always_inline void
  1542. yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
  1543. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1544. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1545. int yalpha, int uvalpha, int y,
  1546. enum AVPixelFormat target, int hasAlpha)
  1547. {
  1548. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1549. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1550. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1551. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1552. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1553. int yalpha1 = 4096 - yalpha;
  1554. int uvalpha1 = 4096 - uvalpha;
  1555. int i;
  1556. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1557. int err[4] = {0};
  1558. int A = 0; // init to silcene warning
  1559. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1560. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1561. step = 1;
  1562. for (i = 0; i < dstW; i++) {
  1563. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1564. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1565. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1566. if (hasAlpha) {
  1567. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1568. if (A & 0x100)
  1569. A = av_clip_uint8(A);
  1570. }
  1571. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1572. dest += step;
  1573. }
  1574. c->dither_error[0][i] = err[0];
  1575. c->dither_error[1][i] = err[1];
  1576. c->dither_error[2][i] = err[2];
  1577. }
  1578. static av_always_inline void
  1579. yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
  1580. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1581. const int16_t *abuf0, uint8_t *dest, int dstW,
  1582. int uvalpha, int y, enum AVPixelFormat target,
  1583. int hasAlpha)
  1584. {
  1585. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1586. int i;
  1587. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1588. int err[4] = {0};
  1589. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1590. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1591. step = 1;
  1592. if (uvalpha < 2048) {
  1593. int A = 0; //init to silence warning
  1594. for (i = 0; i < dstW; i++) {
  1595. int Y = buf0[i] << 2;
  1596. int U = (ubuf0[i] - (128<<7)) * 4;
  1597. int V = (vbuf0[i] - (128<<7)) * 4;
  1598. if (hasAlpha) {
  1599. A = (abuf0[i] + 64) >> 7;
  1600. if (A & 0x100)
  1601. A = av_clip_uint8(A);
  1602. }
  1603. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1604. dest += step;
  1605. }
  1606. } else {
  1607. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1608. int A = 0; //init to silence warning
  1609. for (i = 0; i < dstW; i++) {
  1610. int Y = buf0[i] << 2;
  1611. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
  1612. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
  1613. if (hasAlpha) {
  1614. A = (abuf0[i] + 64) >> 7;
  1615. if (A & 0x100)
  1616. A = av_clip_uint8(A);
  1617. }
  1618. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1619. dest += step;
  1620. }
  1621. }
  1622. c->dither_error[0][i] = err[0];
  1623. c->dither_error[1][i] = err[1];
  1624. c->dither_error[2][i] = err[2];
  1625. }
  1626. #if CONFIG_SMALL
  1627. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1628. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1629. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1630. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1631. #else
  1632. #if CONFIG_SWSCALE_ALPHA
  1633. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1634. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1635. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1636. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1637. #endif
  1638. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1639. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1640. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1641. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1642. #endif
  1643. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1644. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1645. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  1646. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  1647. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  1648. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  1649. static void
  1650. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1651. const int16_t **lumSrc, int lumFilterSize,
  1652. const int16_t *chrFilter, const int16_t **chrUSrc,
  1653. const int16_t **chrVSrc, int chrFilterSize,
  1654. const int16_t **alpSrc, uint8_t **dest,
  1655. int dstW, int y)
  1656. {
  1657. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1658. int i;
  1659. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  1660. uint16_t **dest16 = (uint16_t**)dest;
  1661. int SH = 22 + 8 - desc->comp[0].depth;
  1662. int A = 0; // init to silence warning
  1663. for (i = 0; i < dstW; i++) {
  1664. int j;
  1665. int Y = 1 << 9;
  1666. int U = (1 << 9) - (128 << 19);
  1667. int V = (1 << 9) - (128 << 19);
  1668. int R, G, B;
  1669. for (j = 0; j < lumFilterSize; j++)
  1670. Y += lumSrc[j][i] * lumFilter[j];
  1671. for (j = 0; j < chrFilterSize; j++) {
  1672. U += chrUSrc[j][i] * chrFilter[j];
  1673. V += chrVSrc[j][i] * chrFilter[j];
  1674. }
  1675. Y >>= 10;
  1676. U >>= 10;
  1677. V >>= 10;
  1678. if (hasAlpha) {
  1679. A = 1 << 18;
  1680. for (j = 0; j < lumFilterSize; j++)
  1681. A += alpSrc[j][i] * lumFilter[j];
  1682. A >>= 19;
  1683. if (A & 0x100)
  1684. A = av_clip_uint8(A);
  1685. }
  1686. Y -= c->yuv2rgb_y_offset;
  1687. Y *= c->yuv2rgb_y_coeff;
  1688. Y += 1 << 21;
  1689. R = Y + V * c->yuv2rgb_v2r_coeff;
  1690. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1691. B = Y + U * c->yuv2rgb_u2b_coeff;
  1692. if ((R | G | B) & 0xC0000000) {
  1693. R = av_clip_uintp2(R, 30);
  1694. G = av_clip_uintp2(G, 30);
  1695. B = av_clip_uintp2(B, 30);
  1696. }
  1697. if (SH != 22) {
  1698. dest16[0][i] = G >> SH;
  1699. dest16[1][i] = B >> SH;
  1700. dest16[2][i] = R >> SH;
  1701. if (hasAlpha)
  1702. dest16[3][i] = A;
  1703. } else {
  1704. dest[0][i] = G >> 22;
  1705. dest[1][i] = B >> 22;
  1706. dest[2][i] = R >> 22;
  1707. if (hasAlpha)
  1708. dest[3][i] = A;
  1709. }
  1710. }
  1711. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1712. for (i = 0; i < dstW; i++) {
  1713. dest16[0][i] = av_bswap16(dest16[0][i]);
  1714. dest16[1][i] = av_bswap16(dest16[1][i]);
  1715. dest16[2][i] = av_bswap16(dest16[2][i]);
  1716. if (hasAlpha)
  1717. dest16[3][i] = av_bswap16(dest16[3][i]);
  1718. }
  1719. }
  1720. }
  1721. static void
  1722. yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
  1723. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1724. const int16_t *abuf0, uint8_t *dest, int dstW,
  1725. int uvalpha, int y)
  1726. {
  1727. int hasAlpha = !!abuf0;
  1728. int i;
  1729. for (i = 0; i < dstW; i++) {
  1730. int Y = (buf0[i] + 64) >> 7;
  1731. int A;
  1732. Y = av_clip_uint8(Y);
  1733. if (hasAlpha) {
  1734. A = (abuf0[i] + 64) >> 7;
  1735. if (A & 0x100)
  1736. A = av_clip_uint8(A);
  1737. }
  1738. dest[i * 2 ] = Y;
  1739. dest[i * 2 + 1] = hasAlpha ? A : 255;
  1740. }
  1741. }
  1742. static void
  1743. yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
  1744. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1745. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1746. int yalpha, int uvalpha, int y)
  1747. {
  1748. int hasAlpha = abuf && abuf[0] && abuf[1];
  1749. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1750. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1751. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1752. int yalpha1 = 4096 - yalpha;
  1753. int i;
  1754. for (i = 0; i < dstW; i++) {
  1755. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  1756. int A;
  1757. Y = av_clip_uint8(Y);
  1758. if (hasAlpha) {
  1759. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  1760. A = av_clip_uint8(A);
  1761. }
  1762. dest[i * 2 ] = Y;
  1763. dest[i * 2 + 1] = hasAlpha ? A : 255;
  1764. }
  1765. }
  1766. static void
  1767. yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
  1768. const int16_t **lumSrc, int lumFilterSize,
  1769. const int16_t *chrFilter, const int16_t **chrUSrc,
  1770. const int16_t **chrVSrc, int chrFilterSize,
  1771. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  1772. {
  1773. int hasAlpha = !!alpSrc;
  1774. int i;
  1775. for (i = 0; i < dstW; i++) {
  1776. int j;
  1777. int Y = 1 << 18, A = 1 << 18;
  1778. for (j = 0; j < lumFilterSize; j++)
  1779. Y += lumSrc[j][i] * lumFilter[j];
  1780. Y >>= 19;
  1781. if (Y & 0x100)
  1782. Y = av_clip_uint8(Y);
  1783. if (hasAlpha) {
  1784. for (j = 0; j < lumFilterSize; j++)
  1785. A += alpSrc[j][i] * lumFilter[j];
  1786. A >>= 19;
  1787. if (A & 0x100)
  1788. A = av_clip_uint8(A);
  1789. }
  1790. dest[2 * i ] = Y;
  1791. dest[2 * i + 1] = hasAlpha ? A : 255;
  1792. }
  1793. }
  1794. static void
  1795. yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
  1796. const int16_t **_lumSrc, int lumFilterSize,
  1797. const int16_t *chrFilter, const int16_t **_chrUSrc,
  1798. const int16_t **_chrVSrc, int chrFilterSize,
  1799. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
  1800. {
  1801. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  1802. **chrUSrc = (const int32_t **) _chrUSrc,
  1803. **chrVSrc = (const int32_t **) _chrVSrc,
  1804. **alpSrc = (const int32_t **) _alpSrc;
  1805. int hasAlpha = !!alpSrc;
  1806. int i;
  1807. for (i = 0; i < dstW; i++) {
  1808. int Y = 1 << 14, U = 1 << 14;
  1809. int V = 1 << 14, A = 1 << 14;
  1810. int j;
  1811. Y -= 0x40000000;
  1812. U -= 0x40000000;
  1813. V -= 0x40000000;
  1814. A -= 0x40000000;
  1815. for (j = 0; j < lumFilterSize; j++)
  1816. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1817. for (j = 0; j < chrFilterSize; j++)
  1818. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1819. for (j = 0; j < chrFilterSize; j++)
  1820. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1821. if (hasAlpha)
  1822. for (j = 0; j < lumFilterSize; j++)
  1823. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1824. Y = 0x8000 + av_clip_int16(Y >> 15);
  1825. U = 0x8000 + av_clip_int16(U >> 15);
  1826. V = 0x8000 + av_clip_int16(V >> 15);
  1827. A = 0x8000 + av_clip_int16(A >> 15);
  1828. AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
  1829. AV_WL16(dest + 8 * i + 2, Y);
  1830. AV_WL16(dest + 8 * i + 4, U);
  1831. AV_WL16(dest + 8 * i + 6, V);
  1832. }
  1833. }
  1834. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  1835. yuv2planar1_fn *yuv2plane1,
  1836. yuv2planarX_fn *yuv2planeX,
  1837. yuv2interleavedX_fn *yuv2nv12cX,
  1838. yuv2packed1_fn *yuv2packed1,
  1839. yuv2packed2_fn *yuv2packed2,
  1840. yuv2packedX_fn *yuv2packedX,
  1841. yuv2anyX_fn *yuv2anyX)
  1842. {
  1843. enum AVPixelFormat dstFormat = c->dstFormat;
  1844. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  1845. if (is16BPS(dstFormat)) {
  1846. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  1847. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  1848. } else if (is9_OR_10BPS(dstFormat)) {
  1849. if (desc->comp[0].depth == 9) {
  1850. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  1851. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  1852. } else if (desc->comp[0].depth == 10) {
  1853. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  1854. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  1855. } else if (desc->comp[0].depth == 12) {
  1856. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  1857. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  1858. } else if (desc->comp[0].depth == 14) {
  1859. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  1860. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  1861. } else
  1862. av_assert0(0);
  1863. } else {
  1864. *yuv2plane1 = yuv2plane1_8_c;
  1865. *yuv2planeX = yuv2planeX_8_c;
  1866. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  1867. *yuv2nv12cX = yuv2nv12cX_c;
  1868. }
  1869. if(c->flags & SWS_FULL_CHR_H_INT) {
  1870. switch (dstFormat) {
  1871. case AV_PIX_FMT_RGBA:
  1872. #if CONFIG_SMALL
  1873. *yuv2packedX = yuv2rgba32_full_X_c;
  1874. *yuv2packed2 = yuv2rgba32_full_2_c;
  1875. *yuv2packed1 = yuv2rgba32_full_1_c;
  1876. #else
  1877. #if CONFIG_SWSCALE_ALPHA
  1878. if (c->alpPixBuf) {
  1879. *yuv2packedX = yuv2rgba32_full_X_c;
  1880. *yuv2packed2 = yuv2rgba32_full_2_c;
  1881. *yuv2packed1 = yuv2rgba32_full_1_c;
  1882. } else
  1883. #endif /* CONFIG_SWSCALE_ALPHA */
  1884. {
  1885. *yuv2packedX = yuv2rgbx32_full_X_c;
  1886. *yuv2packed2 = yuv2rgbx32_full_2_c;
  1887. *yuv2packed1 = yuv2rgbx32_full_1_c;
  1888. }
  1889. #endif /* !CONFIG_SMALL */
  1890. break;
  1891. case AV_PIX_FMT_ARGB:
  1892. #if CONFIG_SMALL
  1893. *yuv2packedX = yuv2argb32_full_X_c;
  1894. *yuv2packed2 = yuv2argb32_full_2_c;
  1895. *yuv2packed1 = yuv2argb32_full_1_c;
  1896. #else
  1897. #if CONFIG_SWSCALE_ALPHA
  1898. if (c->alpPixBuf) {
  1899. *yuv2packedX = yuv2argb32_full_X_c;
  1900. *yuv2packed2 = yuv2argb32_full_2_c;
  1901. *yuv2packed1 = yuv2argb32_full_1_c;
  1902. } else
  1903. #endif /* CONFIG_SWSCALE_ALPHA */
  1904. {
  1905. *yuv2packedX = yuv2xrgb32_full_X_c;
  1906. *yuv2packed2 = yuv2xrgb32_full_2_c;
  1907. *yuv2packed1 = yuv2xrgb32_full_1_c;
  1908. }
  1909. #endif /* !CONFIG_SMALL */
  1910. break;
  1911. case AV_PIX_FMT_BGRA:
  1912. #if CONFIG_SMALL
  1913. *yuv2packedX = yuv2bgra32_full_X_c;
  1914. *yuv2packed2 = yuv2bgra32_full_2_c;
  1915. *yuv2packed1 = yuv2bgra32_full_1_c;
  1916. #else
  1917. #if CONFIG_SWSCALE_ALPHA
  1918. if (c->alpPixBuf) {
  1919. *yuv2packedX = yuv2bgra32_full_X_c;
  1920. *yuv2packed2 = yuv2bgra32_full_2_c;
  1921. *yuv2packed1 = yuv2bgra32_full_1_c;
  1922. } else
  1923. #endif /* CONFIG_SWSCALE_ALPHA */
  1924. {
  1925. *yuv2packedX = yuv2bgrx32_full_X_c;
  1926. *yuv2packed2 = yuv2bgrx32_full_2_c;
  1927. *yuv2packed1 = yuv2bgrx32_full_1_c;
  1928. }
  1929. #endif /* !CONFIG_SMALL */
  1930. break;
  1931. case AV_PIX_FMT_ABGR:
  1932. #if CONFIG_SMALL
  1933. *yuv2packedX = yuv2abgr32_full_X_c;
  1934. *yuv2packed2 = yuv2abgr32_full_2_c;
  1935. *yuv2packed1 = yuv2abgr32_full_1_c;
  1936. #else
  1937. #if CONFIG_SWSCALE_ALPHA
  1938. if (c->alpPixBuf) {
  1939. *yuv2packedX = yuv2abgr32_full_X_c;
  1940. *yuv2packed2 = yuv2abgr32_full_2_c;
  1941. *yuv2packed1 = yuv2abgr32_full_1_c;
  1942. } else
  1943. #endif /* CONFIG_SWSCALE_ALPHA */
  1944. {
  1945. *yuv2packedX = yuv2xbgr32_full_X_c;
  1946. *yuv2packed2 = yuv2xbgr32_full_2_c;
  1947. *yuv2packed1 = yuv2xbgr32_full_1_c;
  1948. }
  1949. #endif /* !CONFIG_SMALL */
  1950. break;
  1951. case AV_PIX_FMT_RGBA64LE:
  1952. #if CONFIG_SWSCALE_ALPHA
  1953. if (c->alpPixBuf) {
  1954. *yuv2packedX = yuv2rgba64le_full_X_c;
  1955. *yuv2packed2 = yuv2rgba64le_full_2_c;
  1956. *yuv2packed1 = yuv2rgba64le_full_1_c;
  1957. } else
  1958. #endif /* CONFIG_SWSCALE_ALPHA */
  1959. {
  1960. *yuv2packedX = yuv2rgbx64le_full_X_c;
  1961. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  1962. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  1963. }
  1964. break;
  1965. case AV_PIX_FMT_RGBA64BE:
  1966. #if CONFIG_SWSCALE_ALPHA
  1967. if (c->alpPixBuf) {
  1968. *yuv2packedX = yuv2rgba64be_full_X_c;
  1969. *yuv2packed2 = yuv2rgba64be_full_2_c;
  1970. *yuv2packed1 = yuv2rgba64be_full_1_c;
  1971. } else
  1972. #endif /* CONFIG_SWSCALE_ALPHA */
  1973. {
  1974. *yuv2packedX = yuv2rgbx64be_full_X_c;
  1975. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  1976. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  1977. }
  1978. break;
  1979. case AV_PIX_FMT_BGRA64LE:
  1980. #if CONFIG_SWSCALE_ALPHA
  1981. if (c->alpPixBuf) {
  1982. *yuv2packedX = yuv2bgra64le_full_X_c;
  1983. *yuv2packed2 = yuv2bgra64le_full_2_c;
  1984. *yuv2packed1 = yuv2bgra64le_full_1_c;
  1985. } else
  1986. #endif /* CONFIG_SWSCALE_ALPHA */
  1987. {
  1988. *yuv2packedX = yuv2bgrx64le_full_X_c;
  1989. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  1990. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  1991. }
  1992. break;
  1993. case AV_PIX_FMT_BGRA64BE:
  1994. #if CONFIG_SWSCALE_ALPHA
  1995. if (c->alpPixBuf) {
  1996. *yuv2packedX = yuv2bgra64be_full_X_c;
  1997. *yuv2packed2 = yuv2bgra64be_full_2_c;
  1998. *yuv2packed1 = yuv2bgra64be_full_1_c;
  1999. } else
  2000. #endif /* CONFIG_SWSCALE_ALPHA */
  2001. {
  2002. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2003. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2004. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2005. }
  2006. break;
  2007. case AV_PIX_FMT_RGB24:
  2008. *yuv2packedX = yuv2rgb24_full_X_c;
  2009. *yuv2packed2 = yuv2rgb24_full_2_c;
  2010. *yuv2packed1 = yuv2rgb24_full_1_c;
  2011. break;
  2012. case AV_PIX_FMT_BGR24:
  2013. *yuv2packedX = yuv2bgr24_full_X_c;
  2014. *yuv2packed2 = yuv2bgr24_full_2_c;
  2015. *yuv2packed1 = yuv2bgr24_full_1_c;
  2016. break;
  2017. case AV_PIX_FMT_RGB48LE:
  2018. *yuv2packedX = yuv2rgb48le_full_X_c;
  2019. *yuv2packed2 = yuv2rgb48le_full_2_c;
  2020. *yuv2packed1 = yuv2rgb48le_full_1_c;
  2021. break;
  2022. case AV_PIX_FMT_BGR48LE:
  2023. *yuv2packedX = yuv2bgr48le_full_X_c;
  2024. *yuv2packed2 = yuv2bgr48le_full_2_c;
  2025. *yuv2packed1 = yuv2bgr48le_full_1_c;
  2026. break;
  2027. case AV_PIX_FMT_RGB48BE:
  2028. *yuv2packedX = yuv2rgb48be_full_X_c;
  2029. *yuv2packed2 = yuv2rgb48be_full_2_c;
  2030. *yuv2packed1 = yuv2rgb48be_full_1_c;
  2031. break;
  2032. case AV_PIX_FMT_BGR48BE:
  2033. *yuv2packedX = yuv2bgr48be_full_X_c;
  2034. *yuv2packed2 = yuv2bgr48be_full_2_c;
  2035. *yuv2packed1 = yuv2bgr48be_full_1_c;
  2036. break;
  2037. case AV_PIX_FMT_BGR4_BYTE:
  2038. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  2039. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  2040. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  2041. break;
  2042. case AV_PIX_FMT_RGB4_BYTE:
  2043. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  2044. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  2045. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  2046. break;
  2047. case AV_PIX_FMT_BGR8:
  2048. *yuv2packedX = yuv2bgr8_full_X_c;
  2049. *yuv2packed2 = yuv2bgr8_full_2_c;
  2050. *yuv2packed1 = yuv2bgr8_full_1_c;
  2051. break;
  2052. case AV_PIX_FMT_RGB8:
  2053. *yuv2packedX = yuv2rgb8_full_X_c;
  2054. *yuv2packed2 = yuv2rgb8_full_2_c;
  2055. *yuv2packed1 = yuv2rgb8_full_1_c;
  2056. break;
  2057. case AV_PIX_FMT_GBRP:
  2058. case AV_PIX_FMT_GBRP9BE:
  2059. case AV_PIX_FMT_GBRP9LE:
  2060. case AV_PIX_FMT_GBRP10BE:
  2061. case AV_PIX_FMT_GBRP10LE:
  2062. case AV_PIX_FMT_GBRP12BE:
  2063. case AV_PIX_FMT_GBRP12LE:
  2064. case AV_PIX_FMT_GBRP14BE:
  2065. case AV_PIX_FMT_GBRP14LE:
  2066. case AV_PIX_FMT_GBRP16BE:
  2067. case AV_PIX_FMT_GBRP16LE:
  2068. case AV_PIX_FMT_GBRAP:
  2069. *yuv2anyX = yuv2gbrp_full_X_c;
  2070. break;
  2071. }
  2072. if (!*yuv2packedX && !*yuv2anyX)
  2073. goto YUV_PACKED;
  2074. } else {
  2075. YUV_PACKED:
  2076. switch (dstFormat) {
  2077. case AV_PIX_FMT_RGBA64LE:
  2078. #if CONFIG_SWSCALE_ALPHA
  2079. if (c->alpPixBuf) {
  2080. *yuv2packed1 = yuv2rgba64le_1_c;
  2081. *yuv2packed2 = yuv2rgba64le_2_c;
  2082. *yuv2packedX = yuv2rgba64le_X_c;
  2083. } else
  2084. #endif /* CONFIG_SWSCALE_ALPHA */
  2085. {
  2086. *yuv2packed1 = yuv2rgbx64le_1_c;
  2087. *yuv2packed2 = yuv2rgbx64le_2_c;
  2088. *yuv2packedX = yuv2rgbx64le_X_c;
  2089. }
  2090. break;
  2091. case AV_PIX_FMT_RGBA64BE:
  2092. #if CONFIG_SWSCALE_ALPHA
  2093. if (c->alpPixBuf) {
  2094. *yuv2packed1 = yuv2rgba64be_1_c;
  2095. *yuv2packed2 = yuv2rgba64be_2_c;
  2096. *yuv2packedX = yuv2rgba64be_X_c;
  2097. } else
  2098. #endif /* CONFIG_SWSCALE_ALPHA */
  2099. {
  2100. *yuv2packed1 = yuv2rgbx64be_1_c;
  2101. *yuv2packed2 = yuv2rgbx64be_2_c;
  2102. *yuv2packedX = yuv2rgbx64be_X_c;
  2103. }
  2104. break;
  2105. case AV_PIX_FMT_BGRA64LE:
  2106. #if CONFIG_SWSCALE_ALPHA
  2107. if (c->alpPixBuf) {
  2108. *yuv2packed1 = yuv2bgra64le_1_c;
  2109. *yuv2packed2 = yuv2bgra64le_2_c;
  2110. *yuv2packedX = yuv2bgra64le_X_c;
  2111. } else
  2112. #endif /* CONFIG_SWSCALE_ALPHA */
  2113. {
  2114. *yuv2packed1 = yuv2bgrx64le_1_c;
  2115. *yuv2packed2 = yuv2bgrx64le_2_c;
  2116. *yuv2packedX = yuv2bgrx64le_X_c;
  2117. }
  2118. break;
  2119. case AV_PIX_FMT_BGRA64BE:
  2120. #if CONFIG_SWSCALE_ALPHA
  2121. if (c->alpPixBuf) {
  2122. *yuv2packed1 = yuv2bgra64be_1_c;
  2123. *yuv2packed2 = yuv2bgra64be_2_c;
  2124. *yuv2packedX = yuv2bgra64be_X_c;
  2125. } else
  2126. #endif /* CONFIG_SWSCALE_ALPHA */
  2127. {
  2128. *yuv2packed1 = yuv2bgrx64be_1_c;
  2129. *yuv2packed2 = yuv2bgrx64be_2_c;
  2130. *yuv2packedX = yuv2bgrx64be_X_c;
  2131. }
  2132. break;
  2133. case AV_PIX_FMT_RGB48LE:
  2134. *yuv2packed1 = yuv2rgb48le_1_c;
  2135. *yuv2packed2 = yuv2rgb48le_2_c;
  2136. *yuv2packedX = yuv2rgb48le_X_c;
  2137. break;
  2138. case AV_PIX_FMT_RGB48BE:
  2139. *yuv2packed1 = yuv2rgb48be_1_c;
  2140. *yuv2packed2 = yuv2rgb48be_2_c;
  2141. *yuv2packedX = yuv2rgb48be_X_c;
  2142. break;
  2143. case AV_PIX_FMT_BGR48LE:
  2144. *yuv2packed1 = yuv2bgr48le_1_c;
  2145. *yuv2packed2 = yuv2bgr48le_2_c;
  2146. *yuv2packedX = yuv2bgr48le_X_c;
  2147. break;
  2148. case AV_PIX_FMT_BGR48BE:
  2149. *yuv2packed1 = yuv2bgr48be_1_c;
  2150. *yuv2packed2 = yuv2bgr48be_2_c;
  2151. *yuv2packedX = yuv2bgr48be_X_c;
  2152. break;
  2153. case AV_PIX_FMT_RGB32:
  2154. case AV_PIX_FMT_BGR32:
  2155. #if CONFIG_SMALL
  2156. *yuv2packed1 = yuv2rgb32_1_c;
  2157. *yuv2packed2 = yuv2rgb32_2_c;
  2158. *yuv2packedX = yuv2rgb32_X_c;
  2159. #else
  2160. #if CONFIG_SWSCALE_ALPHA
  2161. if (c->alpPixBuf) {
  2162. *yuv2packed1 = yuv2rgba32_1_c;
  2163. *yuv2packed2 = yuv2rgba32_2_c;
  2164. *yuv2packedX = yuv2rgba32_X_c;
  2165. } else
  2166. #endif /* CONFIG_SWSCALE_ALPHA */
  2167. {
  2168. *yuv2packed1 = yuv2rgbx32_1_c;
  2169. *yuv2packed2 = yuv2rgbx32_2_c;
  2170. *yuv2packedX = yuv2rgbx32_X_c;
  2171. }
  2172. #endif /* !CONFIG_SMALL */
  2173. break;
  2174. case AV_PIX_FMT_RGB32_1:
  2175. case AV_PIX_FMT_BGR32_1:
  2176. #if CONFIG_SMALL
  2177. *yuv2packed1 = yuv2rgb32_1_1_c;
  2178. *yuv2packed2 = yuv2rgb32_1_2_c;
  2179. *yuv2packedX = yuv2rgb32_1_X_c;
  2180. #else
  2181. #if CONFIG_SWSCALE_ALPHA
  2182. if (c->alpPixBuf) {
  2183. *yuv2packed1 = yuv2rgba32_1_1_c;
  2184. *yuv2packed2 = yuv2rgba32_1_2_c;
  2185. *yuv2packedX = yuv2rgba32_1_X_c;
  2186. } else
  2187. #endif /* CONFIG_SWSCALE_ALPHA */
  2188. {
  2189. *yuv2packed1 = yuv2rgbx32_1_1_c;
  2190. *yuv2packed2 = yuv2rgbx32_1_2_c;
  2191. *yuv2packedX = yuv2rgbx32_1_X_c;
  2192. }
  2193. #endif /* !CONFIG_SMALL */
  2194. break;
  2195. case AV_PIX_FMT_RGB24:
  2196. *yuv2packed1 = yuv2rgb24_1_c;
  2197. *yuv2packed2 = yuv2rgb24_2_c;
  2198. *yuv2packedX = yuv2rgb24_X_c;
  2199. break;
  2200. case AV_PIX_FMT_BGR24:
  2201. *yuv2packed1 = yuv2bgr24_1_c;
  2202. *yuv2packed2 = yuv2bgr24_2_c;
  2203. *yuv2packedX = yuv2bgr24_X_c;
  2204. break;
  2205. case AV_PIX_FMT_RGB565LE:
  2206. case AV_PIX_FMT_RGB565BE:
  2207. case AV_PIX_FMT_BGR565LE:
  2208. case AV_PIX_FMT_BGR565BE:
  2209. *yuv2packed1 = yuv2rgb16_1_c;
  2210. *yuv2packed2 = yuv2rgb16_2_c;
  2211. *yuv2packedX = yuv2rgb16_X_c;
  2212. break;
  2213. case AV_PIX_FMT_RGB555LE:
  2214. case AV_PIX_FMT_RGB555BE:
  2215. case AV_PIX_FMT_BGR555LE:
  2216. case AV_PIX_FMT_BGR555BE:
  2217. *yuv2packed1 = yuv2rgb15_1_c;
  2218. *yuv2packed2 = yuv2rgb15_2_c;
  2219. *yuv2packedX = yuv2rgb15_X_c;
  2220. break;
  2221. case AV_PIX_FMT_RGB444LE:
  2222. case AV_PIX_FMT_RGB444BE:
  2223. case AV_PIX_FMT_BGR444LE:
  2224. case AV_PIX_FMT_BGR444BE:
  2225. *yuv2packed1 = yuv2rgb12_1_c;
  2226. *yuv2packed2 = yuv2rgb12_2_c;
  2227. *yuv2packedX = yuv2rgb12_X_c;
  2228. break;
  2229. case AV_PIX_FMT_RGB8:
  2230. case AV_PIX_FMT_BGR8:
  2231. *yuv2packed1 = yuv2rgb8_1_c;
  2232. *yuv2packed2 = yuv2rgb8_2_c;
  2233. *yuv2packedX = yuv2rgb8_X_c;
  2234. break;
  2235. case AV_PIX_FMT_RGB4:
  2236. case AV_PIX_FMT_BGR4:
  2237. *yuv2packed1 = yuv2rgb4_1_c;
  2238. *yuv2packed2 = yuv2rgb4_2_c;
  2239. *yuv2packedX = yuv2rgb4_X_c;
  2240. break;
  2241. case AV_PIX_FMT_RGB4_BYTE:
  2242. case AV_PIX_FMT_BGR4_BYTE:
  2243. *yuv2packed1 = yuv2rgb4b_1_c;
  2244. *yuv2packed2 = yuv2rgb4b_2_c;
  2245. *yuv2packedX = yuv2rgb4b_X_c;
  2246. break;
  2247. }
  2248. }
  2249. switch (dstFormat) {
  2250. case AV_PIX_FMT_MONOWHITE:
  2251. *yuv2packed1 = yuv2monowhite_1_c;
  2252. *yuv2packed2 = yuv2monowhite_2_c;
  2253. *yuv2packedX = yuv2monowhite_X_c;
  2254. break;
  2255. case AV_PIX_FMT_MONOBLACK:
  2256. *yuv2packed1 = yuv2monoblack_1_c;
  2257. *yuv2packed2 = yuv2monoblack_2_c;
  2258. *yuv2packedX = yuv2monoblack_X_c;
  2259. break;
  2260. case AV_PIX_FMT_YUYV422:
  2261. *yuv2packed1 = yuv2yuyv422_1_c;
  2262. *yuv2packed2 = yuv2yuyv422_2_c;
  2263. *yuv2packedX = yuv2yuyv422_X_c;
  2264. break;
  2265. case AV_PIX_FMT_YVYU422:
  2266. *yuv2packed1 = yuv2yvyu422_1_c;
  2267. *yuv2packed2 = yuv2yvyu422_2_c;
  2268. *yuv2packedX = yuv2yvyu422_X_c;
  2269. break;
  2270. case AV_PIX_FMT_UYVY422:
  2271. *yuv2packed1 = yuv2uyvy422_1_c;
  2272. *yuv2packed2 = yuv2uyvy422_2_c;
  2273. *yuv2packedX = yuv2uyvy422_X_c;
  2274. break;
  2275. case AV_PIX_FMT_YA8:
  2276. *yuv2packed1 = yuv2ya8_1_c;
  2277. *yuv2packed2 = yuv2ya8_2_c;
  2278. *yuv2packedX = yuv2ya8_X_c;
  2279. break;
  2280. case AV_PIX_FMT_AYUV64LE:
  2281. *yuv2packedX = yuv2ayuv64le_X_c;
  2282. break;
  2283. }
  2284. }