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.

2938 lines
105KB

  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. static void yuv2p016cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  168. const int16_t **chrUSrc, const int16_t **chrVSrc,
  169. uint8_t *dest8, int chrDstW)
  170. {
  171. uint16_t *dest = (uint16_t*)dest8;
  172. const int32_t **uSrc = (const int32_t **)chrUSrc;
  173. const int32_t **vSrc = (const int32_t **)chrVSrc;
  174. int shift = 15;
  175. int big_endian = c->dstFormat == AV_PIX_FMT_P016BE;
  176. int i, j;
  177. for (i = 0; i < chrDstW; i++) {
  178. int u = 1 << (shift - 1);
  179. int v = 1 << (shift - 1);
  180. /* See yuv2planeX_16_c_template for details. */
  181. u -= 0x40000000;
  182. v -= 0x40000000;
  183. for (j = 0; j < chrFilterSize; j++) {
  184. u += uSrc[j][i] * (unsigned)chrFilter[j];
  185. v += vSrc[j][i] * (unsigned)chrFilter[j];
  186. }
  187. output_pixel(&dest[2*i] , u, 0x8000, int);
  188. output_pixel(&dest[2*i+1], v, 0x8000, int);
  189. }
  190. }
  191. static av_always_inline void
  192. yuv2plane1_float_c_template(const int32_t *src, float *dest, int dstW)
  193. {
  194. static const int big_endian = HAVE_BIGENDIAN;
  195. static const int shift = 3;
  196. static const float float_mult = 1.0f / 65535.0f;
  197. int i, val;
  198. uint16_t val_uint;
  199. for (i = 0; i < dstW; ++i){
  200. val = src[i] + (1 << (shift - 1));
  201. output_pixel(&val_uint, val, 0, uint);
  202. dest[i] = float_mult * (float)val_uint;
  203. }
  204. }
  205. static av_always_inline void
  206. yuv2plane1_float_bswap_c_template(const int32_t *src, uint32_t *dest, int dstW)
  207. {
  208. static const int big_endian = HAVE_BIGENDIAN;
  209. static const int shift = 3;
  210. static const float float_mult = 1.0f / 65535.0f;
  211. int i, val;
  212. uint16_t val_uint;
  213. for (i = 0; i < dstW; ++i){
  214. val = src[i] + (1 << (shift - 1));
  215. output_pixel(&val_uint, val, 0, uint);
  216. dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
  217. }
  218. }
  219. static av_always_inline void
  220. yuv2planeX_float_c_template(const int16_t *filter, int filterSize, const int32_t **src,
  221. float *dest, int dstW)
  222. {
  223. static const int big_endian = HAVE_BIGENDIAN;
  224. static const int shift = 15;
  225. static const float float_mult = 1.0f / 65535.0f;
  226. int i, j, val;
  227. uint16_t val_uint;
  228. for (i = 0; i < dstW; ++i){
  229. val = (1 << (shift - 1)) - 0x40000000;
  230. for (j = 0; j < filterSize; ++j){
  231. val += src[j][i] * (unsigned)filter[j];
  232. }
  233. output_pixel(&val_uint, val, 0x8000, int);
  234. dest[i] = float_mult * (float)val_uint;
  235. }
  236. }
  237. static av_always_inline void
  238. yuv2planeX_float_bswap_c_template(const int16_t *filter, int filterSize, const int32_t **src,
  239. uint32_t *dest, int dstW)
  240. {
  241. static const int big_endian = HAVE_BIGENDIAN;
  242. static const int shift = 15;
  243. static const float float_mult = 1.0f / 65535.0f;
  244. int i, j, val;
  245. uint16_t val_uint;
  246. for (i = 0; i < dstW; ++i){
  247. val = (1 << (shift - 1)) - 0x40000000;
  248. for (j = 0; j < filterSize; ++j){
  249. val += src[j][i] * (unsigned)filter[j];
  250. }
  251. output_pixel(&val_uint, val, 0x8000, int);
  252. dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint));
  253. }
  254. }
  255. #define yuv2plane1_float(template, dest_type, BE_LE) \
  256. static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
  257. const uint8_t *dither, int offset) \
  258. { \
  259. template((const int32_t *)src, (dest_type *)dest, dstW); \
  260. }
  261. #define yuv2planeX_float(template, dest_type, BE_LE) \
  262. static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  263. const int16_t **src, uint8_t *dest, int dstW, \
  264. const uint8_t *dither, int offset) \
  265. { \
  266. template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
  267. }
  268. #if HAVE_BIGENDIAN
  269. yuv2plane1_float(yuv2plane1_float_c_template, float, BE)
  270. yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, LE)
  271. yuv2planeX_float(yuv2planeX_float_c_template, float, BE)
  272. yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, LE)
  273. #else
  274. yuv2plane1_float(yuv2plane1_float_c_template, float, LE)
  275. yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, BE)
  276. yuv2planeX_float(yuv2planeX_float_c_template, float, LE)
  277. yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, BE)
  278. #endif
  279. #undef output_pixel
  280. #define output_pixel(pos, val) \
  281. if (big_endian) { \
  282. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  283. } else { \
  284. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  285. }
  286. static av_always_inline void
  287. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  288. int big_endian, int output_bits)
  289. {
  290. int i;
  291. int shift = 15 - output_bits;
  292. for (i = 0; i < dstW; i++) {
  293. int val = src[i] + (1 << (shift - 1));
  294. output_pixel(&dest[i], val);
  295. }
  296. }
  297. static av_always_inline void
  298. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  299. const int16_t **src, uint16_t *dest, int dstW,
  300. int big_endian, int output_bits)
  301. {
  302. int i;
  303. int shift = 11 + 16 - output_bits;
  304. for (i = 0; i < dstW; i++) {
  305. int val = 1 << (shift - 1);
  306. int j;
  307. for (j = 0; j < filterSize; j++)
  308. val += src[j][i] * filter[j];
  309. output_pixel(&dest[i], val);
  310. }
  311. }
  312. #undef output_pixel
  313. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  314. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  315. uint8_t *dest, int dstW, \
  316. const uint8_t *dither, int offset)\
  317. { \
  318. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  319. (uint16_t *) dest, dstW, is_be, bits); \
  320. }\
  321. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  322. const int16_t **src, uint8_t *dest, int dstW, \
  323. const uint8_t *dither, int offset)\
  324. { \
  325. yuv2planeX_## template_size ## _c_template(filter, \
  326. filterSize, (const typeX_t **) src, \
  327. (uint16_t *) dest, dstW, is_be, bits); \
  328. }
  329. yuv2NBPS( 9, BE, 1, 10, int16_t)
  330. yuv2NBPS( 9, LE, 0, 10, int16_t)
  331. yuv2NBPS(10, BE, 1, 10, int16_t)
  332. yuv2NBPS(10, LE, 0, 10, int16_t)
  333. yuv2NBPS(12, BE, 1, 10, int16_t)
  334. yuv2NBPS(12, LE, 0, 10, int16_t)
  335. yuv2NBPS(14, BE, 1, 10, int16_t)
  336. yuv2NBPS(14, LE, 0, 10, int16_t)
  337. yuv2NBPS(16, BE, 1, 16, int32_t)
  338. yuv2NBPS(16, LE, 0, 16, int32_t)
  339. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  340. const int16_t **src, uint8_t *dest, int dstW,
  341. const uint8_t *dither, int offset)
  342. {
  343. int i;
  344. for (i=0; i<dstW; i++) {
  345. int val = dither[(i + offset) & 7] << 12;
  346. int j;
  347. for (j=0; j<filterSize; j++)
  348. val += src[j][i] * filter[j];
  349. dest[i]= av_clip_uint8(val>>19);
  350. }
  351. }
  352. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  353. const uint8_t *dither, int offset)
  354. {
  355. int i;
  356. for (i=0; i<dstW; i++) {
  357. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  358. dest[i]= av_clip_uint8(val);
  359. }
  360. }
  361. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  362. const int16_t **chrUSrc, const int16_t **chrVSrc,
  363. uint8_t *dest, int chrDstW)
  364. {
  365. enum AVPixelFormat dstFormat = c->dstFormat;
  366. const uint8_t *chrDither = c->chrDither8;
  367. int i;
  368. if (dstFormat == AV_PIX_FMT_NV12)
  369. for (i=0; i<chrDstW; i++) {
  370. int u = chrDither[i & 7] << 12;
  371. int v = chrDither[(i + 3) & 7] << 12;
  372. int j;
  373. for (j=0; j<chrFilterSize; j++) {
  374. u += chrUSrc[j][i] * chrFilter[j];
  375. v += chrVSrc[j][i] * chrFilter[j];
  376. }
  377. dest[2*i]= av_clip_uint8(u>>19);
  378. dest[2*i+1]= av_clip_uint8(v>>19);
  379. }
  380. else
  381. for (i=0; i<chrDstW; i++) {
  382. int u = chrDither[i & 7] << 12;
  383. int v = chrDither[(i + 3) & 7] << 12;
  384. int j;
  385. for (j=0; j<chrFilterSize; j++) {
  386. u += chrUSrc[j][i] * chrFilter[j];
  387. v += chrVSrc[j][i] * chrFilter[j];
  388. }
  389. dest[2*i]= av_clip_uint8(v>>19);
  390. dest[2*i+1]= av_clip_uint8(u>>19);
  391. }
  392. }
  393. #define output_pixel(pos, val) \
  394. if (big_endian) { \
  395. AV_WB16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
  396. } else { \
  397. AV_WL16(pos, av_clip_uintp2(val >> shift, 10) << 6); \
  398. }
  399. static void yuv2p010l1_c(const int16_t *src,
  400. uint16_t *dest, int dstW,
  401. int big_endian)
  402. {
  403. int i;
  404. int shift = 5;
  405. for (i = 0; i < dstW; i++) {
  406. int val = src[i] + (1 << (shift - 1));
  407. output_pixel(&dest[i], val);
  408. }
  409. }
  410. static void yuv2p010lX_c(const int16_t *filter, int filterSize,
  411. const int16_t **src, uint16_t *dest, int dstW,
  412. int big_endian)
  413. {
  414. int i, j;
  415. int shift = 17;
  416. for (i = 0; i < dstW; i++) {
  417. int val = 1 << (shift - 1);
  418. for (j = 0; j < filterSize; j++)
  419. val += src[j][i] * filter[j];
  420. output_pixel(&dest[i], val);
  421. }
  422. }
  423. static void yuv2p010cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  424. const int16_t **chrUSrc, const int16_t **chrVSrc,
  425. uint8_t *dest8, int chrDstW)
  426. {
  427. uint16_t *dest = (uint16_t*)dest8;
  428. int shift = 17;
  429. int big_endian = c->dstFormat == AV_PIX_FMT_P010BE;
  430. int i, j;
  431. for (i = 0; i < chrDstW; i++) {
  432. int u = 1 << (shift - 1);
  433. int v = 1 << (shift - 1);
  434. for (j = 0; j < chrFilterSize; j++) {
  435. u += chrUSrc[j][i] * chrFilter[j];
  436. v += chrVSrc[j][i] * chrFilter[j];
  437. }
  438. output_pixel(&dest[2*i] , u);
  439. output_pixel(&dest[2*i+1], v);
  440. }
  441. }
  442. static void yuv2p010l1_LE_c(const int16_t *src,
  443. uint8_t *dest, int dstW,
  444. const uint8_t *dither, int offset)
  445. {
  446. yuv2p010l1_c(src, (uint16_t*)dest, dstW, 0);
  447. }
  448. static void yuv2p010l1_BE_c(const int16_t *src,
  449. uint8_t *dest, int dstW,
  450. const uint8_t *dither, int offset)
  451. {
  452. yuv2p010l1_c(src, (uint16_t*)dest, dstW, 1);
  453. }
  454. static void yuv2p010lX_LE_c(const int16_t *filter, int filterSize,
  455. const int16_t **src, uint8_t *dest, int dstW,
  456. const uint8_t *dither, int offset)
  457. {
  458. yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0);
  459. }
  460. static void yuv2p010lX_BE_c(const int16_t *filter, int filterSize,
  461. const int16_t **src, uint8_t *dest, int dstW,
  462. const uint8_t *dither, int offset)
  463. {
  464. yuv2p010lX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1);
  465. }
  466. #undef output_pixel
  467. #define accumulate_bit(acc, val) \
  468. acc <<= 1; \
  469. acc |= (val) >= 234
  470. #define output_pixel(pos, acc) \
  471. if (target == AV_PIX_FMT_MONOBLACK) { \
  472. pos = acc; \
  473. } else { \
  474. pos = ~acc; \
  475. }
  476. static av_always_inline void
  477. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  478. const int16_t **lumSrc, int lumFilterSize,
  479. const int16_t *chrFilter, const int16_t **chrUSrc,
  480. const int16_t **chrVSrc, int chrFilterSize,
  481. const int16_t **alpSrc, uint8_t *dest, int dstW,
  482. int y, enum AVPixelFormat target)
  483. {
  484. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  485. int i;
  486. unsigned acc = 0;
  487. int err = 0;
  488. for (i = 0; i < dstW; i += 2) {
  489. int j;
  490. int Y1 = 1 << 18;
  491. int Y2 = 1 << 18;
  492. for (j = 0; j < lumFilterSize; j++) {
  493. Y1 += lumSrc[j][i] * lumFilter[j];
  494. Y2 += lumSrc[j][i+1] * lumFilter[j];
  495. }
  496. Y1 >>= 19;
  497. Y2 >>= 19;
  498. if ((Y1 | Y2) & 0x100) {
  499. Y1 = av_clip_uint8(Y1);
  500. Y2 = av_clip_uint8(Y2);
  501. }
  502. if (c->dither == SWS_DITHER_ED) {
  503. 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;
  504. c->dither_error[0][i] = err;
  505. acc = 2*acc + (Y1 >= 128);
  506. Y1 -= 220*(acc&1);
  507. 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);
  508. c->dither_error[0][i+1] = Y1;
  509. acc = 2*acc + (err >= 128);
  510. err -= 220*(acc&1);
  511. } else {
  512. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  513. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  514. }
  515. if ((i & 7) == 6) {
  516. output_pixel(*dest++, acc);
  517. }
  518. }
  519. c->dither_error[0][i] = err;
  520. if (i & 6) {
  521. output_pixel(*dest, acc);
  522. }
  523. }
  524. static av_always_inline void
  525. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  526. const int16_t *ubuf[2], const int16_t *vbuf[2],
  527. const int16_t *abuf[2], uint8_t *dest, int dstW,
  528. int yalpha, int uvalpha, int y,
  529. enum AVPixelFormat target)
  530. {
  531. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  532. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  533. int yalpha1 = 4096 - yalpha;
  534. int i;
  535. av_assert2(yalpha <= 4096U);
  536. if (c->dither == SWS_DITHER_ED) {
  537. int err = 0;
  538. int acc = 0;
  539. for (i = 0; i < dstW; i +=2) {
  540. int Y;
  541. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  542. 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;
  543. c->dither_error[0][i] = err;
  544. acc = 2*acc + (Y >= 128);
  545. Y -= 220*(acc&1);
  546. err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  547. 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;
  548. c->dither_error[0][i+1] = Y;
  549. acc = 2*acc + (err >= 128);
  550. err -= 220*(acc&1);
  551. if ((i & 7) == 6)
  552. output_pixel(*dest++, acc);
  553. }
  554. c->dither_error[0][i] = err;
  555. } else {
  556. for (i = 0; i < dstW; i += 8) {
  557. int Y, acc = 0;
  558. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  559. accumulate_bit(acc, Y + d128[0]);
  560. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  561. accumulate_bit(acc, Y + d128[1]);
  562. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  563. accumulate_bit(acc, Y + d128[2]);
  564. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  565. accumulate_bit(acc, Y + d128[3]);
  566. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  567. accumulate_bit(acc, Y + d128[4]);
  568. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  569. accumulate_bit(acc, Y + d128[5]);
  570. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  571. accumulate_bit(acc, Y + d128[6]);
  572. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  573. accumulate_bit(acc, Y + d128[7]);
  574. output_pixel(*dest++, acc);
  575. }
  576. }
  577. }
  578. static av_always_inline void
  579. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  580. const int16_t *ubuf[2], const int16_t *vbuf[2],
  581. const int16_t *abuf0, uint8_t *dest, int dstW,
  582. int uvalpha, int y, enum AVPixelFormat target)
  583. {
  584. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  585. int i;
  586. if (c->dither == SWS_DITHER_ED) {
  587. int err = 0;
  588. int acc = 0;
  589. for (i = 0; i < dstW; i +=2) {
  590. int Y;
  591. Y = ((buf0[i + 0] + 64) >> 7);
  592. 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;
  593. c->dither_error[0][i] = err;
  594. acc = 2*acc + (Y >= 128);
  595. Y -= 220*(acc&1);
  596. err = ((buf0[i + 1] + 64) >> 7);
  597. 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;
  598. c->dither_error[0][i+1] = Y;
  599. acc = 2*acc + (err >= 128);
  600. err -= 220*(acc&1);
  601. if ((i & 7) == 6)
  602. output_pixel(*dest++, acc);
  603. }
  604. c->dither_error[0][i] = err;
  605. } else {
  606. for (i = 0; i < dstW; i += 8) {
  607. int acc = 0;
  608. accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
  609. accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
  610. accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
  611. accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
  612. accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
  613. accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
  614. accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
  615. accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
  616. output_pixel(*dest++, acc);
  617. }
  618. }
  619. }
  620. #undef output_pixel
  621. #undef accumulate_bit
  622. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  623. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  624. const int16_t **lumSrc, int lumFilterSize, \
  625. const int16_t *chrFilter, const int16_t **chrUSrc, \
  626. const int16_t **chrVSrc, int chrFilterSize, \
  627. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  628. int y) \
  629. { \
  630. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  631. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  632. alpSrc, dest, dstW, y, fmt); \
  633. } \
  634. \
  635. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  636. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  637. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  638. int yalpha, int uvalpha, int y) \
  639. { \
  640. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  641. dest, dstW, yalpha, uvalpha, y, fmt); \
  642. } \
  643. \
  644. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  645. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  646. const int16_t *abuf0, uint8_t *dest, int dstW, \
  647. int uvalpha, int y) \
  648. { \
  649. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  650. abuf0, dest, dstW, uvalpha, \
  651. y, fmt); \
  652. }
  653. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  654. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  655. #define output_pixels(pos, Y1, U, Y2, V) \
  656. if (target == AV_PIX_FMT_YUYV422) { \
  657. dest[pos + 0] = Y1; \
  658. dest[pos + 1] = U; \
  659. dest[pos + 2] = Y2; \
  660. dest[pos + 3] = V; \
  661. } else if (target == AV_PIX_FMT_YVYU422) { \
  662. dest[pos + 0] = Y1; \
  663. dest[pos + 1] = V; \
  664. dest[pos + 2] = Y2; \
  665. dest[pos + 3] = U; \
  666. } else { /* AV_PIX_FMT_UYVY422 */ \
  667. dest[pos + 0] = U; \
  668. dest[pos + 1] = Y1; \
  669. dest[pos + 2] = V; \
  670. dest[pos + 3] = Y2; \
  671. }
  672. static av_always_inline void
  673. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  674. const int16_t **lumSrc, int lumFilterSize,
  675. const int16_t *chrFilter, const int16_t **chrUSrc,
  676. const int16_t **chrVSrc, int chrFilterSize,
  677. const int16_t **alpSrc, uint8_t *dest, int dstW,
  678. int y, enum AVPixelFormat target)
  679. {
  680. int i;
  681. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  682. int j;
  683. int Y1 = 1 << 18;
  684. int Y2 = 1 << 18;
  685. int U = 1 << 18;
  686. int V = 1 << 18;
  687. for (j = 0; j < lumFilterSize; j++) {
  688. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  689. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  690. }
  691. for (j = 0; j < chrFilterSize; j++) {
  692. U += chrUSrc[j][i] * chrFilter[j];
  693. V += chrVSrc[j][i] * chrFilter[j];
  694. }
  695. Y1 >>= 19;
  696. Y2 >>= 19;
  697. U >>= 19;
  698. V >>= 19;
  699. if ((Y1 | Y2 | U | V) & 0x100) {
  700. Y1 = av_clip_uint8(Y1);
  701. Y2 = av_clip_uint8(Y2);
  702. U = av_clip_uint8(U);
  703. V = av_clip_uint8(V);
  704. }
  705. output_pixels(4*i, Y1, U, Y2, V);
  706. }
  707. }
  708. static av_always_inline void
  709. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  710. const int16_t *ubuf[2], const int16_t *vbuf[2],
  711. const int16_t *abuf[2], uint8_t *dest, int dstW,
  712. int yalpha, int uvalpha, int y,
  713. enum AVPixelFormat target)
  714. {
  715. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  716. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  717. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  718. int yalpha1 = 4096 - yalpha;
  719. int uvalpha1 = 4096 - uvalpha;
  720. int i;
  721. av_assert2(yalpha <= 4096U);
  722. av_assert2(uvalpha <= 4096U);
  723. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  724. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  725. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  726. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  727. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  728. if ((Y1 | Y2 | U | V) & 0x100) {
  729. Y1 = av_clip_uint8(Y1);
  730. Y2 = av_clip_uint8(Y2);
  731. U = av_clip_uint8(U);
  732. V = av_clip_uint8(V);
  733. }
  734. output_pixels(i * 4, Y1, U, Y2, V);
  735. }
  736. }
  737. static av_always_inline void
  738. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  739. const int16_t *ubuf[2], const int16_t *vbuf[2],
  740. const int16_t *abuf0, uint8_t *dest, int dstW,
  741. int uvalpha, int y, enum AVPixelFormat target)
  742. {
  743. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  744. int i;
  745. if (uvalpha < 2048) {
  746. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  747. int Y1 = (buf0[i * 2 ]+64) >> 7;
  748. int Y2 = (buf0[i * 2 + 1]+64) >> 7;
  749. int U = (ubuf0[i] +64) >> 7;
  750. int V = (vbuf0[i] +64) >> 7;
  751. if ((Y1 | Y2 | U | V) & 0x100) {
  752. Y1 = av_clip_uint8(Y1);
  753. Y2 = av_clip_uint8(Y2);
  754. U = av_clip_uint8(U);
  755. V = av_clip_uint8(V);
  756. }
  757. output_pixels(i * 4, Y1, U, Y2, V);
  758. }
  759. } else {
  760. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  761. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  762. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  763. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  764. int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
  765. int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
  766. if ((Y1 | Y2 | U | V) & 0x100) {
  767. Y1 = av_clip_uint8(Y1);
  768. Y2 = av_clip_uint8(Y2);
  769. U = av_clip_uint8(U);
  770. V = av_clip_uint8(V);
  771. }
  772. output_pixels(i * 4, Y1, U, Y2, V);
  773. }
  774. }
  775. }
  776. #undef output_pixels
  777. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  778. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  779. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  780. #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)
  781. #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)
  782. #define output_pixel(pos, val) \
  783. if (isBE(target)) { \
  784. AV_WB16(pos, val); \
  785. } else { \
  786. AV_WL16(pos, val); \
  787. }
  788. static av_always_inline void
  789. yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter,
  790. const int32_t **lumSrc, int lumFilterSize,
  791. const int16_t *chrFilter, const int32_t **unused_chrUSrc,
  792. const int32_t **unused_chrVSrc, int unused_chrFilterSize,
  793. const int32_t **alpSrc, uint16_t *dest, int dstW,
  794. int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
  795. {
  796. int hasAlpha = !!alpSrc;
  797. int i;
  798. for (i = 0; i < dstW; i++) {
  799. int j;
  800. int Y = 1 << 18;
  801. int64_t A = 0xffff<<14;
  802. for (j = 0; j < lumFilterSize; j++)
  803. Y += lumSrc[j][i] * lumFilter[j];
  804. Y >>= 15;
  805. Y = av_clip_uint16(Y);
  806. if (hasAlpha) {
  807. for (j = 0; j < lumFilterSize; j++)
  808. A += alpSrc[j][i] * lumFilter[j];
  809. A >>= 15;
  810. A = av_clip_uint16(A);
  811. }
  812. output_pixel(&dest[2 * i ], Y);
  813. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  814. }
  815. }
  816. static av_always_inline void
  817. yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2],
  818. const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
  819. const int32_t *abuf[2], uint16_t *dest, int dstW,
  820. int yalpha, int unused_uvalpha, int y,
  821. enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
  822. {
  823. int hasAlpha = abuf && abuf[0] && abuf[1];
  824. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  825. *abuf0 = hasAlpha ? abuf[0] : NULL,
  826. *abuf1 = hasAlpha ? abuf[1] : NULL;
  827. int yalpha1 = 4096 - yalpha;
  828. int i;
  829. av_assert2(yalpha <= 4096U);
  830. for (i = 0; i < dstW; i++) {
  831. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 15;
  832. int A;
  833. Y = av_clip_uint16(Y);
  834. if (hasAlpha) {
  835. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 15;
  836. A = av_clip_uint16(A);
  837. }
  838. output_pixel(&dest[2 * i ], Y);
  839. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  840. }
  841. }
  842. static av_always_inline void
  843. yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0,
  844. const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2],
  845. const int32_t *abuf0, uint16_t *dest, int dstW,
  846. int unused_uvalpha, int y, enum AVPixelFormat target, int unused_hasAlpha, int unused_eightbytes)
  847. {
  848. int hasAlpha = !!abuf0;
  849. int i;
  850. for (i = 0; i < dstW; i++) {
  851. int Y = buf0[i] >> 3;/* 19 - 16 */
  852. int A;
  853. Y = av_clip_uint16(Y);
  854. if (hasAlpha) {
  855. A = abuf0[i] >> 3;
  856. if (A & 0x100)
  857. A = av_clip_uint16(A);
  858. }
  859. output_pixel(&dest[2 * i ], Y);
  860. output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
  861. }
  862. }
  863. static av_always_inline void
  864. yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
  865. const int32_t **lumSrc, int lumFilterSize,
  866. const int16_t *chrFilter, const int32_t **chrUSrc,
  867. const int32_t **chrVSrc, int chrFilterSize,
  868. const int32_t **alpSrc, uint16_t *dest, int dstW,
  869. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  870. {
  871. int i;
  872. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  873. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  874. int j;
  875. int Y1 = -0x40000000;
  876. int Y2 = -0x40000000;
  877. int U = -(128 << 23); // 19
  878. int V = -(128 << 23);
  879. int R, G, B;
  880. for (j = 0; j < lumFilterSize; j++) {
  881. Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
  882. Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  883. }
  884. for (j = 0; j < chrFilterSize; j++) {;
  885. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  886. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  887. }
  888. if (hasAlpha) {
  889. A1 = -0x40000000;
  890. A2 = -0x40000000;
  891. for (j = 0; j < lumFilterSize; j++) {
  892. A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
  893. A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
  894. }
  895. A1 >>= 1;
  896. A1 += 0x20002000;
  897. A2 >>= 1;
  898. A2 += 0x20002000;
  899. }
  900. // 8 bits: 12+15=27; 16 bits: 12+19=31
  901. Y1 >>= 14; // 10
  902. Y1 += 0x10000;
  903. Y2 >>= 14;
  904. Y2 += 0x10000;
  905. U >>= 14;
  906. V >>= 14;
  907. // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
  908. Y1 -= c->yuv2rgb_y_offset;
  909. Y2 -= c->yuv2rgb_y_offset;
  910. Y1 *= c->yuv2rgb_y_coeff;
  911. Y2 *= c->yuv2rgb_y_coeff;
  912. Y1 += 1 << 13; // 21
  913. Y2 += 1 << 13;
  914. // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
  915. R = V * c->yuv2rgb_v2r_coeff;
  916. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  917. B = U * c->yuv2rgb_u2b_coeff;
  918. // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
  919. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  920. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  921. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  922. if (eightbytes) {
  923. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  924. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  925. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  926. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  927. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  928. dest += 8;
  929. } else {
  930. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  931. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  932. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  933. dest += 6;
  934. }
  935. }
  936. }
  937. static av_always_inline void
  938. yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
  939. const int32_t *ubuf[2], const int32_t *vbuf[2],
  940. const int32_t *abuf[2], uint16_t *dest, int dstW,
  941. int yalpha, int uvalpha, int y,
  942. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  943. {
  944. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  945. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  946. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  947. *abuf0 = hasAlpha ? abuf[0] : NULL,
  948. *abuf1 = hasAlpha ? abuf[1] : NULL;
  949. int yalpha1 = 4096 - yalpha;
  950. int uvalpha1 = 4096 - uvalpha;
  951. int i;
  952. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  953. av_assert2(yalpha <= 4096U);
  954. av_assert2(uvalpha <= 4096U);
  955. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  956. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  957. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  958. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  959. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  960. int R, G, B;
  961. Y1 -= c->yuv2rgb_y_offset;
  962. Y2 -= c->yuv2rgb_y_offset;
  963. Y1 *= c->yuv2rgb_y_coeff;
  964. Y2 *= c->yuv2rgb_y_coeff;
  965. Y1 += 1 << 13;
  966. Y2 += 1 << 13;
  967. R = V * c->yuv2rgb_v2r_coeff;
  968. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  969. B = U * c->yuv2rgb_u2b_coeff;
  970. if (hasAlpha) {
  971. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
  972. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
  973. A1 += 1 << 13;
  974. A2 += 1 << 13;
  975. }
  976. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  977. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  978. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  979. if (eightbytes) {
  980. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  981. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  982. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  983. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  984. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  985. dest += 8;
  986. } else {
  987. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  988. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  989. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  990. dest += 6;
  991. }
  992. }
  993. }
  994. static av_always_inline void
  995. yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
  996. const int32_t *ubuf[2], const int32_t *vbuf[2],
  997. const int32_t *abuf0, uint16_t *dest, int dstW,
  998. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  999. {
  1000. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1001. int i;
  1002. int A1 = 0xffff<<14, A2= 0xffff<<14;
  1003. if (uvalpha < 2048) {
  1004. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1005. int Y1 = (buf0[i * 2] ) >> 2;
  1006. int Y2 = (buf0[i * 2 + 1]) >> 2;
  1007. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1008. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1009. int R, G, B;
  1010. Y1 -= c->yuv2rgb_y_offset;
  1011. Y2 -= c->yuv2rgb_y_offset;
  1012. Y1 *= c->yuv2rgb_y_coeff;
  1013. Y2 *= c->yuv2rgb_y_coeff;
  1014. Y1 += 1 << 13;
  1015. Y2 += 1 << 13;
  1016. if (hasAlpha) {
  1017. A1 = abuf0[i * 2 ] << 11;
  1018. A2 = abuf0[i * 2 + 1] << 11;
  1019. A1 += 1 << 13;
  1020. A2 += 1 << 13;
  1021. }
  1022. R = V * c->yuv2rgb_v2r_coeff;
  1023. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1024. B = U * c->yuv2rgb_u2b_coeff;
  1025. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  1026. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  1027. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  1028. if (eightbytes) {
  1029. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1030. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  1031. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  1032. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  1033. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1034. dest += 8;
  1035. } else {
  1036. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  1037. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  1038. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  1039. dest += 6;
  1040. }
  1041. }
  1042. } else {
  1043. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1044. int A1 = 0xffff<<14, A2 = 0xffff<<14;
  1045. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1046. int Y1 = (buf0[i * 2] ) >> 2;
  1047. int Y2 = (buf0[i * 2 + 1]) >> 2;
  1048. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1049. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1050. int R, G, B;
  1051. Y1 -= c->yuv2rgb_y_offset;
  1052. Y2 -= c->yuv2rgb_y_offset;
  1053. Y1 *= c->yuv2rgb_y_coeff;
  1054. Y2 *= c->yuv2rgb_y_coeff;
  1055. Y1 += 1 << 13;
  1056. Y2 += 1 << 13;
  1057. if (hasAlpha) {
  1058. A1 = abuf0[i * 2 ] << 11;
  1059. A2 = abuf0[i * 2 + 1] << 11;
  1060. A1 += 1 << 13;
  1061. A2 += 1 << 13;
  1062. }
  1063. R = V * c->yuv2rgb_v2r_coeff;
  1064. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1065. B = U * c->yuv2rgb_u2b_coeff;
  1066. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  1067. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  1068. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  1069. if (eightbytes) {
  1070. output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
  1071. output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
  1072. output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
  1073. output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
  1074. output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
  1075. dest += 8;
  1076. } else {
  1077. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  1078. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  1079. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  1080. dest += 6;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. static av_always_inline void
  1086. yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1087. const int32_t **lumSrc, int lumFilterSize,
  1088. const int16_t *chrFilter, const int32_t **chrUSrc,
  1089. const int32_t **chrVSrc, int chrFilterSize,
  1090. const int32_t **alpSrc, uint16_t *dest, int dstW,
  1091. int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1092. {
  1093. int i;
  1094. int A = 0xffff<<14;
  1095. for (i = 0; i < dstW; i++) {
  1096. int j;
  1097. int Y = -0x40000000;
  1098. int U = -(128 << 23); // 19
  1099. int V = -(128 << 23);
  1100. int R, G, B;
  1101. for (j = 0; j < lumFilterSize; j++) {
  1102. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  1103. }
  1104. for (j = 0; j < chrFilterSize; j++) {;
  1105. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  1106. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  1107. }
  1108. if (hasAlpha) {
  1109. A = -0x40000000;
  1110. for (j = 0; j < lumFilterSize; j++) {
  1111. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  1112. }
  1113. A >>= 1;
  1114. A += 0x20002000;
  1115. }
  1116. // 8bit: 12+15=27; 16-bit: 12+19=31
  1117. Y >>= 14; // 10
  1118. Y += 0x10000;
  1119. U >>= 14;
  1120. V >>= 14;
  1121. // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
  1122. Y -= c->yuv2rgb_y_offset;
  1123. Y *= c->yuv2rgb_y_coeff;
  1124. Y += 1 << 13; // 21
  1125. // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
  1126. R = V * c->yuv2rgb_v2r_coeff;
  1127. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1128. B = U * c->yuv2rgb_u2b_coeff;
  1129. // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
  1130. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1131. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1132. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1133. if (eightbytes) {
  1134. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1135. dest += 4;
  1136. } else {
  1137. dest += 3;
  1138. }
  1139. }
  1140. }
  1141. static av_always_inline void
  1142. yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
  1143. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1144. const int32_t *abuf[2], uint16_t *dest, int dstW,
  1145. int yalpha, int uvalpha, int y,
  1146. enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1147. {
  1148. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  1149. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1150. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1151. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1152. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1153. int yalpha1 = 4096 - yalpha;
  1154. int uvalpha1 = 4096 - uvalpha;
  1155. int i;
  1156. int A = 0xffff<<14;
  1157. av_assert2(yalpha <= 4096U);
  1158. av_assert2(uvalpha <= 4096U);
  1159. for (i = 0; i < dstW; i++) {
  1160. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14;
  1161. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha - (128 << 23)) >> 14;
  1162. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha - (128 << 23)) >> 14;
  1163. int R, G, B;
  1164. Y -= c->yuv2rgb_y_offset;
  1165. Y *= c->yuv2rgb_y_coeff;
  1166. Y += 1 << 13;
  1167. R = V * c->yuv2rgb_v2r_coeff;
  1168. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1169. B = U * c->yuv2rgb_u2b_coeff;
  1170. if (hasAlpha) {
  1171. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1;
  1172. A += 1 << 13;
  1173. }
  1174. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1175. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1176. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1177. if (eightbytes) {
  1178. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1179. dest += 4;
  1180. } else {
  1181. dest += 3;
  1182. }
  1183. }
  1184. }
  1185. static av_always_inline void
  1186. yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
  1187. const int32_t *ubuf[2], const int32_t *vbuf[2],
  1188. const int32_t *abuf0, uint16_t *dest, int dstW,
  1189. int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)
  1190. {
  1191. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1192. int i;
  1193. int A = 0xffff<<14;
  1194. if (uvalpha < 2048) {
  1195. for (i = 0; i < dstW; i++) {
  1196. int Y = (buf0[i]) >> 2;
  1197. int U = (ubuf0[i] - (128 << 11)) >> 2;
  1198. int V = (vbuf0[i] - (128 << 11)) >> 2;
  1199. int R, G, B;
  1200. Y -= c->yuv2rgb_y_offset;
  1201. Y *= c->yuv2rgb_y_coeff;
  1202. Y += 1 << 13;
  1203. if (hasAlpha) {
  1204. A = abuf0[i] << 11;
  1205. A += 1 << 13;
  1206. }
  1207. R = V * c->yuv2rgb_v2r_coeff;
  1208. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1209. B = U * c->yuv2rgb_u2b_coeff;
  1210. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1211. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1212. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1213. if (eightbytes) {
  1214. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1215. dest += 4;
  1216. } else {
  1217. dest += 3;
  1218. }
  1219. }
  1220. } else {
  1221. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1222. int A = 0xffff<<14;
  1223. for (i = 0; i < dstW; i++) {
  1224. int Y = (buf0[i] ) >> 2;
  1225. int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
  1226. int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
  1227. int R, G, B;
  1228. Y -= c->yuv2rgb_y_offset;
  1229. Y *= c->yuv2rgb_y_coeff;
  1230. Y += 1 << 13;
  1231. if (hasAlpha) {
  1232. A = abuf0[i] << 11;
  1233. A += 1 << 13;
  1234. }
  1235. R = V * c->yuv2rgb_v2r_coeff;
  1236. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1237. B = U * c->yuv2rgb_u2b_coeff;
  1238. output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
  1239. output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);
  1240. output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
  1241. if (eightbytes) {
  1242. output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
  1243. dest += 4;
  1244. } else {
  1245. dest += 3;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. #undef output_pixel
  1251. #undef r_b
  1252. #undef b_r
  1253. #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha, eightbytes) \
  1254. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1255. const int16_t **_lumSrc, int lumFilterSize, \
  1256. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  1257. const int16_t **_chrVSrc, int chrFilterSize, \
  1258. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  1259. int y) \
  1260. { \
  1261. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  1262. **chrUSrc = (const int32_t **) _chrUSrc, \
  1263. **chrVSrc = (const int32_t **) _chrVSrc, \
  1264. **alpSrc = (const int32_t **) _alpSrc; \
  1265. uint16_t *dest = (uint16_t *) _dest; \
  1266. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1267. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1268. alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes); \
  1269. } \
  1270. \
  1271. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  1272. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1273. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  1274. int yalpha, int uvalpha, int y) \
  1275. { \
  1276. const int32_t **buf = (const int32_t **) _buf, \
  1277. **ubuf = (const int32_t **) _ubuf, \
  1278. **vbuf = (const int32_t **) _vbuf, \
  1279. **abuf = (const int32_t **) _abuf; \
  1280. uint16_t *dest = (uint16_t *) _dest; \
  1281. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1282. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1283. } \
  1284. \
  1285. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  1286. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  1287. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  1288. int uvalpha, int y) \
  1289. { \
  1290. const int32_t *buf0 = (const int32_t *) _buf0, \
  1291. **ubuf = (const int32_t **) _ubuf, \
  1292. **vbuf = (const int32_t **) _vbuf, \
  1293. *abuf0 = (const int32_t *) _abuf0; \
  1294. uint16_t *dest = (uint16_t *) _dest; \
  1295. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1296. dstW, uvalpha, y, fmt, hasAlpha, eightbytes); \
  1297. }
  1298. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48be, AV_PIX_FMT_RGB48BE, 0, 0)
  1299. YUV2PACKED16WRAPPER(yuv2, rgba64, rgb48le, AV_PIX_FMT_RGB48LE, 0, 0)
  1300. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48be, AV_PIX_FMT_BGR48BE, 0, 0)
  1301. YUV2PACKED16WRAPPER(yuv2, rgba64, bgr48le, AV_PIX_FMT_BGR48LE, 0, 0)
  1302. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1, 1)
  1303. YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1, 1)
  1304. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0, 1)
  1305. YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0, 1)
  1306. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64be, AV_PIX_FMT_BGRA64BE, 1, 1)
  1307. YUV2PACKED16WRAPPER(yuv2, rgba64, bgra64le, AV_PIX_FMT_BGRA64LE, 1, 1)
  1308. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64BE, 0, 1)
  1309. YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64LE, 0, 1)
  1310. YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16BE, 1, 0)
  1311. YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16LE, 1, 0)
  1312. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48BE, 0, 0)
  1313. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48LE, 0, 0)
  1314. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48be_full, AV_PIX_FMT_BGR48BE, 0, 0)
  1315. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgr48le_full, AV_PIX_FMT_BGR48LE, 0, 0)
  1316. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64be_full, AV_PIX_FMT_RGBA64BE, 1, 1)
  1317. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgba64le_full, AV_PIX_FMT_RGBA64LE, 1, 1)
  1318. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64be_full, AV_PIX_FMT_RGBA64BE, 0, 1)
  1319. YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgbx64le_full, AV_PIX_FMT_RGBA64LE, 0, 1)
  1320. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64be_full, AV_PIX_FMT_BGRA64BE, 1, 1)
  1321. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgra64le_full, AV_PIX_FMT_BGRA64LE, 1, 1)
  1322. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64be_full, AV_PIX_FMT_BGRA64BE, 0, 1)
  1323. YUV2PACKED16WRAPPER(yuv2, rgba64_full, bgrx64le_full, AV_PIX_FMT_BGRA64LE, 0, 1)
  1324. /*
  1325. * Write out 2 RGB pixels in the target pixel format. This function takes a
  1326. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  1327. * things like endianness conversion and shifting. The caller takes care of
  1328. * setting the correct offset in these tables from the chroma (U/V) values.
  1329. * This function then uses the luminance (Y1/Y2) values to write out the
  1330. * correct RGB values into the destination buffer.
  1331. */
  1332. static av_always_inline void
  1333. yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
  1334. unsigned A1, unsigned A2,
  1335. const void *_r, const void *_g, const void *_b, int y,
  1336. enum AVPixelFormat target, int hasAlpha)
  1337. {
  1338. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  1339. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  1340. uint32_t *dest = (uint32_t *) _dest;
  1341. const uint32_t *r = (const uint32_t *) _r;
  1342. const uint32_t *g = (const uint32_t *) _g;
  1343. const uint32_t *b = (const uint32_t *) _b;
  1344. #if CONFIG_SMALL
  1345. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  1346. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  1347. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  1348. #else
  1349. if (hasAlpha) {
  1350. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1351. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
  1352. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  1353. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  1354. } else {
  1355. #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
  1356. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  1357. av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
  1358. #endif
  1359. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  1360. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  1361. }
  1362. #endif
  1363. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  1364. uint8_t *dest = (uint8_t *) _dest;
  1365. const uint8_t *r = (const uint8_t *) _r;
  1366. const uint8_t *g = (const uint8_t *) _g;
  1367. const uint8_t *b = (const uint8_t *) _b;
  1368. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  1369. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  1370. dest[i * 6 + 0] = r_b[Y1];
  1371. dest[i * 6 + 1] = g[Y1];
  1372. dest[i * 6 + 2] = b_r[Y1];
  1373. dest[i * 6 + 3] = r_b[Y2];
  1374. dest[i * 6 + 4] = g[Y2];
  1375. dest[i * 6 + 5] = b_r[Y2];
  1376. #undef r_b
  1377. #undef b_r
  1378. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  1379. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  1380. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  1381. uint16_t *dest = (uint16_t *) _dest;
  1382. const uint16_t *r = (const uint16_t *) _r;
  1383. const uint16_t *g = (const uint16_t *) _g;
  1384. const uint16_t *b = (const uint16_t *) _b;
  1385. int dr1, dg1, db1, dr2, dg2, db2;
  1386. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  1387. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1388. dg1 = ff_dither_2x2_4[ y & 1 ][0];
  1389. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1390. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1391. dg2 = ff_dither_2x2_4[ y & 1 ][1];
  1392. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1393. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  1394. dr1 = ff_dither_2x2_8[ y & 1 ][0];
  1395. dg1 = ff_dither_2x2_8[ y & 1 ][1];
  1396. db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
  1397. dr2 = ff_dither_2x2_8[ y & 1 ][1];
  1398. dg2 = ff_dither_2x2_8[ y & 1 ][0];
  1399. db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
  1400. } else {
  1401. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  1402. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  1403. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  1404. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  1405. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  1406. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  1407. }
  1408. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1409. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1410. } else /* 8/4 bits */ {
  1411. uint8_t *dest = (uint8_t *) _dest;
  1412. const uint8_t *r = (const uint8_t *) _r;
  1413. const uint8_t *g = (const uint8_t *) _g;
  1414. const uint8_t *b = (const uint8_t *) _b;
  1415. int dr1, dg1, db1, dr2, dg2, db2;
  1416. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  1417. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  1418. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  1419. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  1420. db1 = d64[(i * 2 + 0) & 7];
  1421. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  1422. db2 = d64[(i * 2 + 1) & 7];
  1423. } else {
  1424. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  1425. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  1426. dr1 = db1 = d128[(i * 2 + 0) & 7];
  1427. dg1 = d64[(i * 2 + 0) & 7];
  1428. dr2 = db2 = d128[(i * 2 + 1) & 7];
  1429. dg2 = d64[(i * 2 + 1) & 7];
  1430. }
  1431. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  1432. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  1433. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  1434. } else {
  1435. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  1436. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  1437. }
  1438. }
  1439. }
  1440. static av_always_inline void
  1441. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1442. const int16_t **lumSrc, int lumFilterSize,
  1443. const int16_t *chrFilter, const int16_t **chrUSrc,
  1444. const int16_t **chrVSrc, int chrFilterSize,
  1445. const int16_t **alpSrc, uint8_t *dest, int dstW,
  1446. int y, enum AVPixelFormat target, int hasAlpha)
  1447. {
  1448. int i;
  1449. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1450. int j, A1, A2;
  1451. int Y1 = 1 << 18;
  1452. int Y2 = 1 << 18;
  1453. int U = 1 << 18;
  1454. int V = 1 << 18;
  1455. const void *r, *g, *b;
  1456. for (j = 0; j < lumFilterSize; j++) {
  1457. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  1458. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  1459. }
  1460. for (j = 0; j < chrFilterSize; j++) {
  1461. U += chrUSrc[j][i] * chrFilter[j];
  1462. V += chrVSrc[j][i] * chrFilter[j];
  1463. }
  1464. Y1 >>= 19;
  1465. Y2 >>= 19;
  1466. U >>= 19;
  1467. V >>= 19;
  1468. if (hasAlpha) {
  1469. A1 = 1 << 18;
  1470. A2 = 1 << 18;
  1471. for (j = 0; j < lumFilterSize; j++) {
  1472. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  1473. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  1474. }
  1475. A1 >>= 19;
  1476. A2 >>= 19;
  1477. if ((A1 | A2) & 0x100) {
  1478. A1 = av_clip_uint8(A1);
  1479. A2 = av_clip_uint8(A2);
  1480. }
  1481. }
  1482. r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
  1483. g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
  1484. b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1485. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1486. r, g, b, y, target, hasAlpha);
  1487. }
  1488. }
  1489. static av_always_inline void
  1490. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  1491. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1492. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1493. int yalpha, int uvalpha, int y,
  1494. enum AVPixelFormat target, int hasAlpha)
  1495. {
  1496. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1497. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1498. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1499. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1500. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1501. int yalpha1 = 4096 - yalpha;
  1502. int uvalpha1 = 4096 - uvalpha;
  1503. int i;
  1504. av_assert2(yalpha <= 4096U);
  1505. av_assert2(uvalpha <= 4096U);
  1506. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1507. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  1508. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  1509. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  1510. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  1511. int A1, A2;
  1512. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1513. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1514. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1515. if (hasAlpha) {
  1516. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  1517. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  1518. A1 = av_clip_uint8(A1);
  1519. A2 = av_clip_uint8(A2);
  1520. }
  1521. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1522. r, g, b, y, target, hasAlpha);
  1523. }
  1524. }
  1525. static av_always_inline void
  1526. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  1527. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1528. const int16_t *abuf0, uint8_t *dest, int dstW,
  1529. int uvalpha, int y, enum AVPixelFormat target,
  1530. int hasAlpha)
  1531. {
  1532. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1533. int i;
  1534. if (uvalpha < 2048) {
  1535. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1536. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1537. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1538. int U = (ubuf0[i] + 64) >> 7;
  1539. int V = (vbuf0[i] + 64) >> 7;
  1540. int A1, A2;
  1541. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1542. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1543. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1544. if (hasAlpha) {
  1545. A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
  1546. A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
  1547. A1 = av_clip_uint8(A1);
  1548. A2 = av_clip_uint8(A2);
  1549. }
  1550. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1551. r, g, b, y, target, hasAlpha);
  1552. }
  1553. } else {
  1554. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1555. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  1556. int Y1 = (buf0[i * 2 ] + 64) >> 7;
  1557. int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
  1558. int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
  1559. int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
  1560. int A1, A2;
  1561. const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
  1562. *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
  1563. *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
  1564. if (hasAlpha) {
  1565. A1 = (abuf0[i * 2 ] + 64) >> 7;
  1566. A2 = (abuf0[i * 2 + 1] + 64) >> 7;
  1567. A1 = av_clip_uint8(A1);
  1568. A2 = av_clip_uint8(A2);
  1569. }
  1570. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  1571. r, g, b, y, target, hasAlpha);
  1572. }
  1573. }
  1574. }
  1575. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1576. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  1577. const int16_t **lumSrc, int lumFilterSize, \
  1578. const int16_t *chrFilter, const int16_t **chrUSrc, \
  1579. const int16_t **chrVSrc, int chrFilterSize, \
  1580. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  1581. int y) \
  1582. { \
  1583. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  1584. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1585. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1586. }
  1587. #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1588. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1589. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1590. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1591. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1592. int yalpha, int uvalpha, int y) \
  1593. { \
  1594. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1595. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1596. }
  1597. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1598. YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
  1599. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1600. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1601. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1602. int uvalpha, int y) \
  1603. { \
  1604. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1605. dstW, uvalpha, y, fmt, hasAlpha); \
  1606. }
  1607. #if CONFIG_SMALL
  1608. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1609. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1610. #else
  1611. #if CONFIG_SWSCALE_ALPHA
  1612. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1613. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1614. #endif
  1615. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1616. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1617. #endif
  1618. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1619. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1620. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1621. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1622. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1623. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1624. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1625. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1626. static av_always_inline void yuv2rgb_write_full(SwsContext *c,
  1627. uint8_t *dest, int i, int Y, int A, int U, int V,
  1628. int y, enum AVPixelFormat target, int hasAlpha, int err[4])
  1629. {
  1630. int R, G, B;
  1631. int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
  1632. Y -= c->yuv2rgb_y_offset;
  1633. Y *= c->yuv2rgb_y_coeff;
  1634. Y += 1 << 21;
  1635. R = Y + V*c->yuv2rgb_v2r_coeff;
  1636. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1637. B = Y + U*c->yuv2rgb_u2b_coeff;
  1638. if ((R | G | B) & 0xC0000000) {
  1639. R = av_clip_uintp2(R, 30);
  1640. G = av_clip_uintp2(G, 30);
  1641. B = av_clip_uintp2(B, 30);
  1642. }
  1643. switch(target) {
  1644. case AV_PIX_FMT_ARGB:
  1645. dest[0] = hasAlpha ? A : 255;
  1646. dest[1] = R >> 22;
  1647. dest[2] = G >> 22;
  1648. dest[3] = B >> 22;
  1649. break;
  1650. case AV_PIX_FMT_RGB24:
  1651. dest[0] = R >> 22;
  1652. dest[1] = G >> 22;
  1653. dest[2] = B >> 22;
  1654. break;
  1655. case AV_PIX_FMT_RGBA:
  1656. dest[0] = R >> 22;
  1657. dest[1] = G >> 22;
  1658. dest[2] = B >> 22;
  1659. dest[3] = hasAlpha ? A : 255;
  1660. break;
  1661. case AV_PIX_FMT_ABGR:
  1662. dest[0] = hasAlpha ? A : 255;
  1663. dest[1] = B >> 22;
  1664. dest[2] = G >> 22;
  1665. dest[3] = R >> 22;
  1666. break;
  1667. case AV_PIX_FMT_BGR24:
  1668. dest[0] = B >> 22;
  1669. dest[1] = G >> 22;
  1670. dest[2] = R >> 22;
  1671. break;
  1672. case AV_PIX_FMT_BGRA:
  1673. dest[0] = B >> 22;
  1674. dest[1] = G >> 22;
  1675. dest[2] = R >> 22;
  1676. dest[3] = hasAlpha ? A : 255;
  1677. break;
  1678. case AV_PIX_FMT_BGR4_BYTE:
  1679. case AV_PIX_FMT_RGB4_BYTE:
  1680. case AV_PIX_FMT_BGR8:
  1681. case AV_PIX_FMT_RGB8:
  1682. {
  1683. int r,g,b;
  1684. switch (c->dither) {
  1685. default:
  1686. case SWS_DITHER_AUTO:
  1687. case SWS_DITHER_ED:
  1688. R >>= 22;
  1689. G >>= 22;
  1690. B >>= 22;
  1691. 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;
  1692. 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;
  1693. 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;
  1694. c->dither_error[0][i] = err[0];
  1695. c->dither_error[1][i] = err[1];
  1696. c->dither_error[2][i] = err[2];
  1697. r = R >> (isrgb8 ? 5 : 7);
  1698. g = G >> (isrgb8 ? 5 : 6);
  1699. b = B >> (isrgb8 ? 6 : 7);
  1700. r = av_clip(r, 0, isrgb8 ? 7 : 1);
  1701. g = av_clip(g, 0, isrgb8 ? 7 : 3);
  1702. b = av_clip(b, 0, isrgb8 ? 3 : 1);
  1703. err[0] = R - r*(isrgb8 ? 36 : 255);
  1704. err[1] = G - g*(isrgb8 ? 36 : 85);
  1705. err[2] = B - b*(isrgb8 ? 85 : 255);
  1706. break;
  1707. case SWS_DITHER_A_DITHER:
  1708. if (isrgb8) {
  1709. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1710. #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
  1711. r = (((R >> 19) + A_DITHER(i,y) -96)>>8);
  1712. g = (((G >> 19) + A_DITHER(i + 17,y) - 96)>>8);
  1713. b = (((B >> 20) + A_DITHER(i + 17*2,y) -96)>>8);
  1714. r = av_clip_uintp2(r, 3);
  1715. g = av_clip_uintp2(g, 3);
  1716. b = av_clip_uintp2(b, 2);
  1717. } else {
  1718. r = (((R >> 21) + A_DITHER(i,y)-256)>>8);
  1719. g = (((G >> 19) + A_DITHER(i + 17,y)-256)>>8);
  1720. b = (((B >> 21) + A_DITHER(i + 17*2,y)-256)>>8);
  1721. r = av_clip_uintp2(r, 1);
  1722. g = av_clip_uintp2(g, 2);
  1723. b = av_clip_uintp2(b, 1);
  1724. }
  1725. break;
  1726. case SWS_DITHER_X_DITHER:
  1727. if (isrgb8) {
  1728. /* see http://pippin.gimp.org/a_dither/ for details/origin */
  1729. #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
  1730. r = (((R >> 19) + X_DITHER(i,y) - 96)>>8);
  1731. g = (((G >> 19) + X_DITHER(i + 17,y) - 96)>>8);
  1732. b = (((B >> 20) + X_DITHER(i + 17*2,y) - 96)>>8);
  1733. r = av_clip_uintp2(r, 3);
  1734. g = av_clip_uintp2(g, 3);
  1735. b = av_clip_uintp2(b, 2);
  1736. } else {
  1737. r = (((R >> 21) + X_DITHER(i,y)-256)>>8);
  1738. g = (((G >> 19) + X_DITHER(i + 17,y)-256)>>8);
  1739. b = (((B >> 21) + X_DITHER(i + 17*2,y)-256)>>8);
  1740. r = av_clip_uintp2(r, 1);
  1741. g = av_clip_uintp2(g, 2);
  1742. b = av_clip_uintp2(b, 1);
  1743. }
  1744. break;
  1745. }
  1746. if(target == AV_PIX_FMT_BGR4_BYTE) {
  1747. dest[0] = r + 2*g + 8*b;
  1748. } else if(target == AV_PIX_FMT_RGB4_BYTE) {
  1749. dest[0] = b + 2*g + 8*r;
  1750. } else if(target == AV_PIX_FMT_BGR8) {
  1751. dest[0] = r + 8*g + 64*b;
  1752. } else if(target == AV_PIX_FMT_RGB8) {
  1753. dest[0] = b + 4*g + 32*r;
  1754. } else
  1755. av_assert2(0);
  1756. break;}
  1757. }
  1758. }
  1759. static av_always_inline void
  1760. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1761. const int16_t **lumSrc, int lumFilterSize,
  1762. const int16_t *chrFilter, const int16_t **chrUSrc,
  1763. const int16_t **chrVSrc, int chrFilterSize,
  1764. const int16_t **alpSrc, uint8_t *dest,
  1765. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1766. {
  1767. int i;
  1768. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1769. int err[4] = {0};
  1770. int A = 0; //init to silence warning
  1771. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1772. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1773. step = 1;
  1774. for (i = 0; i < dstW; i++) {
  1775. int j;
  1776. int Y = 1<<9;
  1777. int U = (1<<9)-(128 << 19);
  1778. int V = (1<<9)-(128 << 19);
  1779. for (j = 0; j < lumFilterSize; j++) {
  1780. Y += lumSrc[j][i] * lumFilter[j];
  1781. }
  1782. for (j = 0; j < chrFilterSize; j++) {
  1783. U += chrUSrc[j][i] * chrFilter[j];
  1784. V += chrVSrc[j][i] * chrFilter[j];
  1785. }
  1786. Y >>= 10;
  1787. U >>= 10;
  1788. V >>= 10;
  1789. if (hasAlpha) {
  1790. A = 1 << 18;
  1791. for (j = 0; j < lumFilterSize; j++) {
  1792. A += alpSrc[j][i] * lumFilter[j];
  1793. }
  1794. A >>= 19;
  1795. if (A & 0x100)
  1796. A = av_clip_uint8(A);
  1797. }
  1798. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1799. dest += step;
  1800. }
  1801. c->dither_error[0][i] = err[0];
  1802. c->dither_error[1][i] = err[1];
  1803. c->dither_error[2][i] = err[2];
  1804. }
  1805. static av_always_inline void
  1806. yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
  1807. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1808. const int16_t *abuf[2], uint8_t *dest, int dstW,
  1809. int yalpha, int uvalpha, int y,
  1810. enum AVPixelFormat target, int hasAlpha)
  1811. {
  1812. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  1813. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  1814. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  1815. *abuf0 = hasAlpha ? abuf[0] : NULL,
  1816. *abuf1 = hasAlpha ? abuf[1] : NULL;
  1817. int yalpha1 = 4096 - yalpha;
  1818. int uvalpha1 = 4096 - uvalpha;
  1819. int i;
  1820. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1821. int err[4] = {0};
  1822. int A = 0; // init to silcene warning
  1823. av_assert2(yalpha <= 4096U);
  1824. av_assert2(uvalpha <= 4096U);
  1825. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1826. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1827. step = 1;
  1828. for (i = 0; i < dstW; i++) {
  1829. int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
  1830. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
  1831. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
  1832. if (hasAlpha) {
  1833. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
  1834. if (A & 0x100)
  1835. A = av_clip_uint8(A);
  1836. }
  1837. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1838. dest += step;
  1839. }
  1840. c->dither_error[0][i] = err[0];
  1841. c->dither_error[1][i] = err[1];
  1842. c->dither_error[2][i] = err[2];
  1843. }
  1844. static av_always_inline void
  1845. yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
  1846. const int16_t *ubuf[2], const int16_t *vbuf[2],
  1847. const int16_t *abuf0, uint8_t *dest, int dstW,
  1848. int uvalpha, int y, enum AVPixelFormat target,
  1849. int hasAlpha)
  1850. {
  1851. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  1852. int i;
  1853. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1854. int err[4] = {0};
  1855. if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
  1856. || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
  1857. step = 1;
  1858. if (uvalpha < 2048) {
  1859. int A = 0; //init to silence warning
  1860. for (i = 0; i < dstW; i++) {
  1861. int Y = buf0[i] << 2;
  1862. int U = (ubuf0[i] - (128<<7)) * 4;
  1863. int V = (vbuf0[i] - (128<<7)) * 4;
  1864. if (hasAlpha) {
  1865. A = (abuf0[i] + 64) >> 7;
  1866. if (A & 0x100)
  1867. A = av_clip_uint8(A);
  1868. }
  1869. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1870. dest += step;
  1871. }
  1872. } else {
  1873. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  1874. int A = 0; //init to silence warning
  1875. for (i = 0; i < dstW; i++) {
  1876. int Y = buf0[i] << 2;
  1877. int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
  1878. int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
  1879. if (hasAlpha) {
  1880. A = (abuf0[i] + 64) >> 7;
  1881. if (A & 0x100)
  1882. A = av_clip_uint8(A);
  1883. }
  1884. yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
  1885. dest += step;
  1886. }
  1887. }
  1888. c->dither_error[0][i] = err[0];
  1889. c->dither_error[1][i] = err[1];
  1890. c->dither_error[2][i] = err[2];
  1891. }
  1892. #if CONFIG_SMALL
  1893. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1894. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1895. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1896. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->needAlpha)
  1897. #else
  1898. #if CONFIG_SWSCALE_ALPHA
  1899. YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1900. YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1901. YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1902. YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1903. #endif
  1904. YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1905. YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1906. YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1907. YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1908. #endif
  1909. YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1910. YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1911. YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
  1912. YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
  1913. YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
  1914. YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
  1915. static void
  1916. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1917. const int16_t **lumSrc, int lumFilterSize,
  1918. const int16_t *chrFilter, const int16_t **chrUSrc,
  1919. const int16_t **chrVSrc, int chrFilterSize,
  1920. const int16_t **alpSrc, uint8_t **dest,
  1921. int dstW, int y)
  1922. {
  1923. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1924. int i;
  1925. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  1926. uint16_t **dest16 = (uint16_t**)dest;
  1927. int SH = 22 + 8 - desc->comp[0].depth;
  1928. int A = 0; // init to silence warning
  1929. for (i = 0; i < dstW; i++) {
  1930. int j;
  1931. int Y = 1 << 9;
  1932. int U = (1 << 9) - (128 << 19);
  1933. int V = (1 << 9) - (128 << 19);
  1934. int R, G, B;
  1935. for (j = 0; j < lumFilterSize; j++)
  1936. Y += lumSrc[j][i] * lumFilter[j];
  1937. for (j = 0; j < chrFilterSize; j++) {
  1938. U += chrUSrc[j][i] * chrFilter[j];
  1939. V += chrVSrc[j][i] * chrFilter[j];
  1940. }
  1941. Y >>= 10;
  1942. U >>= 10;
  1943. V >>= 10;
  1944. if (hasAlpha) {
  1945. A = 1 << 18;
  1946. for (j = 0; j < lumFilterSize; j++)
  1947. A += alpSrc[j][i] * lumFilter[j];
  1948. if (A & 0xF8000000)
  1949. A = av_clip_uintp2(A, 27);
  1950. }
  1951. Y -= c->yuv2rgb_y_offset;
  1952. Y *= c->yuv2rgb_y_coeff;
  1953. Y += 1 << (SH-1);
  1954. R = Y + V * c->yuv2rgb_v2r_coeff;
  1955. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1956. B = Y + U * c->yuv2rgb_u2b_coeff;
  1957. if ((R | G | B) & 0xC0000000) {
  1958. R = av_clip_uintp2(R, 30);
  1959. G = av_clip_uintp2(G, 30);
  1960. B = av_clip_uintp2(B, 30);
  1961. }
  1962. if (SH != 22) {
  1963. dest16[0][i] = G >> SH;
  1964. dest16[1][i] = B >> SH;
  1965. dest16[2][i] = R >> SH;
  1966. if (hasAlpha)
  1967. dest16[3][i] = A >> (SH - 3);
  1968. } else {
  1969. dest[0][i] = G >> 22;
  1970. dest[1][i] = B >> 22;
  1971. dest[2][i] = R >> 22;
  1972. if (hasAlpha)
  1973. dest[3][i] = A >> 19;
  1974. }
  1975. }
  1976. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1977. for (i = 0; i < dstW; i++) {
  1978. dest16[0][i] = av_bswap16(dest16[0][i]);
  1979. dest16[1][i] = av_bswap16(dest16[1][i]);
  1980. dest16[2][i] = av_bswap16(dest16[2][i]);
  1981. if (hasAlpha)
  1982. dest16[3][i] = av_bswap16(dest16[3][i]);
  1983. }
  1984. }
  1985. }
  1986. static void
  1987. yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1988. const int16_t **lumSrcx, int lumFilterSize,
  1989. const int16_t *chrFilter, const int16_t **chrUSrcx,
  1990. const int16_t **chrVSrcx, int chrFilterSize,
  1991. const int16_t **alpSrcx, uint8_t **dest,
  1992. int dstW, int y)
  1993. {
  1994. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1995. int i;
  1996. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
  1997. uint16_t **dest16 = (uint16_t**)dest;
  1998. const int32_t **lumSrc = (const int32_t**)lumSrcx;
  1999. const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
  2000. const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
  2001. const int32_t **alpSrc = (const int32_t**)alpSrcx;
  2002. for (i = 0; i < dstW; i++) {
  2003. int j;
  2004. int Y = -0x40000000;
  2005. int U = -(128 << 23);
  2006. int V = -(128 << 23);
  2007. int R, G, B, A;
  2008. for (j = 0; j < lumFilterSize; j++)
  2009. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2010. for (j = 0; j < chrFilterSize; j++) {
  2011. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2012. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2013. }
  2014. Y >>= 14;
  2015. Y += 0x10000;
  2016. U >>= 14;
  2017. V >>= 14;
  2018. if (hasAlpha) {
  2019. A = -0x40000000;
  2020. for (j = 0; j < lumFilterSize; j++)
  2021. A += alpSrc[j][i] * lumFilter[j];
  2022. A >>= 1;
  2023. A += 0x20002000;
  2024. }
  2025. Y -= c->yuv2rgb_y_offset;
  2026. Y *= c->yuv2rgb_y_coeff;
  2027. Y += 1 << 13;
  2028. R = V * c->yuv2rgb_v2r_coeff;
  2029. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  2030. B = U * c->yuv2rgb_u2b_coeff;
  2031. R = av_clip_uintp2(Y + R, 30);
  2032. G = av_clip_uintp2(Y + G, 30);
  2033. B = av_clip_uintp2(Y + B, 30);
  2034. dest16[0][i] = G >> 14;
  2035. dest16[1][i] = B >> 14;
  2036. dest16[2][i] = R >> 14;
  2037. if (hasAlpha)
  2038. dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
  2039. }
  2040. if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  2041. for (i = 0; i < dstW; i++) {
  2042. dest16[0][i] = av_bswap16(dest16[0][i]);
  2043. dest16[1][i] = av_bswap16(dest16[1][i]);
  2044. dest16[2][i] = av_bswap16(dest16[2][i]);
  2045. if (hasAlpha)
  2046. dest16[3][i] = av_bswap16(dest16[3][i]);
  2047. }
  2048. }
  2049. }
  2050. static void
  2051. yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
  2052. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2053. const int16_t *abuf0, uint8_t *dest, int dstW,
  2054. int uvalpha, int y)
  2055. {
  2056. int hasAlpha = !!abuf0;
  2057. int i;
  2058. for (i = 0; i < dstW; i++) {
  2059. int Y = (buf0[i] + 64) >> 7;
  2060. int A;
  2061. Y = av_clip_uint8(Y);
  2062. if (hasAlpha) {
  2063. A = (abuf0[i] + 64) >> 7;
  2064. if (A & 0x100)
  2065. A = av_clip_uint8(A);
  2066. }
  2067. dest[i * 2 ] = Y;
  2068. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2069. }
  2070. }
  2071. static void
  2072. yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
  2073. const int16_t *ubuf[2], const int16_t *vbuf[2],
  2074. const int16_t *abuf[2], uint8_t *dest, int dstW,
  2075. int yalpha, int uvalpha, int y)
  2076. {
  2077. int hasAlpha = abuf && abuf[0] && abuf[1];
  2078. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  2079. *abuf0 = hasAlpha ? abuf[0] : NULL,
  2080. *abuf1 = hasAlpha ? abuf[1] : NULL;
  2081. int yalpha1 = 4096 - yalpha;
  2082. int i;
  2083. av_assert2(yalpha <= 4096U);
  2084. for (i = 0; i < dstW; i++) {
  2085. int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 19;
  2086. int A;
  2087. Y = av_clip_uint8(Y);
  2088. if (hasAlpha) {
  2089. A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 19;
  2090. A = av_clip_uint8(A);
  2091. }
  2092. dest[i * 2 ] = Y;
  2093. dest[i * 2 + 1] = hasAlpha ? A : 255;
  2094. }
  2095. }
  2096. static void
  2097. yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
  2098. const int16_t **lumSrc, int lumFilterSize,
  2099. const int16_t *chrFilter, const int16_t **chrUSrc,
  2100. const int16_t **chrVSrc, int chrFilterSize,
  2101. const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
  2102. {
  2103. int hasAlpha = !!alpSrc;
  2104. int i;
  2105. for (i = 0; i < dstW; i++) {
  2106. int j;
  2107. int Y = 1 << 18, A = 1 << 18;
  2108. for (j = 0; j < lumFilterSize; j++)
  2109. Y += lumSrc[j][i] * lumFilter[j];
  2110. Y >>= 19;
  2111. if (Y & 0x100)
  2112. Y = av_clip_uint8(Y);
  2113. if (hasAlpha) {
  2114. for (j = 0; j < lumFilterSize; j++)
  2115. A += alpSrc[j][i] * lumFilter[j];
  2116. A >>= 19;
  2117. if (A & 0x100)
  2118. A = av_clip_uint8(A);
  2119. }
  2120. dest[2 * i ] = Y;
  2121. dest[2 * i + 1] = hasAlpha ? A : 255;
  2122. }
  2123. }
  2124. static void
  2125. yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
  2126. const int16_t **_lumSrc, int lumFilterSize,
  2127. const int16_t *chrFilter, const int16_t **_chrUSrc,
  2128. const int16_t **_chrVSrc, int chrFilterSize,
  2129. const int16_t **_alpSrc, uint8_t *dest, int dstW, int y)
  2130. {
  2131. const int32_t **lumSrc = (const int32_t **) _lumSrc,
  2132. **chrUSrc = (const int32_t **) _chrUSrc,
  2133. **chrVSrc = (const int32_t **) _chrVSrc,
  2134. **alpSrc = (const int32_t **) _alpSrc;
  2135. int hasAlpha = !!alpSrc;
  2136. int i;
  2137. for (i = 0; i < dstW; i++) {
  2138. int Y = 1 << 14, U = 1 << 14;
  2139. int V = 1 << 14, A = 1 << 14;
  2140. int j;
  2141. Y -= 0x40000000;
  2142. U -= 0x40000000;
  2143. V -= 0x40000000;
  2144. A -= 0x40000000;
  2145. for (j = 0; j < lumFilterSize; j++)
  2146. Y += lumSrc[j][i] * (unsigned)lumFilter[j];
  2147. for (j = 0; j < chrFilterSize; j++)
  2148. U += chrUSrc[j][i] * (unsigned)chrFilter[j];
  2149. for (j = 0; j < chrFilterSize; j++)
  2150. V += chrVSrc[j][i] * (unsigned)chrFilter[j];
  2151. if (hasAlpha)
  2152. for (j = 0; j < lumFilterSize; j++)
  2153. A += alpSrc[j][i] * (unsigned)lumFilter[j];
  2154. Y = 0x8000 + av_clip_int16(Y >> 15);
  2155. U = 0x8000 + av_clip_int16(U >> 15);
  2156. V = 0x8000 + av_clip_int16(V >> 15);
  2157. A = 0x8000 + av_clip_int16(A >> 15);
  2158. AV_WL16(dest + 8 * i, hasAlpha ? A : 65535);
  2159. AV_WL16(dest + 8 * i + 2, Y);
  2160. AV_WL16(dest + 8 * i + 4, U);
  2161. AV_WL16(dest + 8 * i + 6, V);
  2162. }
  2163. }
  2164. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  2165. yuv2planar1_fn *yuv2plane1,
  2166. yuv2planarX_fn *yuv2planeX,
  2167. yuv2interleavedX_fn *yuv2nv12cX,
  2168. yuv2packed1_fn *yuv2packed1,
  2169. yuv2packed2_fn *yuv2packed2,
  2170. yuv2packedX_fn *yuv2packedX,
  2171. yuv2anyX_fn *yuv2anyX)
  2172. {
  2173. enum AVPixelFormat dstFormat = c->dstFormat;
  2174. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  2175. if (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P010BE) {
  2176. *yuv2plane1 = isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
  2177. *yuv2planeX = isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
  2178. *yuv2nv12cX = yuv2p010cX_c;
  2179. } else if (is16BPS(dstFormat)) {
  2180. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  2181. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  2182. if (dstFormat == AV_PIX_FMT_P016LE || dstFormat == AV_PIX_FMT_P016BE) {
  2183. *yuv2nv12cX = yuv2p016cX_c;
  2184. }
  2185. } else if (isNBPS(dstFormat)) {
  2186. if (desc->comp[0].depth == 9) {
  2187. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  2188. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  2189. } else if (desc->comp[0].depth == 10) {
  2190. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  2191. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  2192. } else if (desc->comp[0].depth == 12) {
  2193. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  2194. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  2195. } else if (desc->comp[0].depth == 14) {
  2196. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
  2197. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
  2198. } else
  2199. av_assert0(0);
  2200. } else if (dstFormat == AV_PIX_FMT_GRAYF32BE) {
  2201. *yuv2planeX = yuv2planeX_floatBE_c;
  2202. *yuv2plane1 = yuv2plane1_floatBE_c;
  2203. } else if (dstFormat == AV_PIX_FMT_GRAYF32LE) {
  2204. *yuv2planeX = yuv2planeX_floatLE_c;
  2205. *yuv2plane1 = yuv2plane1_floatLE_c;
  2206. } else {
  2207. *yuv2plane1 = yuv2plane1_8_c;
  2208. *yuv2planeX = yuv2planeX_8_c;
  2209. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  2210. *yuv2nv12cX = yuv2nv12cX_c;
  2211. }
  2212. if(c->flags & SWS_FULL_CHR_H_INT) {
  2213. switch (dstFormat) {
  2214. case AV_PIX_FMT_RGBA:
  2215. #if CONFIG_SMALL
  2216. *yuv2packedX = yuv2rgba32_full_X_c;
  2217. *yuv2packed2 = yuv2rgba32_full_2_c;
  2218. *yuv2packed1 = yuv2rgba32_full_1_c;
  2219. #else
  2220. #if CONFIG_SWSCALE_ALPHA
  2221. if (c->needAlpha) {
  2222. *yuv2packedX = yuv2rgba32_full_X_c;
  2223. *yuv2packed2 = yuv2rgba32_full_2_c;
  2224. *yuv2packed1 = yuv2rgba32_full_1_c;
  2225. } else
  2226. #endif /* CONFIG_SWSCALE_ALPHA */
  2227. {
  2228. *yuv2packedX = yuv2rgbx32_full_X_c;
  2229. *yuv2packed2 = yuv2rgbx32_full_2_c;
  2230. *yuv2packed1 = yuv2rgbx32_full_1_c;
  2231. }
  2232. #endif /* !CONFIG_SMALL */
  2233. break;
  2234. case AV_PIX_FMT_ARGB:
  2235. #if CONFIG_SMALL
  2236. *yuv2packedX = yuv2argb32_full_X_c;
  2237. *yuv2packed2 = yuv2argb32_full_2_c;
  2238. *yuv2packed1 = yuv2argb32_full_1_c;
  2239. #else
  2240. #if CONFIG_SWSCALE_ALPHA
  2241. if (c->needAlpha) {
  2242. *yuv2packedX = yuv2argb32_full_X_c;
  2243. *yuv2packed2 = yuv2argb32_full_2_c;
  2244. *yuv2packed1 = yuv2argb32_full_1_c;
  2245. } else
  2246. #endif /* CONFIG_SWSCALE_ALPHA */
  2247. {
  2248. *yuv2packedX = yuv2xrgb32_full_X_c;
  2249. *yuv2packed2 = yuv2xrgb32_full_2_c;
  2250. *yuv2packed1 = yuv2xrgb32_full_1_c;
  2251. }
  2252. #endif /* !CONFIG_SMALL */
  2253. break;
  2254. case AV_PIX_FMT_BGRA:
  2255. #if CONFIG_SMALL
  2256. *yuv2packedX = yuv2bgra32_full_X_c;
  2257. *yuv2packed2 = yuv2bgra32_full_2_c;
  2258. *yuv2packed1 = yuv2bgra32_full_1_c;
  2259. #else
  2260. #if CONFIG_SWSCALE_ALPHA
  2261. if (c->needAlpha) {
  2262. *yuv2packedX = yuv2bgra32_full_X_c;
  2263. *yuv2packed2 = yuv2bgra32_full_2_c;
  2264. *yuv2packed1 = yuv2bgra32_full_1_c;
  2265. } else
  2266. #endif /* CONFIG_SWSCALE_ALPHA */
  2267. {
  2268. *yuv2packedX = yuv2bgrx32_full_X_c;
  2269. *yuv2packed2 = yuv2bgrx32_full_2_c;
  2270. *yuv2packed1 = yuv2bgrx32_full_1_c;
  2271. }
  2272. #endif /* !CONFIG_SMALL */
  2273. break;
  2274. case AV_PIX_FMT_ABGR:
  2275. #if CONFIG_SMALL
  2276. *yuv2packedX = yuv2abgr32_full_X_c;
  2277. *yuv2packed2 = yuv2abgr32_full_2_c;
  2278. *yuv2packed1 = yuv2abgr32_full_1_c;
  2279. #else
  2280. #if CONFIG_SWSCALE_ALPHA
  2281. if (c->needAlpha) {
  2282. *yuv2packedX = yuv2abgr32_full_X_c;
  2283. *yuv2packed2 = yuv2abgr32_full_2_c;
  2284. *yuv2packed1 = yuv2abgr32_full_1_c;
  2285. } else
  2286. #endif /* CONFIG_SWSCALE_ALPHA */
  2287. {
  2288. *yuv2packedX = yuv2xbgr32_full_X_c;
  2289. *yuv2packed2 = yuv2xbgr32_full_2_c;
  2290. *yuv2packed1 = yuv2xbgr32_full_1_c;
  2291. }
  2292. #endif /* !CONFIG_SMALL */
  2293. break;
  2294. case AV_PIX_FMT_RGBA64LE:
  2295. #if CONFIG_SWSCALE_ALPHA
  2296. if (c->needAlpha) {
  2297. *yuv2packedX = yuv2rgba64le_full_X_c;
  2298. *yuv2packed2 = yuv2rgba64le_full_2_c;
  2299. *yuv2packed1 = yuv2rgba64le_full_1_c;
  2300. } else
  2301. #endif /* CONFIG_SWSCALE_ALPHA */
  2302. {
  2303. *yuv2packedX = yuv2rgbx64le_full_X_c;
  2304. *yuv2packed2 = yuv2rgbx64le_full_2_c;
  2305. *yuv2packed1 = yuv2rgbx64le_full_1_c;
  2306. }
  2307. break;
  2308. case AV_PIX_FMT_RGBA64BE:
  2309. #if CONFIG_SWSCALE_ALPHA
  2310. if (c->needAlpha) {
  2311. *yuv2packedX = yuv2rgba64be_full_X_c;
  2312. *yuv2packed2 = yuv2rgba64be_full_2_c;
  2313. *yuv2packed1 = yuv2rgba64be_full_1_c;
  2314. } else
  2315. #endif /* CONFIG_SWSCALE_ALPHA */
  2316. {
  2317. *yuv2packedX = yuv2rgbx64be_full_X_c;
  2318. *yuv2packed2 = yuv2rgbx64be_full_2_c;
  2319. *yuv2packed1 = yuv2rgbx64be_full_1_c;
  2320. }
  2321. break;
  2322. case AV_PIX_FMT_BGRA64LE:
  2323. #if CONFIG_SWSCALE_ALPHA
  2324. if (c->needAlpha) {
  2325. *yuv2packedX = yuv2bgra64le_full_X_c;
  2326. *yuv2packed2 = yuv2bgra64le_full_2_c;
  2327. *yuv2packed1 = yuv2bgra64le_full_1_c;
  2328. } else
  2329. #endif /* CONFIG_SWSCALE_ALPHA */
  2330. {
  2331. *yuv2packedX = yuv2bgrx64le_full_X_c;
  2332. *yuv2packed2 = yuv2bgrx64le_full_2_c;
  2333. *yuv2packed1 = yuv2bgrx64le_full_1_c;
  2334. }
  2335. break;
  2336. case AV_PIX_FMT_BGRA64BE:
  2337. #if CONFIG_SWSCALE_ALPHA
  2338. if (c->needAlpha) {
  2339. *yuv2packedX = yuv2bgra64be_full_X_c;
  2340. *yuv2packed2 = yuv2bgra64be_full_2_c;
  2341. *yuv2packed1 = yuv2bgra64be_full_1_c;
  2342. } else
  2343. #endif /* CONFIG_SWSCALE_ALPHA */
  2344. {
  2345. *yuv2packedX = yuv2bgrx64be_full_X_c;
  2346. *yuv2packed2 = yuv2bgrx64be_full_2_c;
  2347. *yuv2packed1 = yuv2bgrx64be_full_1_c;
  2348. }
  2349. break;
  2350. case AV_PIX_FMT_RGB24:
  2351. *yuv2packedX = yuv2rgb24_full_X_c;
  2352. *yuv2packed2 = yuv2rgb24_full_2_c;
  2353. *yuv2packed1 = yuv2rgb24_full_1_c;
  2354. break;
  2355. case AV_PIX_FMT_BGR24:
  2356. *yuv2packedX = yuv2bgr24_full_X_c;
  2357. *yuv2packed2 = yuv2bgr24_full_2_c;
  2358. *yuv2packed1 = yuv2bgr24_full_1_c;
  2359. break;
  2360. case AV_PIX_FMT_RGB48LE:
  2361. *yuv2packedX = yuv2rgb48le_full_X_c;
  2362. *yuv2packed2 = yuv2rgb48le_full_2_c;
  2363. *yuv2packed1 = yuv2rgb48le_full_1_c;
  2364. break;
  2365. case AV_PIX_FMT_BGR48LE:
  2366. *yuv2packedX = yuv2bgr48le_full_X_c;
  2367. *yuv2packed2 = yuv2bgr48le_full_2_c;
  2368. *yuv2packed1 = yuv2bgr48le_full_1_c;
  2369. break;
  2370. case AV_PIX_FMT_RGB48BE:
  2371. *yuv2packedX = yuv2rgb48be_full_X_c;
  2372. *yuv2packed2 = yuv2rgb48be_full_2_c;
  2373. *yuv2packed1 = yuv2rgb48be_full_1_c;
  2374. break;
  2375. case AV_PIX_FMT_BGR48BE:
  2376. *yuv2packedX = yuv2bgr48be_full_X_c;
  2377. *yuv2packed2 = yuv2bgr48be_full_2_c;
  2378. *yuv2packed1 = yuv2bgr48be_full_1_c;
  2379. break;
  2380. case AV_PIX_FMT_BGR4_BYTE:
  2381. *yuv2packedX = yuv2bgr4_byte_full_X_c;
  2382. *yuv2packed2 = yuv2bgr4_byte_full_2_c;
  2383. *yuv2packed1 = yuv2bgr4_byte_full_1_c;
  2384. break;
  2385. case AV_PIX_FMT_RGB4_BYTE:
  2386. *yuv2packedX = yuv2rgb4_byte_full_X_c;
  2387. *yuv2packed2 = yuv2rgb4_byte_full_2_c;
  2388. *yuv2packed1 = yuv2rgb4_byte_full_1_c;
  2389. break;
  2390. case AV_PIX_FMT_BGR8:
  2391. *yuv2packedX = yuv2bgr8_full_X_c;
  2392. *yuv2packed2 = yuv2bgr8_full_2_c;
  2393. *yuv2packed1 = yuv2bgr8_full_1_c;
  2394. break;
  2395. case AV_PIX_FMT_RGB8:
  2396. *yuv2packedX = yuv2rgb8_full_X_c;
  2397. *yuv2packed2 = yuv2rgb8_full_2_c;
  2398. *yuv2packed1 = yuv2rgb8_full_1_c;
  2399. break;
  2400. case AV_PIX_FMT_GBRP:
  2401. case AV_PIX_FMT_GBRP9BE:
  2402. case AV_PIX_FMT_GBRP9LE:
  2403. case AV_PIX_FMT_GBRP10BE:
  2404. case AV_PIX_FMT_GBRP10LE:
  2405. case AV_PIX_FMT_GBRP12BE:
  2406. case AV_PIX_FMT_GBRP12LE:
  2407. case AV_PIX_FMT_GBRP14BE:
  2408. case AV_PIX_FMT_GBRP14LE:
  2409. case AV_PIX_FMT_GBRAP:
  2410. case AV_PIX_FMT_GBRAP10BE:
  2411. case AV_PIX_FMT_GBRAP10LE:
  2412. case AV_PIX_FMT_GBRAP12BE:
  2413. case AV_PIX_FMT_GBRAP12LE:
  2414. *yuv2anyX = yuv2gbrp_full_X_c;
  2415. break;
  2416. case AV_PIX_FMT_GBRP16BE:
  2417. case AV_PIX_FMT_GBRP16LE:
  2418. case AV_PIX_FMT_GBRAP16BE:
  2419. case AV_PIX_FMT_GBRAP16LE:
  2420. *yuv2anyX = yuv2gbrp16_full_X_c;
  2421. break;
  2422. }
  2423. if (!*yuv2packedX && !*yuv2anyX)
  2424. goto YUV_PACKED;
  2425. } else {
  2426. YUV_PACKED:
  2427. switch (dstFormat) {
  2428. case AV_PIX_FMT_RGBA64LE:
  2429. #if CONFIG_SWSCALE_ALPHA
  2430. if (c->needAlpha) {
  2431. *yuv2packed1 = yuv2rgba64le_1_c;
  2432. *yuv2packed2 = yuv2rgba64le_2_c;
  2433. *yuv2packedX = yuv2rgba64le_X_c;
  2434. } else
  2435. #endif /* CONFIG_SWSCALE_ALPHA */
  2436. {
  2437. *yuv2packed1 = yuv2rgbx64le_1_c;
  2438. *yuv2packed2 = yuv2rgbx64le_2_c;
  2439. *yuv2packedX = yuv2rgbx64le_X_c;
  2440. }
  2441. break;
  2442. case AV_PIX_FMT_RGBA64BE:
  2443. #if CONFIG_SWSCALE_ALPHA
  2444. if (c->needAlpha) {
  2445. *yuv2packed1 = yuv2rgba64be_1_c;
  2446. *yuv2packed2 = yuv2rgba64be_2_c;
  2447. *yuv2packedX = yuv2rgba64be_X_c;
  2448. } else
  2449. #endif /* CONFIG_SWSCALE_ALPHA */
  2450. {
  2451. *yuv2packed1 = yuv2rgbx64be_1_c;
  2452. *yuv2packed2 = yuv2rgbx64be_2_c;
  2453. *yuv2packedX = yuv2rgbx64be_X_c;
  2454. }
  2455. break;
  2456. case AV_PIX_FMT_BGRA64LE:
  2457. #if CONFIG_SWSCALE_ALPHA
  2458. if (c->needAlpha) {
  2459. *yuv2packed1 = yuv2bgra64le_1_c;
  2460. *yuv2packed2 = yuv2bgra64le_2_c;
  2461. *yuv2packedX = yuv2bgra64le_X_c;
  2462. } else
  2463. #endif /* CONFIG_SWSCALE_ALPHA */
  2464. {
  2465. *yuv2packed1 = yuv2bgrx64le_1_c;
  2466. *yuv2packed2 = yuv2bgrx64le_2_c;
  2467. *yuv2packedX = yuv2bgrx64le_X_c;
  2468. }
  2469. break;
  2470. case AV_PIX_FMT_BGRA64BE:
  2471. #if CONFIG_SWSCALE_ALPHA
  2472. if (c->needAlpha) {
  2473. *yuv2packed1 = yuv2bgra64be_1_c;
  2474. *yuv2packed2 = yuv2bgra64be_2_c;
  2475. *yuv2packedX = yuv2bgra64be_X_c;
  2476. } else
  2477. #endif /* CONFIG_SWSCALE_ALPHA */
  2478. {
  2479. *yuv2packed1 = yuv2bgrx64be_1_c;
  2480. *yuv2packed2 = yuv2bgrx64be_2_c;
  2481. *yuv2packedX = yuv2bgrx64be_X_c;
  2482. }
  2483. break;
  2484. case AV_PIX_FMT_RGB48LE:
  2485. *yuv2packed1 = yuv2rgb48le_1_c;
  2486. *yuv2packed2 = yuv2rgb48le_2_c;
  2487. *yuv2packedX = yuv2rgb48le_X_c;
  2488. break;
  2489. case AV_PIX_FMT_RGB48BE:
  2490. *yuv2packed1 = yuv2rgb48be_1_c;
  2491. *yuv2packed2 = yuv2rgb48be_2_c;
  2492. *yuv2packedX = yuv2rgb48be_X_c;
  2493. break;
  2494. case AV_PIX_FMT_BGR48LE:
  2495. *yuv2packed1 = yuv2bgr48le_1_c;
  2496. *yuv2packed2 = yuv2bgr48le_2_c;
  2497. *yuv2packedX = yuv2bgr48le_X_c;
  2498. break;
  2499. case AV_PIX_FMT_BGR48BE:
  2500. *yuv2packed1 = yuv2bgr48be_1_c;
  2501. *yuv2packed2 = yuv2bgr48be_2_c;
  2502. *yuv2packedX = yuv2bgr48be_X_c;
  2503. break;
  2504. case AV_PIX_FMT_RGB32:
  2505. case AV_PIX_FMT_BGR32:
  2506. #if CONFIG_SMALL
  2507. *yuv2packed1 = yuv2rgb32_1_c;
  2508. *yuv2packed2 = yuv2rgb32_2_c;
  2509. *yuv2packedX = yuv2rgb32_X_c;
  2510. #else
  2511. #if CONFIG_SWSCALE_ALPHA
  2512. if (c->needAlpha) {
  2513. *yuv2packed1 = yuv2rgba32_1_c;
  2514. *yuv2packed2 = yuv2rgba32_2_c;
  2515. *yuv2packedX = yuv2rgba32_X_c;
  2516. } else
  2517. #endif /* CONFIG_SWSCALE_ALPHA */
  2518. {
  2519. *yuv2packed1 = yuv2rgbx32_1_c;
  2520. *yuv2packed2 = yuv2rgbx32_2_c;
  2521. *yuv2packedX = yuv2rgbx32_X_c;
  2522. }
  2523. #endif /* !CONFIG_SMALL */
  2524. break;
  2525. case AV_PIX_FMT_RGB32_1:
  2526. case AV_PIX_FMT_BGR32_1:
  2527. #if CONFIG_SMALL
  2528. *yuv2packed1 = yuv2rgb32_1_1_c;
  2529. *yuv2packed2 = yuv2rgb32_1_2_c;
  2530. *yuv2packedX = yuv2rgb32_1_X_c;
  2531. #else
  2532. #if CONFIG_SWSCALE_ALPHA
  2533. if (c->needAlpha) {
  2534. *yuv2packed1 = yuv2rgba32_1_1_c;
  2535. *yuv2packed2 = yuv2rgba32_1_2_c;
  2536. *yuv2packedX = yuv2rgba32_1_X_c;
  2537. } else
  2538. #endif /* CONFIG_SWSCALE_ALPHA */
  2539. {
  2540. *yuv2packed1 = yuv2rgbx32_1_1_c;
  2541. *yuv2packed2 = yuv2rgbx32_1_2_c;
  2542. *yuv2packedX = yuv2rgbx32_1_X_c;
  2543. }
  2544. #endif /* !CONFIG_SMALL */
  2545. break;
  2546. case AV_PIX_FMT_RGB24:
  2547. *yuv2packed1 = yuv2rgb24_1_c;
  2548. *yuv2packed2 = yuv2rgb24_2_c;
  2549. *yuv2packedX = yuv2rgb24_X_c;
  2550. break;
  2551. case AV_PIX_FMT_BGR24:
  2552. *yuv2packed1 = yuv2bgr24_1_c;
  2553. *yuv2packed2 = yuv2bgr24_2_c;
  2554. *yuv2packedX = yuv2bgr24_X_c;
  2555. break;
  2556. case AV_PIX_FMT_RGB565LE:
  2557. case AV_PIX_FMT_RGB565BE:
  2558. case AV_PIX_FMT_BGR565LE:
  2559. case AV_PIX_FMT_BGR565BE:
  2560. *yuv2packed1 = yuv2rgb16_1_c;
  2561. *yuv2packed2 = yuv2rgb16_2_c;
  2562. *yuv2packedX = yuv2rgb16_X_c;
  2563. break;
  2564. case AV_PIX_FMT_RGB555LE:
  2565. case AV_PIX_FMT_RGB555BE:
  2566. case AV_PIX_FMT_BGR555LE:
  2567. case AV_PIX_FMT_BGR555BE:
  2568. *yuv2packed1 = yuv2rgb15_1_c;
  2569. *yuv2packed2 = yuv2rgb15_2_c;
  2570. *yuv2packedX = yuv2rgb15_X_c;
  2571. break;
  2572. case AV_PIX_FMT_RGB444LE:
  2573. case AV_PIX_FMT_RGB444BE:
  2574. case AV_PIX_FMT_BGR444LE:
  2575. case AV_PIX_FMT_BGR444BE:
  2576. *yuv2packed1 = yuv2rgb12_1_c;
  2577. *yuv2packed2 = yuv2rgb12_2_c;
  2578. *yuv2packedX = yuv2rgb12_X_c;
  2579. break;
  2580. case AV_PIX_FMT_RGB8:
  2581. case AV_PIX_FMT_BGR8:
  2582. *yuv2packed1 = yuv2rgb8_1_c;
  2583. *yuv2packed2 = yuv2rgb8_2_c;
  2584. *yuv2packedX = yuv2rgb8_X_c;
  2585. break;
  2586. case AV_PIX_FMT_RGB4:
  2587. case AV_PIX_FMT_BGR4:
  2588. *yuv2packed1 = yuv2rgb4_1_c;
  2589. *yuv2packed2 = yuv2rgb4_2_c;
  2590. *yuv2packedX = yuv2rgb4_X_c;
  2591. break;
  2592. case AV_PIX_FMT_RGB4_BYTE:
  2593. case AV_PIX_FMT_BGR4_BYTE:
  2594. *yuv2packed1 = yuv2rgb4b_1_c;
  2595. *yuv2packed2 = yuv2rgb4b_2_c;
  2596. *yuv2packedX = yuv2rgb4b_X_c;
  2597. break;
  2598. }
  2599. }
  2600. switch (dstFormat) {
  2601. case AV_PIX_FMT_MONOWHITE:
  2602. *yuv2packed1 = yuv2monowhite_1_c;
  2603. *yuv2packed2 = yuv2monowhite_2_c;
  2604. *yuv2packedX = yuv2monowhite_X_c;
  2605. break;
  2606. case AV_PIX_FMT_MONOBLACK:
  2607. *yuv2packed1 = yuv2monoblack_1_c;
  2608. *yuv2packed2 = yuv2monoblack_2_c;
  2609. *yuv2packedX = yuv2monoblack_X_c;
  2610. break;
  2611. case AV_PIX_FMT_YUYV422:
  2612. *yuv2packed1 = yuv2yuyv422_1_c;
  2613. *yuv2packed2 = yuv2yuyv422_2_c;
  2614. *yuv2packedX = yuv2yuyv422_X_c;
  2615. break;
  2616. case AV_PIX_FMT_YVYU422:
  2617. *yuv2packed1 = yuv2yvyu422_1_c;
  2618. *yuv2packed2 = yuv2yvyu422_2_c;
  2619. *yuv2packedX = yuv2yvyu422_X_c;
  2620. break;
  2621. case AV_PIX_FMT_UYVY422:
  2622. *yuv2packed1 = yuv2uyvy422_1_c;
  2623. *yuv2packed2 = yuv2uyvy422_2_c;
  2624. *yuv2packedX = yuv2uyvy422_X_c;
  2625. break;
  2626. case AV_PIX_FMT_YA8:
  2627. *yuv2packed1 = yuv2ya8_1_c;
  2628. *yuv2packed2 = yuv2ya8_2_c;
  2629. *yuv2packedX = yuv2ya8_X_c;
  2630. break;
  2631. case AV_PIX_FMT_YA16LE:
  2632. *yuv2packed1 = yuv2ya16le_1_c;
  2633. *yuv2packed2 = yuv2ya16le_2_c;
  2634. *yuv2packedX = yuv2ya16le_X_c;
  2635. break;
  2636. case AV_PIX_FMT_YA16BE:
  2637. *yuv2packed1 = yuv2ya16be_1_c;
  2638. *yuv2packed2 = yuv2ya16be_2_c;
  2639. *yuv2packedX = yuv2ya16be_X_c;
  2640. break;
  2641. case AV_PIX_FMT_AYUV64LE:
  2642. *yuv2packedX = yuv2ayuv64le_X_c;
  2643. break;
  2644. }
  2645. }