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.

3039 lines
109KB

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