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.

1500 lines
55KB

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