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.

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