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.

1586 lines
57KB

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