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.

1614 lines
58KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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/bswap.h"
  27. #include "libavutil/cpu.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/mathematics.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "config.h"
  32. #include "rgb2rgb.h"
  33. #include "swscale.h"
  34. #include "swscale_internal.h"
  35. DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4)[2][8]={
  36. { 1, 3, 1, 3, 1, 3, 1, 3, },
  37. { 2, 0, 2, 0, 2, 0, 2, 0, },
  38. };
  39. DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8)[2][8]={
  40. { 6, 2, 6, 2, 6, 2, 6, 2, },
  41. { 0, 4, 0, 4, 0, 4, 0, 4, },
  42. };
  43. DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[4][8] = {
  44. { 8, 4, 11, 7, 8, 4, 11, 7, },
  45. { 2, 14, 1, 13, 2, 14, 1, 13, },
  46. { 10, 6, 9, 5, 10, 6, 9, 5, },
  47. { 0, 12, 3, 15, 0, 12, 3, 15, },
  48. };
  49. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[8][8] = {
  50. { 17, 9, 23, 15, 16, 8, 22, 14, },
  51. { 5, 29, 3, 27, 4, 28, 2, 26, },
  52. { 21, 13, 19, 11, 20, 12, 18, 10, },
  53. { 0, 24, 6, 30, 1, 25, 7, 31, },
  54. { 16, 8, 22, 14, 17, 9, 23, 15, },
  55. { 4, 28, 2, 26, 5, 29, 3, 27, },
  56. { 20, 12, 18, 10, 21, 13, 19, 11, },
  57. { 1, 25, 7, 31, 0, 24, 6, 30, },
  58. };
  59. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[8][8] = {
  60. { 0, 55, 14, 68, 3, 58, 17, 72, },
  61. { 37, 18, 50, 32, 40, 22, 54, 35, },
  62. { 9, 64, 5, 59, 13, 67, 8, 63, },
  63. { 46, 27, 41, 23, 49, 31, 44, 26, },
  64. { 2, 57, 16, 71, 1, 56, 15, 70, },
  65. { 39, 21, 52, 34, 38, 19, 51, 33, },
  66. { 11, 66, 7, 62, 10, 65, 6, 60, },
  67. { 48, 30, 43, 25, 47, 29, 42, 24, },
  68. };
  69. #if 1
  70. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[8][8] = {
  71. {117, 62, 158, 103, 113, 58, 155, 100, },
  72. { 34, 199, 21, 186, 31, 196, 17, 182, },
  73. {144, 89, 131, 76, 141, 86, 127, 72, },
  74. { 0, 165, 41, 206, 10, 175, 52, 217, },
  75. {110, 55, 151, 96, 120, 65, 162, 107, },
  76. { 28, 193, 14, 179, 38, 203, 24, 189, },
  77. {138, 83, 124, 69, 148, 93, 134, 79, },
  78. { 7, 172, 48, 213, 3, 168, 45, 210, },
  79. };
  80. #elif 1
  81. // tries to correct a gamma of 1.5
  82. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[8][8] = {
  83. { 0, 143, 18, 200, 2, 156, 25, 215, },
  84. { 78, 28, 125, 64, 89, 36, 138, 74, },
  85. { 10, 180, 3, 161, 16, 195, 8, 175, },
  86. {109, 51, 93, 38, 121, 60, 105, 47, },
  87. { 1, 152, 23, 210, 0, 147, 20, 205, },
  88. { 85, 33, 134, 71, 81, 30, 130, 67, },
  89. { 14, 190, 6, 171, 12, 185, 5, 166, },
  90. {117, 57, 101, 44, 113, 54, 97, 41, },
  91. };
  92. #elif 1
  93. // tries to correct a gamma of 2.0
  94. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[8][8] = {
  95. { 0, 124, 8, 193, 0, 140, 12, 213, },
  96. { 55, 14, 104, 42, 66, 19, 119, 52, },
  97. { 3, 168, 1, 145, 6, 187, 3, 162, },
  98. { 86, 31, 70, 21, 99, 39, 82, 28, },
  99. { 0, 134, 11, 206, 0, 129, 9, 200, },
  100. { 62, 17, 114, 48, 58, 16, 109, 45, },
  101. { 5, 181, 2, 157, 4, 175, 1, 151, },
  102. { 95, 36, 78, 26, 90, 34, 74, 24, },
  103. };
  104. #else
  105. // tries to correct a gamma of 2.5
  106. DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[8][8] = {
  107. { 0, 107, 3, 187, 0, 125, 6, 212, },
  108. { 39, 7, 86, 28, 49, 11, 102, 36, },
  109. { 1, 158, 0, 131, 3, 180, 1, 151, },
  110. { 68, 19, 52, 12, 81, 25, 64, 17, },
  111. { 0, 119, 5, 203, 0, 113, 4, 195, },
  112. { 45, 9, 96, 33, 42, 8, 91, 30, },
  113. { 2, 172, 1, 144, 2, 165, 0, 137, },
  114. { 77, 23, 60, 15, 72, 21, 56, 14, },
  115. };
  116. #endif
  117. #define output_pixel(pos, val, bias, signedness) \
  118. if (big_endian) { \
  119. AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  120. } else { \
  121. AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
  122. }
  123. static av_always_inline void
  124. yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
  125. int big_endian, int output_bits)
  126. {
  127. int i;
  128. int shift = 19 - output_bits;
  129. for (i = 0; i < dstW; i++) {
  130. int val = src[i] + (1 << (shift - 1));
  131. output_pixel(&dest[i], val, 0, uint);
  132. }
  133. }
  134. static av_always_inline void
  135. yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
  136. const int32_t **src, uint16_t *dest, int dstW,
  137. int big_endian, int output_bits)
  138. {
  139. int i;
  140. int shift = 15 + 16 - output_bits;
  141. for (i = 0; i < dstW; i++) {
  142. int val = 1 << (30-output_bits);
  143. int j;
  144. /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
  145. * filters (or anything with negative coeffs, the range can be slightly
  146. * wider in both directions. To account for this overflow, we subtract
  147. * a constant so it always fits in the signed range (assuming a
  148. * reasonable filterSize), and re-add that at the end. */
  149. val -= 0x40000000;
  150. for (j = 0; j < filterSize; j++)
  151. val += src[j][i] * filter[j];
  152. output_pixel(&dest[i], val, 0x8000, int);
  153. }
  154. }
  155. #undef output_pixel
  156. #define output_pixel(pos, val) \
  157. if (big_endian) { \
  158. AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  159. } else { \
  160. AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
  161. }
  162. static av_always_inline void
  163. yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
  164. int big_endian, int output_bits)
  165. {
  166. int i;
  167. int shift = 15 - output_bits;
  168. for (i = 0; i < dstW; i++) {
  169. int val = src[i] + (1 << (shift - 1));
  170. output_pixel(&dest[i], val);
  171. }
  172. }
  173. static av_always_inline void
  174. yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
  175. const int16_t **src, uint16_t *dest, int dstW,
  176. int big_endian, int output_bits)
  177. {
  178. int i;
  179. int shift = 11 + 16 - output_bits;
  180. for (i = 0; i < dstW; i++) {
  181. int val = 1 << (26-output_bits);
  182. int j;
  183. for (j = 0; j < filterSize; j++)
  184. val += src[j][i] * filter[j];
  185. output_pixel(&dest[i], val);
  186. }
  187. }
  188. #undef output_pixel
  189. #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
  190. static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
  191. uint8_t *dest, int dstW, \
  192. const uint8_t *dither, int offset)\
  193. { \
  194. yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
  195. (uint16_t *) dest, dstW, is_be, bits); \
  196. }\
  197. static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
  198. const int16_t **src, uint8_t *dest, int dstW, \
  199. const uint8_t *dither, int offset)\
  200. { \
  201. yuv2planeX_## template_size ## _c_template(filter, \
  202. filterSize, (const typeX_t **) src, \
  203. (uint16_t *) dest, dstW, is_be, bits); \
  204. }
  205. yuv2NBPS( 9, BE, 1, 10, int16_t)
  206. yuv2NBPS( 9, LE, 0, 10, int16_t)
  207. yuv2NBPS(10, BE, 1, 10, int16_t)
  208. yuv2NBPS(10, LE, 0, 10, int16_t)
  209. yuv2NBPS(12, BE, 1, 10, int16_t)
  210. yuv2NBPS(12, LE, 0, 10, int16_t)
  211. yuv2NBPS(16, BE, 1, 16, int32_t)
  212. yuv2NBPS(16, LE, 0, 16, int32_t)
  213. static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
  214. const int16_t **src, uint8_t *dest, int dstW,
  215. const uint8_t *dither, int offset)
  216. {
  217. int i;
  218. for (i=0; i<dstW; i++) {
  219. int val = dither[(i + offset) & 7] << 12;
  220. int j;
  221. for (j=0; j<filterSize; j++)
  222. val += src[j][i] * filter[j];
  223. dest[i]= av_clip_uint8(val>>19);
  224. }
  225. }
  226. static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
  227. const uint8_t *dither, int offset)
  228. {
  229. int i;
  230. for (i=0; i<dstW; i++) {
  231. int val = (src[i] + dither[(i + offset) & 7]) >> 7;
  232. dest[i]= av_clip_uint8(val);
  233. }
  234. }
  235. static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
  236. const int16_t **chrUSrc, const int16_t **chrVSrc,
  237. uint8_t *dest, int chrDstW)
  238. {
  239. enum AVPixelFormat dstFormat = c->dstFormat;
  240. const uint8_t *chrDither = c->chrDither8;
  241. int i;
  242. if (dstFormat == AV_PIX_FMT_NV12)
  243. for (i=0; i<chrDstW; i++) {
  244. int u = chrDither[i & 7] << 12;
  245. int v = chrDither[(i + 3) & 7] << 12;
  246. int j;
  247. for (j=0; j<chrFilterSize; j++) {
  248. u += chrUSrc[j][i] * chrFilter[j];
  249. v += chrVSrc[j][i] * chrFilter[j];
  250. }
  251. dest[2*i]= av_clip_uint8(u>>19);
  252. dest[2*i+1]= av_clip_uint8(v>>19);
  253. }
  254. else
  255. for (i=0; i<chrDstW; i++) {
  256. int u = chrDither[i & 7] << 12;
  257. int v = chrDither[(i + 3) & 7] << 12;
  258. int j;
  259. for (j=0; j<chrFilterSize; j++) {
  260. u += chrUSrc[j][i] * chrFilter[j];
  261. v += chrVSrc[j][i] * chrFilter[j];
  262. }
  263. dest[2*i]= av_clip_uint8(v>>19);
  264. dest[2*i+1]= av_clip_uint8(u>>19);
  265. }
  266. }
  267. #define accumulate_bit(acc, val) \
  268. acc <<= 1; \
  269. acc |= (val) >= (128 + 110)
  270. #define output_pixel(pos, acc) \
  271. if (target == AV_PIX_FMT_MONOBLACK) { \
  272. pos = acc; \
  273. } else { \
  274. pos = ~acc; \
  275. }
  276. static av_always_inline void
  277. yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
  278. const int16_t **lumSrc, int lumFilterSize,
  279. const int16_t *chrFilter, const int16_t **chrUSrc,
  280. const int16_t **chrVSrc, int chrFilterSize,
  281. const int16_t **alpSrc, uint8_t *dest, int dstW,
  282. int y, enum AVPixelFormat target)
  283. {
  284. const uint8_t * const d128 = ff_dither_8x8_220[y&7];
  285. int i;
  286. unsigned acc = 0;
  287. for (i = 0; i < dstW; i += 2) {
  288. int j;
  289. int Y1 = 1 << 18;
  290. int Y2 = 1 << 18;
  291. for (j = 0; j < lumFilterSize; j++) {
  292. Y1 += lumSrc[j][i] * lumFilter[j];
  293. Y2 += lumSrc[j][i+1] * lumFilter[j];
  294. }
  295. Y1 >>= 19;
  296. Y2 >>= 19;
  297. if ((Y1 | Y2) & 0x100) {
  298. Y1 = av_clip_uint8(Y1);
  299. Y2 = av_clip_uint8(Y2);
  300. }
  301. accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
  302. accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
  303. if ((i & 7) == 6) {
  304. output_pixel(*dest++, acc);
  305. }
  306. }
  307. if (i & 6) {
  308. output_pixel(*dest, acc);
  309. }
  310. }
  311. static av_always_inline void
  312. yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
  313. const int16_t *ubuf[2], const int16_t *vbuf[2],
  314. const int16_t *abuf[2], uint8_t *dest, int dstW,
  315. int yalpha, int uvalpha, int y,
  316. enum AVPixelFormat target)
  317. {
  318. const int16_t *buf0 = buf[0], *buf1 = buf[1];
  319. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  320. int yalpha1 = 4096 - yalpha;
  321. int i;
  322. for (i = 0; i < dstW; i += 8) {
  323. int Y, acc = 0;
  324. Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
  325. accumulate_bit(acc, Y + d128[0]);
  326. Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
  327. accumulate_bit(acc, Y + d128[1]);
  328. Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
  329. accumulate_bit(acc, Y + d128[2]);
  330. Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
  331. accumulate_bit(acc, Y + d128[3]);
  332. Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
  333. accumulate_bit(acc, Y + d128[4]);
  334. Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
  335. accumulate_bit(acc, Y + d128[5]);
  336. Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
  337. accumulate_bit(acc, Y + d128[6]);
  338. Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
  339. accumulate_bit(acc, Y + d128[7]);
  340. output_pixel(*dest++, acc);
  341. }
  342. }
  343. static av_always_inline void
  344. yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
  345. const int16_t *ubuf[2], const int16_t *vbuf[2],
  346. const int16_t *abuf0, uint8_t *dest, int dstW,
  347. int uvalpha, int y, enum AVPixelFormat target)
  348. {
  349. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  350. int i;
  351. for (i = 0; i < dstW; i += 8) {
  352. int acc = 0;
  353. accumulate_bit(acc, (buf0[i + 0] >> 7) + d128[0]);
  354. accumulate_bit(acc, (buf0[i + 1] >> 7) + d128[1]);
  355. accumulate_bit(acc, (buf0[i + 2] >> 7) + d128[2]);
  356. accumulate_bit(acc, (buf0[i + 3] >> 7) + d128[3]);
  357. accumulate_bit(acc, (buf0[i + 4] >> 7) + d128[4]);
  358. accumulate_bit(acc, (buf0[i + 5] >> 7) + d128[5]);
  359. accumulate_bit(acc, (buf0[i + 6] >> 7) + d128[6]);
  360. accumulate_bit(acc, (buf0[i + 7] >> 7) + d128[7]);
  361. output_pixel(*dest++, acc);
  362. }
  363. }
  364. #undef output_pixel
  365. #undef accumulate_bit
  366. #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
  367. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  368. const int16_t **lumSrc, int lumFilterSize, \
  369. const int16_t *chrFilter, const int16_t **chrUSrc, \
  370. const int16_t **chrVSrc, int chrFilterSize, \
  371. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  372. int y) \
  373. { \
  374. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  375. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  376. alpSrc, dest, dstW, y, fmt); \
  377. } \
  378. \
  379. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  380. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  381. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  382. int yalpha, int uvalpha, int y) \
  383. { \
  384. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  385. dest, dstW, yalpha, uvalpha, y, fmt); \
  386. } \
  387. \
  388. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  389. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  390. const int16_t *abuf0, uint8_t *dest, int dstW, \
  391. int uvalpha, int y) \
  392. { \
  393. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
  394. abuf0, dest, dstW, uvalpha, \
  395. y, fmt); \
  396. }
  397. YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
  398. YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
  399. #define output_pixels(pos, Y1, U, Y2, V) \
  400. if (target == AV_PIX_FMT_YUYV422) { \
  401. dest[pos + 0] = Y1; \
  402. dest[pos + 1] = U; \
  403. dest[pos + 2] = Y2; \
  404. dest[pos + 3] = V; \
  405. } else if (target == AV_PIX_FMT_YVYU422) { \
  406. dest[pos + 0] = Y1; \
  407. dest[pos + 1] = V; \
  408. dest[pos + 2] = Y2; \
  409. dest[pos + 3] = U; \
  410. } else { /* AV_PIX_FMT_UYVY422 */ \
  411. dest[pos + 0] = U; \
  412. dest[pos + 1] = Y1; \
  413. dest[pos + 2] = V; \
  414. dest[pos + 3] = Y2; \
  415. }
  416. static av_always_inline void
  417. yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
  418. const int16_t **lumSrc, int lumFilterSize,
  419. const int16_t *chrFilter, const int16_t **chrUSrc,
  420. const int16_t **chrVSrc, int chrFilterSize,
  421. const int16_t **alpSrc, uint8_t *dest, int dstW,
  422. int y, enum AVPixelFormat target)
  423. {
  424. int i;
  425. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  426. int j;
  427. int Y1 = 1 << 18;
  428. int Y2 = 1 << 18;
  429. int U = 1 << 18;
  430. int V = 1 << 18;
  431. for (j = 0; j < lumFilterSize; j++) {
  432. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  433. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  434. }
  435. for (j = 0; j < chrFilterSize; j++) {
  436. U += chrUSrc[j][i] * chrFilter[j];
  437. V += chrVSrc[j][i] * chrFilter[j];
  438. }
  439. Y1 >>= 19;
  440. Y2 >>= 19;
  441. U >>= 19;
  442. V >>= 19;
  443. if ((Y1 | Y2 | U | V) & 0x100) {
  444. Y1 = av_clip_uint8(Y1);
  445. Y2 = av_clip_uint8(Y2);
  446. U = av_clip_uint8(U);
  447. V = av_clip_uint8(V);
  448. }
  449. output_pixels(4*i, Y1, U, Y2, V);
  450. }
  451. }
  452. static av_always_inline void
  453. yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
  454. const int16_t *ubuf[2], const int16_t *vbuf[2],
  455. const int16_t *abuf[2], uint8_t *dest, int dstW,
  456. int yalpha, int uvalpha, int y,
  457. enum AVPixelFormat target)
  458. {
  459. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  460. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  461. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  462. int yalpha1 = 4096 - yalpha;
  463. int uvalpha1 = 4096 - uvalpha;
  464. int i;
  465. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  466. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  467. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  468. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  469. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  470. Y1 = av_clip_uint8(Y1);
  471. Y2 = av_clip_uint8(Y2);
  472. U = av_clip_uint8(U);
  473. V = av_clip_uint8(V);
  474. output_pixels(i * 4, Y1, U, Y2, V);
  475. }
  476. }
  477. static av_always_inline void
  478. yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
  479. const int16_t *ubuf[2], const int16_t *vbuf[2],
  480. const int16_t *abuf0, uint8_t *dest, int dstW,
  481. int uvalpha, int y, enum AVPixelFormat target)
  482. {
  483. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  484. int i;
  485. if (uvalpha < 2048) {
  486. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  487. int Y1 = buf0[i * 2] >> 7;
  488. int Y2 = buf0[i * 2 + 1] >> 7;
  489. int U = ubuf0[i] >> 7;
  490. int V = vbuf0[i] >> 7;
  491. Y1 = av_clip_uint8(Y1);
  492. Y2 = av_clip_uint8(Y2);
  493. U = av_clip_uint8(U);
  494. V = av_clip_uint8(V);
  495. output_pixels(i * 4, Y1, U, Y2, V);
  496. }
  497. } else {
  498. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  499. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  500. int Y1 = buf0[i * 2] >> 7;
  501. int Y2 = buf0[i * 2 + 1] >> 7;
  502. int U = (ubuf0[i] + ubuf1[i]) >> 8;
  503. int V = (vbuf0[i] + vbuf1[i]) >> 8;
  504. Y1 = av_clip_uint8(Y1);
  505. Y2 = av_clip_uint8(Y2);
  506. U = av_clip_uint8(U);
  507. V = av_clip_uint8(V);
  508. output_pixels(i * 4, Y1, U, Y2, V);
  509. }
  510. }
  511. }
  512. #undef output_pixels
  513. YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
  514. YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422)
  515. YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
  516. #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? R : B)
  517. #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? B : R)
  518. #define output_pixel(pos, val) \
  519. if (isBE(target)) { \
  520. AV_WB16(pos, val); \
  521. } else { \
  522. AV_WL16(pos, val); \
  523. }
  524. static av_always_inline void
  525. yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
  526. const int32_t **lumSrc, int lumFilterSize,
  527. const int16_t *chrFilter, const int32_t **chrUSrc,
  528. const int32_t **chrVSrc, int chrFilterSize,
  529. const int32_t **alpSrc, uint16_t *dest, int dstW,
  530. int y, enum AVPixelFormat target)
  531. {
  532. int i;
  533. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  534. int j;
  535. int Y1 = -0x40000000;
  536. int Y2 = -0x40000000;
  537. int U = -128 << 23; // 19
  538. int V = -128 << 23;
  539. int R, G, B;
  540. for (j = 0; j < lumFilterSize; j++) {
  541. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  542. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  543. }
  544. for (j = 0; j < chrFilterSize; j++) {
  545. U += chrUSrc[j][i] * chrFilter[j];
  546. V += chrVSrc[j][i] * chrFilter[j];
  547. }
  548. // 8 bits: 12+15=27; 16 bits: 12+19=31
  549. Y1 >>= 14; // 10
  550. Y1 += 0x10000;
  551. Y2 >>= 14;
  552. Y2 += 0x10000;
  553. U >>= 14;
  554. V >>= 14;
  555. // 8 bits: 27 -> 17 bits, 16 bits: 31 - 14 = 17 bits
  556. Y1 -= c->yuv2rgb_y_offset;
  557. Y2 -= c->yuv2rgb_y_offset;
  558. Y1 *= c->yuv2rgb_y_coeff;
  559. Y2 *= c->yuv2rgb_y_coeff;
  560. Y1 += 1 << 13; // 21
  561. Y2 += 1 << 13;
  562. // 8 bits: 17 + 13 bits = 30 bits, 16 bits: 17 + 13 bits = 30 bits
  563. R = V * c->yuv2rgb_v2r_coeff;
  564. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  565. B = U * c->yuv2rgb_u2b_coeff;
  566. // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
  567. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  568. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  569. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  570. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  571. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  572. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  573. dest += 6;
  574. }
  575. }
  576. static av_always_inline void
  577. yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
  578. const int32_t *ubuf[2], const int32_t *vbuf[2],
  579. const int32_t *abuf[2], uint16_t *dest, int dstW,
  580. int yalpha, int uvalpha, int y,
  581. enum AVPixelFormat target)
  582. {
  583. const int32_t *buf0 = buf[0], *buf1 = buf[1],
  584. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  585. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
  586. int yalpha1 = 4096 - yalpha;
  587. int uvalpha1 = 4096 - uvalpha;
  588. int i;
  589. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  590. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
  591. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
  592. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
  593. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
  594. int R, G, B;
  595. Y1 -= c->yuv2rgb_y_offset;
  596. Y2 -= c->yuv2rgb_y_offset;
  597. Y1 *= c->yuv2rgb_y_coeff;
  598. Y2 *= c->yuv2rgb_y_coeff;
  599. Y1 += 1 << 13;
  600. Y2 += 1 << 13;
  601. R = V * c->yuv2rgb_v2r_coeff;
  602. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  603. B = U * c->yuv2rgb_u2b_coeff;
  604. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  605. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  606. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  607. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  608. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  609. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  610. dest += 6;
  611. }
  612. }
  613. static av_always_inline void
  614. yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
  615. const int32_t *ubuf[2], const int32_t *vbuf[2],
  616. const int32_t *abuf0, uint16_t *dest, int dstW,
  617. int uvalpha, int y, enum AVPixelFormat target)
  618. {
  619. const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  620. int i;
  621. if (uvalpha < 2048) {
  622. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  623. int Y1 = (buf0[i * 2] ) >> 2;
  624. int Y2 = (buf0[i * 2 + 1]) >> 2;
  625. int U = (ubuf0[i] + (-128 << 11)) >> 2;
  626. int V = (vbuf0[i] + (-128 << 11)) >> 2;
  627. int R, G, B;
  628. Y1 -= c->yuv2rgb_y_offset;
  629. Y2 -= c->yuv2rgb_y_offset;
  630. Y1 *= c->yuv2rgb_y_coeff;
  631. Y2 *= c->yuv2rgb_y_coeff;
  632. Y1 += 1 << 13;
  633. Y2 += 1 << 13;
  634. R = V * c->yuv2rgb_v2r_coeff;
  635. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  636. B = U * c->yuv2rgb_u2b_coeff;
  637. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  638. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  639. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  640. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  641. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  642. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  643. dest += 6;
  644. }
  645. } else {
  646. const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  647. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  648. int Y1 = (buf0[i * 2] ) >> 2;
  649. int Y2 = (buf0[i * 2 + 1]) >> 2;
  650. int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
  651. int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
  652. int R, G, B;
  653. Y1 -= c->yuv2rgb_y_offset;
  654. Y2 -= c->yuv2rgb_y_offset;
  655. Y1 *= c->yuv2rgb_y_coeff;
  656. Y2 *= c->yuv2rgb_y_coeff;
  657. Y1 += 1 << 13;
  658. Y2 += 1 << 13;
  659. R = V * c->yuv2rgb_v2r_coeff;
  660. G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  661. B = U * c->yuv2rgb_u2b_coeff;
  662. output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
  663. output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
  664. output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
  665. output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
  666. output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
  667. output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
  668. dest += 6;
  669. }
  670. }
  671. }
  672. #undef output_pixel
  673. #undef r_b
  674. #undef b_r
  675. #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
  676. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  677. const int16_t **_lumSrc, int lumFilterSize, \
  678. const int16_t *chrFilter, const int16_t **_chrUSrc, \
  679. const int16_t **_chrVSrc, int chrFilterSize, \
  680. const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
  681. int y) \
  682. { \
  683. const int32_t **lumSrc = (const int32_t **) _lumSrc, \
  684. **chrUSrc = (const int32_t **) _chrUSrc, \
  685. **chrVSrc = (const int32_t **) _chrVSrc, \
  686. **alpSrc = (const int32_t **) _alpSrc; \
  687. uint16_t *dest = (uint16_t *) _dest; \
  688. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  689. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  690. alpSrc, dest, dstW, y, fmt); \
  691. } \
  692. \
  693. static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
  694. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  695. const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
  696. int yalpha, int uvalpha, int y) \
  697. { \
  698. const int32_t **buf = (const int32_t **) _buf, \
  699. **ubuf = (const int32_t **) _ubuf, \
  700. **vbuf = (const int32_t **) _vbuf, \
  701. **abuf = (const int32_t **) _abuf; \
  702. uint16_t *dest = (uint16_t *) _dest; \
  703. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  704. dest, dstW, yalpha, uvalpha, y, fmt); \
  705. } \
  706. \
  707. static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
  708. const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
  709. const int16_t *_abuf0, uint8_t *_dest, int dstW, \
  710. int uvalpha, int y) \
  711. { \
  712. const int32_t *buf0 = (const int32_t *) _buf0, \
  713. **ubuf = (const int32_t **) _ubuf, \
  714. **vbuf = (const int32_t **) _vbuf, \
  715. *abuf0 = (const int32_t *) _abuf0; \
  716. uint16_t *dest = (uint16_t *) _dest; \
  717. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  718. dstW, uvalpha, y, fmt); \
  719. }
  720. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, AV_PIX_FMT_RGB48BE)
  721. YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, AV_PIX_FMT_RGB48LE)
  722. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, AV_PIX_FMT_BGR48BE)
  723. YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, AV_PIX_FMT_BGR48LE)
  724. /*
  725. * Write out 2 RGB pixels in the target pixel format. This function takes a
  726. * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
  727. * things like endianness conversion and shifting. The caller takes care of
  728. * setting the correct offset in these tables from the chroma (U/V) values.
  729. * This function then uses the luminance (Y1/Y2) values to write out the
  730. * correct RGB values into the destination buffer.
  731. */
  732. static av_always_inline void
  733. yuv2rgb_write(uint8_t *_dest, int i, unsigned Y1, unsigned Y2,
  734. unsigned A1, unsigned A2,
  735. const void *_r, const void *_g, const void *_b, int y,
  736. enum AVPixelFormat target, int hasAlpha)
  737. {
  738. if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
  739. target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
  740. uint32_t *dest = (uint32_t *) _dest;
  741. const uint32_t *r = (const uint32_t *) _r;
  742. const uint32_t *g = (const uint32_t *) _g;
  743. const uint32_t *b = (const uint32_t *) _b;
  744. #if CONFIG_SMALL
  745. int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
  746. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
  747. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
  748. #else
  749. if (hasAlpha) {
  750. int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
  751. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
  752. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
  753. } else {
  754. dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
  755. dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
  756. }
  757. #endif
  758. } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
  759. uint8_t *dest = (uint8_t *) _dest;
  760. const uint8_t *r = (const uint8_t *) _r;
  761. const uint8_t *g = (const uint8_t *) _g;
  762. const uint8_t *b = (const uint8_t *) _b;
  763. #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
  764. #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
  765. dest[i * 6 + 0] = r_b[Y1];
  766. dest[i * 6 + 1] = g[Y1];
  767. dest[i * 6 + 2] = b_r[Y1];
  768. dest[i * 6 + 3] = r_b[Y2];
  769. dest[i * 6 + 4] = g[Y2];
  770. dest[i * 6 + 5] = b_r[Y2];
  771. #undef r_b
  772. #undef b_r
  773. } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
  774. target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
  775. target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
  776. uint16_t *dest = (uint16_t *) _dest;
  777. const uint16_t *r = (const uint16_t *) _r;
  778. const uint16_t *g = (const uint16_t *) _g;
  779. const uint16_t *b = (const uint16_t *) _b;
  780. int dr1, dg1, db1, dr2, dg2, db2;
  781. if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
  782. dr1 = dither_2x2_8[ y & 1 ][0];
  783. dg1 = dither_2x2_4[ y & 1 ][0];
  784. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  785. dr2 = dither_2x2_8[ y & 1 ][1];
  786. dg2 = dither_2x2_4[ y & 1 ][1];
  787. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  788. } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
  789. dr1 = dither_2x2_8[ y & 1 ][0];
  790. dg1 = dither_2x2_8[ y & 1 ][1];
  791. db1 = dither_2x2_8[(y & 1) ^ 1][0];
  792. dr2 = dither_2x2_8[ y & 1 ][1];
  793. dg2 = dither_2x2_8[ y & 1 ][0];
  794. db2 = dither_2x2_8[(y & 1) ^ 1][1];
  795. } else {
  796. dr1 = ff_dither_4x4_16[ y & 3 ][0];
  797. dg1 = ff_dither_4x4_16[ y & 3 ][1];
  798. db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
  799. dr2 = ff_dither_4x4_16[ y & 3 ][1];
  800. dg2 = ff_dither_4x4_16[ y & 3 ][0];
  801. db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
  802. }
  803. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  804. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  805. } else /* 8/4 bits */ {
  806. uint8_t *dest = (uint8_t *) _dest;
  807. const uint8_t *r = (const uint8_t *) _r;
  808. const uint8_t *g = (const uint8_t *) _g;
  809. const uint8_t *b = (const uint8_t *) _b;
  810. int dr1, dg1, db1, dr2, dg2, db2;
  811. if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
  812. const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
  813. const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
  814. dr1 = dg1 = d32[(i * 2 + 0) & 7];
  815. db1 = d64[(i * 2 + 0) & 7];
  816. dr2 = dg2 = d32[(i * 2 + 1) & 7];
  817. db2 = d64[(i * 2 + 1) & 7];
  818. } else {
  819. const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
  820. const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
  821. dr1 = db1 = d128[(i * 2 + 0) & 7];
  822. dg1 = d64[(i * 2 + 0) & 7];
  823. dr2 = db2 = d128[(i * 2 + 1) & 7];
  824. dg2 = d64[(i * 2 + 1) & 7];
  825. }
  826. if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
  827. dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
  828. ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
  829. } else {
  830. dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
  831. dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
  832. }
  833. }
  834. }
  835. static av_always_inline void
  836. yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
  837. const int16_t **lumSrc, int lumFilterSize,
  838. const int16_t *chrFilter, const int16_t **chrUSrc,
  839. const int16_t **chrVSrc, int chrFilterSize,
  840. const int16_t **alpSrc, uint8_t *dest, int dstW,
  841. int y, enum AVPixelFormat target, int hasAlpha)
  842. {
  843. int i;
  844. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  845. int j, A1, A2;
  846. int Y1 = 1 << 18;
  847. int Y2 = 1 << 18;
  848. int U = 1 << 18;
  849. int V = 1 << 18;
  850. const void *r, *g, *b;
  851. for (j = 0; j < lumFilterSize; j++) {
  852. Y1 += lumSrc[j][i * 2] * lumFilter[j];
  853. Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
  854. }
  855. for (j = 0; j < chrFilterSize; j++) {
  856. U += chrUSrc[j][i] * chrFilter[j];
  857. V += chrVSrc[j][i] * chrFilter[j];
  858. }
  859. Y1 >>= 19;
  860. Y2 >>= 19;
  861. U >>= 19;
  862. V >>= 19;
  863. if ((Y1 | Y2 | U | V) & 0x100) {
  864. Y1 = av_clip_uint8(Y1);
  865. Y2 = av_clip_uint8(Y2);
  866. U = av_clip_uint8(U);
  867. V = av_clip_uint8(V);
  868. }
  869. if (hasAlpha) {
  870. A1 = 1 << 18;
  871. A2 = 1 << 18;
  872. for (j = 0; j < lumFilterSize; j++) {
  873. A1 += alpSrc[j][i * 2 ] * lumFilter[j];
  874. A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
  875. }
  876. A1 >>= 19;
  877. A2 >>= 19;
  878. if ((A1 | A2) & 0x100) {
  879. A1 = av_clip_uint8(A1);
  880. A2 = av_clip_uint8(A2);
  881. }
  882. }
  883. /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/
  884. r = c->table_rV[V];
  885. g = (c->table_gU[U] + c->table_gV[V]);
  886. b = c->table_bU[U];
  887. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  888. r, g, b, y, target, hasAlpha);
  889. }
  890. }
  891. static av_always_inline void
  892. yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
  893. const int16_t *ubuf[2], const int16_t *vbuf[2],
  894. const int16_t *abuf[2], uint8_t *dest, int dstW,
  895. int yalpha, int uvalpha, int y,
  896. enum AVPixelFormat target, int hasAlpha)
  897. {
  898. const int16_t *buf0 = buf[0], *buf1 = buf[1],
  899. *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
  900. *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
  901. *abuf0 = hasAlpha ? abuf[0] : NULL,
  902. *abuf1 = hasAlpha ? abuf[1] : NULL;
  903. int yalpha1 = 4096 - yalpha;
  904. int uvalpha1 = 4096 - uvalpha;
  905. int i;
  906. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  907. int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
  908. int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
  909. int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
  910. int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
  911. int A1, A2;
  912. const void *r, *g, *b;
  913. Y1 = av_clip_uint8(Y1);
  914. Y2 = av_clip_uint8(Y2);
  915. U = av_clip_uint8(U);
  916. V = av_clip_uint8(V);
  917. r = c->table_rV[V];
  918. g = (c->table_gU[U] + c->table_gV[V]);
  919. b = c->table_bU[U];
  920. if (hasAlpha) {
  921. A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
  922. A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
  923. A1 = av_clip_uint8(A1);
  924. A2 = av_clip_uint8(A2);
  925. }
  926. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  927. r, g, b, y, target, hasAlpha);
  928. }
  929. }
  930. static av_always_inline void
  931. yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
  932. const int16_t *ubuf[2], const int16_t *vbuf[2],
  933. const int16_t *abuf0, uint8_t *dest, int dstW,
  934. int uvalpha, int y, enum AVPixelFormat target,
  935. int hasAlpha)
  936. {
  937. const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
  938. int i;
  939. if (uvalpha < 2048) {
  940. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  941. int Y1 = buf0[i * 2] >> 7;
  942. int Y2 = buf0[i * 2 + 1] >> 7;
  943. int U = ubuf0[i] >> 7;
  944. int V = vbuf0[i] >> 7;
  945. int A1, A2;
  946. const void *r, *g, *b;
  947. Y1 = av_clip_uint8(Y1);
  948. Y2 = av_clip_uint8(Y2);
  949. U = av_clip_uint8(U);
  950. V = av_clip_uint8(V);
  951. r = c->table_rV[V];
  952. g = (c->table_gU[U] + c->table_gV[V]);
  953. b = c->table_bU[U];
  954. if (hasAlpha) {
  955. A1 = abuf0[i * 2 ] >> 7;
  956. A2 = abuf0[i * 2 + 1] >> 7;
  957. A1 = av_clip_uint8(A1);
  958. A2 = av_clip_uint8(A2);
  959. }
  960. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  961. r, g, b, y, target, hasAlpha);
  962. }
  963. } else {
  964. const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
  965. for (i = 0; i < ((dstW + 1) >> 1); i++) {
  966. int Y1 = buf0[i * 2] >> 7;
  967. int Y2 = buf0[i * 2 + 1] >> 7;
  968. int U = (ubuf0[i] + ubuf1[i]) >> 8;
  969. int V = (vbuf0[i] + vbuf1[i]) >> 8;
  970. int A1, A2;
  971. const void *r, *g, *b;
  972. Y1 = av_clip_uint8(Y1);
  973. Y2 = av_clip_uint8(Y2);
  974. U = av_clip_uint8(U);
  975. V = av_clip_uint8(V);
  976. r = c->table_rV[V];
  977. g = (c->table_gU[U] + c->table_gV[V]);
  978. b = c->table_bU[U];
  979. if (hasAlpha) {
  980. A1 = abuf0[i * 2 ] >> 7;
  981. A2 = abuf0[i * 2 + 1] >> 7;
  982. A1 = av_clip_uint8(A1);
  983. A2 = av_clip_uint8(A2);
  984. }
  985. yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
  986. r, g, b, y, target, hasAlpha);
  987. }
  988. }
  989. }
  990. #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  991. static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
  992. const int16_t **lumSrc, int lumFilterSize, \
  993. const int16_t *chrFilter, const int16_t **chrUSrc, \
  994. const int16_t **chrVSrc, int chrFilterSize, \
  995. const int16_t **alpSrc, uint8_t *dest, int dstW, \
  996. int y) \
  997. { \
  998. name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
  999. chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
  1000. alpSrc, dest, dstW, y, fmt, hasAlpha); \
  1001. }
  1002. #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
  1003. YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
  1004. static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
  1005. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1006. const int16_t *abuf[2], uint8_t *dest, int dstW, \
  1007. int yalpha, int uvalpha, int y) \
  1008. { \
  1009. name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
  1010. dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
  1011. } \
  1012. \
  1013. static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
  1014. const int16_t *ubuf[2], const int16_t *vbuf[2], \
  1015. const int16_t *abuf0, uint8_t *dest, int dstW, \
  1016. int uvalpha, int y) \
  1017. { \
  1018. name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
  1019. dstW, uvalpha, y, fmt, hasAlpha); \
  1020. }
  1021. #if CONFIG_SMALL
  1022. YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1023. YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1024. #else
  1025. #if CONFIG_SWSCALE_ALPHA
  1026. YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
  1027. YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
  1028. #endif
  1029. YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
  1030. YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
  1031. #endif
  1032. YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
  1033. YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
  1034. YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
  1035. YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
  1036. YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
  1037. YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
  1038. YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
  1039. YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
  1040. static av_always_inline void
  1041. yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
  1042. const int16_t **lumSrc, int lumFilterSize,
  1043. const int16_t *chrFilter, const int16_t **chrUSrc,
  1044. const int16_t **chrVSrc, int chrFilterSize,
  1045. const int16_t **alpSrc, uint8_t *dest,
  1046. int dstW, int y, enum AVPixelFormat target, int hasAlpha)
  1047. {
  1048. int i;
  1049. int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
  1050. for (i = 0; i < dstW; i++) {
  1051. int j;
  1052. int Y = 0;
  1053. int U = -128 << 19;
  1054. int V = -128 << 19;
  1055. int R, G, B, A;
  1056. for (j = 0; j < lumFilterSize; j++) {
  1057. Y += lumSrc[j][i] * lumFilter[j];
  1058. }
  1059. for (j = 0; j < chrFilterSize; j++) {
  1060. U += chrUSrc[j][i] * chrFilter[j];
  1061. V += chrVSrc[j][i] * chrFilter[j];
  1062. }
  1063. Y >>= 10;
  1064. U >>= 10;
  1065. V >>= 10;
  1066. if (hasAlpha) {
  1067. A = 1 << 21;
  1068. for (j = 0; j < lumFilterSize; j++) {
  1069. A += alpSrc[j][i] * lumFilter[j];
  1070. }
  1071. A >>= 19;
  1072. if (A & 0x100)
  1073. A = av_clip_uint8(A);
  1074. }
  1075. Y -= c->yuv2rgb_y_offset;
  1076. Y *= c->yuv2rgb_y_coeff;
  1077. Y += 1 << 21;
  1078. R = Y + V*c->yuv2rgb_v2r_coeff;
  1079. G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
  1080. B = Y + U*c->yuv2rgb_u2b_coeff;
  1081. if ((R | G | B) & 0xC0000000) {
  1082. R = av_clip_uintp2(R, 30);
  1083. G = av_clip_uintp2(G, 30);
  1084. B = av_clip_uintp2(B, 30);
  1085. }
  1086. switch(target) {
  1087. case AV_PIX_FMT_ARGB:
  1088. dest[0] = hasAlpha ? A : 255;
  1089. dest[1] = R >> 22;
  1090. dest[2] = G >> 22;
  1091. dest[3] = B >> 22;
  1092. break;
  1093. case AV_PIX_FMT_RGB24:
  1094. dest[0] = R >> 22;
  1095. dest[1] = G >> 22;
  1096. dest[2] = B >> 22;
  1097. break;
  1098. case AV_PIX_FMT_RGBA:
  1099. dest[0] = R >> 22;
  1100. dest[1] = G >> 22;
  1101. dest[2] = B >> 22;
  1102. dest[3] = hasAlpha ? A : 255;
  1103. break;
  1104. case AV_PIX_FMT_ABGR:
  1105. dest[0] = hasAlpha ? A : 255;
  1106. dest[1] = B >> 22;
  1107. dest[2] = G >> 22;
  1108. dest[3] = R >> 22;
  1109. dest += 4;
  1110. break;
  1111. case AV_PIX_FMT_BGR24:
  1112. dest[0] = B >> 22;
  1113. dest[1] = G >> 22;
  1114. dest[2] = R >> 22;
  1115. break;
  1116. case AV_PIX_FMT_BGRA:
  1117. dest[0] = B >> 22;
  1118. dest[1] = G >> 22;
  1119. dest[2] = R >> 22;
  1120. dest[3] = hasAlpha ? A : 255;
  1121. break;
  1122. }
  1123. dest += step;
  1124. }
  1125. }
  1126. #if CONFIG_SMALL
  1127. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1128. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1129. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1130. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
  1131. #else
  1132. #if CONFIG_SWSCALE_ALPHA
  1133. YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
  1134. YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
  1135. YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
  1136. YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
  1137. #endif
  1138. YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
  1139. YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
  1140. YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
  1141. YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
  1142. #endif
  1143. YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
  1144. YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
  1145. static void
  1146. yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
  1147. const int16_t **lumSrc, int lumFilterSize,
  1148. const int16_t *chrFilter, const int16_t **chrUSrc,
  1149. const int16_t **chrVSrc, int chrFilterSize,
  1150. const int16_t **alpSrc, uint8_t **dest,
  1151. int dstW, int y)
  1152. {
  1153. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
  1154. int i;
  1155. int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
  1156. uint16_t **dest16 = (uint16_t**)dest;
  1157. int SH = 22 + 8 - desc->comp[0].depth;
  1158. for (i = 0; i < dstW; i++) {
  1159. int j;
  1160. int Y = 1 << 9;
  1161. int U = (1 << 9) - (128 << 19);
  1162. int V = (1 << 9) - (128 << 19);
  1163. int R, G, B, A;
  1164. for (j = 0; j < lumFilterSize; j++)
  1165. Y += lumSrc[j][i] * lumFilter[j];
  1166. for (j = 0; j < chrFilterSize; j++) {
  1167. U += chrUSrc[j][i] * chrFilter[j];
  1168. V += chrVSrc[j][i] * chrFilter[j];
  1169. }
  1170. Y >>= 10;
  1171. U >>= 10;
  1172. V >>= 10;
  1173. if (hasAlpha) {
  1174. A = 1 << 18;
  1175. for (j = 0; j < lumFilterSize; j++)
  1176. A += alpSrc[j][i] * lumFilter[j];
  1177. A >>= 19;
  1178. if (A & 0x100)
  1179. A = av_clip_uint8(A);
  1180. }
  1181. Y -= c->yuv2rgb_y_offset;
  1182. Y *= c->yuv2rgb_y_coeff;
  1183. Y += 1 << 21;
  1184. R = Y + V * c->yuv2rgb_v2r_coeff;
  1185. G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
  1186. B = Y + U * c->yuv2rgb_u2b_coeff;
  1187. if ((R | G | B) & 0xC0000000) {
  1188. R = av_clip_uintp2(R, 30);
  1189. G = av_clip_uintp2(G, 30);
  1190. B = av_clip_uintp2(B, 30);
  1191. }
  1192. if (SH != 22) {
  1193. dest16[0][i] = G >> SH;
  1194. dest16[1][i] = B >> SH;
  1195. dest16[2][i] = R >> SH;
  1196. if (hasAlpha)
  1197. dest16[3][i] = A;
  1198. } else {
  1199. dest[0][i] = G >> 22;
  1200. dest[1][i] = B >> 22;
  1201. dest[2][i] = R >> 22;
  1202. if (hasAlpha)
  1203. dest[3][i] = A;
  1204. }
  1205. }
  1206. if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
  1207. for (i = 0; i < dstW; i++) {
  1208. dest16[0][i] = av_bswap16(dest16[0][i]);
  1209. dest16[1][i] = av_bswap16(dest16[1][i]);
  1210. dest16[2][i] = av_bswap16(dest16[2][i]);
  1211. if (hasAlpha)
  1212. dest16[3][i] = av_bswap16(dest16[3][i]);
  1213. }
  1214. }
  1215. }
  1216. av_cold void ff_sws_init_output_funcs(SwsContext *c,
  1217. yuv2planar1_fn *yuv2plane1,
  1218. yuv2planarX_fn *yuv2planeX,
  1219. yuv2interleavedX_fn *yuv2nv12cX,
  1220. yuv2packed1_fn *yuv2packed1,
  1221. yuv2packed2_fn *yuv2packed2,
  1222. yuv2packedX_fn *yuv2packedX,
  1223. yuv2anyX_fn *yuv2anyX)
  1224. {
  1225. enum AVPixelFormat dstFormat = c->dstFormat;
  1226. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
  1227. if (is16BPS(dstFormat)) {
  1228. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
  1229. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
  1230. } else if (is9_15BPS(dstFormat)) {
  1231. if (desc->comp[0].depth == 9) {
  1232. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
  1233. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
  1234. } else if (desc->comp[0].depth == 10) {
  1235. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
  1236. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
  1237. } else if (desc->comp[0].depth == 12) {
  1238. *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
  1239. *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
  1240. } else {
  1241. assert(0);
  1242. }
  1243. } else {
  1244. *yuv2plane1 = yuv2plane1_8_c;
  1245. *yuv2planeX = yuv2planeX_8_c;
  1246. if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
  1247. *yuv2nv12cX = yuv2nv12cX_c;
  1248. }
  1249. if(c->flags & SWS_FULL_CHR_H_INT) {
  1250. switch (dstFormat) {
  1251. case AV_PIX_FMT_RGBA:
  1252. #if CONFIG_SMALL
  1253. *yuv2packedX = yuv2rgba32_full_X_c;
  1254. #else
  1255. #if CONFIG_SWSCALE_ALPHA
  1256. if (c->alpPixBuf) {
  1257. *yuv2packedX = yuv2rgba32_full_X_c;
  1258. } else
  1259. #endif /* CONFIG_SWSCALE_ALPHA */
  1260. {
  1261. *yuv2packedX = yuv2rgbx32_full_X_c;
  1262. }
  1263. #endif /* !CONFIG_SMALL */
  1264. break;
  1265. case AV_PIX_FMT_ARGB:
  1266. #if CONFIG_SMALL
  1267. *yuv2packedX = yuv2argb32_full_X_c;
  1268. #else
  1269. #if CONFIG_SWSCALE_ALPHA
  1270. if (c->alpPixBuf) {
  1271. *yuv2packedX = yuv2argb32_full_X_c;
  1272. } else
  1273. #endif /* CONFIG_SWSCALE_ALPHA */
  1274. {
  1275. *yuv2packedX = yuv2xrgb32_full_X_c;
  1276. }
  1277. #endif /* !CONFIG_SMALL */
  1278. break;
  1279. case AV_PIX_FMT_BGRA:
  1280. #if CONFIG_SMALL
  1281. *yuv2packedX = yuv2bgra32_full_X_c;
  1282. #else
  1283. #if CONFIG_SWSCALE_ALPHA
  1284. if (c->alpPixBuf) {
  1285. *yuv2packedX = yuv2bgra32_full_X_c;
  1286. } else
  1287. #endif /* CONFIG_SWSCALE_ALPHA */
  1288. {
  1289. *yuv2packedX = yuv2bgrx32_full_X_c;
  1290. }
  1291. #endif /* !CONFIG_SMALL */
  1292. break;
  1293. case AV_PIX_FMT_ABGR:
  1294. #if CONFIG_SMALL
  1295. *yuv2packedX = yuv2abgr32_full_X_c;
  1296. #else
  1297. #if CONFIG_SWSCALE_ALPHA
  1298. if (c->alpPixBuf) {
  1299. *yuv2packedX = yuv2abgr32_full_X_c;
  1300. } else
  1301. #endif /* CONFIG_SWSCALE_ALPHA */
  1302. {
  1303. *yuv2packedX = yuv2xbgr32_full_X_c;
  1304. }
  1305. #endif /* !CONFIG_SMALL */
  1306. break;
  1307. case AV_PIX_FMT_RGB24:
  1308. *yuv2packedX = yuv2rgb24_full_X_c;
  1309. break;
  1310. case AV_PIX_FMT_BGR24:
  1311. *yuv2packedX = yuv2bgr24_full_X_c;
  1312. break;
  1313. case AV_PIX_FMT_GBRP:
  1314. case AV_PIX_FMT_GBRP9BE:
  1315. case AV_PIX_FMT_GBRP9LE:
  1316. case AV_PIX_FMT_GBRP10BE:
  1317. case AV_PIX_FMT_GBRP10LE:
  1318. case AV_PIX_FMT_GBRP12BE:
  1319. case AV_PIX_FMT_GBRP12LE:
  1320. case AV_PIX_FMT_GBRAP12BE:
  1321. case AV_PIX_FMT_GBRAP12LE:
  1322. case AV_PIX_FMT_GBRP16BE:
  1323. case AV_PIX_FMT_GBRP16LE:
  1324. case AV_PIX_FMT_GBRAP:
  1325. *yuv2anyX = yuv2gbrp_full_X_c;
  1326. break;
  1327. }
  1328. } else {
  1329. switch (dstFormat) {
  1330. case AV_PIX_FMT_RGB48LE:
  1331. *yuv2packed1 = yuv2rgb48le_1_c;
  1332. *yuv2packed2 = yuv2rgb48le_2_c;
  1333. *yuv2packedX = yuv2rgb48le_X_c;
  1334. break;
  1335. case AV_PIX_FMT_RGB48BE:
  1336. *yuv2packed1 = yuv2rgb48be_1_c;
  1337. *yuv2packed2 = yuv2rgb48be_2_c;
  1338. *yuv2packedX = yuv2rgb48be_X_c;
  1339. break;
  1340. case AV_PIX_FMT_BGR48LE:
  1341. *yuv2packed1 = yuv2bgr48le_1_c;
  1342. *yuv2packed2 = yuv2bgr48le_2_c;
  1343. *yuv2packedX = yuv2bgr48le_X_c;
  1344. break;
  1345. case AV_PIX_FMT_BGR48BE:
  1346. *yuv2packed1 = yuv2bgr48be_1_c;
  1347. *yuv2packed2 = yuv2bgr48be_2_c;
  1348. *yuv2packedX = yuv2bgr48be_X_c;
  1349. break;
  1350. case AV_PIX_FMT_RGB32:
  1351. case AV_PIX_FMT_BGR32:
  1352. #if CONFIG_SMALL
  1353. *yuv2packed1 = yuv2rgb32_1_c;
  1354. *yuv2packed2 = yuv2rgb32_2_c;
  1355. *yuv2packedX = yuv2rgb32_X_c;
  1356. #else
  1357. #if CONFIG_SWSCALE_ALPHA
  1358. if (c->alpPixBuf) {
  1359. *yuv2packed1 = yuv2rgba32_1_c;
  1360. *yuv2packed2 = yuv2rgba32_2_c;
  1361. *yuv2packedX = yuv2rgba32_X_c;
  1362. } else
  1363. #endif /* CONFIG_SWSCALE_ALPHA */
  1364. {
  1365. *yuv2packed1 = yuv2rgbx32_1_c;
  1366. *yuv2packed2 = yuv2rgbx32_2_c;
  1367. *yuv2packedX = yuv2rgbx32_X_c;
  1368. }
  1369. #endif /* !CONFIG_SMALL */
  1370. break;
  1371. case AV_PIX_FMT_RGB32_1:
  1372. case AV_PIX_FMT_BGR32_1:
  1373. #if CONFIG_SMALL
  1374. *yuv2packed1 = yuv2rgb32_1_1_c;
  1375. *yuv2packed2 = yuv2rgb32_1_2_c;
  1376. *yuv2packedX = yuv2rgb32_1_X_c;
  1377. #else
  1378. #if CONFIG_SWSCALE_ALPHA
  1379. if (c->alpPixBuf) {
  1380. *yuv2packed1 = yuv2rgba32_1_1_c;
  1381. *yuv2packed2 = yuv2rgba32_1_2_c;
  1382. *yuv2packedX = yuv2rgba32_1_X_c;
  1383. } else
  1384. #endif /* CONFIG_SWSCALE_ALPHA */
  1385. {
  1386. *yuv2packed1 = yuv2rgbx32_1_1_c;
  1387. *yuv2packed2 = yuv2rgbx32_1_2_c;
  1388. *yuv2packedX = yuv2rgbx32_1_X_c;
  1389. }
  1390. #endif /* !CONFIG_SMALL */
  1391. break;
  1392. case AV_PIX_FMT_RGB24:
  1393. *yuv2packed1 = yuv2rgb24_1_c;
  1394. *yuv2packed2 = yuv2rgb24_2_c;
  1395. *yuv2packedX = yuv2rgb24_X_c;
  1396. break;
  1397. case AV_PIX_FMT_BGR24:
  1398. *yuv2packed1 = yuv2bgr24_1_c;
  1399. *yuv2packed2 = yuv2bgr24_2_c;
  1400. *yuv2packedX = yuv2bgr24_X_c;
  1401. break;
  1402. case AV_PIX_FMT_RGB565LE:
  1403. case AV_PIX_FMT_RGB565BE:
  1404. case AV_PIX_FMT_BGR565LE:
  1405. case AV_PIX_FMT_BGR565BE:
  1406. *yuv2packed1 = yuv2rgb16_1_c;
  1407. *yuv2packed2 = yuv2rgb16_2_c;
  1408. *yuv2packedX = yuv2rgb16_X_c;
  1409. break;
  1410. case AV_PIX_FMT_RGB555LE:
  1411. case AV_PIX_FMT_RGB555BE:
  1412. case AV_PIX_FMT_BGR555LE:
  1413. case AV_PIX_FMT_BGR555BE:
  1414. *yuv2packed1 = yuv2rgb15_1_c;
  1415. *yuv2packed2 = yuv2rgb15_2_c;
  1416. *yuv2packedX = yuv2rgb15_X_c;
  1417. break;
  1418. case AV_PIX_FMT_RGB444LE:
  1419. case AV_PIX_FMT_RGB444BE:
  1420. case AV_PIX_FMT_BGR444LE:
  1421. case AV_PIX_FMT_BGR444BE:
  1422. *yuv2packed1 = yuv2rgb12_1_c;
  1423. *yuv2packed2 = yuv2rgb12_2_c;
  1424. *yuv2packedX = yuv2rgb12_X_c;
  1425. break;
  1426. case AV_PIX_FMT_RGB8:
  1427. case AV_PIX_FMT_BGR8:
  1428. *yuv2packed1 = yuv2rgb8_1_c;
  1429. *yuv2packed2 = yuv2rgb8_2_c;
  1430. *yuv2packedX = yuv2rgb8_X_c;
  1431. break;
  1432. case AV_PIX_FMT_RGB4:
  1433. case AV_PIX_FMT_BGR4:
  1434. *yuv2packed1 = yuv2rgb4_1_c;
  1435. *yuv2packed2 = yuv2rgb4_2_c;
  1436. *yuv2packedX = yuv2rgb4_X_c;
  1437. break;
  1438. case AV_PIX_FMT_RGB4_BYTE:
  1439. case AV_PIX_FMT_BGR4_BYTE:
  1440. *yuv2packed1 = yuv2rgb4b_1_c;
  1441. *yuv2packed2 = yuv2rgb4b_2_c;
  1442. *yuv2packedX = yuv2rgb4b_X_c;
  1443. break;
  1444. }
  1445. }
  1446. switch (dstFormat) {
  1447. case AV_PIX_FMT_MONOWHITE:
  1448. *yuv2packed1 = yuv2monowhite_1_c;
  1449. *yuv2packed2 = yuv2monowhite_2_c;
  1450. *yuv2packedX = yuv2monowhite_X_c;
  1451. break;
  1452. case AV_PIX_FMT_MONOBLACK:
  1453. *yuv2packed1 = yuv2monoblack_1_c;
  1454. *yuv2packed2 = yuv2monoblack_2_c;
  1455. *yuv2packedX = yuv2monoblack_X_c;
  1456. break;
  1457. case AV_PIX_FMT_YUYV422:
  1458. *yuv2packed1 = yuv2yuyv422_1_c;
  1459. *yuv2packed2 = yuv2yuyv422_2_c;
  1460. *yuv2packedX = yuv2yuyv422_X_c;
  1461. break;
  1462. case AV_PIX_FMT_YVYU422:
  1463. *yuv2packed1 = yuv2yvyu422_1_c;
  1464. *yuv2packed2 = yuv2yvyu422_2_c;
  1465. *yuv2packedX = yuv2yvyu422_X_c;
  1466. break;
  1467. case AV_PIX_FMT_UYVY422:
  1468. *yuv2packed1 = yuv2uyvy422_1_c;
  1469. *yuv2packed2 = yuv2uyvy422_2_c;
  1470. *yuv2packedX = yuv2uyvy422_X_c;
  1471. break;
  1472. }
  1473. }