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.

2948 lines
106KB

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