2 * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
26 #include "libavutil/attributes.h"
27 #include "libavutil/avutil.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/bswap.h"
30 #include "libavutil/cpu.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/pixdesc.h"
37 #include "swscale_internal.h"
39 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_4)[][8] = {
40 { 1, 3, 1, 3, 1, 3, 1, 3, },
41 { 2, 0, 2, 0, 2, 0, 2, 0, },
42 { 1, 3, 1, 3, 1, 3, 1, 3, },
45 DECLARE_ALIGNED(8, const uint8_t, ff_dither_2x2_8)[][8] = {
46 { 6, 2, 6, 2, 6, 2, 6, 2, },
47 { 0, 4, 0, 4, 0, 4, 0, 4, },
48 { 6, 2, 6, 2, 6, 2, 6, 2, },
51 DECLARE_ALIGNED(8, const uint8_t, ff_dither_4x4_16)[][8] = {
52 { 8, 4, 11, 7, 8, 4, 11, 7, },
53 { 2, 14, 1, 13, 2, 14, 1, 13, },
54 { 10, 6, 9, 5, 10, 6, 9, 5, },
55 { 0, 12, 3, 15, 0, 12, 3, 15, },
56 { 8, 4, 11, 7, 8, 4, 11, 7, },
59 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_32)[][8] = {
60 { 17, 9, 23, 15, 16, 8, 22, 14, },
61 { 5, 29, 3, 27, 4, 28, 2, 26, },
62 { 21, 13, 19, 11, 20, 12, 18, 10, },
63 { 0, 24, 6, 30, 1, 25, 7, 31, },
64 { 16, 8, 22, 14, 17, 9, 23, 15, },
65 { 4, 28, 2, 26, 5, 29, 3, 27, },
66 { 20, 12, 18, 10, 21, 13, 19, 11, },
67 { 1, 25, 7, 31, 0, 24, 6, 30, },
68 { 17, 9, 23, 15, 16, 8, 22, 14, },
71 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_73)[][8] = {
72 { 0, 55, 14, 68, 3, 58, 17, 72, },
73 { 37, 18, 50, 32, 40, 22, 54, 35, },
74 { 9, 64, 5, 59, 13, 67, 8, 63, },
75 { 46, 27, 41, 23, 49, 31, 44, 26, },
76 { 2, 57, 16, 71, 1, 56, 15, 70, },
77 { 39, 21, 52, 34, 38, 19, 51, 33, },
78 { 11, 66, 7, 62, 10, 65, 6, 60, },
79 { 48, 30, 43, 25, 47, 29, 42, 24, },
80 { 0, 55, 14, 68, 3, 58, 17, 72, },
84 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
85 {117, 62, 158, 103, 113, 58, 155, 100, },
86 { 34, 199, 21, 186, 31, 196, 17, 182, },
87 {144, 89, 131, 76, 141, 86, 127, 72, },
88 { 0, 165, 41, 206, 10, 175, 52, 217, },
89 {110, 55, 151, 96, 120, 65, 162, 107, },
90 { 28, 193, 14, 179, 38, 203, 24, 189, },
91 {138, 83, 124, 69, 148, 93, 134, 79, },
92 { 7, 172, 48, 213, 3, 168, 45, 210, },
93 {117, 62, 158, 103, 113, 58, 155, 100, },
96 // tries to correct a gamma of 1.5
97 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
98 { 0, 143, 18, 200, 2, 156, 25, 215, },
99 { 78, 28, 125, 64, 89, 36, 138, 74, },
100 { 10, 180, 3, 161, 16, 195, 8, 175, },
101 {109, 51, 93, 38, 121, 60, 105, 47, },
102 { 1, 152, 23, 210, 0, 147, 20, 205, },
103 { 85, 33, 134, 71, 81, 30, 130, 67, },
104 { 14, 190, 6, 171, 12, 185, 5, 166, },
105 {117, 57, 101, 44, 113, 54, 97, 41, },
106 { 0, 143, 18, 200, 2, 156, 25, 215, },
109 // tries to correct a gamma of 2.0
110 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
111 { 0, 124, 8, 193, 0, 140, 12, 213, },
112 { 55, 14, 104, 42, 66, 19, 119, 52, },
113 { 3, 168, 1, 145, 6, 187, 3, 162, },
114 { 86, 31, 70, 21, 99, 39, 82, 28, },
115 { 0, 134, 11, 206, 0, 129, 9, 200, },
116 { 62, 17, 114, 48, 58, 16, 109, 45, },
117 { 5, 181, 2, 157, 4, 175, 1, 151, },
118 { 95, 36, 78, 26, 90, 34, 74, 24, },
119 { 0, 124, 8, 193, 0, 140, 12, 213, },
122 // tries to correct a gamma of 2.5
123 DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] = {
124 { 0, 107, 3, 187, 0, 125, 6, 212, },
125 { 39, 7, 86, 28, 49, 11, 102, 36, },
126 { 1, 158, 0, 131, 3, 180, 1, 151, },
127 { 68, 19, 52, 12, 81, 25, 64, 17, },
128 { 0, 119, 5, 203, 0, 113, 4, 195, },
129 { 45, 9, 96, 33, 42, 8, 91, 30, },
130 { 2, 172, 1, 144, 2, 165, 0, 137, },
131 { 77, 23, 60, 15, 72, 21, 56, 14, },
132 { 0, 107, 3, 187, 0, 125, 6, 212, },
136 #define output_pixel(pos, val, bias, signedness) \
138 AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
140 AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
143 static av_always_inline void
144 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
145 int big_endian, int output_bits)
149 av_assert0(output_bits == 16);
151 for (i = 0; i < dstW; i++) {
152 int val = src[i] + (1 << (shift - 1));
153 output_pixel(&dest[i], val, 0, uint);
157 static av_always_inline void
158 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
159 const int32_t **src, uint16_t *dest, int dstW,
160 int big_endian, int output_bits)
164 av_assert0(output_bits == 16);
166 for (i = 0; i < dstW; i++) {
167 int val = 1 << (shift - 1);
170 /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
171 * filters (or anything with negative coeffs, the range can be slightly
172 * wider in both directions. To account for this overflow, we subtract
173 * a constant so it always fits in the signed range (assuming a
174 * reasonable filterSize), and re-add that at the end. */
176 for (j = 0; j < filterSize; j++)
177 val += src[j][i] * (unsigned)filter[j];
179 output_pixel(&dest[i], val, 0x8000, int);
185 #define output_pixel(pos, val) \
187 AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
189 AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
192 static av_always_inline void
193 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
194 int big_endian, int output_bits)
197 int shift = 15 - output_bits;
199 for (i = 0; i < dstW; i++) {
200 int val = src[i] + (1 << (shift - 1));
201 output_pixel(&dest[i], val);
205 static av_always_inline void
206 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
207 const int16_t **src, uint16_t *dest, int dstW,
208 int big_endian, int output_bits)
211 int shift = 11 + 16 - output_bits;
213 for (i = 0; i < dstW; i++) {
214 int val = 1 << (shift - 1);
217 for (j = 0; j < filterSize; j++)
218 val += src[j][i] * filter[j];
220 output_pixel(&dest[i], val);
226 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
227 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
228 uint8_t *dest, int dstW, \
229 const uint8_t *dither, int offset)\
231 yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
232 (uint16_t *) dest, dstW, is_be, bits); \
234 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
235 const int16_t **src, uint8_t *dest, int dstW, \
236 const uint8_t *dither, int offset)\
238 yuv2planeX_## template_size ## _c_template(filter, \
239 filterSize, (const typeX_t **) src, \
240 (uint16_t *) dest, dstW, is_be, bits); \
242 yuv2NBPS( 9, BE, 1, 10, int16_t)
243 yuv2NBPS( 9, LE, 0, 10, int16_t)
244 yuv2NBPS(10, BE, 1, 10, int16_t)
245 yuv2NBPS(10, LE, 0, 10, int16_t)
246 yuv2NBPS(12, BE, 1, 10, int16_t)
247 yuv2NBPS(12, LE, 0, 10, int16_t)
248 yuv2NBPS(14, BE, 1, 10, int16_t)
249 yuv2NBPS(14, LE, 0, 10, int16_t)
250 yuv2NBPS(16, BE, 1, 16, int32_t)
251 yuv2NBPS(16, LE, 0, 16, int32_t)
253 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
254 const int16_t **src, uint8_t *dest, int dstW,
255 const uint8_t *dither, int offset)
258 for (i=0; i<dstW; i++) {
259 int val = dither[(i + offset) & 7] << 12;
261 for (j=0; j<filterSize; j++)
262 val += src[j][i] * filter[j];
264 dest[i]= av_clip_uint8(val>>19);
268 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
269 const uint8_t *dither, int offset)
272 for (i=0; i<dstW; i++) {
273 int val = (src[i] + dither[(i + offset) & 7]) >> 7;
274 dest[i]= av_clip_uint8(val);
278 static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
279 const int16_t **chrUSrc, const int16_t **chrVSrc,
280 uint8_t *dest, int chrDstW)
282 enum AVPixelFormat dstFormat = c->dstFormat;
283 const uint8_t *chrDither = c->chrDither8;
286 if (dstFormat == AV_PIX_FMT_NV12)
287 for (i=0; i<chrDstW; i++) {
288 int u = chrDither[i & 7] << 12;
289 int v = chrDither[(i + 3) & 7] << 12;
291 for (j=0; j<chrFilterSize; j++) {
292 u += chrUSrc[j][i] * chrFilter[j];
293 v += chrVSrc[j][i] * chrFilter[j];
296 dest[2*i]= av_clip_uint8(u>>19);
297 dest[2*i+1]= av_clip_uint8(v>>19);
300 for (i=0; i<chrDstW; i++) {
301 int u = chrDither[i & 7] << 12;
302 int v = chrDither[(i + 3) & 7] << 12;
304 for (j=0; j<chrFilterSize; j++) {
305 u += chrUSrc[j][i] * chrFilter[j];
306 v += chrVSrc[j][i] * chrFilter[j];
309 dest[2*i]= av_clip_uint8(v>>19);
310 dest[2*i+1]= av_clip_uint8(u>>19);
314 #define accumulate_bit(acc, val) \
316 acc |= (val) >= (128 + 110)
317 #define output_pixel(pos, acc) \
318 if (target == AV_PIX_FMT_MONOBLACK) { \
324 static av_always_inline void
325 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
326 const int16_t **lumSrc, int lumFilterSize,
327 const int16_t *chrFilter, const int16_t **chrUSrc,
328 const int16_t **chrVSrc, int chrFilterSize,
329 const int16_t **alpSrc, uint8_t *dest, int dstW,
330 int y, enum AVPixelFormat target)
332 const uint8_t * const d128 = ff_dither_8x8_220[y&7];
337 for (i = 0; i < dstW; i += 2) {
342 for (j = 0; j < lumFilterSize; j++) {
343 Y1 += lumSrc[j][i] * lumFilter[j];
344 Y2 += lumSrc[j][i+1] * lumFilter[j];
348 if ((Y1 | Y2) & 0x100) {
349 Y1 = av_clip_uint8(Y1);
350 Y2 = av_clip_uint8(Y2);
352 if (c->dither == SWS_DITHER_ED) {
353 Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
354 c->dither_error[0][i] = err;
355 acc = 2*acc + (Y1 >= 128);
358 err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
359 c->dither_error[0][i+1] = Y1;
360 acc = 2*acc + (err >= 128);
363 accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
364 accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
367 output_pixel(*dest++, acc);
370 c->dither_error[0][i] = err;
373 output_pixel(*dest, acc);
377 static av_always_inline void
378 yuv2mono_2_c_template(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 enum AVPixelFormat target)
384 const int16_t *buf0 = buf[0], *buf1 = buf[1];
385 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
386 int yalpha1 = 4096 - yalpha;
389 if (c->dither == SWS_DITHER_ED) {
392 for (i = 0; i < dstW; i +=2) {
395 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
396 Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
397 c->dither_error[0][i] = err;
398 acc = 2*acc + (Y >= 128);
401 err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
402 err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
403 c->dither_error[0][i+1] = Y;
404 acc = 2*acc + (err >= 128);
408 output_pixel(*dest++, acc);
410 c->dither_error[0][i] = err;
412 for (i = 0; i < dstW; i += 8) {
415 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
416 accumulate_bit(acc, Y + d128[0]);
417 Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
418 accumulate_bit(acc, Y + d128[1]);
419 Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
420 accumulate_bit(acc, Y + d128[2]);
421 Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
422 accumulate_bit(acc, Y + d128[3]);
423 Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
424 accumulate_bit(acc, Y + d128[4]);
425 Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
426 accumulate_bit(acc, Y + d128[5]);
427 Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
428 accumulate_bit(acc, Y + d128[6]);
429 Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
430 accumulate_bit(acc, Y + d128[7]);
432 output_pixel(*dest++, acc);
437 static av_always_inline void
438 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
439 const int16_t *ubuf[2], const int16_t *vbuf[2],
440 const int16_t *abuf0, uint8_t *dest, int dstW,
441 int uvalpha, int y, enum AVPixelFormat target)
443 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
446 if (c->dither == SWS_DITHER_ED) {
449 for (i = 0; i < dstW; i +=2) {
452 Y = ((buf0[i + 0] + 64) >> 7);
453 Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
454 c->dither_error[0][i] = err;
455 acc = 2*acc + (Y >= 128);
458 err = ((buf0[i + 1] + 64) >> 7);
459 err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
460 c->dither_error[0][i+1] = Y;
461 acc = 2*acc + (err >= 128);
465 output_pixel(*dest++, acc);
467 c->dither_error[0][i] = err;
469 for (i = 0; i < dstW; i += 8) {
471 accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
472 accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
473 accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
474 accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
475 accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
476 accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
477 accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
478 accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
480 output_pixel(*dest++, acc);
486 #undef accumulate_bit
488 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
489 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
490 const int16_t **lumSrc, int lumFilterSize, \
491 const int16_t *chrFilter, const int16_t **chrUSrc, \
492 const int16_t **chrVSrc, int chrFilterSize, \
493 const int16_t **alpSrc, uint8_t *dest, int dstW, \
496 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
497 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
498 alpSrc, dest, dstW, y, fmt); \
501 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
502 const int16_t *ubuf[2], const int16_t *vbuf[2], \
503 const int16_t *abuf[2], uint8_t *dest, int dstW, \
504 int yalpha, int uvalpha, int y) \
506 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
507 dest, dstW, yalpha, uvalpha, y, fmt); \
510 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
511 const int16_t *ubuf[2], const int16_t *vbuf[2], \
512 const int16_t *abuf0, uint8_t *dest, int dstW, \
513 int uvalpha, int y) \
515 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
516 abuf0, dest, dstW, uvalpha, \
520 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
521 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
523 #define output_pixels(pos, Y1, U, Y2, V) \
524 if (target == AV_PIX_FMT_YUYV422) { \
525 dest[pos + 0] = Y1; \
527 dest[pos + 2] = Y2; \
531 dest[pos + 1] = Y1; \
533 dest[pos + 3] = Y2; \
536 static av_always_inline void
537 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
538 const int16_t **lumSrc, int lumFilterSize,
539 const int16_t *chrFilter, const int16_t **chrUSrc,
540 const int16_t **chrVSrc, int chrFilterSize,
541 const int16_t **alpSrc, uint8_t *dest, int dstW,
542 int y, enum AVPixelFormat target)
546 for (i = 0; i < ((dstW + 1) >> 1); i++) {
553 for (j = 0; j < lumFilterSize; j++) {
554 Y1 += lumSrc[j][i * 2] * lumFilter[j];
555 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
557 for (j = 0; j < chrFilterSize; j++) {
558 U += chrUSrc[j][i] * chrFilter[j];
559 V += chrVSrc[j][i] * chrFilter[j];
565 if ((Y1 | Y2 | U | V) & 0x100) {
566 Y1 = av_clip_uint8(Y1);
567 Y2 = av_clip_uint8(Y2);
568 U = av_clip_uint8(U);
569 V = av_clip_uint8(V);
571 output_pixels(4*i, Y1, U, Y2, V);
575 static av_always_inline void
576 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
577 const int16_t *ubuf[2], const int16_t *vbuf[2],
578 const int16_t *abuf[2], uint8_t *dest, int dstW,
579 int yalpha, int uvalpha, int y,
580 enum AVPixelFormat target)
582 const int16_t *buf0 = buf[0], *buf1 = buf[1],
583 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
584 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
585 int yalpha1 = 4096 - yalpha;
586 int uvalpha1 = 4096 - uvalpha;
589 for (i = 0; i < ((dstW + 1) >> 1); i++) {
590 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
591 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
592 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
593 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
595 if ((Y1 | Y2 | U | V) & 0x100) {
596 Y1 = av_clip_uint8(Y1);
597 Y2 = av_clip_uint8(Y2);
598 U = av_clip_uint8(U);
599 V = av_clip_uint8(V);
602 output_pixels(i * 4, Y1, U, Y2, V);
606 static av_always_inline void
607 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
608 const int16_t *ubuf[2], const int16_t *vbuf[2],
609 const int16_t *abuf0, uint8_t *dest, int dstW,
610 int uvalpha, int y, enum AVPixelFormat target)
612 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
615 if (uvalpha < 2048) {
616 for (i = 0; i < ((dstW + 1) >> 1); i++) {
617 int Y1 = (buf0[i * 2 ]+64) >> 7;
618 int Y2 = (buf0[i * 2 + 1]+64) >> 7;
619 int U = (ubuf0[i] +64) >> 7;
620 int V = (vbuf0[i] +64) >> 7;
622 if ((Y1 | Y2 | U | V) & 0x100) {
623 Y1 = av_clip_uint8(Y1);
624 Y2 = av_clip_uint8(Y2);
625 U = av_clip_uint8(U);
626 V = av_clip_uint8(V);
629 Y1 = av_clip_uint8(Y1);
630 Y2 = av_clip_uint8(Y2);
631 U = av_clip_uint8(U);
632 V = av_clip_uint8(V);
634 output_pixels(i * 4, Y1, U, Y2, V);
637 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
638 for (i = 0; i < ((dstW + 1) >> 1); i++) {
639 int Y1 = (buf0[i * 2 ] + 64) >> 7;
640 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
641 int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
642 int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
644 if ((Y1 | Y2 | U | V) & 0x100) {
645 Y1 = av_clip_uint8(Y1);
646 Y2 = av_clip_uint8(Y2);
647 U = av_clip_uint8(U);
648 V = av_clip_uint8(V);
651 Y1 = av_clip_uint8(Y1);
652 Y2 = av_clip_uint8(Y2);
653 U = av_clip_uint8(U);
654 V = av_clip_uint8(V);
656 output_pixels(i * 4, Y1, U, Y2, V);
663 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
664 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
666 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? R : B)
667 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? B : R)
668 #define output_pixel(pos, val) \
669 if (isBE(target)) { \
675 static av_always_inline void
676 yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
677 const int32_t **lumSrc, int lumFilterSize,
678 const int16_t *chrFilter, const int32_t **chrUSrc,
679 const int32_t **chrVSrc, int chrFilterSize,
680 const int32_t **alpSrc, uint16_t *dest, int dstW,
681 int y, enum AVPixelFormat target, int hasAlpha)
684 int A1 = 0xffff<<14, A2 = 0xffff<<14;
686 for (i = 0; i < ((dstW + 1) >> 1); i++) {
688 int Y1 = -0x40000000;
689 int Y2 = -0x40000000;
690 int U = -128 << 23; // 19
694 for (j = 0; j < lumFilterSize; j++) {
695 Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
696 Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
698 for (j = 0; j < chrFilterSize; j++) {;
699 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
700 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
706 for (j = 0; j < lumFilterSize; j++) {
707 A1 += alpSrc[j][i * 2] * (unsigned)lumFilter[j];
708 A2 += alpSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
716 // 8bit: 12+15=27; 16-bit: 12+19=31
724 // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
725 Y1 -= c->yuv2rgb_y_offset;
726 Y2 -= c->yuv2rgb_y_offset;
727 Y1 *= c->yuv2rgb_y_coeff;
728 Y2 *= c->yuv2rgb_y_coeff;
731 // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
733 R = V * c->yuv2rgb_v2r_coeff;
734 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
735 B = U * c->yuv2rgb_u2b_coeff;
737 // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
738 output_pixel(&dest[0], av_clip_uintp2(B_R + Y1, 30) >> 14);
739 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
740 output_pixel(&dest[2], av_clip_uintp2(R_B + Y1, 30) >> 14);
741 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
742 output_pixel(&dest[4], av_clip_uintp2(B_R + Y2, 30) >> 14);
743 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
744 output_pixel(&dest[6], av_clip_uintp2(R_B + Y2, 30) >> 14);
745 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
750 static av_always_inline void
751 yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
752 const int32_t *ubuf[2], const int32_t *vbuf[2],
753 const int32_t *abuf[2], uint16_t *dest, int dstW,
754 int yalpha, int uvalpha, int y,
755 enum AVPixelFormat target, int hasAlpha)
757 const int32_t *buf0 = buf[0], *buf1 = buf[1],
758 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
759 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
760 *abuf0 = hasAlpha ? abuf[0] : NULL,
761 *abuf1 = hasAlpha ? abuf[1] : NULL;
762 int yalpha1 = 4096 - yalpha;
763 int uvalpha1 = 4096 - uvalpha;
765 int A1 = 0xffff<<14, A2 = 0xffff<<14;
767 for (i = 0; i < ((dstW + 1) >> 1); i++) {
768 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
769 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
770 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
771 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
774 Y1 -= c->yuv2rgb_y_offset;
775 Y2 -= c->yuv2rgb_y_offset;
776 Y1 *= c->yuv2rgb_y_coeff;
777 Y2 *= c->yuv2rgb_y_coeff;
781 R = V * c->yuv2rgb_v2r_coeff;
782 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
783 B = U * c->yuv2rgb_u2b_coeff;
786 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 1;
787 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 1;
793 output_pixel(&dest[0], av_clip_uintp2(B_R + Y1, 30) >> 14);
794 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
795 output_pixel(&dest[2], av_clip_uintp2(R_B + Y1, 30) >> 14);
796 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
797 output_pixel(&dest[4], av_clip_uintp2(B_R + Y2, 30) >> 14);
798 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
799 output_pixel(&dest[6], av_clip_uintp2(R_B + Y2, 30) >> 14);
800 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
805 static av_always_inline void
806 yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
807 const int32_t *ubuf[2], const int32_t *vbuf[2],
808 const int32_t *abuf0, uint16_t *dest, int dstW,
809 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
811 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
813 int A1 = 0xffff<<14, A2= 0xffff<<14;
815 if (uvalpha < 2048) {
816 for (i = 0; i < ((dstW + 1) >> 1); i++) {
817 int Y1 = (buf0[i * 2] ) >> 2;
818 int Y2 = (buf0[i * 2 + 1]) >> 2;
819 int U = (ubuf0[i] + (-128 << 11)) >> 2;
820 int V = (vbuf0[i] + (-128 << 11)) >> 2;
823 Y1 -= c->yuv2rgb_y_offset;
824 Y2 -= c->yuv2rgb_y_offset;
825 Y1 *= c->yuv2rgb_y_coeff;
826 Y2 *= c->yuv2rgb_y_coeff;
831 A1 = abuf0[i * 2 ] << 11;
832 A2 = abuf0[i * 2 + 1] << 11;
838 R = V * c->yuv2rgb_v2r_coeff;
839 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
840 B = U * c->yuv2rgb_u2b_coeff;
842 output_pixel(&dest[0], av_clip_uintp2(B_R + Y1, 30) >> 14);
843 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
844 output_pixel(&dest[2], av_clip_uintp2(R_B + Y1, 30) >> 14);
845 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
846 output_pixel(&dest[4], av_clip_uintp2(B_R + Y2, 30) >> 14);
847 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
848 output_pixel(&dest[6], av_clip_uintp2(R_B + Y2, 30) >> 14);
849 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
853 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
854 int A1 = 0xffff<<14, A2 = 0xffff<<14;
855 for (i = 0; i < ((dstW + 1) >> 1); i++) {
856 int Y1 = (buf0[i * 2] ) >> 2;
857 int Y2 = (buf0[i * 2 + 1]) >> 2;
858 int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
859 int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
862 Y1 -= c->yuv2rgb_y_offset;
863 Y2 -= c->yuv2rgb_y_offset;
864 Y1 *= c->yuv2rgb_y_coeff;
865 Y2 *= c->yuv2rgb_y_coeff;
870 A1 = abuf0[i * 2 ] << 11;
871 A2 = abuf0[i * 2 + 1] << 11;
877 R = V * c->yuv2rgb_v2r_coeff;
878 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
879 B = U * c->yuv2rgb_u2b_coeff;
881 output_pixel(&dest[0], av_clip_uintp2(B_R + Y1, 30) >> 14);
882 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
883 output_pixel(&dest[2], av_clip_uintp2(R_B + Y1, 30) >> 14);
884 output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14);
885 output_pixel(&dest[4], av_clip_uintp2(B_R + Y2, 30) >> 14);
886 output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14);
887 output_pixel(&dest[6], av_clip_uintp2(R_B + Y2, 30) >> 14);
888 output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14);
894 static av_always_inline void
895 yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
896 const int32_t **lumSrc, int lumFilterSize,
897 const int16_t *chrFilter, const int32_t **chrUSrc,
898 const int32_t **chrVSrc, int chrFilterSize,
899 const int32_t **alpSrc, uint16_t *dest, int dstW,
900 int y, enum AVPixelFormat target, int hasAlpha)
904 for (i = 0; i < ((dstW + 1) >> 1); i++) {
906 int Y1 = -0x40000000;
907 int Y2 = -0x40000000;
908 int U = -128 << 23; // 19
912 for (j = 0; j < lumFilterSize; j++) {
913 Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
914 Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
916 for (j = 0; j < chrFilterSize; j++) {;
917 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
918 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
921 // 8bit: 12+15=27; 16-bit: 12+19=31
929 // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
930 Y1 -= c->yuv2rgb_y_offset;
931 Y2 -= c->yuv2rgb_y_offset;
932 Y1 *= c->yuv2rgb_y_coeff;
933 Y2 *= c->yuv2rgb_y_coeff;
936 // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
938 R = V * c->yuv2rgb_v2r_coeff;
939 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
940 B = U * c->yuv2rgb_u2b_coeff;
942 // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
943 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
944 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
945 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
946 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
947 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
948 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
953 static av_always_inline void
954 yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
955 const int32_t *ubuf[2], const int32_t *vbuf[2],
956 const int32_t *abuf[2], uint16_t *dest, int dstW,
957 int yalpha, int uvalpha, int y,
958 enum AVPixelFormat target, int hasAlpha)
960 const int32_t *buf0 = buf[0], *buf1 = buf[1],
961 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
962 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
963 int yalpha1 = 4096 - yalpha;
964 int uvalpha1 = 4096 - uvalpha;
967 for (i = 0; i < ((dstW + 1) >> 1); i++) {
968 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
969 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
970 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
971 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
974 Y1 -= c->yuv2rgb_y_offset;
975 Y2 -= c->yuv2rgb_y_offset;
976 Y1 *= c->yuv2rgb_y_coeff;
977 Y2 *= c->yuv2rgb_y_coeff;
981 R = V * c->yuv2rgb_v2r_coeff;
982 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
983 B = U * c->yuv2rgb_u2b_coeff;
985 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
986 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
987 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
988 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
989 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
990 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
995 static av_always_inline void
996 yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
997 const int32_t *ubuf[2], const int32_t *vbuf[2],
998 const int32_t *abuf0, uint16_t *dest, int dstW,
999 int uvalpha, int y, enum AVPixelFormat target, int hasAlpha)
1001 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1004 if (uvalpha < 2048) {
1005 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1006 int Y1 = (buf0[i * 2] ) >> 2;
1007 int Y2 = (buf0[i * 2 + 1]) >> 2;
1008 int U = (ubuf0[i] + (-128 << 11)) >> 2;
1009 int V = (vbuf0[i] + (-128 << 11)) >> 2;
1012 Y1 -= c->yuv2rgb_y_offset;
1013 Y2 -= c->yuv2rgb_y_offset;
1014 Y1 *= c->yuv2rgb_y_coeff;
1015 Y2 *= c->yuv2rgb_y_coeff;
1019 R = V * c->yuv2rgb_v2r_coeff;
1020 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1021 B = U * c->yuv2rgb_u2b_coeff;
1023 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1024 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1025 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1026 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1027 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1028 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1032 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1033 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1034 int Y1 = (buf0[i * 2] ) >> 2;
1035 int Y2 = (buf0[i * 2 + 1]) >> 2;
1036 int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
1037 int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
1040 Y1 -= c->yuv2rgb_y_offset;
1041 Y2 -= c->yuv2rgb_y_offset;
1042 Y1 *= c->yuv2rgb_y_coeff;
1043 Y2 *= c->yuv2rgb_y_coeff;
1047 R = V * c->yuv2rgb_v2r_coeff;
1048 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1049 B = U * c->yuv2rgb_u2b_coeff;
1051 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
1052 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
1053 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
1054 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
1055 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
1056 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
1066 #define YUV2PACKED16WRAPPER(name, base, ext, fmt, hasAlpha) \
1067 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1068 const int16_t **_lumSrc, int lumFilterSize, \
1069 const int16_t *chrFilter, const int16_t **_chrUSrc, \
1070 const int16_t **_chrVSrc, int chrFilterSize, \
1071 const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1074 const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1075 **chrUSrc = (const int32_t **) _chrUSrc, \
1076 **chrVSrc = (const int32_t **) _chrVSrc, \
1077 **alpSrc = (const int32_t **) _alpSrc; \
1078 uint16_t *dest = (uint16_t *) _dest; \
1079 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1080 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1081 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1084 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1085 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1086 const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1087 int yalpha, int uvalpha, int y) \
1089 const int32_t **buf = (const int32_t **) _buf, \
1090 **ubuf = (const int32_t **) _ubuf, \
1091 **vbuf = (const int32_t **) _vbuf, \
1092 **abuf = (const int32_t **) _abuf; \
1093 uint16_t *dest = (uint16_t *) _dest; \
1094 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1095 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1098 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1099 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1100 const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1101 int uvalpha, int y) \
1103 const int32_t *buf0 = (const int32_t *) _buf0, \
1104 **ubuf = (const int32_t **) _ubuf, \
1105 **vbuf = (const int32_t **) _vbuf, \
1106 *abuf0 = (const int32_t *) _abuf0; \
1107 uint16_t *dest = (uint16_t *) _dest; \
1108 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1109 dstW, uvalpha, y, fmt, hasAlpha); \
1112 YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, AV_PIX_FMT_RGB48BE, 0)
1113 YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, AV_PIX_FMT_RGB48LE, 0)
1114 YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, AV_PIX_FMT_BGR48BE, 0)
1115 YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, AV_PIX_FMT_BGR48LE, 0)
1116 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64be, AV_PIX_FMT_RGBA64BE, 1)
1117 YUV2PACKED16WRAPPER(yuv2, rgba64, rgba64le, AV_PIX_FMT_RGBA64LE, 1)
1118 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64be, AV_PIX_FMT_RGBA64BE, 0)
1119 YUV2PACKED16WRAPPER(yuv2, rgba64, rgbx64le, AV_PIX_FMT_RGBA64LE, 0)
1122 * Write out 2 RGB pixels in the target pixel format. This function takes a
1123 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
1124 * things like endianness conversion and shifting. The caller takes care of
1125 * setting the correct offset in these tables from the chroma (U/V) values.
1126 * This function then uses the luminance (Y1/Y2) values to write out the
1127 * correct RGB values into the destination buffer.
1129 static av_always_inline void
1130 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
1131 unsigned A1, unsigned A2,
1132 const void *_r, const void *_g, const void *_b, int y,
1133 enum AVPixelFormat target, int hasAlpha)
1135 if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
1136 target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
1137 uint32_t *dest = (uint32_t *) _dest;
1138 const uint32_t *r = (const uint32_t *) _r;
1139 const uint32_t *g = (const uint32_t *) _g;
1140 const uint32_t *b = (const uint32_t *) _b;
1143 int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
1145 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
1146 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
1149 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1151 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0);
1152 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
1153 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
1155 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1156 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
1158 av_assert2((((r[Y1] + g[Y1] + b[Y1]) >> sh) & 0xFF) == 0xFF);
1160 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
1161 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
1164 } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
1165 uint8_t *dest = (uint8_t *) _dest;
1166 const uint8_t *r = (const uint8_t *) _r;
1167 const uint8_t *g = (const uint8_t *) _g;
1168 const uint8_t *b = (const uint8_t *) _b;
1170 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1171 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1173 dest[i * 6 + 0] = r_b[Y1];
1174 dest[i * 6 + 1] = g[Y1];
1175 dest[i * 6 + 2] = b_r[Y1];
1176 dest[i * 6 + 3] = r_b[Y2];
1177 dest[i * 6 + 4] = g[Y2];
1178 dest[i * 6 + 5] = b_r[Y2];
1181 } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
1182 target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
1183 target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
1184 uint16_t *dest = (uint16_t *) _dest;
1185 const uint16_t *r = (const uint16_t *) _r;
1186 const uint16_t *g = (const uint16_t *) _g;
1187 const uint16_t *b = (const uint16_t *) _b;
1188 int dr1, dg1, db1, dr2, dg2, db2;
1190 if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
1191 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1192 dg1 = ff_dither_2x2_4[ y & 1 ][0];
1193 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1194 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1195 dg2 = ff_dither_2x2_4[ y & 1 ][1];
1196 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1197 } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
1198 dr1 = ff_dither_2x2_8[ y & 1 ][0];
1199 dg1 = ff_dither_2x2_8[ y & 1 ][1];
1200 db1 = ff_dither_2x2_8[(y & 1) ^ 1][0];
1201 dr2 = ff_dither_2x2_8[ y & 1 ][1];
1202 dg2 = ff_dither_2x2_8[ y & 1 ][0];
1203 db2 = ff_dither_2x2_8[(y & 1) ^ 1][1];
1205 dr1 = ff_dither_4x4_16[ y & 3 ][0];
1206 dg1 = ff_dither_4x4_16[ y & 3 ][1];
1207 db1 = ff_dither_4x4_16[(y & 3) ^ 3][0];
1208 dr2 = ff_dither_4x4_16[ y & 3 ][1];
1209 dg2 = ff_dither_4x4_16[ y & 3 ][0];
1210 db2 = ff_dither_4x4_16[(y & 3) ^ 3][1];
1213 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1214 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1215 } else /* 8/4-bit */ {
1216 uint8_t *dest = (uint8_t *) _dest;
1217 const uint8_t *r = (const uint8_t *) _r;
1218 const uint8_t *g = (const uint8_t *) _g;
1219 const uint8_t *b = (const uint8_t *) _b;
1220 int dr1, dg1, db1, dr2, dg2, db2;
1222 if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
1223 const uint8_t * const d64 = ff_dither_8x8_73[y & 7];
1224 const uint8_t * const d32 = ff_dither_8x8_32[y & 7];
1225 dr1 = dg1 = d32[(i * 2 + 0) & 7];
1226 db1 = d64[(i * 2 + 0) & 7];
1227 dr2 = dg2 = d32[(i * 2 + 1) & 7];
1228 db2 = d64[(i * 2 + 1) & 7];
1230 const uint8_t * const d64 = ff_dither_8x8_73 [y & 7];
1231 const uint8_t * const d128 = ff_dither_8x8_220[y & 7];
1232 dr1 = db1 = d128[(i * 2 + 0) & 7];
1233 dg1 = d64[(i * 2 + 0) & 7];
1234 dr2 = db2 = d128[(i * 2 + 1) & 7];
1235 dg2 = d64[(i * 2 + 1) & 7];
1238 if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
1239 dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
1240 ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
1242 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
1243 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
1248 static av_always_inline void
1249 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
1250 const int16_t **lumSrc, int lumFilterSize,
1251 const int16_t *chrFilter, const int16_t **chrUSrc,
1252 const int16_t **chrVSrc, int chrFilterSize,
1253 const int16_t **alpSrc, uint8_t *dest, int dstW,
1254 int y, enum AVPixelFormat target, int hasAlpha)
1258 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1264 const void *r, *g, *b;
1266 for (j = 0; j < lumFilterSize; j++) {
1267 Y1 += lumSrc[j][i * 2] * lumFilter[j];
1268 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
1270 for (j = 0; j < chrFilterSize; j++) {
1271 U += chrUSrc[j][i] * chrFilter[j];
1272 V += chrVSrc[j][i] * chrFilter[j];
1281 for (j = 0; j < lumFilterSize; j++) {
1282 A1 += alpSrc[j][i * 2 ] * lumFilter[j];
1283 A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
1287 if ((A1 | A2) & 0x100) {
1288 A1 = av_clip_uint8(A1);
1289 A2 = av_clip_uint8(A2);
1293 r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
1294 g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
1295 b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1297 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1298 r, g, b, y, target, hasAlpha);
1302 static av_always_inline void
1303 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1304 const int16_t *ubuf[2], const int16_t *vbuf[2],
1305 const int16_t *abuf[2], uint8_t *dest, int dstW,
1306 int yalpha, int uvalpha, int y,
1307 enum AVPixelFormat target, int hasAlpha)
1309 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1310 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1311 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1312 *abuf0 = hasAlpha ? abuf[0] : NULL,
1313 *abuf1 = hasAlpha ? abuf[1] : NULL;
1314 int yalpha1 = 4096 - yalpha;
1315 int uvalpha1 = 4096 - uvalpha;
1318 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1319 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
1320 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
1321 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
1322 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
1324 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1325 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1326 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1329 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
1330 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
1331 A1 = av_clip_uint8(A1);
1332 A2 = av_clip_uint8(A2);
1335 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1336 r, g, b, y, target, hasAlpha);
1340 static av_always_inline void
1341 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1342 const int16_t *ubuf[2], const int16_t *vbuf[2],
1343 const int16_t *abuf0, uint8_t *dest, int dstW,
1344 int uvalpha, int y, enum AVPixelFormat target,
1347 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1350 if (uvalpha < 2048) {
1351 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1352 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1353 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1354 int U = (ubuf0[i] + 64) >> 7;
1355 int V = (vbuf0[i] + 64) >> 7;
1357 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1358 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1359 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1362 A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
1363 A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
1364 A1 = av_clip_uint8(A1);
1365 A2 = av_clip_uint8(A2);
1368 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1369 r, g, b, y, target, hasAlpha);
1372 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1373 for (i = 0; i < ((dstW + 1) >> 1); i++) {
1374 int Y1 = (buf0[i * 2 ] + 64) >> 7;
1375 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1376 int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
1377 int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
1379 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
1380 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
1381 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
1384 A1 = (abuf0[i * 2 ] + 64) >> 7;
1385 A2 = (abuf0[i * 2 + 1] + 64) >> 7;
1386 A1 = av_clip_uint8(A1);
1387 A2 = av_clip_uint8(A2);
1390 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
1391 r, g, b, y, target, hasAlpha);
1396 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1397 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1398 const int16_t **lumSrc, int lumFilterSize, \
1399 const int16_t *chrFilter, const int16_t **chrUSrc, \
1400 const int16_t **chrVSrc, int chrFilterSize, \
1401 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1404 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1405 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1406 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1409 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1410 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1411 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1412 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1413 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1414 int yalpha, int uvalpha, int y) \
1416 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1417 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1420 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1421 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1422 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1423 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1424 const int16_t *abuf0, uint8_t *dest, int dstW, \
1425 int uvalpha, int y) \
1427 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1428 dstW, uvalpha, y, fmt, hasAlpha); \
1432 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1433 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1435 #if CONFIG_SWSCALE_ALPHA
1436 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
1437 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
1439 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
1440 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
1442 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
1443 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
1444 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
1445 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
1446 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
1447 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
1448 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
1449 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
1451 static av_always_inline void yuv2rgb_write_full(SwsContext *c,
1452 uint8_t *dest, int i, int Y, int A, int U, int V,
1453 int y, enum AVPixelFormat target, int hasAlpha, int err[4])
1456 int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
1458 Y -= c->yuv2rgb_y_offset;
1459 Y *= c->yuv2rgb_y_coeff;
1461 R = Y + V*c->yuv2rgb_v2r_coeff;
1462 G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
1463 B = Y + U*c->yuv2rgb_u2b_coeff;
1464 if ((R | G | B) & 0xC0000000) {
1465 R = av_clip_uintp2(R, 30);
1466 G = av_clip_uintp2(G, 30);
1467 B = av_clip_uintp2(B, 30);
1471 case AV_PIX_FMT_ARGB:
1472 dest[0] = hasAlpha ? A : 255;
1477 case AV_PIX_FMT_RGB24:
1482 case AV_PIX_FMT_RGBA:
1486 dest[3] = hasAlpha ? A : 255;
1488 case AV_PIX_FMT_ABGR:
1489 dest[0] = hasAlpha ? A : 255;
1494 case AV_PIX_FMT_BGR24:
1499 case AV_PIX_FMT_BGRA:
1503 dest[3] = hasAlpha ? A : 255;
1505 case AV_PIX_FMT_BGR4_BYTE:
1506 case AV_PIX_FMT_RGB4_BYTE:
1507 case AV_PIX_FMT_BGR8:
1508 case AV_PIX_FMT_RGB8:
1514 R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
1515 G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
1516 B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
1517 c->dither_error[0][i] = err[0];
1518 c->dither_error[1][i] = err[1];
1519 c->dither_error[2][i] = err[2];
1520 r = R >> (isrgb8 ? 5 : 7);
1521 g = G >> (isrgb8 ? 5 : 6);
1522 b = B >> (isrgb8 ? 6 : 7);
1523 r = av_clip(r, 0, isrgb8 ? 7 : 1);
1524 g = av_clip(g, 0, isrgb8 ? 7 : 3);
1525 b = av_clip(b, 0, isrgb8 ? 3 : 1);
1526 err[0] = R - r*(isrgb8 ? 36 : 255);
1527 err[1] = G - g*(isrgb8 ? 36 : 85);
1528 err[2] = B - b*(isrgb8 ? 85 : 255);
1529 if(target == AV_PIX_FMT_BGR4_BYTE) {
1530 dest[0] = r + 2*g + 8*b;
1531 } else if(target == AV_PIX_FMT_RGB4_BYTE) {
1532 dest[0] = b + 2*g + 8*r;
1533 } else if(target == AV_PIX_FMT_BGR8) {
1534 dest[0] = r + 8*g + 64*b;
1535 } else if(target == AV_PIX_FMT_RGB8) {
1536 dest[0] = b + 4*g + 32*r;
1543 static av_always_inline void
1544 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1545 const int16_t **lumSrc, int lumFilterSize,
1546 const int16_t *chrFilter, const int16_t **chrUSrc,
1547 const int16_t **chrVSrc, int chrFilterSize,
1548 const int16_t **alpSrc, uint8_t *dest,
1549 int dstW, int y, enum AVPixelFormat target, int hasAlpha)
1552 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1554 int A = 0; //init to silence warning
1556 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1557 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1560 for (i = 0; i < dstW; i++) {
1563 int U = (1<<9)-(128 << 19);
1564 int V = (1<<9)-(128 << 19);
1566 for (j = 0; j < lumFilterSize; j++) {
1567 Y += lumSrc[j][i] * lumFilter[j];
1569 for (j = 0; j < chrFilterSize; j++) {
1570 U += chrUSrc[j][i] * chrFilter[j];
1571 V += chrVSrc[j][i] * chrFilter[j];
1578 for (j = 0; j < lumFilterSize; j++) {
1579 A += alpSrc[j][i] * lumFilter[j];
1583 A = av_clip_uint8(A);
1585 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
1588 c->dither_error[0][i] = err[0];
1589 c->dither_error[1][i] = err[1];
1590 c->dither_error[2][i] = err[2];
1593 static av_always_inline void
1594 yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
1595 const int16_t *ubuf[2], const int16_t *vbuf[2],
1596 const int16_t *abuf[2], uint8_t *dest, int dstW,
1597 int yalpha, int uvalpha, int y,
1598 enum AVPixelFormat target, int hasAlpha)
1600 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1601 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1602 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1603 *abuf0 = hasAlpha ? abuf[0] : NULL,
1604 *abuf1 = hasAlpha ? abuf[1] : NULL;
1605 int yalpha1 = 4096 - yalpha;
1606 int uvalpha1 = 4096 - uvalpha;
1608 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1610 int A = 0; // init to silcene warning
1612 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1613 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1616 for (i = 0; i < dstW; i++) {
1617 int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
1618 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
1619 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
1622 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
1624 A = av_clip_uint8(A);
1627 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
1630 c->dither_error[0][i] = err[0];
1631 c->dither_error[1][i] = err[1];
1632 c->dither_error[2][i] = err[2];
1635 static av_always_inline void
1636 yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
1637 const int16_t *ubuf[2], const int16_t *vbuf[2],
1638 const int16_t *abuf0, uint8_t *dest, int dstW,
1639 int uvalpha, int y, enum AVPixelFormat target,
1642 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1644 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
1647 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
1648 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
1651 if (uvalpha < 2048) {
1652 int A = 0; //init to silence warning
1653 for (i = 0; i < dstW; i++) {
1654 int Y = buf0[i] << 2;
1655 int U = (ubuf0[i] - (128<<7)) << 2;
1656 int V = (vbuf0[i] - (128<<7)) << 2;
1659 A = (abuf0[i] + 64) >> 7;
1661 A = av_clip_uint8(A);
1664 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
1668 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1669 int A = 0; //init to silence warning
1670 for (i = 0; i < dstW; i++) {
1671 int Y = buf0[i] << 2;
1672 int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
1673 int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
1676 A = (abuf0[i] + 64) >> 7;
1678 A = av_clip_uint8(A);
1681 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
1686 c->dither_error[0][i] = err[0];
1687 c->dither_error[1][i] = err[1];
1688 c->dither_error[2][i] = err[2];
1692 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1693 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1694 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1695 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1697 #if CONFIG_SWSCALE_ALPHA
1698 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
1699 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
1700 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
1701 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
1703 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
1704 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
1705 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
1706 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
1708 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
1709 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
1711 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
1712 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
1713 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
1714 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
1717 yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
1718 const int16_t **lumSrc, int lumFilterSize,
1719 const int16_t *chrFilter, const int16_t **chrUSrc,
1720 const int16_t **chrVSrc, int chrFilterSize,
1721 const int16_t **alpSrc, uint8_t **dest,
1724 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
1726 int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
1727 uint16_t **dest16 = (uint16_t**)dest;
1728 int SH = 22 + 7 - desc->comp[0].depth_minus1;
1729 int A = 0; // init to silence warning
1731 for (i = 0; i < dstW; i++) {
1734 int U = (1 << 9) - (128 << 19);
1735 int V = (1 << 9) - (128 << 19);
1738 for (j = 0; j < lumFilterSize; j++)
1739 Y += lumSrc[j][i] * lumFilter[j];
1741 for (j = 0; j < chrFilterSize; j++) {
1742 U += chrUSrc[j][i] * chrFilter[j];
1743 V += chrVSrc[j][i] * chrFilter[j];
1753 for (j = 0; j < lumFilterSize; j++)
1754 A += alpSrc[j][i] * lumFilter[j];
1759 A = av_clip_uint8(A);
1762 Y -= c->yuv2rgb_y_offset;
1763 Y *= c->yuv2rgb_y_coeff;
1765 R = Y + V * c->yuv2rgb_v2r_coeff;
1766 G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1767 B = Y + U * c->yuv2rgb_u2b_coeff;
1769 if ((R | G | B) & 0xC0000000) {
1770 R = av_clip_uintp2(R, 30);
1771 G = av_clip_uintp2(G, 30);
1772 B = av_clip_uintp2(B, 30);
1776 dest16[0][i] = G >> SH;
1777 dest16[1][i] = B >> SH;
1778 dest16[2][i] = R >> SH;
1782 dest[0][i] = G >> 22;
1783 dest[1][i] = B >> 22;
1784 dest[2][i] = R >> 22;
1789 if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
1790 for (i = 0; i < dstW; i++) {
1791 dest16[0][i] = av_bswap16(dest16[0][i]);
1792 dest16[1][i] = av_bswap16(dest16[1][i]);
1793 dest16[2][i] = av_bswap16(dest16[2][i]);
1795 dest16[3][i] = av_bswap16(dest16[3][i]);
1800 av_cold void ff_sws_init_output_funcs(SwsContext *c,
1801 yuv2planar1_fn *yuv2plane1,
1802 yuv2planarX_fn *yuv2planeX,
1803 yuv2interleavedX_fn *yuv2nv12cX,
1804 yuv2packed1_fn *yuv2packed1,
1805 yuv2packed2_fn *yuv2packed2,
1806 yuv2packedX_fn *yuv2packedX,
1807 yuv2anyX_fn *yuv2anyX)
1809 enum AVPixelFormat dstFormat = c->dstFormat;
1810 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
1812 if (is16BPS(dstFormat)) {
1813 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
1814 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
1815 } else if (is9_OR_10BPS(dstFormat)) {
1816 if (desc->comp[0].depth_minus1 == 8) {
1817 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
1818 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
1819 } else if (desc->comp[0].depth_minus1 == 9) {
1820 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
1821 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
1822 } else if (desc->comp[0].depth_minus1 == 11) {
1823 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
1824 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
1825 } else if (desc->comp[0].depth_minus1 == 13) {
1826 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
1827 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
1831 *yuv2plane1 = yuv2plane1_8_c;
1832 *yuv2planeX = yuv2planeX_8_c;
1833 if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
1834 *yuv2nv12cX = yuv2nv12cX_c;
1837 if(c->flags & SWS_FULL_CHR_H_INT) {
1838 switch (dstFormat) {
1839 case AV_PIX_FMT_RGBA:
1841 *yuv2packedX = yuv2rgba32_full_X_c;
1842 *yuv2packed2 = yuv2rgba32_full_2_c;
1843 *yuv2packed1 = yuv2rgba32_full_1_c;
1845 #if CONFIG_SWSCALE_ALPHA
1847 *yuv2packedX = yuv2rgba32_full_X_c;
1848 *yuv2packed2 = yuv2rgba32_full_2_c;
1849 *yuv2packed1 = yuv2rgba32_full_1_c;
1851 #endif /* CONFIG_SWSCALE_ALPHA */
1853 *yuv2packedX = yuv2rgbx32_full_X_c;
1854 *yuv2packed2 = yuv2rgbx32_full_2_c;
1855 *yuv2packed1 = yuv2rgbx32_full_1_c;
1857 #endif /* !CONFIG_SMALL */
1859 case AV_PIX_FMT_ARGB:
1861 *yuv2packedX = yuv2argb32_full_X_c;
1862 *yuv2packed2 = yuv2argb32_full_2_c;
1863 *yuv2packed1 = yuv2argb32_full_1_c;
1865 #if CONFIG_SWSCALE_ALPHA
1867 *yuv2packedX = yuv2argb32_full_X_c;
1868 *yuv2packed2 = yuv2argb32_full_2_c;
1869 *yuv2packed1 = yuv2argb32_full_1_c;
1871 #endif /* CONFIG_SWSCALE_ALPHA */
1873 *yuv2packedX = yuv2xrgb32_full_X_c;
1874 *yuv2packed2 = yuv2xrgb32_full_2_c;
1875 *yuv2packed1 = yuv2xrgb32_full_1_c;
1877 #endif /* !CONFIG_SMALL */
1879 case AV_PIX_FMT_BGRA:
1881 *yuv2packedX = yuv2bgra32_full_X_c;
1882 *yuv2packed2 = yuv2bgra32_full_2_c;
1883 *yuv2packed1 = yuv2bgra32_full_1_c;
1885 #if CONFIG_SWSCALE_ALPHA
1887 *yuv2packedX = yuv2bgra32_full_X_c;
1888 *yuv2packed2 = yuv2bgra32_full_2_c;
1889 *yuv2packed1 = yuv2bgra32_full_1_c;
1891 #endif /* CONFIG_SWSCALE_ALPHA */
1893 *yuv2packedX = yuv2bgrx32_full_X_c;
1894 *yuv2packed2 = yuv2bgrx32_full_2_c;
1895 *yuv2packed1 = yuv2bgrx32_full_1_c;
1897 #endif /* !CONFIG_SMALL */
1899 case AV_PIX_FMT_ABGR:
1901 *yuv2packedX = yuv2abgr32_full_X_c;
1902 *yuv2packed2 = yuv2abgr32_full_2_c;
1903 *yuv2packed1 = yuv2abgr32_full_1_c;
1905 #if CONFIG_SWSCALE_ALPHA
1907 *yuv2packedX = yuv2abgr32_full_X_c;
1908 *yuv2packed2 = yuv2abgr32_full_2_c;
1909 *yuv2packed1 = yuv2abgr32_full_1_c;
1911 #endif /* CONFIG_SWSCALE_ALPHA */
1913 *yuv2packedX = yuv2xbgr32_full_X_c;
1914 *yuv2packed2 = yuv2xbgr32_full_2_c;
1915 *yuv2packed1 = yuv2xbgr32_full_1_c;
1917 #endif /* !CONFIG_SMALL */
1919 case AV_PIX_FMT_RGB24:
1920 *yuv2packedX = yuv2rgb24_full_X_c;
1921 *yuv2packed2 = yuv2rgb24_full_2_c;
1922 *yuv2packed1 = yuv2rgb24_full_1_c;
1924 case AV_PIX_FMT_BGR24:
1925 *yuv2packedX = yuv2bgr24_full_X_c;
1926 *yuv2packed2 = yuv2bgr24_full_2_c;
1927 *yuv2packed1 = yuv2bgr24_full_1_c;
1929 case AV_PIX_FMT_BGR4_BYTE:
1930 *yuv2packedX = yuv2bgr4_byte_full_X_c;
1931 *yuv2packed2 = yuv2bgr4_byte_full_2_c;
1932 *yuv2packed1 = yuv2bgr4_byte_full_1_c;
1934 case AV_PIX_FMT_RGB4_BYTE:
1935 *yuv2packedX = yuv2rgb4_byte_full_X_c;
1936 *yuv2packed2 = yuv2rgb4_byte_full_2_c;
1937 *yuv2packed1 = yuv2rgb4_byte_full_1_c;
1939 case AV_PIX_FMT_BGR8:
1940 *yuv2packedX = yuv2bgr8_full_X_c;
1941 *yuv2packed2 = yuv2bgr8_full_2_c;
1942 *yuv2packed1 = yuv2bgr8_full_1_c;
1944 case AV_PIX_FMT_RGB8:
1945 *yuv2packedX = yuv2rgb8_full_X_c;
1946 *yuv2packed2 = yuv2rgb8_full_2_c;
1947 *yuv2packed1 = yuv2rgb8_full_1_c;
1949 case AV_PIX_FMT_GBRP:
1950 case AV_PIX_FMT_GBRP9BE:
1951 case AV_PIX_FMT_GBRP9LE:
1952 case AV_PIX_FMT_GBRP10BE:
1953 case AV_PIX_FMT_GBRP10LE:
1954 case AV_PIX_FMT_GBRP12BE:
1955 case AV_PIX_FMT_GBRP12LE:
1956 case AV_PIX_FMT_GBRP14BE:
1957 case AV_PIX_FMT_GBRP14LE:
1958 case AV_PIX_FMT_GBRP16BE:
1959 case AV_PIX_FMT_GBRP16LE:
1960 case AV_PIX_FMT_GBRAP:
1961 *yuv2anyX = yuv2gbrp_full_X_c;
1964 if (!*yuv2packedX && !*yuv2anyX)
1968 switch (dstFormat) {
1969 case AV_PIX_FMT_RGBA64LE:
1970 #if CONFIG_SWSCALE_ALPHA
1972 *yuv2packed1 = yuv2rgba64le_1_c;
1973 *yuv2packed2 = yuv2rgba64le_2_c;
1974 *yuv2packedX = yuv2rgba64le_X_c;
1976 #endif /* CONFIG_SWSCALE_ALPHA */
1978 *yuv2packed1 = yuv2rgbx64le_1_c;
1979 *yuv2packed2 = yuv2rgbx64le_2_c;
1980 *yuv2packedX = yuv2rgbx64le_X_c;
1983 case AV_PIX_FMT_RGBA64BE:
1984 #if CONFIG_SWSCALE_ALPHA
1986 *yuv2packed1 = yuv2rgba64be_1_c;
1987 *yuv2packed2 = yuv2rgba64be_2_c;
1988 *yuv2packedX = yuv2rgba64be_X_c;
1990 #endif /* CONFIG_SWSCALE_ALPHA */
1992 *yuv2packed1 = yuv2rgbx64be_1_c;
1993 *yuv2packed2 = yuv2rgbx64be_2_c;
1994 *yuv2packedX = yuv2rgbx64be_X_c;
1997 case AV_PIX_FMT_RGB48LE:
1998 *yuv2packed1 = yuv2rgb48le_1_c;
1999 *yuv2packed2 = yuv2rgb48le_2_c;
2000 *yuv2packedX = yuv2rgb48le_X_c;
2002 case AV_PIX_FMT_RGB48BE:
2003 *yuv2packed1 = yuv2rgb48be_1_c;
2004 *yuv2packed2 = yuv2rgb48be_2_c;
2005 *yuv2packedX = yuv2rgb48be_X_c;
2007 case AV_PIX_FMT_BGR48LE:
2008 *yuv2packed1 = yuv2bgr48le_1_c;
2009 *yuv2packed2 = yuv2bgr48le_2_c;
2010 *yuv2packedX = yuv2bgr48le_X_c;
2012 case AV_PIX_FMT_BGR48BE:
2013 *yuv2packed1 = yuv2bgr48be_1_c;
2014 *yuv2packed2 = yuv2bgr48be_2_c;
2015 *yuv2packedX = yuv2bgr48be_X_c;
2017 case AV_PIX_FMT_RGB32:
2018 case AV_PIX_FMT_BGR32:
2020 *yuv2packed1 = yuv2rgb32_1_c;
2021 *yuv2packed2 = yuv2rgb32_2_c;
2022 *yuv2packedX = yuv2rgb32_X_c;
2024 #if CONFIG_SWSCALE_ALPHA
2026 *yuv2packed1 = yuv2rgba32_1_c;
2027 *yuv2packed2 = yuv2rgba32_2_c;
2028 *yuv2packedX = yuv2rgba32_X_c;
2030 #endif /* CONFIG_SWSCALE_ALPHA */
2032 *yuv2packed1 = yuv2rgbx32_1_c;
2033 *yuv2packed2 = yuv2rgbx32_2_c;
2034 *yuv2packedX = yuv2rgbx32_X_c;
2036 #endif /* !CONFIG_SMALL */
2038 case AV_PIX_FMT_RGB32_1:
2039 case AV_PIX_FMT_BGR32_1:
2041 *yuv2packed1 = yuv2rgb32_1_1_c;
2042 *yuv2packed2 = yuv2rgb32_1_2_c;
2043 *yuv2packedX = yuv2rgb32_1_X_c;
2045 #if CONFIG_SWSCALE_ALPHA
2047 *yuv2packed1 = yuv2rgba32_1_1_c;
2048 *yuv2packed2 = yuv2rgba32_1_2_c;
2049 *yuv2packedX = yuv2rgba32_1_X_c;
2051 #endif /* CONFIG_SWSCALE_ALPHA */
2053 *yuv2packed1 = yuv2rgbx32_1_1_c;
2054 *yuv2packed2 = yuv2rgbx32_1_2_c;
2055 *yuv2packedX = yuv2rgbx32_1_X_c;
2057 #endif /* !CONFIG_SMALL */
2059 case AV_PIX_FMT_RGB24:
2060 *yuv2packed1 = yuv2rgb24_1_c;
2061 *yuv2packed2 = yuv2rgb24_2_c;
2062 *yuv2packedX = yuv2rgb24_X_c;
2064 case AV_PIX_FMT_BGR24:
2065 *yuv2packed1 = yuv2bgr24_1_c;
2066 *yuv2packed2 = yuv2bgr24_2_c;
2067 *yuv2packedX = yuv2bgr24_X_c;
2069 case AV_PIX_FMT_RGB565LE:
2070 case AV_PIX_FMT_RGB565BE:
2071 case AV_PIX_FMT_BGR565LE:
2072 case AV_PIX_FMT_BGR565BE:
2073 *yuv2packed1 = yuv2rgb16_1_c;
2074 *yuv2packed2 = yuv2rgb16_2_c;
2075 *yuv2packedX = yuv2rgb16_X_c;
2077 case AV_PIX_FMT_RGB555LE:
2078 case AV_PIX_FMT_RGB555BE:
2079 case AV_PIX_FMT_BGR555LE:
2080 case AV_PIX_FMT_BGR555BE:
2081 *yuv2packed1 = yuv2rgb15_1_c;
2082 *yuv2packed2 = yuv2rgb15_2_c;
2083 *yuv2packedX = yuv2rgb15_X_c;
2085 case AV_PIX_FMT_RGB444LE:
2086 case AV_PIX_FMT_RGB444BE:
2087 case AV_PIX_FMT_BGR444LE:
2088 case AV_PIX_FMT_BGR444BE:
2089 *yuv2packed1 = yuv2rgb12_1_c;
2090 *yuv2packed2 = yuv2rgb12_2_c;
2091 *yuv2packedX = yuv2rgb12_X_c;
2093 case AV_PIX_FMT_RGB8:
2094 case AV_PIX_FMT_BGR8:
2095 *yuv2packed1 = yuv2rgb8_1_c;
2096 *yuv2packed2 = yuv2rgb8_2_c;
2097 *yuv2packedX = yuv2rgb8_X_c;
2099 case AV_PIX_FMT_RGB4:
2100 case AV_PIX_FMT_BGR4:
2101 *yuv2packed1 = yuv2rgb4_1_c;
2102 *yuv2packed2 = yuv2rgb4_2_c;
2103 *yuv2packedX = yuv2rgb4_X_c;
2105 case AV_PIX_FMT_RGB4_BYTE:
2106 case AV_PIX_FMT_BGR4_BYTE:
2107 *yuv2packed1 = yuv2rgb4b_1_c;
2108 *yuv2packed2 = yuv2rgb4b_2_c;
2109 *yuv2packedX = yuv2rgb4b_X_c;
2113 switch (dstFormat) {
2114 case AV_PIX_FMT_MONOWHITE:
2115 *yuv2packed1 = yuv2monowhite_1_c;
2116 *yuv2packed2 = yuv2monowhite_2_c;
2117 *yuv2packedX = yuv2monowhite_X_c;
2119 case AV_PIX_FMT_MONOBLACK:
2120 *yuv2packed1 = yuv2monoblack_1_c;
2121 *yuv2packed2 = yuv2monoblack_2_c;
2122 *yuv2packedX = yuv2monoblack_X_c;
2124 case AV_PIX_FMT_YUYV422:
2125 *yuv2packed1 = yuv2yuyv422_1_c;
2126 *yuv2packed2 = yuv2yuyv422_2_c;
2127 *yuv2packedX = yuv2yuyv422_X_c;
2129 case AV_PIX_FMT_UYVY422:
2130 *yuv2packed1 = yuv2uyvy422_1_c;
2131 *yuv2packed2 = yuv2uyvy422_2_c;
2132 *yuv2packedX = yuv2uyvy422_X_c;