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, },
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, },
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, },
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, },
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, },
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, },
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, },
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, },
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, },
139 #define IS_BE(ENDIAN_IDENTIFIER) IS_BE_ ## ENDIAN_IDENTIFIER
141 #define output_pixel(pos, val, bias, signedness) \
143 AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
145 AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
150 int big_endian,
int output_bits)
156 for (
i = 0;
i < dstW;
i++) {
164 const int32_t **
src, uint16_t *dest,
int dstW,
165 int big_endian,
int output_bits)
171 for (
i = 0;
i < dstW;
i++) {
181 for (j = 0; j < filterSize; j++)
190 const int16_t *chrFilter,
int chrFilterSize,
191 const int16_t **chrUSrc,
const int16_t **chrVSrc,
192 uint8_t *dest8,
int chrDstW,
int output_bits)
194 uint16_t *dest = (uint16_t*)dest8;
201 for (
i = 0;
i < chrDstW;
i++) {
203 int v = 1 << (
shift - 1);
208 for (j = 0; j < chrFilterSize; j++) {
209 u += uSrc[j][
i] * (unsigned)chrFilter[j];
210 v += vSrc[j][
i] * (unsigned)chrFilter[j];
221 static const int big_endian = HAVE_BIGENDIAN;
222 static const int shift = 3;
223 static const float float_mult = 1.0f / 65535.0f;
227 for (
i = 0;
i < dstW; ++
i){
230 dest[
i] = float_mult * (
float)val_uint;
237 static const int big_endian = HAVE_BIGENDIAN;
238 static const int shift = 3;
239 static const float float_mult = 1.0f / 65535.0f;
243 for (
i = 0;
i < dstW; ++
i){
252 float *dest,
int dstW)
254 static const int big_endian = HAVE_BIGENDIAN;
255 static const int shift = 15;
256 static const float float_mult = 1.0f / 65535.0f;
260 for (
i = 0;
i < dstW; ++
i){
261 val = (1 << (
shift - 1)) - 0x40000000;
262 for (j = 0; j < filterSize; ++j){
266 dest[
i] = float_mult * (
float)val_uint;
272 uint32_t *dest,
int dstW)
274 static const int big_endian = HAVE_BIGENDIAN;
275 static const int shift = 15;
276 static const float float_mult = 1.0f / 65535.0f;
280 for (
i = 0;
i < dstW; ++
i){
281 val = (1 << (
shift - 1)) - 0x40000000;
282 for (j = 0; j < filterSize; ++j){
290 #define yuv2plane1_float(template, dest_type, BE_LE) \
291 static void yuv2plane1_float ## BE_LE ## _c(const int16_t *src, uint8_t *dest, int dstW, \
292 const uint8_t *dither, int offset) \
294 template((const int32_t *)src, (dest_type *)dest, dstW); \
297 #define yuv2planeX_float(template, dest_type, BE_LE) \
298 static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSize, \
299 const int16_t **src, uint8_t *dest, int dstW, \
300 const uint8_t *dither, int offset) \
302 template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW); \
319 #define output_pixel(pos, val) \
321 AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
323 AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
327 yuv2plane1_10_c_template(
const int16_t *
src, uint16_t *dest,
int dstW,
328 int big_endian,
int output_bits)
331 int shift = 15 - output_bits;
333 for (
i = 0;
i < dstW;
i++) {
341 const int16_t **
src, uint16_t *dest,
int dstW,
342 int big_endian,
int output_bits)
345 int shift = 11 + 16 - output_bits;
347 for (
i = 0;
i < dstW;
i++) {
351 for (j = 0; j < filterSize; j++)
360 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
361 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
362 uint8_t *dest, int dstW, \
363 const uint8_t *dither, int offset)\
365 yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
366 (uint16_t *) dest, dstW, is_be, bits); \
368 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
369 const int16_t **src, uint8_t *dest, int dstW, \
370 const uint8_t *dither, int offset)\
372 yuv2planeX_## template_size ## _c_template(filter, \
373 filterSize, (const typeX_t **) src, \
374 (uint16_t *) dest, dstW, is_be, bits); \
389 static void yuv2nv12cX_16LE_c(
enum AVPixelFormat dstFormat,
const uint8_t *chrDither,
390 const int16_t *chrFilter,
int chrFilterSize,
391 const int16_t **chrUSrc,
const int16_t **chrVSrc,
392 uint8_t *dest8,
int chrDstW)
398 const int16_t *chrFilter,
int chrFilterSize,
399 const int16_t **chrUSrc,
const int16_t **chrVSrc,
400 uint8_t *dest8,
int chrDstW)
406 const int16_t **
src, uint8_t *dest,
int dstW,
410 for (
i=0;
i<dstW;
i++) {
413 for (j=0; j<filterSize; j++)
424 for (
i=0;
i<dstW;
i++) {
431 const int16_t *chrFilter,
int chrFilterSize,
432 const int16_t **chrUSrc,
const int16_t **chrVSrc,
433 uint8_t *dest,
int chrDstW)
438 for (
i=0;
i<chrDstW;
i++) {
439 int u = chrDither[
i & 7] << 12;
440 int v = chrDither[(
i + 3) & 7] << 12;
442 for (j=0; j<chrFilterSize; j++) {
443 u += chrUSrc[j][
i] * chrFilter[j];
444 v += chrVSrc[j][
i] * chrFilter[j];
451 for (
i=0;
i<chrDstW;
i++) {
452 int u = chrDither[
i & 7] << 12;
453 int v = chrDither[(
i + 3) & 7] << 12;
455 for (j=0; j<chrFilterSize; j++) {
456 u += chrUSrc[j][
i] * chrFilter[j];
457 v += chrVSrc[j][
i] * chrFilter[j];
466 #define output_pixel(pos, val) \
468 AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
470 AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits) << output_shift); \
474 uint16_t *dest,
int dstW,
475 int big_endian,
int output_bits)
478 int shift = 15 - output_bits;
479 int output_shift = 16 - output_bits;
481 for (
i = 0;
i < dstW;
i++) {
488 const int16_t **
src, uint16_t *dest,
int dstW,
489 int big_endian,
int output_bits)
492 int shift = 11 + 16 - output_bits;
493 int output_shift = 16 - output_bits;
495 for (
i = 0;
i < dstW;
i++) {
498 for (j = 0; j < filterSize; j++)
506 const int16_t *chrFilter,
int chrFilterSize,
507 const int16_t **chrUSrc,
const int16_t **chrVSrc,
508 uint8_t *dest8,
int chrDstW,
int output_bits)
510 uint16_t *dest = (uint16_t*)dest8;
512 int shift = 11 + 16 - output_bits;
513 int output_shift = 16 - output_bits;
515 for (
i = 0;
i < chrDstW;
i++) {
517 int v = 1 << (
shift - 1);
519 for (j = 0; j < chrFilterSize; j++) {
520 u += chrUSrc[j][
i] * chrFilter[j];
521 v += chrVSrc[j][
i] * chrFilter[j];
531 #define yuv2p01x_wrapper(bits) \
532 static void yuv2p0 ## bits ## l1_LE_c(const int16_t *src, \
533 uint8_t *dest, int dstW, \
534 const uint8_t *dither, int offset) \
536 yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 0, bits); \
539 static void yuv2p0 ## bits ## l1_BE_c(const int16_t *src, \
540 uint8_t *dest, int dstW, \
541 const uint8_t *dither, int offset) \
543 yuv2p01xl1_c(src, (uint16_t*)dest, dstW, 1, bits); \
546 static void yuv2p0 ## bits ## lX_LE_c(const int16_t *filter, \
547 int filterSize, const int16_t **src, \
548 uint8_t *dest, int dstW, \
549 const uint8_t *dither, int offset) \
551 yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 0, bits); \
554 static void yuv2p0 ## bits ## lX_BE_c(const int16_t *filter, \
555 int filterSize, const int16_t **src, \
556 uint8_t *dest, int dstW, \
557 const uint8_t *dither, int offset) \
559 yuv2p01xlX_c(filter, filterSize, src, (uint16_t*)dest, dstW, 1, bits); \
562 static void yuv2p0 ## bits ## cX_LE_c(enum AVPixelFormat dstFormat, \
563 const uint8_t *chrDither, \
564 const int16_t *chrFilter, \
566 const int16_t **chrUSrc, \
567 const int16_t **chrVSrc, \
568 uint8_t *dest8, int chrDstW) \
570 yuv2p01xcX_c(0, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
571 dest8, chrDstW, bits); \
574 static void yuv2p0 ## bits ## cX_BE_c(enum AVPixelFormat dstFormat, \
575 const uint8_t *chrDither, \
576 const int16_t *chrFilter, \
578 const int16_t **chrUSrc, \
579 const int16_t **chrVSrc, \
580 uint8_t *dest8, int chrDstW) \
582 yuv2p01xcX_c(1, chrDither, chrFilter, chrFilterSize, chrUSrc, chrVSrc, \
583 dest8, chrDstW, bits); \
589 #define accumulate_bit(acc, val) \
592 #define output_pixel(pos, acc) \
593 if (target == AV_PIX_FMT_MONOBLACK) { \
600 yuv2mono_X_c_template(
SwsContext *
c,
const int16_t *lumFilter,
601 const int16_t **lumSrc,
int lumFilterSize,
602 const int16_t *chrFilter,
const int16_t **chrUSrc,
603 const int16_t **chrVSrc,
int chrFilterSize,
604 const int16_t **alpSrc, uint8_t *dest,
int dstW,
612 for (
i = 0;
i < dstW;
i += 2) {
617 for (j = 0; j < lumFilterSize; j++) {
618 Y1 += lumSrc[j][
i] * lumFilter[j];
619 Y2 += lumSrc[j][
i+1] * lumFilter[j];
623 if ((Y1 | Y2) & 0x100) {
628 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;
629 c->dither_error[0][
i] = err;
630 acc = 2*acc + (Y1 >= 128);
633 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);
634 c->dither_error[0][
i+1] = Y1;
635 acc = 2*acc + (err >= 128);
645 c->dither_error[0][
i] = err;
654 const int16_t *ubuf[2],
const int16_t *vbuf[2],
655 const int16_t *abuf[2], uint8_t *dest,
int dstW,
656 int yalpha,
int uvalpha,
int y,
659 const int16_t *buf0 = buf[0], *buf1 = buf[1];
661 int yalpha1 = 4096 - yalpha;
668 for (
i = 0;
i < dstW;
i +=2) {
671 Y = (buf0[
i + 0] * yalpha1 + buf1[
i + 0] * yalpha) >> 19;
672 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;
673 c->dither_error[0][
i] = err;
674 acc = 2*acc + (
Y >= 128);
677 err = (buf0[
i + 1] * yalpha1 + buf1[
i + 1] * yalpha) >> 19;
678 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;
679 c->dither_error[0][
i+1] =
Y;
680 acc = 2*acc + (err >= 128);
686 c->dither_error[0][
i] = err;
688 for (
i = 0;
i < dstW;
i += 8) {
691 Y = (buf0[
i + 0] * yalpha1 + buf1[
i + 0] * yalpha) >> 19;
693 Y = (buf0[
i + 1] * yalpha1 + buf1[
i + 1] * yalpha) >> 19;
695 Y = (buf0[
i + 2] * yalpha1 + buf1[
i + 2] * yalpha) >> 19;
697 Y = (buf0[
i + 3] * yalpha1 + buf1[
i + 3] * yalpha) >> 19;
699 Y = (buf0[
i + 4] * yalpha1 + buf1[
i + 4] * yalpha) >> 19;
701 Y = (buf0[
i + 5] * yalpha1 + buf1[
i + 5] * yalpha) >> 19;
703 Y = (buf0[
i + 6] * yalpha1 + buf1[
i + 6] * yalpha) >> 19;
705 Y = (buf0[
i + 7] * yalpha1 + buf1[
i + 7] * yalpha) >> 19;
715 const int16_t *ubuf[2],
const int16_t *vbuf[2],
716 const int16_t *abuf0, uint8_t *dest,
int dstW,
725 for (
i = 0;
i < dstW;
i +=2) {
728 Y = ((buf0[
i + 0] + 64) >> 7);
729 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;
730 c->dither_error[0][
i] = err;
731 acc = 2*acc + (
Y >= 128);
734 err = ((buf0[
i + 1] + 64) >> 7);
735 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;
736 c->dither_error[0][
i+1] =
Y;
737 acc = 2*acc + (err >= 128);
743 c->dither_error[0][
i] = err;
745 for (
i = 0;
i < dstW;
i += 8) {
762 #undef accumulate_bit
764 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
765 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
766 const int16_t **lumSrc, int lumFilterSize, \
767 const int16_t *chrFilter, const int16_t **chrUSrc, \
768 const int16_t **chrVSrc, int chrFilterSize, \
769 const int16_t **alpSrc, uint8_t *dest, int dstW, \
772 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
773 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
774 alpSrc, dest, dstW, y, fmt); \
777 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
778 const int16_t *ubuf[2], const int16_t *vbuf[2], \
779 const int16_t *abuf[2], uint8_t *dest, int dstW, \
780 int yalpha, int uvalpha, int y) \
782 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
783 dest, dstW, yalpha, uvalpha, y, fmt); \
786 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
787 const int16_t *ubuf[2], const int16_t *vbuf[2], \
788 const int16_t *abuf0, uint8_t *dest, int dstW, \
789 int uvalpha, int y) \
791 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
792 abuf0, dest, dstW, uvalpha, \
799 #define output_pixels(pos, Y1, U, Y2, V) \
800 if (target == AV_PIX_FMT_YUYV422) { \
801 dest[pos + 0] = Y1; \
803 dest[pos + 2] = Y2; \
805 } else if (target == AV_PIX_FMT_YVYU422) { \
806 dest[pos + 0] = Y1; \
808 dest[pos + 2] = Y2; \
812 dest[pos + 1] = Y1; \
814 dest[pos + 3] = Y2; \
819 const int16_t **lumSrc,
int lumFilterSize,
820 const int16_t *chrFilter,
const int16_t **chrUSrc,
821 const int16_t **chrVSrc,
int chrFilterSize,
822 const int16_t **alpSrc, uint8_t *dest,
int dstW,
827 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
834 for (j = 0; j < lumFilterSize; j++) {
835 Y1 += lumSrc[j][
i * 2] * lumFilter[j];
836 Y2 += lumSrc[j][
i * 2 + 1] * lumFilter[j];
838 for (j = 0; j < chrFilterSize; j++) {
839 U += chrUSrc[j][
i] * chrFilter[j];
840 V += chrVSrc[j][
i] * chrFilter[j];
846 if ((Y1 | Y2 |
U |
V) & 0x100) {
858 const int16_t *ubuf[2],
const int16_t *vbuf[2],
859 const int16_t *abuf[2], uint8_t *dest,
int dstW,
860 int yalpha,
int uvalpha,
int y,
863 const int16_t *buf0 = buf[0], *buf1 = buf[1],
864 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
865 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
866 int yalpha1 = 4096 - yalpha;
867 int uvalpha1 = 4096 - uvalpha;
872 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
873 int Y1 = (buf0[
i * 2] * yalpha1 + buf1[
i * 2] * yalpha) >> 19;
874 int Y2 = (buf0[
i * 2 + 1] * yalpha1 + buf1[
i * 2 + 1] * yalpha) >> 19;
875 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha) >> 19;
876 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha) >> 19;
878 if ((Y1 | Y2 |
U |
V) & 0x100) {
891 const int16_t *ubuf[2],
const int16_t *vbuf[2],
892 const int16_t *abuf0, uint8_t *dest,
int dstW,
895 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
898 if (uvalpha < 2048) {
899 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
900 int Y1 = (buf0[
i * 2 ]+64) >> 7;
901 int Y2 = (buf0[
i * 2 + 1]+64) >> 7;
902 int U = (ubuf0[
i] +64) >> 7;
903 int V = (vbuf0[
i] +64) >> 7;
905 if ((Y1 | Y2 |
U |
V) & 0x100) {
915 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
916 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
917 int Y1 = (buf0[
i * 2 ] + 64) >> 7;
918 int Y2 = (buf0[
i * 2 + 1] + 64) >> 7;
919 int U = (ubuf0[
i] + ubuf1[
i]+128) >> 8;
920 int V = (vbuf0[
i] + vbuf1[
i]+128) >> 8;
922 if ((Y1 | Y2 |
U |
V) & 0x100) {
940 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
941 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
942 #define output_pixel(pos, val) \
951 const int32_t **lumSrc,
int lumFilterSize,
952 const int16_t *chrFilter,
const int32_t **unused_chrUSrc,
953 const int32_t **unused_chrVSrc,
int unused_chrFilterSize,
954 const int32_t **alpSrc, uint16_t *dest,
int dstW,
956 int unused_hasAlpha,
int unused_eightbytes,
int is_be)
958 int hasAlpha = !!alpSrc;
961 for (
i = 0;
i < dstW;
i++) {
966 for (j = 0; j < lumFilterSize; j++)
967 Y += lumSrc[j][
i] * lumFilter[j];
970 Y += (1<<3) + 0x8000;
974 A = -0x40000000 + (1<<14);
975 for (j = 0; j < lumFilterSize; j++)
976 A += alpSrc[j][
i] * lumFilter[j];
991 const int32_t *abuf[2], uint16_t *dest,
int dstW,
992 int yalpha,
int unused_uvalpha,
int y,
994 int unused_eightbytes,
int is_be)
996 int hasAlpha = abuf && abuf[0] && abuf[1];
997 const int32_t *buf0 = buf[0], *buf1 = buf[1],
998 *abuf0 = hasAlpha ? abuf[0] :
NULL,
999 *abuf1 = hasAlpha ? abuf[1] :
NULL;
1000 int yalpha1 = 4096 - yalpha;
1005 for (
i = 0;
i < dstW;
i++) {
1006 int Y = (buf0[
i] * yalpha1 + buf1[
i] * yalpha) >> 15;
1012 A = (abuf0[
i] * yalpha1 + abuf1[
i] * yalpha) >> 15;
1024 const int32_t *abuf0, uint16_t *dest,
int dstW,
1026 int unused_hasAlpha,
int unused_eightbytes,
int is_be)
1028 int hasAlpha = !!abuf0;
1031 for (
i = 0;
i < dstW;
i++) {
1032 int Y = buf0[
i] >> 3;
1050 const int32_t **lumSrc,
int lumFilterSize,
1051 const int16_t *chrFilter,
const int32_t **chrUSrc,
1052 const int32_t **chrVSrc,
int chrFilterSize,
1053 const int32_t **alpSrc, uint16_t *dest,
int dstW,
1054 int y,
enum AVPixelFormat target,
int hasAlpha,
int eightbytes,
1058 int A1 = 0xffff<<14,
A2 = 0xffff<<14;
1060 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1062 unsigned Y1 = -0x40000000;
1063 unsigned Y2 = -0x40000000;
1064 int U = -(128 << 23);
1065 int V = -(128 << 23);
1068 for (j = 0; j < lumFilterSize; j++) {
1069 Y1 += lumSrc[j][
i * 2] * (unsigned)lumFilter[j];
1070 Y2 += lumSrc[j][
i * 2 + 1] * (unsigned)lumFilter[j];
1072 for (j = 0; j < chrFilterSize; j++) {;
1073 U += chrUSrc[j][
i] * (unsigned)chrFilter[j];
1074 V += chrVSrc[j][
i] * (unsigned)chrFilter[j];
1080 for (j = 0; j < lumFilterSize; j++) {
1081 A1 += alpSrc[j][
i * 2] * (unsigned)lumFilter[j];
1082 A2 += alpSrc[j][
i * 2 + 1] * (unsigned)lumFilter[j];
1099 Y1 -=
c->yuv2rgb_y_offset;
1100 Y2 -=
c->yuv2rgb_y_offset;
1101 Y1 *=
c->yuv2rgb_y_coeff;
1102 Y2 *=
c->yuv2rgb_y_coeff;
1103 Y1 += (1 << 13) - (1 << 29);
1104 Y2 += (1 << 13) - (1 << 29);
1107 R =
V *
c->yuv2rgb_v2r_coeff;
1108 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1109 B =
U *
c->yuv2rgb_u2b_coeff;
1134 const int32_t *abuf[2], uint16_t *dest,
int dstW,
1135 int yalpha,
int uvalpha,
int y,
1139 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1140 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1141 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1142 *abuf0 = hasAlpha ? abuf[0] :
NULL,
1143 *abuf1 = hasAlpha ? abuf[1] :
NULL;
1144 int yalpha1 = 4096 - yalpha;
1145 int uvalpha1 = 4096 - uvalpha;
1147 int A1 = 0xffff<<14,
A2 = 0xffff<<14;
1152 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1153 unsigned Y1 = (buf0[
i * 2] * yalpha1 + buf1[
i * 2] * yalpha) >> 14;
1154 unsigned Y2 = (buf0[
i * 2 + 1] * yalpha1 + buf1[
i * 2 + 1] * yalpha) >> 14;
1155 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha - (128 << 23)) >> 14;
1156 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha - (128 << 23)) >> 14;
1159 Y1 -=
c->yuv2rgb_y_offset;
1160 Y2 -=
c->yuv2rgb_y_offset;
1161 Y1 *=
c->yuv2rgb_y_coeff;
1162 Y2 *=
c->yuv2rgb_y_coeff;
1163 Y1 += (1 << 13) - (1 << 29);
1164 Y2 += (1 << 13) - (1 << 29);
1166 R =
V *
c->yuv2rgb_v2r_coeff;
1167 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1168 B =
U *
c->yuv2rgb_u2b_coeff;
1171 A1 = (abuf0[
i * 2 ] * yalpha1 + abuf1[
i * 2 ] * yalpha) >> 1;
1172 A2 = (abuf0[
i * 2 + 1] * yalpha1 + abuf1[
i * 2 + 1] * yalpha) >> 1;
1200 const int32_t *abuf0, uint16_t *dest,
int dstW,
1202 int hasAlpha,
int eightbytes,
int is_be)
1204 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1206 int A1 = 0xffff<<14,
A2= 0xffff<<14;
1208 if (uvalpha < 2048) {
1209 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1210 SUINT Y1 = (buf0[
i * 2] ) >> 2;
1211 SUINT Y2 = (buf0[
i * 2 + 1]) >> 2;
1212 int U = (ubuf0[
i] - (128 << 11)) >> 2;
1213 int V = (vbuf0[
i] - (128 << 11)) >> 2;
1216 Y1 -=
c->yuv2rgb_y_offset;
1217 Y2 -=
c->yuv2rgb_y_offset;
1218 Y1 *=
c->yuv2rgb_y_coeff;
1219 Y2 *=
c->yuv2rgb_y_coeff;
1220 Y1 += (1 << 13) - (1 << 29);
1221 Y2 += (1 << 13) - (1 << 29);
1224 A1 = abuf0[
i * 2 ] * (1 << 11);
1225 A2 = abuf0[
i * 2 + 1] * (1 << 11);
1231 R =
V *
c->yuv2rgb_v2r_coeff;
1232 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1233 B =
U *
c->yuv2rgb_u2b_coeff;
1253 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1254 int A1 = 0xffff<<14,
A2 = 0xffff<<14;
1255 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1256 SUINT Y1 = (buf0[
i * 2] ) >> 2;
1257 SUINT Y2 = (buf0[
i * 2 + 1]) >> 2;
1258 int U = (ubuf0[
i] + ubuf1[
i] - (128 << 12)) >> 3;
1259 int V = (vbuf0[
i] + vbuf1[
i] - (128 << 12)) >> 3;
1262 Y1 -=
c->yuv2rgb_y_offset;
1263 Y2 -=
c->yuv2rgb_y_offset;
1264 Y1 *=
c->yuv2rgb_y_coeff;
1265 Y2 *=
c->yuv2rgb_y_coeff;
1266 Y1 += (1 << 13) - (1 << 29);
1267 Y2 += (1 << 13) - (1 << 29);
1270 A1 = abuf0[
i * 2 ] * (1 << 11);
1271 A2 = abuf0[
i * 2 + 1] * (1 << 11);
1277 R =
V *
c->yuv2rgb_v2r_coeff;
1278 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1279 B =
U *
c->yuv2rgb_u2b_coeff;
1303 const int32_t **lumSrc,
int lumFilterSize,
1304 const int16_t *chrFilter,
const int32_t **chrUSrc,
1305 const int32_t **chrVSrc,
int chrFilterSize,
1306 const int32_t **alpSrc, uint16_t *dest,
int dstW,
1308 int eightbytes,
int is_be)
1313 for (
i = 0;
i < dstW;
i++) {
1315 int Y = -0x40000000;
1316 int U = -(128 << 23);
1317 int V = -(128 << 23);
1320 for (j = 0; j < lumFilterSize; j++) {
1321 Y += lumSrc[j][
i] * (unsigned)lumFilter[j];
1323 for (j = 0; j < chrFilterSize; j++) {;
1324 U += chrUSrc[j][
i] * (unsigned)chrFilter[j];
1325 V += chrVSrc[j][
i] * (unsigned)chrFilter[j];
1330 for (j = 0; j < lumFilterSize; j++) {
1331 A += alpSrc[j][
i] * (unsigned)lumFilter[j];
1344 Y -=
c->yuv2rgb_y_offset;
1345 Y *=
c->yuv2rgb_y_coeff;
1346 Y += (1 << 13) - (1<<29);
1349 R =
V *
c->yuv2rgb_v2r_coeff;
1350 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1351 B =
U *
c->yuv2rgb_u2b_coeff;
1369 const int32_t *abuf[2], uint16_t *dest,
int dstW,
1370 int yalpha,
int uvalpha,
int y,
1374 const int32_t *buf0 = buf[0], *buf1 = buf[1],
1375 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1376 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1377 *abuf0 = hasAlpha ? abuf[0] :
NULL,
1378 *abuf1 = hasAlpha ? abuf[1] :
NULL;
1379 int yalpha1 = 4096 - yalpha;
1380 int uvalpha1 = 4096 - uvalpha;
1387 for (
i = 0;
i < dstW;
i++) {
1388 int Y = (buf0[
i] * yalpha1 + buf1[
i] * yalpha) >> 14;
1389 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha - (128 << 23)) >> 14;
1390 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha - (128 << 23)) >> 14;
1393 Y -=
c->yuv2rgb_y_offset;
1394 Y *=
c->yuv2rgb_y_coeff;
1395 Y += (1 << 13) - (1 << 29);
1397 R =
V *
c->yuv2rgb_v2r_coeff;
1398 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1399 B =
U *
c->yuv2rgb_u2b_coeff;
1402 A = (abuf0[
i] * yalpha1 + abuf1[
i] * yalpha) >> 1;
1422 const int32_t *abuf0, uint16_t *dest,
int dstW,
1424 int hasAlpha,
int eightbytes,
int is_be)
1426 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1430 if (uvalpha < 2048) {
1431 for (
i = 0;
i < dstW;
i++) {
1433 int U = (ubuf0[
i] - (128 << 11)) >> 2;
1434 int V = (vbuf0[
i] - (128 << 11)) >> 2;
1437 Y -=
c->yuv2rgb_y_offset;
1438 Y *=
c->yuv2rgb_y_coeff;
1439 Y += (1 << 13) - (1 << 29);
1442 A = abuf0[
i] * (1 << 11);
1447 R =
V *
c->yuv2rgb_v2r_coeff;
1448 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1449 B =
U *
c->yuv2rgb_u2b_coeff;
1462 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1464 for (
i = 0;
i < dstW;
i++) {
1466 int U = (ubuf0[
i] + ubuf1[
i] - (128 << 12)) >> 3;
1467 int V = (vbuf0[
i] + vbuf1[
i] - (128 << 12)) >> 3;
1470 Y -=
c->yuv2rgb_y_offset;
1471 Y *=
c->yuv2rgb_y_coeff;
1472 Y += (1 << 13) - (1 << 29);
1475 A = abuf0[
i] * (1 << 11);
1480 R =
V *
c->yuv2rgb_v2r_coeff;
1481 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
1482 B =
U *
c->yuv2rgb_u2b_coeff;
1501 #define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \
1502 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1503 const int16_t **_lumSrc, int lumFilterSize, \
1504 const int16_t *chrFilter, const int16_t **_chrUSrc, \
1505 const int16_t **_chrVSrc, int chrFilterSize, \
1506 const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
1509 const int32_t **lumSrc = (const int32_t **) _lumSrc, \
1510 **chrUSrc = (const int32_t **) _chrUSrc, \
1511 **chrVSrc = (const int32_t **) _chrVSrc, \
1512 **alpSrc = (const int32_t **) _alpSrc; \
1513 uint16_t *dest = (uint16_t *) _dest; \
1514 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1515 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1516 alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \
1519 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
1520 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1521 const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
1522 int yalpha, int uvalpha, int y) \
1524 const int32_t **buf = (const int32_t **) _buf, \
1525 **ubuf = (const int32_t **) _ubuf, \
1526 **vbuf = (const int32_t **) _vbuf, \
1527 **abuf = (const int32_t **) _abuf; \
1528 uint16_t *dest = (uint16_t *) _dest; \
1529 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1530 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
1533 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
1534 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
1535 const int16_t *_abuf0, uint8_t *_dest, int dstW, \
1536 int uvalpha, int y) \
1538 const int32_t *buf0 = (const int32_t *) _buf0, \
1539 **ubuf = (const int32_t **) _ubuf, \
1540 **vbuf = (const int32_t **) _vbuf, \
1541 *abuf0 = (const int32_t *) _abuf0; \
1542 uint16_t *dest = (uint16_t *) _dest; \
1543 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1544 dstW, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \
1546 #define YUV2PACKED16WRAPPER(name, base, ext, base_fmt, endianness, hasAlpha, eightbytes) \
1547 YUV2PACKED16WRAPPER_EXT(name, base, ext, base_fmt ## endianness, IS_BE(endianness), hasAlpha, eightbytes)
1587 unsigned A1,
unsigned A2,
1588 const
void *_r, const
void *_g, const
void *_b,
int y,
1593 uint32_t *dest = (uint32_t *) _dest;
1594 const uint32_t *
r = (
const uint32_t *) _r;
1595 const uint32_t *
g = (
const uint32_t *) _g;
1596 const uint32_t *
b = (
const uint32_t *) _b;
1601 dest[
i * 2 + 0] =
r[Y1] +
g[Y1] +
b[Y1] + (hasAlpha ?
A1 << sh : 0);
1602 dest[
i * 2 + 1] =
r[Y2] +
g[Y2] +
b[Y2] + (hasAlpha ?
A2 << sh : 0);
1608 dest[
i * 2 + 0] =
r[Y1] +
g[Y1] +
b[Y1] + (
A1 << sh);
1609 dest[
i * 2 + 1] =
r[Y2] +
g[Y2] +
b[Y2] + (
A2 << sh);
1611 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
1614 av_assert2((((
r[Y1] +
g[Y1] +
b[Y1]) >> sh) & 0xFF) == 0xFF);
1616 dest[
i * 2 + 0] =
r[Y1] +
g[Y1] +
b[Y1];
1617 dest[
i * 2 + 1] =
r[Y2] +
g[Y2] +
b[Y2];
1621 uint8_t *dest = (uint8_t *) _dest;
1622 const uint8_t *
r = (
const uint8_t *) _r;
1623 const uint8_t *
g = (
const uint8_t *) _g;
1624 const uint8_t *
b = (
const uint8_t *) _b;
1626 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
1627 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
1629 dest[
i * 6 + 0] =
r_b[Y1];
1630 dest[
i * 6 + 1] =
g[Y1];
1631 dest[
i * 6 + 2] =
b_r[Y1];
1632 dest[
i * 6 + 3] =
r_b[Y2];
1633 dest[
i * 6 + 4] =
g[Y2];
1634 dest[
i * 6 + 5] =
b_r[Y2];
1640 uint16_t *dest = (uint16_t *) _dest;
1641 const uint16_t *
r = (
const uint16_t *) _r;
1642 const uint16_t *
g = (
const uint16_t *) _g;
1643 const uint16_t *
b = (
const uint16_t *) _b;
1644 int dr1, dg1, db1, dr2, dg2, db2;
1669 dest[
i * 2 + 0] =
r[Y1 + dr1] +
g[Y1 + dg1] +
b[Y1 + db1];
1670 dest[
i * 2 + 1] =
r[Y2 + dr2] +
g[Y2 + dg2] +
b[Y2 + db2];
1672 uint32_t *dest = (uint32_t *) _dest;
1673 const uint32_t *
r = (
const uint32_t *) _r;
1674 const uint32_t *
g = (
const uint32_t *) _g;
1675 const uint32_t *
b = (
const uint32_t *) _b;
1676 dest[
i * 2 + 0] =
r[Y1] +
g[Y1] +
b[Y1];
1677 dest[
i * 2 + 1] =
r[Y2] +
g[Y2] +
b[Y2];
1679 uint8_t *dest = (uint8_t *) _dest;
1680 const uint8_t *
r = (
const uint8_t *) _r;
1681 const uint8_t *
g = (
const uint8_t *) _g;
1682 const uint8_t *
b = (
const uint8_t *) _b;
1683 int dr1, dg1, db1, dr2, dg2, db2;
1688 dr1 = dg1 = d32[(
i * 2 + 0) & 7];
1689 db1 = d64[(
i * 2 + 0) & 7];
1690 dr2 = dg2 = d32[(
i * 2 + 1) & 7];
1691 db2 = d64[(
i * 2 + 1) & 7];
1695 dr1 = db1 =
d128[(
i * 2 + 0) & 7];
1696 dg1 = d64[(
i * 2 + 0) & 7];
1697 dr2 = db2 =
d128[(
i * 2 + 1) & 7];
1698 dg2 = d64[(
i * 2 + 1) & 7];
1702 dest[
i] =
r[Y1 + dr1] +
g[Y1 + dg1] +
b[Y1 + db1] +
1703 ((
r[Y2 + dr2] +
g[Y2 + dg2] +
b[Y2 + db2]) << 4);
1705 dest[
i * 2 + 0] =
r[Y1 + dr1] +
g[Y1 + dg1] +
b[Y1 + db1];
1706 dest[
i * 2 + 1] =
r[Y2 + dr2] +
g[Y2 + dg2] +
b[Y2 + db2];
1713 const int16_t **lumSrc,
int lumFilterSize,
1714 const int16_t *chrFilter,
const int16_t **chrUSrc,
1715 const int16_t **chrVSrc,
int chrFilterSize,
1716 const int16_t **alpSrc, uint8_t *dest,
int dstW,
1721 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1727 const void *
r, *
g, *
b;
1729 for (j = 0; j < lumFilterSize; j++) {
1730 Y1 += lumSrc[j][
i * 2] * lumFilter[j];
1731 Y2 += lumSrc[j][
i * 2 + 1] * lumFilter[j];
1733 for (j = 0; j < chrFilterSize; j++) {
1734 U += chrUSrc[j][
i] * chrFilter[j];
1735 V += chrVSrc[j][
i] * chrFilter[j];
1744 for (j = 0; j < lumFilterSize; j++) {
1745 A1 += alpSrc[j][
i * 2 ] * lumFilter[j];
1746 A2 += alpSrc[j][
i * 2 + 1] * lumFilter[j];
1750 if ((
A1 |
A2) & 0x100) {
1761 r,
g,
b, y, target, hasAlpha);
1767 const int16_t *ubuf[2],
const int16_t *vbuf[2],
1768 const int16_t *abuf[2], uint8_t *dest,
int dstW,
1769 int yalpha,
int uvalpha,
int y,
1772 const int16_t *buf0 = buf[0], *buf1 = buf[1],
1773 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
1774 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
1775 *abuf0 = hasAlpha ? abuf[0] :
NULL,
1776 *abuf1 = hasAlpha ? abuf[1] :
NULL;
1777 int yalpha1 = 4096 - yalpha;
1778 int uvalpha1 = 4096 - uvalpha;
1783 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1784 int Y1 = (buf0[
i * 2] * yalpha1 + buf1[
i * 2] * yalpha) >> 19;
1785 int Y2 = (buf0[
i * 2 + 1] * yalpha1 + buf1[
i * 2 + 1] * yalpha) >> 19;
1786 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha) >> 19;
1787 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha) >> 19;
1794 A1 = (abuf0[
i * 2 ] * yalpha1 + abuf1[
i * 2 ] * yalpha) >> 19;
1795 A2 = (abuf0[
i * 2 + 1] * yalpha1 + abuf1[
i * 2 + 1] * yalpha) >> 19;
1801 r,
g,
b, y, target, hasAlpha);
1807 const int16_t *ubuf[2],
const int16_t *vbuf[2],
1808 const int16_t *abuf0, uint8_t *dest,
int dstW,
1812 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
1815 if (uvalpha < 2048) {
1816 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1817 int Y1 = (buf0[
i * 2 ] + 64) >> 7;
1818 int Y2 = (buf0[
i * 2 + 1] + 64) >> 7;
1819 int U = (ubuf0[
i] + 64) >> 7;
1820 int V = (vbuf0[
i] + 64) >> 7;
1827 A1 = abuf0[
i * 2 ] * 255 + 16384 >> 15;
1828 A2 = abuf0[
i * 2 + 1] * 255 + 16384 >> 15;
1834 r,
g,
b, y, target, hasAlpha);
1837 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1838 for (
i = 0;
i < ((dstW + 1) >> 1);
i++) {
1839 int Y1 = (buf0[
i * 2 ] + 64) >> 7;
1840 int Y2 = (buf0[
i * 2 + 1] + 64) >> 7;
1841 int U = (ubuf0[
i] + ubuf1[
i] + 128) >> 8;
1842 int V = (vbuf0[
i] + vbuf1[
i] + 128) >> 8;
1849 A1 = (abuf0[
i * 2 ] + 64) >> 7;
1850 A2 = (abuf0[
i * 2 + 1] + 64) >> 7;
1856 r,
g,
b, y, target, hasAlpha);
1861 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1862 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
1863 const int16_t **lumSrc, int lumFilterSize, \
1864 const int16_t *chrFilter, const int16_t **chrUSrc, \
1865 const int16_t **chrVSrc, int chrFilterSize, \
1866 const int16_t **alpSrc, uint8_t *dest, int dstW, \
1869 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
1870 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
1871 alpSrc, dest, dstW, y, fmt, hasAlpha); \
1874 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1875 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
1876 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
1877 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1878 const int16_t *abuf[2], uint8_t *dest, int dstW, \
1879 int yalpha, int uvalpha, int y) \
1881 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
1882 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
1885 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
1886 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
1887 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
1888 const int16_t *ubuf[2], const int16_t *vbuf[2], \
1889 const int16_t *abuf0, uint8_t *dest, int dstW, \
1890 int uvalpha, int y) \
1892 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
1893 dstW, uvalpha, y, fmt, hasAlpha); \
1900 #if CONFIG_SWSCALE_ALPHA
1919 uint8_t *dest,
int i,
int Y,
int A,
int U,
int V,
1925 Y -=
c->yuv2rgb_y_offset;
1926 Y *=
c->yuv2rgb_y_coeff;
1928 R = (unsigned)
Y +
V*(
unsigned)
c->yuv2rgb_v2r_coeff;
1929 G = (unsigned)
Y +
V*(
unsigned)
c->yuv2rgb_v2g_coeff +
U*(unsigned)
c->yuv2rgb_u2g_coeff;
1930 B = (
unsigned)
Y +
U*(unsigned)
c->yuv2rgb_u2b_coeff;
1931 if ((
R |
G |
B) & 0xC0000000) {
1939 dest[0] = hasAlpha ?
A : 255;
1953 dest[3] = hasAlpha ?
A : 255;
1956 dest[0] = hasAlpha ?
A : 255;
1970 dest[3] = hasAlpha ?
A : 255;
1979 switch (
c->dither) {
1997 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;
1998 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;
1999 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;
2000 c->dither_error[0][
i] = err[0];
2001 c->dither_error[1][
i] = err[1];
2002 c->dither_error[2][
i] = err[2];
2003 r =
R >> (isrgb8 ? 5 : 7);
2004 g =
G >> (isrgb8 ? 5 : 6);
2005 b =
B >> (isrgb8 ? 6 : 7);
2009 err[0] =
R -
r*(isrgb8 ? 36 : 255);
2010 err[1] =
G -
g*(isrgb8 ? 36 : 85);
2011 err[2] =
B -
b*(isrgb8 ? 85 : 255);
2016 #define A_DITHER(u,v) (((((u)+((v)*236))*119)&0xff))
2035 #define X_DITHER(u,v) (((((u)^((v)*237))*181)&0x1ff)/2)
2055 dest[0] =
r + 2*
g + 8*
b;
2057 dest[0] =
b + 2*
g + 8*
r;
2059 dest[0] =
r + 8*
g + 64*
b;
2061 dest[0] =
b + 4*
g + 32*
r;
2070 const int16_t **lumSrc,
int lumFilterSize,
2071 const int16_t *chrFilter,
const int16_t **chrUSrc,
2072 const int16_t **chrVSrc,
int chrFilterSize,
2073 const int16_t **alpSrc, uint8_t *dest,
2085 for (
i = 0;
i < dstW;
i++) {
2088 int U = (1<<9)-(128 << 19);
2089 int V = (1<<9)-(128 << 19);
2091 for (j = 0; j < lumFilterSize; j++) {
2092 Y += lumSrc[j][
i] * lumFilter[j];
2094 for (j = 0; j < chrFilterSize; j++) {
2095 U += chrUSrc[j][
i] * chrFilter[j];
2096 V += chrVSrc[j][
i] * chrFilter[j];
2103 for (j = 0; j < lumFilterSize; j++) {
2104 A += alpSrc[j][
i] * lumFilter[j];
2110 yuv2rgb_write_full(
c, dest,
i,
Y,
A,
U,
V, y, target, hasAlpha, err);
2113 c->dither_error[0][
i] = err[0];
2114 c->dither_error[1][
i] = err[1];
2115 c->dither_error[2][
i] = err[2];
2120 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2121 const int16_t *abuf[2], uint8_t *dest,
int dstW,
2122 int yalpha,
int uvalpha,
int y,
2125 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2126 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2127 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2128 *abuf0 = hasAlpha ? abuf[0] :
NULL,
2129 *abuf1 = hasAlpha ? abuf[1] :
NULL;
2130 int yalpha1 = 4096 - yalpha;
2131 int uvalpha1 = 4096 - uvalpha;
2144 for (
i = 0;
i < dstW;
i++) {
2145 int Y = ( buf0[
i] * yalpha1 + buf1[
i] * yalpha ) >> 10;
2146 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha-(128 << 19)) >> 10;
2147 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha-(128 << 19)) >> 10;
2150 A = (abuf0[
i] * yalpha1 + abuf1[
i] * yalpha + (1<<18)) >> 19;
2155 yuv2rgb_write_full(
c, dest,
i,
Y,
A,
U,
V, y, target, hasAlpha, err);
2158 c->dither_error[0][
i] = err[0];
2159 c->dither_error[1][
i] = err[1];
2160 c->dither_error[2][
i] = err[2];
2165 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2166 const int16_t *abuf0, uint8_t *dest,
int dstW,
2170 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
2179 if (uvalpha < 2048) {
2181 for (
i = 0;
i < dstW;
i++) {
2182 int Y = buf0[
i] * 4;
2183 int U = (ubuf0[
i] - (128<<7)) * 4;
2184 int V = (vbuf0[
i] - (128<<7)) * 4;
2187 A = (abuf0[
i] + 64) >> 7;
2192 yuv2rgb_write_full(
c, dest,
i,
Y,
A,
U,
V, y, target, hasAlpha, err);
2196 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
2198 for (
i = 0;
i < dstW;
i++) {
2199 int Y = buf0[
i] * 4;
2200 int U = (ubuf0[
i] + ubuf1[
i] - (128<<8)) * 2;
2201 int V = (vbuf0[
i] + vbuf1[
i] - (128<<8)) * 2;
2204 A = (abuf0[
i] + 64) >> 7;
2209 yuv2rgb_write_full(
c, dest,
i,
Y,
A,
U,
V, y, target, hasAlpha, err);
2214 c->dither_error[0][
i] = err[0];
2215 c->dither_error[1][
i] = err[1];
2216 c->dither_error[2][
i] = err[2];
2225 #if CONFIG_SWSCALE_ALPHA
2246 const int16_t **lumSrc,
int lumFilterSize,
2247 const int16_t *chrFilter, const int16_t **chrUSrc,
2248 const int16_t **chrVSrc,
int chrFilterSize,
2249 const int16_t **alpSrc, uint8_t **dest,
2255 uint16_t **dest16 = (uint16_t**)dest;
2256 int SH = 22 + 8 -
desc->comp[0].depth;
2259 for (
i = 0;
i < dstW;
i++) {
2262 int U = (1 << 9) - (128 << 19);
2263 int V = (1 << 9) - (128 << 19);
2266 for (j = 0; j < lumFilterSize; j++)
2267 Y += lumSrc[j][
i] * lumFilter[j];
2269 for (j = 0; j < chrFilterSize; j++) {
2270 U += chrUSrc[j][
i] * chrFilter[j];
2271 V += chrVSrc[j][
i] * chrFilter[j];
2281 for (j = 0; j < lumFilterSize; j++)
2282 A += alpSrc[j][
i] * lumFilter[j];
2288 Y -=
c->yuv2rgb_y_offset;
2289 Y *=
c->yuv2rgb_y_coeff;
2291 R =
Y +
V *
c->yuv2rgb_v2r_coeff;
2292 G =
Y +
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
2293 B =
Y +
U *
c->yuv2rgb_u2b_coeff;
2295 if ((
R |
G |
B) & 0xC0000000) {
2302 dest16[0][
i] =
G >>
SH;
2303 dest16[1][
i] =
B >>
SH;
2304 dest16[2][
i] =
R >>
SH;
2306 dest16[3][
i] =
A >> (
SH - 3);
2308 dest[0][
i] =
G >> 22;
2309 dest[1][
i] =
B >> 22;
2310 dest[2][
i] =
R >> 22;
2312 dest[3][
i] =
A >> 19;
2315 if (
SH != 22 && (!
isBE(
c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2316 for (
i = 0;
i < dstW;
i++) {
2328 const int16_t **lumSrcx,
int lumFilterSize,
2329 const int16_t *chrFilter,
const int16_t **chrUSrcx,
2330 const int16_t **chrVSrcx,
int chrFilterSize,
2331 const int16_t **alpSrcx, uint8_t **dest,
2337 uint16_t **dest16 = (uint16_t**)dest;
2343 for (
i = 0;
i < dstW;
i++) {
2345 int Y = -0x40000000;
2346 int U = -(128 << 23);
2347 int V = -(128 << 23);
2350 for (j = 0; j < lumFilterSize; j++)
2351 Y += lumSrc[j][
i] * (
unsigned)lumFilter[j];
2353 for (j = 0; j < chrFilterSize; j++) {
2354 U += chrUSrc[j][
i] * (unsigned)chrFilter[j];
2355 V += chrVSrc[j][
i] * (unsigned)chrFilter[j];
2366 for (j = 0; j < lumFilterSize; j++)
2367 A += alpSrc[j][
i] * (
unsigned)lumFilter[j];
2373 Y -=
c->yuv2rgb_y_offset;
2374 Y *=
c->yuv2rgb_y_coeff;
2375 Y += (1 << 13) - (1 << 29);
2376 R =
V *
c->yuv2rgb_v2r_coeff;
2377 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
2378 B =
U *
c->yuv2rgb_u2b_coeff;
2387 if ((!
isBE(
c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2388 for (
i = 0;
i < dstW;
i++) {
2400 const int16_t **lumSrcx,
int lumFilterSize,
2401 const int16_t *chrFilter,
const int16_t **chrUSrcx,
2402 const int16_t **chrVSrcx,
int chrFilterSize,
2403 const int16_t **alpSrcx, uint8_t **dest,
2409 uint32_t **dest32 = (uint32_t**)dest;
2414 static const float float_mult = 1.0f / 65535.0f;
2416 for (
i = 0;
i < dstW;
i++) {
2418 int Y = -0x40000000;
2419 int U = -(128 << 23);
2420 int V = -(128 << 23);
2423 for (j = 0; j < lumFilterSize; j++)
2424 Y += lumSrc[j][
i] * (
unsigned)lumFilter[j];
2426 for (j = 0; j < chrFilterSize; j++) {
2427 U += chrUSrc[j][
i] * (unsigned)chrFilter[j];
2428 V += chrVSrc[j][
i] * (unsigned)chrFilter[j];
2439 for (j = 0; j < lumFilterSize; j++)
2440 A += alpSrc[j][
i] * (
unsigned)lumFilter[j];
2446 Y -=
c->yuv2rgb_y_offset;
2447 Y *=
c->yuv2rgb_y_coeff;
2448 Y += (1 << 13) - (1 << 29);
2449 R =
V *
c->yuv2rgb_v2r_coeff;
2450 G =
V *
c->yuv2rgb_v2g_coeff +
U *
c->yuv2rgb_u2g_coeff;
2451 B =
U *
c->yuv2rgb_u2b_coeff;
2463 if ((!
isBE(
c->dstFormat)) != (!HAVE_BIGENDIAN)) {
2464 for (
i = 0;
i < dstW;
i++) {
2476 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2477 const int16_t *abuf0, uint8_t *dest,
int dstW,
2480 int hasAlpha = !!abuf0;
2483 for (
i = 0;
i < dstW;
i++) {
2484 int Y = (buf0[
i] + 64) >> 7;
2490 A = (abuf0[
i] + 64) >> 7;
2496 dest[
i * 2 + 1] = hasAlpha ?
A : 255;
2502 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2503 const int16_t *abuf[2], uint8_t *dest,
int dstW,
2504 int yalpha,
int uvalpha,
int y)
2506 int hasAlpha = abuf && abuf[0] && abuf[1];
2507 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2508 *abuf0 = hasAlpha ? abuf[0] :
NULL,
2509 *abuf1 = hasAlpha ? abuf[1] :
NULL;
2510 int yalpha1 = 4096 - yalpha;
2515 for (
i = 0;
i < dstW;
i++) {
2516 int Y = (buf0[
i] * yalpha1 + buf1[
i] * yalpha) >> 19;
2522 A = (abuf0[
i] * yalpha1 + abuf1[
i] * yalpha) >> 19;
2527 dest[
i * 2 + 1] = hasAlpha ?
A : 255;
2533 const int16_t **lumSrc,
int lumFilterSize,
2534 const int16_t *chrFilter,
const int16_t **chrUSrc,
2535 const int16_t **chrVSrc,
int chrFilterSize,
2536 const int16_t **alpSrc, uint8_t *dest,
int dstW,
int y)
2538 int hasAlpha = !!alpSrc;
2541 for (
i = 0;
i < dstW;
i++) {
2543 int Y = 1 << 18,
A = 1 << 18;
2545 for (j = 0; j < lumFilterSize; j++)
2546 Y += lumSrc[j][
i] * lumFilter[j];
2553 for (j = 0; j < lumFilterSize; j++)
2554 A += alpSrc[j][
i] * lumFilter[j];
2563 dest[2 *
i + 1] = hasAlpha ?
A : 255;
2569 const int16_t **_lumSrc,
int lumFilterSize,
2570 const int16_t *chrFilter,
const int16_t **_chrUSrc,
2571 const int16_t **_chrVSrc,
int chrFilterSize,
2572 const int16_t **_alpSrc, uint8_t *dest,
int dstW,
int y)
2575 **chrUSrc = (
const int32_t **) _chrUSrc,
2576 **chrVSrc = (
const int32_t **) _chrVSrc,
2577 **alpSrc = (
const int32_t **) _alpSrc;
2578 int hasAlpha = !!alpSrc;
2581 for (
i = 0;
i < dstW;
i++) {
2582 int Y = 1 << 14,
U = 1 << 14;
2583 int V = 1 << 14,
A = 1 << 14;
2591 for (j = 0; j < lumFilterSize; j++)
2592 Y += lumSrc[j][
i] * (
unsigned)lumFilter[j];
2594 for (j = 0; j < chrFilterSize; j++)
2595 U += chrUSrc[j][
i] * (
unsigned)chrFilter[j];
2597 for (j = 0; j < chrFilterSize; j++)
2598 V += chrVSrc[j][
i] * (
unsigned)chrFilter[j];
2601 for (j = 0; j < lumFilterSize; j++)
2602 A += alpSrc[j][
i] * (
unsigned)lumFilter[j];
2609 AV_WL16(dest + 8 *
i, hasAlpha ?
A : 65535);
2619 const int16_t **lumSrc,
int lumFilterSize,
2620 const int16_t *chrFilter,
const int16_t **chrUSrc,
2621 const int16_t **chrVSrc,
int chrFilterSize,
2622 const int16_t **alpSrc, uint8_t *dest,
int dstW,
int y,
2626 for (
i = 0;
i < dstW;
i++) {
2627 int Y = 1 << 16,
U = 1 << 16,
V = 1 << 16;
2630 for (j = 0; j < lumFilterSize; j++)
2631 Y += lumSrc[j][
i] * lumFilter[j];
2633 for (j = 0; j < chrFilterSize; j++) {
2634 U += chrUSrc[j][
i] * chrFilter[j];
2635 V += chrVSrc[j][
i] * chrFilter[j];
2644 (
unsigned)
V << (
shift + 20));
2648 #define V30LE_WRAPPER(name, shift) \
2649 static void yuv2 ## name ## _X_c(SwsContext *c, const int16_t *lumFilter, \
2650 const int16_t **lumSrc, int lumFilterSize, \
2651 const int16_t *chrFilter, const int16_t **chrUSrc, \
2652 const int16_t **chrVSrc, int chrFilterSize, \
2653 const int16_t **alpSrc, uint8_t *dest, int dstW, \
2656 yuv2v30_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
2657 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2658 alpSrc, dest, dstW, y, shift); \
2666 const int16_t **lumSrc,
int lumFilterSize,
2667 const int16_t *chrFilter, const int16_t **chrUSrc,
2668 const int16_t **chrVSrc,
int chrFilterSize,
2669 const int16_t **alpSrc, uint8_t *dest,
int dstW,
int y)
2672 for (
i = 0;
i < dstW;
i++) {
2673 int Y = 1 << 14,
U = 1 << 14,
V = 1 << 14,
A = 255;
2676 for (j = 0; j < lumFilterSize; j++)
2677 Y += lumSrc[j][
i] * lumFilter[j];
2679 for (j = 0; j < chrFilterSize; j++) {
2680 U += chrUSrc[j][
i] * chrFilter[j];
2681 V += chrVSrc[j][
i] * chrFilter[j];
2691 #define output_pixels(pos, A, Y, U, V) \
2692 if (target == AV_PIX_FMT_AYUV) { \
2693 dest[pos + 0] = A; \
2694 dest[pos + 1] = Y; \
2695 dest[pos + 2] = U; \
2696 dest[pos + 3] = V; \
2697 } else if (target == AV_PIX_FMT_UYVA) { \
2698 dest[pos + 0] = U; \
2699 dest[pos + 1] = Y; \
2700 dest[pos + 2] = V; \
2701 dest[pos + 3] = A; \
2703 dest[pos + 0] = V; \
2704 dest[pos + 1] = U; \
2705 dest[pos + 2] = Y; \
2706 dest[pos + 3] = A; \
2711 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2712 const int16_t *abuf0, uint8_t *dest,
int dstW,
2715 int hasAlpha = !!abuf0;
2718 if (uvalpha < 2048) {
2719 for (
i = 0;
i < dstW;
i++) {
2720 int Y = (buf0[
i] + 64) >> 7;
2721 int U = (ubuf[0][
i] + 64) >> 7;
2722 int V = (vbuf[0][
i] + 64) >> 7;
2733 A = (abuf0[
i] + 64) >> 7;
2741 for (
i = 0;
i < dstW;
i++) {
2742 int Y = (buf0[
i] + 64) >> 7;
2743 int U = (ubuf[0][
i] + ubuf[1][
i] + 128) >> 8;
2744 int V = (vbuf[0][
i] + vbuf[1][
i] + 128) >> 8;
2755 A = (abuf0[
i] + 64) >> 7;
2767 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2768 const int16_t *abuf[2], uint8_t *dest,
int dstW,
2769 int yalpha,
int uvalpha,
int y,
2772 int hasAlpha = abuf && abuf[0] && abuf[1];
2773 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2774 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2775 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
2776 *abuf0 = hasAlpha ? abuf[0] :
NULL,
2777 *abuf1 = hasAlpha ? abuf[1] :
NULL;
2778 int yalpha1 = 4096 - yalpha;
2779 int uvalpha1 = 4096 - uvalpha;
2785 for (
i = 0;
i < dstW;
i++) {
2786 int Y = (buf0[
i] * yalpha1 + buf1[
i] * yalpha) >> 19;
2787 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha) >> 19;
2788 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha) >> 19;
2799 A = (abuf0[
i] * yalpha1 + abuf1[
i] * yalpha) >> 19;
2809 const int16_t **lumSrc,
int lumFilterSize,
2810 const int16_t *chrFilter,
const int16_t **chrUSrc,
2811 const int16_t **chrVSrc,
int chrFilterSize,
2812 const int16_t **alpSrc, uint8_t *dest,
int dstW,
2817 for (
i = 0;
i < dstW;
i++) {
2819 int Y = 1 << 18,
U = 1 << 18;
2820 int V = 1 << 18,
A = 255;
2822 for (j = 0; j < lumFilterSize; j++)
2823 Y += lumSrc[j][
i] * lumFilter[j];
2825 for (j = 0; j < chrFilterSize; j++)
2826 U += chrUSrc[j][
i] * chrFilter[j];
2828 for (j = 0; j < chrFilterSize; j++)
2829 V += chrVSrc[j][
i] * chrFilter[j];
2845 for (j = 0; j < lumFilterSize; j++)
2846 A += alpSrc[j][
i] * lumFilter[j];
2858 #undef output_pixels
2860 #define AYUVPACKEDWRAPPER(name, fmt) \
2861 static void yuv2 ## name ## _X_c(SwsContext *c, const int16_t *lumFilter, \
2862 const int16_t **lumSrc, int lumFilterSize, \
2863 const int16_t *chrFilter, const int16_t **chrUSrc, \
2864 const int16_t **chrVSrc, int chrFilterSize, \
2865 const int16_t **alpSrc, uint8_t *dest, int dstW, \
2868 yuv2ayuv_X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
2869 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
2870 alpSrc, dest, dstW, y, fmt); \
2873 static void yuv2 ## name ## _2_c(SwsContext *c, const int16_t *buf[2], \
2874 const int16_t *ubuf[2], const int16_t *vbuf[2], \
2875 const int16_t *abuf[2], uint8_t *dest, int dstW, \
2876 int yalpha, int uvalpha, int y) \
2878 yuv2ayuv_2_c_template(c, buf, ubuf, vbuf, abuf, \
2879 dest, dstW, yalpha, uvalpha, y, fmt); \
2882 static void yuv2 ## name ## _1_c(SwsContext *c, const int16_t *buf0, \
2883 const int16_t *ubuf[2], const int16_t *vbuf[2], \
2884 const int16_t *abuf0, uint8_t *dest, int dstW, \
2885 int uvalpha, int y) \
2887 yuv2ayuv_1_c_template(c, buf0, ubuf, vbuf, \
2888 abuf0, dest, dstW, uvalpha, \
2896 #define output_pixel(pos, val, bits) \
2897 AV_WL16(pos, av_clip_uintp2(val >> shift, bits) << output_shift);
2899 #define yuv2y2xx_wrapper(bits) \
2901 yuv2y2 ## bits ## le_X_c(SwsContext *c, const int16_t *lumFilter, \
2902 const int16_t **lumSrc, int lumFilterSize, \
2903 const int16_t *chrFilter, \
2904 const int16_t **chrUSrc, \
2905 const int16_t **chrVSrc, int chrFilterSize, \
2906 const int16_t **alpSrc, \
2907 uint8_t *dest, int dstW, int y) \
2910 int shift = 11 + 16 - bits; \
2911 int output_shift = 16 - bits; \
2912 for (i = 0; i < ((dstW + 1) >> 1); i++) { \
2913 int Y1 = 1 << (shift - 1), Y2 = 1 << (shift - 1); \
2914 int U = 1 << (shift - 1), V = 1 << (shift - 1); \
2916 for (j = 0; j < lumFilterSize; j++) { \
2917 Y1 += lumSrc[j][i * 2] * lumFilter[j]; \
2918 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; \
2921 for (j = 0; j < chrFilterSize; j++) { \
2922 U += chrUSrc[j][i] * chrFilter[j]; \
2923 V += chrVSrc[j][i] * chrFilter[j]; \
2926 output_pixel(dest + 8 * i + 0, Y1, bits); \
2927 output_pixel(dest + 8 * i + 2, U, bits); \
2928 output_pixel(dest + 8 * i + 4, Y2, bits); \
2929 output_pixel(dest + 8 * i + 6, V, bits); \
2937 yuv2vyu444_1_c(
SwsContext *
c, const int16_t *buf0,
2938 const int16_t *ubuf[2], const int16_t *vbuf[2],
2939 const int16_t *abuf0, uint8_t *dest,
int dstW,
2944 if (uvalpha < 2048) {
2945 for (
i = 0;
i < dstW;
i++) {
2946 int Y = (buf0[
i] + 64) >> 7;
2947 int U = (ubuf[0][
i] + 64) >> 7;
2948 int V = (vbuf[0][
i] + 64) >> 7;
2958 dest[3 *
i + 1] =
Y;
2959 dest[3 *
i + 2] =
U;
2962 for (
i = 0;
i < dstW;
i++) {
2963 int Y = (buf0[
i] + 64) >> 7;
2964 int U = (ubuf[0][
i] + ubuf[1][
i] + 128) >> 8;
2965 int V = (vbuf[0][
i] + vbuf[1][
i] + 128) >> 8;
2975 dest[3 *
i + 1] =
Y;
2976 dest[3 *
i + 2] =
U;
2983 const int16_t *ubuf[2],
const int16_t *vbuf[2],
2984 const int16_t *abuf[2], uint8_t *dest,
int dstW,
2985 int yalpha,
int uvalpha,
int y)
2987 const int16_t *buf0 = buf[0], *buf1 = buf[1],
2988 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
2989 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
2990 int yalpha1 = 4096 - yalpha;
2991 int uvalpha1 = 4096 - uvalpha;
2997 for (
i = 0;
i < dstW;
i++) {
2998 int Y = (buf0[
i] * yalpha1 + buf1[
i] * yalpha) >> 19;
2999 int U = (ubuf0[
i] * uvalpha1 + ubuf1[
i] * uvalpha) >> 19;
3000 int V = (vbuf0[
i] * uvalpha1 + vbuf1[
i] * uvalpha) >> 19;
3010 dest[3 *
i + 1] =
Y;
3011 dest[3 *
i + 2] =
U;
3017 const int16_t **lumSrc,
int lumFilterSize,
3018 const int16_t *chrFilter,
const int16_t **chrUSrc,
3019 const int16_t **chrVSrc,
int chrFilterSize,
3020 const int16_t **alpSrc, uint8_t *dest,
int dstW,
int y)
3024 for (
i = 0;
i < dstW;
i++) {
3026 int Y = 1 << 18,
U = 1 << 18;
3029 for (j = 0; j < lumFilterSize; j++)
3030 Y += lumSrc[j][
i] * lumFilter[j];
3032 for (j = 0; j < chrFilterSize; j++)
3033 U += chrUSrc[j][
i] * chrFilter[j];
3035 for (j = 0; j < chrFilterSize; j++)
3036 V += chrVSrc[j][
i] * chrFilter[j];
3050 dest[3 *
i + 1] =
Y;
3051 dest[3 *
i + 2] =
U;
3070 if (
desc->comp[0].depth == 10) {
3071 *yuv2plane1 =
isBE(dstFormat) ? yuv2p010l1_BE_c : yuv2p010l1_LE_c;
3072 *
yuv2planeX =
isBE(dstFormat) ? yuv2p010lX_BE_c : yuv2p010lX_LE_c;
3073 *yuv2nv12cX =
isBE(dstFormat) ? yuv2p010cX_BE_c : yuv2p010cX_LE_c;
3074 }
else if (
desc->comp[0].depth == 12) {
3075 *yuv2plane1 =
isBE(dstFormat) ? yuv2p012l1_BE_c : yuv2p012l1_LE_c;
3076 *
yuv2planeX =
isBE(dstFormat) ? yuv2p012lX_BE_c : yuv2p012lX_LE_c;
3077 *yuv2nv12cX =
isBE(dstFormat) ? yuv2p012cX_BE_c : yuv2p012cX_LE_c;
3080 }
else if (
is16BPS(dstFormat)) {
3081 *
yuv2planeX =
isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
3082 *yuv2plane1 =
isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
3086 }
else if (
isNBPS(dstFormat)) {
3087 if (
desc->comp[0].depth == 9) {
3088 *
yuv2planeX =
isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
3089 *yuv2plane1 =
isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
3090 }
else if (
desc->comp[0].depth == 10) {
3091 *
yuv2planeX =
isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
3092 *yuv2plane1 =
isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
3093 }
else if (
desc->comp[0].depth == 12) {
3094 *
yuv2planeX =
isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
3095 *yuv2plane1 =
isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
3096 }
else if (
desc->comp[0].depth == 14) {
3097 *
yuv2planeX =
isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
3098 *yuv2plane1 =
isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
3103 *yuv2plane1 = yuv2plane1_floatBE_c;
3106 *yuv2plane1 = yuv2plane1_floatLE_c;
3115 switch (dstFormat) {
3118 *yuv2packedX = yuv2rgba32_full_X_c;
3119 *yuv2packed2 = yuv2rgba32_full_2_c;
3120 *yuv2packed1 = yuv2rgba32_full_1_c;
3122 #if CONFIG_SWSCALE_ALPHA
3124 *yuv2packedX = yuv2rgba32_full_X_c;
3125 *yuv2packed2 = yuv2rgba32_full_2_c;
3126 *yuv2packed1 = yuv2rgba32_full_1_c;
3130 *yuv2packedX = yuv2rgbx32_full_X_c;
3131 *yuv2packed2 = yuv2rgbx32_full_2_c;
3132 *yuv2packed1 = yuv2rgbx32_full_1_c;
3138 *yuv2packedX = yuv2argb32_full_X_c;
3139 *yuv2packed2 = yuv2argb32_full_2_c;
3140 *yuv2packed1 = yuv2argb32_full_1_c;
3142 #if CONFIG_SWSCALE_ALPHA
3144 *yuv2packedX = yuv2argb32_full_X_c;
3145 *yuv2packed2 = yuv2argb32_full_2_c;
3146 *yuv2packed1 = yuv2argb32_full_1_c;
3150 *yuv2packedX = yuv2xrgb32_full_X_c;
3151 *yuv2packed2 = yuv2xrgb32_full_2_c;
3152 *yuv2packed1 = yuv2xrgb32_full_1_c;
3158 *yuv2packedX = yuv2bgra32_full_X_c;
3159 *yuv2packed2 = yuv2bgra32_full_2_c;
3160 *yuv2packed1 = yuv2bgra32_full_1_c;
3162 #if CONFIG_SWSCALE_ALPHA
3164 *yuv2packedX = yuv2bgra32_full_X_c;
3165 *yuv2packed2 = yuv2bgra32_full_2_c;
3166 *yuv2packed1 = yuv2bgra32_full_1_c;
3170 *yuv2packedX = yuv2bgrx32_full_X_c;
3171 *yuv2packed2 = yuv2bgrx32_full_2_c;
3172 *yuv2packed1 = yuv2bgrx32_full_1_c;
3178 *yuv2packedX = yuv2abgr32_full_X_c;
3179 *yuv2packed2 = yuv2abgr32_full_2_c;
3180 *yuv2packed1 = yuv2abgr32_full_1_c;
3182 #if CONFIG_SWSCALE_ALPHA
3184 *yuv2packedX = yuv2abgr32_full_X_c;
3185 *yuv2packed2 = yuv2abgr32_full_2_c;
3186 *yuv2packed1 = yuv2abgr32_full_1_c;
3190 *yuv2packedX = yuv2xbgr32_full_X_c;
3191 *yuv2packed2 = yuv2xbgr32_full_2_c;
3192 *yuv2packed1 = yuv2xbgr32_full_1_c;
3197 #if CONFIG_SWSCALE_ALPHA
3199 *yuv2packedX = yuv2rgba64le_full_X_c;
3200 *yuv2packed2 = yuv2rgba64le_full_2_c;
3201 *yuv2packed1 = yuv2rgba64le_full_1_c;
3205 *yuv2packedX = yuv2rgbx64le_full_X_c;
3206 *yuv2packed2 = yuv2rgbx64le_full_2_c;
3207 *yuv2packed1 = yuv2rgbx64le_full_1_c;
3211 #if CONFIG_SWSCALE_ALPHA
3213 *yuv2packedX = yuv2rgba64be_full_X_c;
3214 *yuv2packed2 = yuv2rgba64be_full_2_c;
3215 *yuv2packed1 = yuv2rgba64be_full_1_c;
3219 *yuv2packedX = yuv2rgbx64be_full_X_c;
3220 *yuv2packed2 = yuv2rgbx64be_full_2_c;
3221 *yuv2packed1 = yuv2rgbx64be_full_1_c;
3225 #if CONFIG_SWSCALE_ALPHA
3227 *yuv2packedX = yuv2bgra64le_full_X_c;
3228 *yuv2packed2 = yuv2bgra64le_full_2_c;
3229 *yuv2packed1 = yuv2bgra64le_full_1_c;
3233 *yuv2packedX = yuv2bgrx64le_full_X_c;
3234 *yuv2packed2 = yuv2bgrx64le_full_2_c;
3235 *yuv2packed1 = yuv2bgrx64le_full_1_c;
3239 #if CONFIG_SWSCALE_ALPHA
3241 *yuv2packedX = yuv2bgra64be_full_X_c;
3242 *yuv2packed2 = yuv2bgra64be_full_2_c;
3243 *yuv2packed1 = yuv2bgra64be_full_1_c;
3247 *yuv2packedX = yuv2bgrx64be_full_X_c;
3248 *yuv2packed2 = yuv2bgrx64be_full_2_c;
3249 *yuv2packed1 = yuv2bgrx64be_full_1_c;
3254 *yuv2packedX = yuv2rgb24_full_X_c;
3255 *yuv2packed2 = yuv2rgb24_full_2_c;
3256 *yuv2packed1 = yuv2rgb24_full_1_c;
3259 *yuv2packedX = yuv2bgr24_full_X_c;
3260 *yuv2packed2 = yuv2bgr24_full_2_c;
3261 *yuv2packed1 = yuv2bgr24_full_1_c;
3264 *yuv2packedX = yuv2rgb48le_full_X_c;
3265 *yuv2packed2 = yuv2rgb48le_full_2_c;
3266 *yuv2packed1 = yuv2rgb48le_full_1_c;
3269 *yuv2packedX = yuv2bgr48le_full_X_c;
3270 *yuv2packed2 = yuv2bgr48le_full_2_c;
3271 *yuv2packed1 = yuv2bgr48le_full_1_c;
3274 *yuv2packedX = yuv2rgb48be_full_X_c;
3275 *yuv2packed2 = yuv2rgb48be_full_2_c;
3276 *yuv2packed1 = yuv2rgb48be_full_1_c;
3279 *yuv2packedX = yuv2bgr48be_full_X_c;
3280 *yuv2packed2 = yuv2bgr48be_full_2_c;
3281 *yuv2packed1 = yuv2bgr48be_full_1_c;
3284 *yuv2packedX = yuv2bgr4_byte_full_X_c;
3285 *yuv2packed2 = yuv2bgr4_byte_full_2_c;
3286 *yuv2packed1 = yuv2bgr4_byte_full_1_c;
3289 *yuv2packedX = yuv2rgb4_byte_full_X_c;
3290 *yuv2packed2 = yuv2rgb4_byte_full_2_c;
3291 *yuv2packed1 = yuv2rgb4_byte_full_1_c;
3294 *yuv2packedX = yuv2bgr8_full_X_c;
3295 *yuv2packed2 = yuv2bgr8_full_2_c;
3296 *yuv2packed1 = yuv2bgr8_full_1_c;
3299 *yuv2packedX = yuv2rgb8_full_X_c;
3300 *yuv2packed2 = yuv2rgb8_full_2_c;
3301 *yuv2packed1 = yuv2rgb8_full_1_c;
3334 if (!*yuv2packedX && !*yuv2anyX)
3338 switch (dstFormat) {
3340 #if CONFIG_SWSCALE_ALPHA
3342 *yuv2packed1 = yuv2rgba64le_1_c;
3343 *yuv2packed2 = yuv2rgba64le_2_c;
3344 *yuv2packedX = yuv2rgba64le_X_c;
3348 *yuv2packed1 = yuv2rgbx64le_1_c;
3349 *yuv2packed2 = yuv2rgbx64le_2_c;
3350 *yuv2packedX = yuv2rgbx64le_X_c;
3354 #if CONFIG_SWSCALE_ALPHA
3356 *yuv2packed1 = yuv2rgba64be_1_c;
3357 *yuv2packed2 = yuv2rgba64be_2_c;
3358 *yuv2packedX = yuv2rgba64be_X_c;
3362 *yuv2packed1 = yuv2rgbx64be_1_c;
3363 *yuv2packed2 = yuv2rgbx64be_2_c;
3364 *yuv2packedX = yuv2rgbx64be_X_c;
3368 #if CONFIG_SWSCALE_ALPHA
3370 *yuv2packed1 = yuv2bgra64le_1_c;
3371 *yuv2packed2 = yuv2bgra64le_2_c;
3372 *yuv2packedX = yuv2bgra64le_X_c;
3376 *yuv2packed1 = yuv2bgrx64le_1_c;
3377 *yuv2packed2 = yuv2bgrx64le_2_c;
3378 *yuv2packedX = yuv2bgrx64le_X_c;
3382 #if CONFIG_SWSCALE_ALPHA
3384 *yuv2packed1 = yuv2bgra64be_1_c;
3385 *yuv2packed2 = yuv2bgra64be_2_c;
3386 *yuv2packedX = yuv2bgra64be_X_c;
3390 *yuv2packed1 = yuv2bgrx64be_1_c;
3391 *yuv2packed2 = yuv2bgrx64be_2_c;
3392 *yuv2packedX = yuv2bgrx64be_X_c;
3396 *yuv2packed1 = yuv2rgb48le_1_c;
3397 *yuv2packed2 = yuv2rgb48le_2_c;
3398 *yuv2packedX = yuv2rgb48le_X_c;
3401 *yuv2packed1 = yuv2rgb48be_1_c;
3402 *yuv2packed2 = yuv2rgb48be_2_c;
3403 *yuv2packedX = yuv2rgb48be_X_c;
3406 *yuv2packed1 = yuv2bgr48le_1_c;
3407 *yuv2packed2 = yuv2bgr48le_2_c;
3408 *yuv2packedX = yuv2bgr48le_X_c;
3411 *yuv2packed1 = yuv2bgr48be_1_c;
3412 *yuv2packed2 = yuv2bgr48be_2_c;
3413 *yuv2packedX = yuv2bgr48be_X_c;
3418 *yuv2packed1 = yuv2rgb32_1_c;
3419 *yuv2packed2 = yuv2rgb32_2_c;
3420 *yuv2packedX = yuv2rgb32_X_c;
3422 #if CONFIG_SWSCALE_ALPHA
3424 *yuv2packed1 = yuv2rgba32_1_c;
3425 *yuv2packed2 = yuv2rgba32_2_c;
3426 *yuv2packedX = yuv2rgba32_X_c;
3430 *yuv2packed1 = yuv2rgbx32_1_c;
3431 *yuv2packed2 = yuv2rgbx32_2_c;
3432 *yuv2packedX = yuv2rgbx32_X_c;
3439 *yuv2packed1 = yuv2rgb32_1_1_c;
3440 *yuv2packed2 = yuv2rgb32_1_2_c;
3441 *yuv2packedX = yuv2rgb32_1_X_c;
3443 #if CONFIG_SWSCALE_ALPHA
3445 *yuv2packed1 = yuv2rgba32_1_1_c;
3446 *yuv2packed2 = yuv2rgba32_1_2_c;
3447 *yuv2packedX = yuv2rgba32_1_X_c;
3451 *yuv2packed1 = yuv2rgbx32_1_1_c;
3452 *yuv2packed2 = yuv2rgbx32_1_2_c;
3453 *yuv2packedX = yuv2rgbx32_1_X_c;
3458 *yuv2packed1 = yuv2rgb24_1_c;
3459 *yuv2packed2 = yuv2rgb24_2_c;
3460 *yuv2packedX = yuv2rgb24_X_c;
3463 *yuv2packed1 = yuv2bgr24_1_c;
3464 *yuv2packed2 = yuv2bgr24_2_c;
3465 *yuv2packedX = yuv2bgr24_X_c;
3471 *yuv2packed1 = yuv2rgb16_1_c;
3472 *yuv2packed2 = yuv2rgb16_2_c;
3473 *yuv2packedX = yuv2rgb16_X_c;
3479 *yuv2packed1 = yuv2rgb15_1_c;
3480 *yuv2packed2 = yuv2rgb15_2_c;
3481 *yuv2packedX = yuv2rgb15_X_c;
3487 *yuv2packed1 = yuv2rgb12_1_c;
3488 *yuv2packed2 = yuv2rgb12_2_c;
3489 *yuv2packedX = yuv2rgb12_X_c;
3493 *yuv2packed1 = yuv2rgb8_1_c;
3494 *yuv2packed2 = yuv2rgb8_2_c;
3495 *yuv2packedX = yuv2rgb8_X_c;
3499 *yuv2packed1 = yuv2rgb4_1_c;
3500 *yuv2packed2 = yuv2rgb4_2_c;
3501 *yuv2packedX = yuv2rgb4_X_c;
3505 *yuv2packed1 = yuv2rgb4b_1_c;
3506 *yuv2packed2 = yuv2rgb4b_2_c;
3507 *yuv2packedX = yuv2rgb4b_X_c;
3511 *yuv2packed1 = yuv2x2rgb10_1_c;
3512 *yuv2packed2 = yuv2x2rgb10_2_c;
3513 *yuv2packedX = yuv2x2rgb10_X_c;
3517 *yuv2packed1 = yuv2x2bgr10_1_c;
3518 *yuv2packed2 = yuv2x2bgr10_2_c;
3519 *yuv2packedX = yuv2x2bgr10_X_c;
3523 switch (dstFormat) {
3525 *yuv2packed1 = yuv2monowhite_1_c;
3526 *yuv2packed2 = yuv2monowhite_2_c;
3527 *yuv2packedX = yuv2monowhite_X_c;
3530 *yuv2packed1 = yuv2monoblack_1_c;
3531 *yuv2packed2 = yuv2monoblack_2_c;
3532 *yuv2packedX = yuv2monoblack_X_c;
3535 *yuv2packed1 = yuv2yuyv422_1_c;
3536 *yuv2packed2 = yuv2yuyv422_2_c;
3537 *yuv2packedX = yuv2yuyv422_X_c;
3540 *yuv2packed1 = yuv2yvyu422_1_c;
3541 *yuv2packed2 = yuv2yvyu422_2_c;
3542 *yuv2packedX = yuv2yvyu422_X_c;
3545 *yuv2packed1 = yuv2uyvy422_1_c;
3546 *yuv2packed2 = yuv2uyvy422_2_c;
3547 *yuv2packedX = yuv2uyvy422_X_c;
3550 *yuv2packed1 = yuv2vyu444_1_c;
3560 *yuv2packed1 = yuv2ya16le_1_c;
3561 *yuv2packed2 = yuv2ya16le_2_c;
3562 *yuv2packedX = yuv2ya16le_X_c;
3565 *yuv2packed1 = yuv2ya16be_1_c;
3566 *yuv2packed2 = yuv2ya16be_2_c;
3567 *yuv2packedX = yuv2ya16be_X_c;
3570 *yuv2packedX = yuv2v30xle_X_c;
3576 *yuv2packed1 = yuv2ayuv_1_c;
3577 *yuv2packed2 = yuv2ayuv_2_c;
3578 *yuv2packedX = yuv2ayuv_X_c;
3582 *yuv2packed1 = yuv2vuyX_1_c;
3583 *yuv2packed2 = yuv2vuyX_2_c;
3584 *yuv2packedX = yuv2vuyX_X_c;
3587 *yuv2packed1 = yuv2uyva_1_c;
3588 *yuv2packed2 = yuv2uyva_2_c;
3589 *yuv2packedX = yuv2uyva_X_c;
3592 *yuv2packedX = yuv2xv30le_X_c;
3598 *yuv2packedX = yuv2y210le_X_c;
3601 *yuv2packedX = yuv2y212le_X_c;