comparison libswscale/swscale.c @ 29481:c080f1f5c07e

Cosmetics: - Place curly brackets in the same line as while/for/if/switch/else/do; - Place curly brackets at column 0 in the next line starting a function.
author ramiro
date Sun, 16 Aug 2009 21:11:28 +0000
parents a4d8dee13834
children 335da85c454c
comparison
equal deleted inserted replaced
29480:a4d8dee13834 29481:c080f1f5c07e
559 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, 559 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
560 const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) 560 const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW)
561 { 561 {
562 //FIXME Optimize (just quickly written not optimized..) 562 //FIXME Optimize (just quickly written not optimized..)
563 int i; 563 int i;
564 for (i=0; i<dstW; i++) 564 for (i=0; i<dstW; i++) {
565 {
566 int val=1<<18; 565 int val=1<<18;
567 int j; 566 int j;
568 for (j=0; j<lumFilterSize; j++) 567 for (j=0; j<lumFilterSize; j++)
569 val += lumSrc[j][i] * lumFilter[j]; 568 val += lumSrc[j][i] * lumFilter[j];
570 569
571 dest[i]= av_clip_uint8(val>>19); 570 dest[i]= av_clip_uint8(val>>19);
572 } 571 }
573 572
574 if (uDest) 573 if (uDest)
575 for (i=0; i<chrDstW; i++) 574 for (i=0; i<chrDstW; i++) {
576 {
577 int u=1<<18; 575 int u=1<<18;
578 int v=1<<18; 576 int v=1<<18;
579 int j; 577 int j;
580 for (j=0; j<chrFilterSize; j++) 578 for (j=0; j<chrFilterSize; j++) {
581 {
582 u += chrSrc[j][i] * chrFilter[j]; 579 u += chrSrc[j][i] * chrFilter[j];
583 v += chrSrc[j][i + VOFW] * chrFilter[j]; 580 v += chrSrc[j][i + VOFW] * chrFilter[j];
584 } 581 }
585 582
586 uDest[i]= av_clip_uint8(u>>19); 583 uDest[i]= av_clip_uint8(u>>19);
587 vDest[i]= av_clip_uint8(v>>19); 584 vDest[i]= av_clip_uint8(v>>19);
588 } 585 }
589 586
590 if (CONFIG_SWSCALE_ALPHA && aDest) 587 if (CONFIG_SWSCALE_ALPHA && aDest)
591 for (i=0; i<dstW; i++){ 588 for (i=0; i<dstW; i++) {
592 int val=1<<18; 589 int val=1<<18;
593 int j; 590 int j;
594 for (j=0; j<lumFilterSize; j++) 591 for (j=0; j<lumFilterSize; j++)
595 val += alpSrc[j][i] * lumFilter[j]; 592 val += alpSrc[j][i] * lumFilter[j];
596 593
603 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, 600 const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
604 uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) 601 uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat)
605 { 602 {
606 //FIXME Optimize (just quickly written not optimized..) 603 //FIXME Optimize (just quickly written not optimized..)
607 int i; 604 int i;
608 for (i=0; i<dstW; i++) 605 for (i=0; i<dstW; i++) {
609 {
610 int val=1<<18; 606 int val=1<<18;
611 int j; 607 int j;
612 for (j=0; j<lumFilterSize; j++) 608 for (j=0; j<lumFilterSize; j++)
613 val += lumSrc[j][i] * lumFilter[j]; 609 val += lumSrc[j][i] * lumFilter[j];
614 610
617 613
618 if (!uDest) 614 if (!uDest)
619 return; 615 return;
620 616
621 if (dstFormat == PIX_FMT_NV12) 617 if (dstFormat == PIX_FMT_NV12)
622 for (i=0; i<chrDstW; i++) 618 for (i=0; i<chrDstW; i++) {
623 {
624 int u=1<<18; 619 int u=1<<18;
625 int v=1<<18; 620 int v=1<<18;
626 int j; 621 int j;
627 for (j=0; j<chrFilterSize; j++) 622 for (j=0; j<chrFilterSize; j++) {
628 {
629 u += chrSrc[j][i] * chrFilter[j]; 623 u += chrSrc[j][i] * chrFilter[j];
630 v += chrSrc[j][i + VOFW] * chrFilter[j]; 624 v += chrSrc[j][i + VOFW] * chrFilter[j];
631 } 625 }
632 626
633 uDest[2*i]= av_clip_uint8(u>>19); 627 uDest[2*i]= av_clip_uint8(u>>19);
634 uDest[2*i+1]= av_clip_uint8(v>>19); 628 uDest[2*i+1]= av_clip_uint8(v>>19);
635 } 629 }
636 else 630 else
637 for (i=0; i<chrDstW; i++) 631 for (i=0; i<chrDstW; i++) {
638 {
639 int u=1<<18; 632 int u=1<<18;
640 int v=1<<18; 633 int v=1<<18;
641 int j; 634 int j;
642 for (j=0; j<chrFilterSize; j++) 635 for (j=0; j<chrFilterSize; j++) {
643 {
644 u += chrSrc[j][i] * chrFilter[j]; 636 u += chrSrc[j][i] * chrFilter[j];
645 v += chrSrc[j][i + VOFW] * chrFilter[j]; 637 v += chrSrc[j][i + VOFW] * chrFilter[j];
646 } 638 }
647 639
648 uDest[2*i]= av_clip_uint8(v>>19); 640 uDest[2*i]= av_clip_uint8(v>>19);
649 uDest[2*i+1]= av_clip_uint8(u>>19); 641 uDest[2*i+1]= av_clip_uint8(u>>19);
650 } 642 }
651 } 643 }
652 644
653 #define YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha) \ 645 #define YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha) \
654 for (i=0; i<(dstW>>1); i++){\ 646 for (i=0; i<(dstW>>1); i++) {\
655 int j;\ 647 int j;\
656 int Y1 = 1<<18;\ 648 int Y1 = 1<<18;\
657 int Y2 = 1<<18;\ 649 int Y2 = 1<<18;\
658 int U = 1<<18;\ 650 int U = 1<<18;\
659 int V = 1<<18;\ 651 int V = 1<<18;\
660 int av_unused A1, A2;\ 652 int av_unused A1, A2;\
661 type av_unused *r, *b, *g;\ 653 type av_unused *r, *b, *g;\
662 const int i2= 2*i;\ 654 const int i2= 2*i;\
663 \ 655 \
664 for (j=0; j<lumFilterSize; j++)\ 656 for (j=0; j<lumFilterSize; j++) {\
665 {\
666 Y1 += lumSrc[j][i2] * lumFilter[j];\ 657 Y1 += lumSrc[j][i2] * lumFilter[j];\
667 Y2 += lumSrc[j][i2+1] * lumFilter[j];\ 658 Y2 += lumSrc[j][i2+1] * lumFilter[j];\
668 }\ 659 }\
669 for (j=0; j<chrFilterSize; j++)\ 660 for (j=0; j<chrFilterSize; j++) {\
670 {\
671 U += chrSrc[j][i] * chrFilter[j];\ 661 U += chrSrc[j][i] * chrFilter[j];\
672 V += chrSrc[j][i+VOFW] * chrFilter[j];\ 662 V += chrSrc[j][i+VOFW] * chrFilter[j];\
673 }\ 663 }\
674 Y1>>=19;\ 664 Y1>>=19;\
675 Y2>>=19;\ 665 Y2>>=19;\
676 U >>=19;\ 666 U >>=19;\
677 V >>=19;\ 667 V >>=19;\
678 if (alpha){\ 668 if (alpha) {\
679 A1 = 1<<18;\ 669 A1 = 1<<18;\
680 A2 = 1<<18;\ 670 A2 = 1<<18;\
681 for (j=0; j<lumFilterSize; j++){\ 671 for (j=0; j<lumFilterSize; j++) {\
682 A1 += alpSrc[j][i2 ] * lumFilter[j];\ 672 A1 += alpSrc[j][i2 ] * lumFilter[j];\
683 A2 += alpSrc[j][i2+1] * lumFilter[j];\ 673 A2 += alpSrc[j][i2+1] * lumFilter[j];\
684 }\ 674 }\
685 A1>>=19;\ 675 A1>>=19;\
686 A2>>=19;\ 676 A2>>=19;\
687 }\ 677 }\
688 678
689 #define YSCALE_YUV_2_PACKEDX_C(type,alpha) \ 679 #define YSCALE_YUV_2_PACKEDX_C(type,alpha) \
690 YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\ 680 YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\
691 if ((Y1|Y2|U|V)&256)\ 681 if ((Y1|Y2|U|V)&256) {\
692 {\
693 if (Y1>255) Y1=255; \ 682 if (Y1>255) Y1=255; \
694 else if (Y1<0)Y1=0; \ 683 else if (Y1<0)Y1=0; \
695 if (Y2>255) Y2=255; \ 684 if (Y2>255) Y2=255; \
696 else if (Y2<0)Y2=0; \ 685 else if (Y2<0)Y2=0; \
697 if (U>255) U=255; \ 686 if (U>255) U=255; \
698 else if (U<0) U=0; \ 687 else if (U<0) U=0; \
699 if (V>255) V=255; \ 688 if (V>255) V=255; \
700 else if (V<0) V=0; \ 689 else if (V<0) V=0; \
701 }\ 690 }\
702 if (alpha && ((A1|A2)&256)){\ 691 if (alpha && ((A1|A2)&256)) {\
703 A1=av_clip_uint8(A1);\ 692 A1=av_clip_uint8(A1);\
704 A2=av_clip_uint8(A2);\ 693 A2=av_clip_uint8(A2);\
705 } 694 }
706 695
707 #define YSCALE_YUV_2_PACKEDX_FULL_C(rnd,alpha) \ 696 #define YSCALE_YUV_2_PACKEDX_FULL_C(rnd,alpha) \
708 for (i=0; i<dstW; i++){\ 697 for (i=0; i<dstW; i++) {\
709 int j;\ 698 int j;\
710 int Y = 0;\ 699 int Y = 0;\
711 int U = -128<<19;\ 700 int U = -128<<19;\
712 int V = -128<<19;\ 701 int V = -128<<19;\
713 int av_unused A;\ 702 int av_unused A;\
714 int R,G,B;\ 703 int R,G,B;\
715 \ 704 \
716 for (j=0; j<lumFilterSize; j++){\ 705 for (j=0; j<lumFilterSize; j++) {\
717 Y += lumSrc[j][i ] * lumFilter[j];\ 706 Y += lumSrc[j][i ] * lumFilter[j];\
718 }\ 707 }\
719 for (j=0; j<chrFilterSize; j++){\ 708 for (j=0; j<chrFilterSize; j++) {\
720 U += chrSrc[j][i ] * chrFilter[j];\ 709 U += chrSrc[j][i ] * chrFilter[j];\
721 V += chrSrc[j][i+VOFW] * chrFilter[j];\ 710 V += chrSrc[j][i+VOFW] * chrFilter[j];\
722 }\ 711 }\
723 Y >>=10;\ 712 Y >>=10;\
724 U >>=10;\ 713 U >>=10;\
725 V >>=10;\ 714 V >>=10;\
726 if (alpha){\ 715 if (alpha) {\
727 A = rnd;\ 716 A = rnd;\
728 for (j=0; j<lumFilterSize; j++)\ 717 for (j=0; j<lumFilterSize; j++)\
729 A += alpSrc[j][i ] * lumFilter[j];\ 718 A += alpSrc[j][i ] * lumFilter[j];\
730 A >>=19;\ 719 A >>=19;\
731 if (A&256)\ 720 if (A&256)\
738 Y*= c->yuv2rgb_y_coeff;\ 727 Y*= c->yuv2rgb_y_coeff;\
739 Y+= rnd;\ 728 Y+= rnd;\
740 R= Y + V*c->yuv2rgb_v2r_coeff;\ 729 R= Y + V*c->yuv2rgb_v2r_coeff;\
741 G= Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;\ 730 G= Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;\
742 B= Y + U*c->yuv2rgb_u2b_coeff;\ 731 B= Y + U*c->yuv2rgb_u2b_coeff;\
743 if ((R|G|B)&(0xC0000000)){\ 732 if ((R|G|B)&(0xC0000000)) {\
744 if (R>=(256<<22)) R=(256<<22)-1; \ 733 if (R>=(256<<22)) R=(256<<22)-1; \
745 else if (R<0)R=0; \ 734 else if (R<0)R=0; \
746 if (G>=(256<<22)) G=(256<<22)-1; \ 735 if (G>=(256<<22)) G=(256<<22)-1; \
747 else if (G<0)G=0; \ 736 else if (G<0)G=0; \
748 if (B>=(256<<22)) B=(256<<22)-1; \ 737 if (B>=(256<<22)) B=(256<<22)-1; \
749 else if (B<0)B=0; \ 738 else if (B<0)B=0; \
750 }\ 739 }\
751 740
752 741
753 #define YSCALE_YUV_2_GRAY16_C \ 742 #define YSCALE_YUV_2_GRAY16_C \
754 for (i=0; i<(dstW>>1); i++){\ 743 for (i=0; i<(dstW>>1); i++) {\
755 int j;\ 744 int j;\
756 int Y1 = 1<<18;\ 745 int Y1 = 1<<18;\
757 int Y2 = 1<<18;\ 746 int Y2 = 1<<18;\
758 int U = 1<<18;\ 747 int U = 1<<18;\
759 int V = 1<<18;\ 748 int V = 1<<18;\
760 \ 749 \
761 const int i2= 2*i;\ 750 const int i2= 2*i;\
762 \ 751 \
763 for (j=0; j<lumFilterSize; j++)\ 752 for (j=0; j<lumFilterSize; j++) {\
764 {\
765 Y1 += lumSrc[j][i2] * lumFilter[j];\ 753 Y1 += lumSrc[j][i2] * lumFilter[j];\
766 Y2 += lumSrc[j][i2+1] * lumFilter[j];\ 754 Y2 += lumSrc[j][i2+1] * lumFilter[j];\
767 }\ 755 }\
768 Y1>>=11;\ 756 Y1>>=11;\
769 Y2>>=11;\ 757 Y2>>=11;\
770 if ((Y1|Y2|U|V)&65536)\ 758 if ((Y1|Y2|U|V)&65536) {\
771 {\
772 if (Y1>65535) Y1=65535; \ 759 if (Y1>65535) Y1=65535; \
773 else if (Y1<0)Y1=0; \ 760 else if (Y1<0)Y1=0; \
774 if (Y2>65535) Y2=65535; \ 761 if (Y2>65535) Y2=65535; \
775 else if (Y2<0)Y2=0; \ 762 else if (Y2<0)Y2=0; \
776 } 763 }
780 r = (type *)c->table_rV[V]; \ 767 r = (type *)c->table_rV[V]; \
781 g = (type *)(c->table_gU[U] + c->table_gV[V]); \ 768 g = (type *)(c->table_gU[U] + c->table_gV[V]); \
782 b = (type *)c->table_bU[U]; \ 769 b = (type *)c->table_bU[U]; \
783 770
784 #define YSCALE_YUV_2_PACKED2_C(type,alpha) \ 771 #define YSCALE_YUV_2_PACKED2_C(type,alpha) \
785 for (i=0; i<(dstW>>1); i++){ \ 772 for (i=0; i<(dstW>>1); i++) { \
786 const int i2= 2*i; \ 773 const int i2= 2*i; \
787 int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19; \ 774 int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19; \
788 int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19; \ 775 int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19; \
789 int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19; \ 776 int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19; \
790 int V= (uvbuf0[i+VOFW]*uvalpha1+uvbuf1[i+VOFW]*uvalpha)>>19; \ 777 int V= (uvbuf0[i+VOFW]*uvalpha1+uvbuf1[i+VOFW]*uvalpha)>>19; \
791 type av_unused *r, *b, *g; \ 778 type av_unused *r, *b, *g; \
792 int av_unused A1, A2; \ 779 int av_unused A1, A2; \
793 if (alpha){\ 780 if (alpha) {\
794 A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \ 781 A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \
795 A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \ 782 A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \
796 }\ 783 }\
797 784
798 #define YSCALE_YUV_2_GRAY16_2_C \ 785 #define YSCALE_YUV_2_GRAY16_2_C \
799 for (i=0; i<(dstW>>1); i++){ \ 786 for (i=0; i<(dstW>>1); i++) { \
800 const int i2= 2*i; \ 787 const int i2= 2*i; \
801 int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>11; \ 788 int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>11; \
802 int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11; \ 789 int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11; \
803 790
804 #define YSCALE_YUV_2_RGB2_C(type,alpha) \ 791 #define YSCALE_YUV_2_RGB2_C(type,alpha) \
806 r = (type *)c->table_rV[V];\ 793 r = (type *)c->table_rV[V];\
807 g = (type *)(c->table_gU[U] + c->table_gV[V]);\ 794 g = (type *)(c->table_gU[U] + c->table_gV[V]);\
808 b = (type *)c->table_bU[U];\ 795 b = (type *)c->table_bU[U];\
809 796
810 #define YSCALE_YUV_2_PACKED1_C(type,alpha) \ 797 #define YSCALE_YUV_2_PACKED1_C(type,alpha) \
811 for (i=0; i<(dstW>>1); i++){\ 798 for (i=0; i<(dstW>>1); i++) {\
812 const int i2= 2*i;\ 799 const int i2= 2*i;\
813 int Y1= buf0[i2 ]>>7;\ 800 int Y1= buf0[i2 ]>>7;\
814 int Y2= buf0[i2+1]>>7;\ 801 int Y2= buf0[i2+1]>>7;\
815 int U= (uvbuf1[i ])>>7;\ 802 int U= (uvbuf1[i ])>>7;\
816 int V= (uvbuf1[i+VOFW])>>7;\ 803 int V= (uvbuf1[i+VOFW])>>7;\
817 type av_unused *r, *b, *g;\ 804 type av_unused *r, *b, *g;\
818 int av_unused A1, A2;\ 805 int av_unused A1, A2;\
819 if (alpha){\ 806 if (alpha) {\
820 A1= abuf0[i2 ]>>7;\ 807 A1= abuf0[i2 ]>>7;\
821 A2= abuf0[i2+1]>>7;\ 808 A2= abuf0[i2+1]>>7;\
822 }\ 809 }\
823 810
824 #define YSCALE_YUV_2_GRAY16_1_C \ 811 #define YSCALE_YUV_2_GRAY16_1_C \
825 for (i=0; i<(dstW>>1); i++){\ 812 for (i=0; i<(dstW>>1); i++) {\
826 const int i2= 2*i;\ 813 const int i2= 2*i;\
827 int Y1= buf0[i2 ]<<1;\ 814 int Y1= buf0[i2 ]<<1;\
828 int Y2= buf0[i2+1]<<1;\ 815 int Y2= buf0[i2+1]<<1;\
829 816
830 #define YSCALE_YUV_2_RGB1_C(type,alpha) \ 817 #define YSCALE_YUV_2_RGB1_C(type,alpha) \
832 r = (type *)c->table_rV[V];\ 819 r = (type *)c->table_rV[V];\
833 g = (type *)(c->table_gU[U] + c->table_gV[V]);\ 820 g = (type *)(c->table_gU[U] + c->table_gV[V]);\
834 b = (type *)c->table_bU[U];\ 821 b = (type *)c->table_bU[U];\
835 822
836 #define YSCALE_YUV_2_PACKED1B_C(type,alpha) \ 823 #define YSCALE_YUV_2_PACKED1B_C(type,alpha) \
837 for (i=0; i<(dstW>>1); i++){\ 824 for (i=0; i<(dstW>>1); i++) {\
838 const int i2= 2*i;\ 825 const int i2= 2*i;\
839 int Y1= buf0[i2 ]>>7;\ 826 int Y1= buf0[i2 ]>>7;\
840 int Y2= buf0[i2+1]>>7;\ 827 int Y2= buf0[i2+1]>>7;\
841 int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\ 828 int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\
842 int V= (uvbuf0[i+VOFW] + uvbuf1[i+VOFW])>>8;\ 829 int V= (uvbuf0[i+VOFW] + uvbuf1[i+VOFW])>>8;\
843 type av_unused *r, *b, *g;\ 830 type av_unused *r, *b, *g;\
844 int av_unused A1, A2;\ 831 int av_unused A1, A2;\
845 if (alpha){\ 832 if (alpha) {\
846 A1= abuf0[i2 ]>>7;\ 833 A1= abuf0[i2 ]>>7;\
847 A2= abuf0[i2+1]>>7;\ 834 A2= abuf0[i2+1]>>7;\
848 }\ 835 }\
849 836
850 #define YSCALE_YUV_2_RGB1B_C(type,alpha) \ 837 #define YSCALE_YUV_2_RGB1B_C(type,alpha) \
854 b = (type *)c->table_bU[U];\ 841 b = (type *)c->table_bU[U];\
855 842
856 #define YSCALE_YUV_2_MONO2_C \ 843 #define YSCALE_YUV_2_MONO2_C \
857 const uint8_t * const d128=dither_8x8_220[y&7];\ 844 const uint8_t * const d128=dither_8x8_220[y&7];\
858 uint8_t *g= c->table_gU[128] + c->table_gV[128];\ 845 uint8_t *g= c->table_gU[128] + c->table_gV[128];\
859 for (i=0; i<dstW-7; i+=8){\ 846 for (i=0; i<dstW-7; i+=8) {\
860 int acc;\ 847 int acc;\
861 acc = g[((buf0[i ]*yalpha1+buf1[i ]*yalpha)>>19) + d128[0]];\ 848 acc = g[((buf0[i ]*yalpha1+buf1[i ]*yalpha)>>19) + d128[0]];\
862 acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\ 849 acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\
863 acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\ 850 acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\
864 acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\ 851 acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\
873 860
874 #define YSCALE_YUV_2_MONOX_C \ 861 #define YSCALE_YUV_2_MONOX_C \
875 const uint8_t * const d128=dither_8x8_220[y&7];\ 862 const uint8_t * const d128=dither_8x8_220[y&7];\
876 uint8_t *g= c->table_gU[128] + c->table_gV[128];\ 863 uint8_t *g= c->table_gU[128] + c->table_gV[128];\
877 int acc=0;\ 864 int acc=0;\
878 for (i=0; i<dstW-1; i+=2){\ 865 for (i=0; i<dstW-1; i+=2) {\
879 int j;\ 866 int j;\
880 int Y1=1<<18;\ 867 int Y1=1<<18;\
881 int Y2=1<<18;\ 868 int Y2=1<<18;\
882 \ 869 \
883 for (j=0; j<lumFilterSize; j++)\ 870 for (j=0; j<lumFilterSize; j++) {\
884 {\
885 Y1 += lumSrc[j][i] * lumFilter[j];\ 871 Y1 += lumSrc[j][i] * lumFilter[j];\
886 Y2 += lumSrc[j][i+1] * lumFilter[j];\ 872 Y2 += lumSrc[j][i+1] * lumFilter[j];\
887 }\ 873 }\
888 Y1>>=19;\ 874 Y1>>=19;\
889 Y2>>=19;\ 875 Y2>>=19;\
890 if ((Y1|Y2)&256)\ 876 if ((Y1|Y2)&256) {\
891 {\
892 if (Y1>255) Y1=255;\ 877 if (Y1>255) Y1=255;\
893 else if (Y1<0)Y1=0;\ 878 else if (Y1<0)Y1=0;\
894 if (Y2>255) Y2=255;\ 879 if (Y2>255) Y2=255;\
895 else if (Y2<0)Y2=0;\ 880 else if (Y2<0)Y2=0;\
896 }\ 881 }\
897 acc+= acc + g[Y1+d128[(i+0)&7]];\ 882 acc+= acc + g[Y1+d128[(i+0)&7]];\
898 acc+= acc + g[Y2+d128[(i+1)&7]];\ 883 acc+= acc + g[Y2+d128[(i+1)&7]];\
899 if ((i&7)==6){\ 884 if ((i&7)==6) {\
900 ((uint8_t*)dest)[0]= c->dstFormat == PIX_FMT_MONOBLACK ? acc : ~acc;\ 885 ((uint8_t*)dest)[0]= c->dstFormat == PIX_FMT_MONOBLACK ? acc : ~acc;\
901 dest++;\ 886 dest++;\
902 }\ 887 }\
903 } 888 }
904 889
905 890
906 #define YSCALE_YUV_2_ANYRGB_C(func, func2, func_g16, func_monoblack)\ 891 #define YSCALE_YUV_2_ANYRGB_C(func, func2, func_g16, func_monoblack)\
907 switch(c->dstFormat)\ 892 switch(c->dstFormat) {\
908 {\
909 case PIX_FMT_RGB48BE:\ 893 case PIX_FMT_RGB48BE:\
910 case PIX_FMT_RGB48LE:\ 894 case PIX_FMT_RGB48LE:\
911 func(uint8_t,0)\ 895 func(uint8_t,0)\
912 ((uint8_t*)dest)[ 0]= r[Y1];\ 896 ((uint8_t*)dest)[ 0]= r[Y1];\
913 ((uint8_t*)dest)[ 1]= r[Y1];\ 897 ((uint8_t*)dest)[ 1]= r[Y1];\
924 dest+=12;\ 908 dest+=12;\
925 }\ 909 }\
926 break;\ 910 break;\
927 case PIX_FMT_RGBA:\ 911 case PIX_FMT_RGBA:\
928 case PIX_FMT_BGRA:\ 912 case PIX_FMT_BGRA:\
929 if (CONFIG_SMALL){\ 913 if (CONFIG_SMALL) {\
930 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\ 914 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\
931 func(uint32_t,needAlpha)\ 915 func(uint32_t,needAlpha)\
932 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? (A1<<24) : 0);\ 916 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? (A1<<24) : 0);\
933 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? (A2<<24) : 0);\ 917 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? (A2<<24) : 0);\
934 }\ 918 }\
935 }else{\ 919 } else {\
936 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){\ 920 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\
937 func(uint32_t,1)\ 921 func(uint32_t,1)\
938 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (A1<<24);\ 922 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (A1<<24);\
939 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (A2<<24);\ 923 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (A2<<24);\
940 }\ 924 }\
941 }else{\ 925 } else {\
942 func(uint32_t,0)\ 926 func(uint32_t,0)\
943 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ 927 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
944 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ 928 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
945 }\ 929 }\
946 }\ 930 }\
947 }\ 931 }\
948 break;\ 932 break;\
949 case PIX_FMT_ARGB:\ 933 case PIX_FMT_ARGB:\
950 case PIX_FMT_ABGR:\ 934 case PIX_FMT_ABGR:\
951 if (CONFIG_SMALL){\ 935 if (CONFIG_SMALL) {\
952 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\ 936 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\
953 func(uint32_t,needAlpha)\ 937 func(uint32_t,needAlpha)\
954 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? A1 : 0);\ 938 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? A1 : 0);\
955 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? A2 : 0);\ 939 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? A2 : 0);\
956 }\ 940 }\
957 }else{\ 941 } else {\
958 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){\ 942 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\
959 func(uint32_t,1)\ 943 func(uint32_t,1)\
960 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + A1;\ 944 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + A1;\
961 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + A2;\ 945 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + A2;\
962 }\ 946 }\
963 }else{\ 947 } else {\
964 func(uint32_t,0)\ 948 func(uint32_t,0)\
965 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ 949 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
966 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ 950 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
967 }\ 951 }\
968 }\ 952 }\
1108 { 1092 {
1109 int i; 1093 int i;
1110 int step= fmt_depth(c->dstFormat)/8; 1094 int step= fmt_depth(c->dstFormat)/8;
1111 int aidx= 3; 1095 int aidx= 3;
1112 1096
1113 switch(c->dstFormat){ 1097 switch(c->dstFormat) {
1114 case PIX_FMT_ARGB: 1098 case PIX_FMT_ARGB:
1115 dest++; 1099 dest++;
1116 aidx= 0; 1100 aidx= 0;
1117 case PIX_FMT_RGB24: 1101 case PIX_FMT_RGB24:
1118 aidx--; 1102 aidx--;
1119 case PIX_FMT_RGBA: 1103 case PIX_FMT_RGBA:
1120 if (CONFIG_SMALL){ 1104 if (CONFIG_SMALL) {
1121 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf; 1105 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;
1122 YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha) 1106 YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha)
1123 dest[aidx]= needAlpha ? A : 255; 1107 dest[aidx]= needAlpha ? A : 255;
1124 dest[0]= R>>22; 1108 dest[0]= R>>22;
1125 dest[1]= G>>22; 1109 dest[1]= G>>22;
1126 dest[2]= B>>22; 1110 dest[2]= B>>22;
1127 dest+= step; 1111 dest+= step;
1128 } 1112 }
1129 }else{ 1113 } else {
1130 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){ 1114 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1131 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1) 1115 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1)
1132 dest[aidx]= A; 1116 dest[aidx]= A;
1133 dest[0]= R>>22; 1117 dest[0]= R>>22;
1134 dest[1]= G>>22; 1118 dest[1]= G>>22;
1135 dest[2]= B>>22; 1119 dest[2]= B>>22;
1136 dest+= step; 1120 dest+= step;
1137 } 1121 }
1138 }else{ 1122 } else {
1139 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0) 1123 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0)
1140 dest[aidx]= 255; 1124 dest[aidx]= 255;
1141 dest[0]= R>>22; 1125 dest[0]= R>>22;
1142 dest[1]= G>>22; 1126 dest[1]= G>>22;
1143 dest[2]= B>>22; 1127 dest[2]= B>>22;
1150 dest++; 1134 dest++;
1151 aidx= 0; 1135 aidx= 0;
1152 case PIX_FMT_BGR24: 1136 case PIX_FMT_BGR24:
1153 aidx--; 1137 aidx--;
1154 case PIX_FMT_BGRA: 1138 case PIX_FMT_BGRA:
1155 if (CONFIG_SMALL){ 1139 if (CONFIG_SMALL) {
1156 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf; 1140 int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;
1157 YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha) 1141 YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha)
1158 dest[aidx]= needAlpha ? A : 255; 1142 dest[aidx]= needAlpha ? A : 255;
1159 dest[0]= B>>22; 1143 dest[0]= B>>22;
1160 dest[1]= G>>22; 1144 dest[1]= G>>22;
1161 dest[2]= R>>22; 1145 dest[2]= R>>22;
1162 dest+= step; 1146 dest+= step;
1163 } 1147 }
1164 }else{ 1148 } else {
1165 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){ 1149 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1166 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1) 1150 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1)
1167 dest[aidx]= A; 1151 dest[aidx]= A;
1168 dest[0]= B>>22; 1152 dest[0]= B>>22;
1169 dest[1]= G>>22; 1153 dest[1]= G>>22;
1170 dest[2]= R>>22; 1154 dest[2]= R>>22;
1171 dest+= step; 1155 dest+= step;
1172 } 1156 }
1173 }else{ 1157 } else {
1174 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0) 1158 YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0)
1175 dest[aidx]= 255; 1159 dest[aidx]= 255;
1176 dest[0]= B>>22; 1160 dest[0]= B>>22;
1177 dest[1]= G>>22; 1161 dest[1]= G>>22;
1178 dest[2]= R>>22; 1162 dest[2]= R>>22;
1184 default: 1168 default:
1185 assert(0); 1169 assert(0);
1186 } 1170 }
1187 } 1171 }
1188 1172
1189 static void fillPlane(uint8_t* plane, int stride, int width, int height, int y, uint8_t val){ 1173 static void fillPlane(uint8_t* plane, int stride, int width, int height, int y, uint8_t val)
1174 {
1190 int i; 1175 int i;
1191 uint8_t *ptr = plane + stride*y; 1176 uint8_t *ptr = plane + stride*y;
1192 for (i=0; i<height; i++){ 1177 for (i=0; i<height; i++) {
1193 memset(ptr, val, width); 1178 memset(ptr, val, width);
1194 ptr += stride; 1179 ptr += stride;
1195 } 1180 }
1196 } 1181 }
1197 1182
1239 1224
1240 #define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\ 1225 #define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\
1241 static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)\ 1226 static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)\
1242 {\ 1227 {\
1243 int i;\ 1228 int i;\
1244 for (i=0; i<width; i++)\ 1229 for (i=0; i<width; i++) {\
1245 {\
1246 int b= (((const type*)src)[i]>>shb)&maskb;\ 1230 int b= (((const type*)src)[i]>>shb)&maskb;\
1247 int g= (((const type*)src)[i]>>shg)&maskg;\ 1231 int g= (((const type*)src)[i]>>shg)&maskg;\
1248 int r= (((const type*)src)[i]>>shr)&maskr;\ 1232 int r= (((const type*)src)[i]>>shr)&maskr;\
1249 \ 1233 \
1250 dst[i]= (((RY)*r + (GY)*g + (BY)*b + (33<<((S)-1)))>>(S));\ 1234 dst[i]= (((RY)*r + (GY)*g + (BY)*b + (33<<((S)-1)))>>(S));\
1256 BGR2Y(uint16_t, bgr16ToY, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RY<<11, GY<<5, BY , RGB2YUV_SHIFT+8) 1240 BGR2Y(uint16_t, bgr16ToY, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RY<<11, GY<<5, BY , RGB2YUV_SHIFT+8)
1257 BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RY<<10, GY<<5, BY , RGB2YUV_SHIFT+7) 1241 BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RY<<10, GY<<5, BY , RGB2YUV_SHIFT+7)
1258 BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY , GY<<5, BY<<11, RGB2YUV_SHIFT+8) 1242 BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY , GY<<5, BY<<11, RGB2YUV_SHIFT+8)
1259 BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY , GY<<5, BY<<10, RGB2YUV_SHIFT+7) 1243 BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY , GY<<5, BY<<10, RGB2YUV_SHIFT+7)
1260 1244
1261 static inline void abgrToA(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused){ 1245 static inline void abgrToA(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1246 {
1262 int i; 1247 int i;
1263 for (i=0; i<width; i++){ 1248 for (i=0; i<width; i++) {
1264 dst[i]= src[4*i]; 1249 dst[i]= src[4*i];
1265 } 1250 }
1266 } 1251 }
1267 1252
1268 #define BGR2UV(type, name, shr, shg, shb, maska, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S)\ 1253 #define BGR2UV(type, name, shr, shg, shb, maska, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S)\
1269 static inline void name(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ 1254 static inline void name(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
1270 {\ 1255 {\
1271 int i;\ 1256 int i;\
1272 for (i=0; i<width; i++)\ 1257 for (i=0; i<width; i++) {\
1273 {\
1274 int b= (((const type*)src)[i]&maskb)>>shb;\ 1258 int b= (((const type*)src)[i]&maskb)>>shb;\
1275 int g= (((const type*)src)[i]&maskg)>>shg;\ 1259 int g= (((const type*)src)[i]&maskg)>>shg;\
1276 int r= (((const type*)src)[i]&maskr)>>shr;\ 1260 int r= (((const type*)src)[i]&maskr)>>shr;\
1277 \ 1261 \
1278 dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\ 1262 dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\
1280 }\ 1264 }\
1281 }\ 1265 }\
1282 static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ 1266 static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
1283 {\ 1267 {\
1284 int i;\ 1268 int i;\
1285 for (i=0; i<width; i++)\ 1269 for (i=0; i<width; i++) {\
1286 {\
1287 int pix0= ((const type*)src)[2*i+0];\ 1270 int pix0= ((const type*)src)[2*i+0];\
1288 int pix1= ((const type*)src)[2*i+1];\ 1271 int pix1= ((const type*)src)[2*i+1];\
1289 int g= (pix0&~(maskr|maskb))+(pix1&~(maskr|maskb));\ 1272 int g= (pix0&~(maskr|maskb))+(pix1&~(maskr|maskb));\
1290 int b= ((pix0+pix1-g)&(maskb|(2*maskb)))>>shb;\ 1273 int b= ((pix0+pix1-g)&(maskb|(2*maskb)))>>shb;\
1291 int r= ((pix0+pix1-g)&(maskr|(2*maskr)))>>shr;\ 1274 int r= ((pix0+pix1-g)&(maskr|(2*maskr)))>>shr;\
1306 BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU , GU<<5, BU<<10, RV , GV<<5, BV<<10, RGB2YUV_SHIFT+7) 1289 BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU , GU<<5, BU<<10, RV , GV<<5, BV<<10, RGB2YUV_SHIFT+7)
1307 1290
1308 static inline void palToY(uint8_t *dst, const uint8_t *src, long width, uint32_t *pal) 1291 static inline void palToY(uint8_t *dst, const uint8_t *src, long width, uint32_t *pal)
1309 { 1292 {
1310 int i; 1293 int i;
1311 for (i=0; i<width; i++) 1294 for (i=0; i<width; i++) {
1312 {
1313 int d= src[i]; 1295 int d= src[i];
1314 1296
1315 dst[i]= pal[d] & 0xFF; 1297 dst[i]= pal[d] & 0xFF;
1316 } 1298 }
1317 } 1299 }
1320 const uint8_t *src1, const uint8_t *src2, 1302 const uint8_t *src1, const uint8_t *src2,
1321 long width, uint32_t *pal) 1303 long width, uint32_t *pal)
1322 { 1304 {
1323 int i; 1305 int i;
1324 assert(src1 == src2); 1306 assert(src1 == src2);
1325 for (i=0; i<width; i++) 1307 for (i=0; i<width; i++) {
1326 {
1327 int p= pal[src1[i]]; 1308 int p= pal[src1[i]];
1328 1309
1329 dstU[i]= p>>8; 1310 dstU[i]= p>>8;
1330 dstV[i]= p>>16; 1311 dstV[i]= p>>16;
1331 } 1312 }
1332 } 1313 }
1333 1314
1334 static inline void monowhite2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) 1315 static inline void monowhite2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1335 { 1316 {
1336 int i, j; 1317 int i, j;
1337 for (i=0; i<width/8; i++){ 1318 for (i=0; i<width/8; i++) {
1338 int d= ~src[i]; 1319 int d= ~src[i];
1339 for(j=0; j<8; j++) 1320 for(j=0; j<8; j++)
1340 dst[8*i+j]= ((d>>(7-j))&1)*255; 1321 dst[8*i+j]= ((d>>(7-j))&1)*255;
1341 } 1322 }
1342 } 1323 }
1343 1324
1344 static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) 1325 static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1345 { 1326 {
1346 int i, j; 1327 int i, j;
1347 for (i=0; i<width/8; i++){ 1328 for (i=0; i<width/8; i++) {
1348 int d= src[i]; 1329 int d= src[i];
1349 for(j=0; j<8; j++) 1330 for(j=0; j<8; j++)
1350 dst[8*i+j]= ((d>>(7-j))&1)*255; 1331 dst[8*i+j]= ((d>>(7-j))&1)*255;
1351 } 1332 }
1352 } 1333 }
1469 #endif 1450 #endif
1470 1451
1471 // NOTE: the +1 is for the MMX scaler which reads over the end 1452 // NOTE: the +1 is for the MMX scaler which reads over the end
1472 *filterPos = av_malloc((dstW+1)*sizeof(int16_t)); 1453 *filterPos = av_malloc((dstW+1)*sizeof(int16_t));
1473 1454
1474 if (FFABS(xInc - 0x10000) <10) // unscaled 1455 if (FFABS(xInc - 0x10000) <10) { // unscaled
1475 {
1476 int i; 1456 int i;
1477 filterSize= 1; 1457 filterSize= 1;
1478 filter= av_mallocz(dstW*sizeof(*filter)*filterSize); 1458 filter= av_mallocz(dstW*sizeof(*filter)*filterSize);
1479 1459
1480 for (i=0; i<dstW; i++) 1460 for (i=0; i<dstW; i++) {
1481 {
1482 filter[i*filterSize]= fone; 1461 filter[i*filterSize]= fone;
1483 (*filterPos)[i]=i; 1462 (*filterPos)[i]=i;
1484 } 1463 }
1485 1464
1486 } 1465 } else if (flags&SWS_POINT) { // lame looking point sampling mode
1487 else if (flags&SWS_POINT) // lame looking point sampling mode
1488 {
1489 int i; 1466 int i;
1490 int xDstInSrc; 1467 int xDstInSrc;
1491 filterSize= 1; 1468 filterSize= 1;
1492 filter= av_malloc(dstW*sizeof(*filter)*filterSize); 1469 filter= av_malloc(dstW*sizeof(*filter)*filterSize);
1493 1470
1494 xDstInSrc= xInc/2 - 0x8000; 1471 xDstInSrc= xInc/2 - 0x8000;
1495 for (i=0; i<dstW; i++) 1472 for (i=0; i<dstW; i++) {
1496 {
1497 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; 1473 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16;
1498 1474
1499 (*filterPos)[i]= xx; 1475 (*filterPos)[i]= xx;
1500 filter[i]= fone; 1476 filter[i]= fone;
1501 xDstInSrc+= xInc; 1477 xDstInSrc+= xInc;
1502 } 1478 }
1503 } 1479 } else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) { // bilinear upscale
1504 else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) // bilinear upscale
1505 {
1506 int i; 1480 int i;
1507 int xDstInSrc; 1481 int xDstInSrc;
1508 filterSize= 2; 1482 filterSize= 2;
1509 filter= av_malloc(dstW*sizeof(*filter)*filterSize); 1483 filter= av_malloc(dstW*sizeof(*filter)*filterSize);
1510 1484
1511 xDstInSrc= xInc/2 - 0x8000; 1485 xDstInSrc= xInc/2 - 0x8000;
1512 for (i=0; i<dstW; i++) 1486 for (i=0; i<dstW; i++) {
1513 {
1514 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; 1487 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16;
1515 int j; 1488 int j;
1516 1489
1517 (*filterPos)[i]= xx; 1490 (*filterPos)[i]= xx;
1518 //bilinear upscale / linear interpolate / area averaging 1491 //bilinear upscale / linear interpolate / area averaging
1519 for (j=0; j<filterSize; j++) 1492 for (j=0; j<filterSize; j++) {
1520 {
1521 int64_t coeff= fone - FFABS((xx<<16) - xDstInSrc)*(fone>>16); 1493 int64_t coeff= fone - FFABS((xx<<16) - xDstInSrc)*(fone>>16);
1522 if (coeff<0) coeff=0; 1494 if (coeff<0) coeff=0;
1523 filter[i*filterSize + j]= coeff; 1495 filter[i*filterSize + j]= coeff;
1524 xx++; 1496 xx++;
1525 } 1497 }
1526 xDstInSrc+= xInc; 1498 xDstInSrc+= xInc;
1527 } 1499 }
1528 } 1500 } else {
1529 else
1530 {
1531 int xDstInSrc; 1501 int xDstInSrc;
1532 int sizeFactor; 1502 int sizeFactor;
1533 1503
1534 if (flags&SWS_BICUBIC) sizeFactor= 4; 1504 if (flags&SWS_BICUBIC) sizeFactor= 4;
1535 else if (flags&SWS_X) sizeFactor= 8; 1505 else if (flags&SWS_X) sizeFactor= 8;
1550 if (filterSize > srcW-2) filterSize=srcW-2; 1520 if (filterSize > srcW-2) filterSize=srcW-2;
1551 1521
1552 filter= av_malloc(dstW*sizeof(*filter)*filterSize); 1522 filter= av_malloc(dstW*sizeof(*filter)*filterSize);
1553 1523
1554 xDstInSrc= xInc - 0x10000; 1524 xDstInSrc= xInc - 0x10000;
1555 for (i=0; i<dstW; i++) 1525 for (i=0; i<dstW; i++) {
1556 {
1557 int xx= (xDstInSrc - ((filterSize-2)<<16)) / (1<<17); 1526 int xx= (xDstInSrc - ((filterSize-2)<<16)) / (1<<17);
1558 int j; 1527 int j;
1559 (*filterPos)[i]= xx; 1528 (*filterPos)[i]= xx;
1560 for (j=0; j<filterSize; j++) 1529 for (j=0; j<filterSize; j++) {
1561 {
1562 int64_t d= ((int64_t)FFABS((xx<<17) - xDstInSrc))<<13; 1530 int64_t d= ((int64_t)FFABS((xx<<17) - xDstInSrc))<<13;
1563 double floatd; 1531 double floatd;
1564 int64_t coeff; 1532 int64_t coeff;
1565 1533
1566 if (xInc > 1<<16) 1534 if (xInc > 1<<16)
1567 d= d*dstW/srcW; 1535 d= d*dstW/srcW;
1568 floatd= d * (1.0/(1<<30)); 1536 floatd= d * (1.0/(1<<30));
1569 1537
1570 if (flags & SWS_BICUBIC) 1538 if (flags & SWS_BICUBIC) {
1571 {
1572 int64_t B= (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1<<24); 1539 int64_t B= (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1<<24);
1573 int64_t C= (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1<<24); 1540 int64_t C= (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1<<24);
1574 int64_t dd = ( d*d)>>30; 1541 int64_t dd = ( d*d)>>30;
1575 int64_t ddd= (dd*d)>>30; 1542 int64_t ddd= (dd*d)>>30;
1576 1543
1580 coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30); 1547 coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30);
1581 else 1548 else
1582 coeff=0.0; 1549 coeff=0.0;
1583 coeff *= fone>>(30+24); 1550 coeff *= fone>>(30+24);
1584 } 1551 }
1585 /* else if (flags & SWS_X) 1552 /* else if (flags & SWS_X) {
1586 {
1587 double p= param ? param*0.01 : 0.3; 1553 double p= param ? param*0.01 : 0.3;
1588 coeff = d ? sin(d*PI)/(d*PI) : 1.0; 1554 coeff = d ? sin(d*PI)/(d*PI) : 1.0;
1589 coeff*= pow(2.0, - p*d*d); 1555 coeff*= pow(2.0, - p*d*d);
1590 }*/ 1556 }*/
1591 else if (flags & SWS_X) 1557 else if (flags & SWS_X) {
1592 {
1593 double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; 1558 double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;
1594 double c; 1559 double c;
1595 1560
1596 if (floatd<1.0) 1561 if (floatd<1.0)
1597 c = cos(floatd*PI); 1562 c = cos(floatd*PI);
1598 else 1563 else
1599 c=-1.0; 1564 c=-1.0;
1600 if (c<0.0) c= -pow(-c, A); 1565 if (c<0.0) c= -pow(-c, A);
1601 else c= pow( c, A); 1566 else c= pow( c, A);
1602 coeff= (c*0.5 + 0.5)*fone; 1567 coeff= (c*0.5 + 0.5)*fone;
1603 } 1568 } else if (flags & SWS_AREA) {
1604 else if (flags & SWS_AREA)
1605 {
1606 int64_t d2= d - (1<<29); 1569 int64_t d2= d - (1<<29);
1607 if (d2*xInc < -(1LL<<(29+16))) coeff= 1.0 * (1LL<<(30+16)); 1570 if (d2*xInc < -(1LL<<(29+16))) coeff= 1.0 * (1LL<<(30+16));
1608 else if (d2*xInc < (1LL<<(29+16))) coeff= -d2*xInc + (1LL<<(29+16)); 1571 else if (d2*xInc < (1LL<<(29+16))) coeff= -d2*xInc + (1LL<<(29+16));
1609 else coeff=0.0; 1572 else coeff=0.0;
1610 coeff *= fone>>(30+16); 1573 coeff *= fone>>(30+16);
1611 } 1574 } else if (flags & SWS_GAUSS) {
1612 else if (flags & SWS_GAUSS)
1613 {
1614 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; 1575 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
1615 coeff = (pow(2.0, - p*floatd*floatd))*fone; 1576 coeff = (pow(2.0, - p*floatd*floatd))*fone;
1616 } 1577 } else if (flags & SWS_SINC) {
1617 else if (flags & SWS_SINC)
1618 {
1619 coeff = (d ? sin(floatd*PI)/(floatd*PI) : 1.0)*fone; 1578 coeff = (d ? sin(floatd*PI)/(floatd*PI) : 1.0)*fone;
1620 } 1579 } else if (flags & SWS_LANCZOS) {
1621 else if (flags & SWS_LANCZOS)
1622 {
1623 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; 1580 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
1624 coeff = (d ? sin(floatd*PI)*sin(floatd*PI/p)/(floatd*floatd*PI*PI/p) : 1.0)*fone; 1581 coeff = (d ? sin(floatd*PI)*sin(floatd*PI/p)/(floatd*floatd*PI*PI/p) : 1.0)*fone;
1625 if (floatd>p) coeff=0; 1582 if (floatd>p) coeff=0;
1626 } 1583 } else if (flags & SWS_BILINEAR) {
1627 else if (flags & SWS_BILINEAR)
1628 {
1629 coeff= (1<<30) - d; 1584 coeff= (1<<30) - d;
1630 if (coeff<0) coeff=0; 1585 if (coeff<0) coeff=0;
1631 coeff *= fone >> 30; 1586 coeff *= fone >> 30;
1632 } 1587 } else if (flags & SWS_SPLINE) {
1633 else if (flags & SWS_SPLINE)
1634 {
1635 double p=-2.196152422706632; 1588 double p=-2.196152422706632;
1636 coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, floatd) * fone; 1589 coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, floatd) * fone;
1637 } 1590 } else {
1638 else {
1639 coeff= 0.0; //GCC warning killer 1591 coeff= 0.0; //GCC warning killer
1640 assert(0); 1592 assert(0);
1641 } 1593 }
1642 1594
1643 filter[i*filterSize + j]= coeff; 1595 filter[i*filterSize + j]= coeff;
1655 if (srcFilter) filter2Size+= srcFilter->length - 1; 1607 if (srcFilter) filter2Size+= srcFilter->length - 1;
1656 if (dstFilter) filter2Size+= dstFilter->length - 1; 1608 if (dstFilter) filter2Size+= dstFilter->length - 1;
1657 assert(filter2Size>0); 1609 assert(filter2Size>0);
1658 filter2= av_mallocz(filter2Size*dstW*sizeof(*filter2)); 1610 filter2= av_mallocz(filter2Size*dstW*sizeof(*filter2));
1659 1611
1660 for (i=0; i<dstW; i++) 1612 for (i=0; i<dstW; i++) {
1661 {
1662 int j, k; 1613 int j, k;
1663 1614
1664 if(srcFilter){ 1615 if(srcFilter) {
1665 for (k=0; k<srcFilter->length; k++){ 1616 for (k=0; k<srcFilter->length; k++) {
1666 for (j=0; j<filterSize; j++) 1617 for (j=0; j<filterSize; j++)
1667 filter2[i*filter2Size + k + j] += srcFilter->coeff[k]*filter[i*filterSize + j]; 1618 filter2[i*filter2Size + k + j] += srcFilter->coeff[k]*filter[i*filterSize + j];
1668 } 1619 }
1669 }else{ 1620 } else {
1670 for (j=0; j<filterSize; j++) 1621 for (j=0; j<filterSize; j++)
1671 filter2[i*filter2Size + j]= filter[i*filterSize + j]; 1622 filter2[i*filter2Size + j]= filter[i*filterSize + j];
1672 } 1623 }
1673 //FIXME dstFilter 1624 //FIXME dstFilter
1674 1625
1677 av_freep(&filter); 1628 av_freep(&filter);
1678 1629
1679 /* try to reduce the filter-size (step1 find size and shift left) */ 1630 /* try to reduce the filter-size (step1 find size and shift left) */
1680 // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not). 1631 // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).
1681 minFilterSize= 0; 1632 minFilterSize= 0;
1682 for (i=dstW-1; i>=0; i--) 1633 for (i=dstW-1; i>=0; i--) {
1683 {
1684 int min= filter2Size; 1634 int min= filter2Size;
1685 int j; 1635 int j;
1686 int64_t cutOff=0.0; 1636 int64_t cutOff=0.0;
1687 1637
1688 /* get rid off near zero elements on the left by shifting left */ 1638 /* get rid off near zero elements on the left by shifting left */
1689 for (j=0; j<filter2Size; j++) 1639 for (j=0; j<filter2Size; j++) {
1690 {
1691 int k; 1640 int k;
1692 cutOff += FFABS(filter2[i*filter2Size]); 1641 cutOff += FFABS(filter2[i*filter2Size]);
1693 1642
1694 if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break; 1643 if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break;
1695 1644
1703 (*filterPos)[i]++; 1652 (*filterPos)[i]++;
1704 } 1653 }
1705 1654
1706 cutOff=0; 1655 cutOff=0;
1707 /* count near zeros on the right */ 1656 /* count near zeros on the right */
1708 for (j=filter2Size-1; j>0; j--) 1657 for (j=filter2Size-1; j>0; j--) {
1709 {
1710 cutOff += FFABS(filter2[i*filter2Size + j]); 1658 cutOff += FFABS(filter2[i*filter2Size + j]);
1711 1659
1712 if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break; 1660 if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break;
1713 min--; 1661 min--;
1714 } 1662 }
1746 *outFilterSize= filterSize; 1694 *outFilterSize= filterSize;
1747 1695
1748 if (flags&SWS_PRINT_INFO) 1696 if (flags&SWS_PRINT_INFO)
1749 av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); 1697 av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize);
1750 /* try to reduce the filter-size (step2 reduce it) */ 1698 /* try to reduce the filter-size (step2 reduce it) */
1751 for (i=0; i<dstW; i++) 1699 for (i=0; i<dstW; i++) {
1752 {
1753 int j; 1700 int j;
1754 1701
1755 for (j=0; j<filterSize; j++) 1702 for (j=0; j<filterSize; j++) {
1756 {
1757 if (j>=filter2Size) filter[i*filterSize + j]= 0; 1703 if (j>=filter2Size) filter[i*filterSize + j]= 0;
1758 else filter[i*filterSize + j]= filter2[i*filter2Size + j]; 1704 else filter[i*filterSize + j]= filter2[i*filter2Size + j];
1759 if((flags & SWS_BITEXACT) && j>=minFilterSize) 1705 if((flags & SWS_BITEXACT) && j>=minFilterSize)
1760 filter[i*filterSize + j]= 0; 1706 filter[i*filterSize + j]= 0;
1761 } 1707 }
1763 1709
1764 1710
1765 //FIXME try to align filterPos if possible 1711 //FIXME try to align filterPos if possible
1766 1712
1767 //fix borders 1713 //fix borders
1768 for (i=0; i<dstW; i++) 1714 for (i=0; i<dstW; i++) {
1769 {
1770 int j; 1715 int j;
1771 if ((*filterPos)[i] < 0) 1716 if ((*filterPos)[i] < 0) {
1772 {
1773 // move filter coefficients left to compensate for filterPos 1717 // move filter coefficients left to compensate for filterPos
1774 for (j=1; j<filterSize; j++) 1718 for (j=1; j<filterSize; j++) {
1775 {
1776 int left= FFMAX(j + (*filterPos)[i], 0); 1719 int left= FFMAX(j + (*filterPos)[i], 0);
1777 filter[i*filterSize + left] += filter[i*filterSize + j]; 1720 filter[i*filterSize + left] += filter[i*filterSize + j];
1778 filter[i*filterSize + j]=0; 1721 filter[i*filterSize + j]=0;
1779 } 1722 }
1780 (*filterPos)[i]= 0; 1723 (*filterPos)[i]= 0;
1781 } 1724 }
1782 1725
1783 if ((*filterPos)[i] + filterSize > srcW) 1726 if ((*filterPos)[i] + filterSize > srcW) {
1784 {
1785 int shift= (*filterPos)[i] + filterSize - srcW; 1727 int shift= (*filterPos)[i] + filterSize - srcW;
1786 // move filter coefficients right to compensate for filterPos 1728 // move filter coefficients right to compensate for filterPos
1787 for (j=filterSize-2; j>=0; j--) 1729 for (j=filterSize-2; j>=0; j--) {
1788 {
1789 int right= FFMIN(j + shift, filterSize-1); 1730 int right= FFMIN(j + shift, filterSize-1);
1790 filter[i*filterSize +right] += filter[i*filterSize +j]; 1731 filter[i*filterSize +right] += filter[i*filterSize +j];
1791 filter[i*filterSize +j]=0; 1732 filter[i*filterSize +j]=0;
1792 } 1733 }
1793 (*filterPos)[i]= srcW - filterSize; 1734 (*filterPos)[i]= srcW - filterSize;
1797 // Note the +1 is for the MMX scaler which reads over the end 1738 // Note the +1 is for the MMX scaler which reads over the end
1798 /* align at 16 for AltiVec (needed by hScale_altivec_real) */ 1739 /* align at 16 for AltiVec (needed by hScale_altivec_real) */
1799 *outFilter= av_mallocz(*outFilterSize*(dstW+1)*sizeof(int16_t)); 1740 *outFilter= av_mallocz(*outFilterSize*(dstW+1)*sizeof(int16_t));
1800 1741
1801 /* normalize & store in outFilter */ 1742 /* normalize & store in outFilter */
1802 for (i=0; i<dstW; i++) 1743 for (i=0; i<dstW; i++) {
1803 {
1804 int j; 1744 int j;
1805 int64_t error=0; 1745 int64_t error=0;
1806 int64_t sum=0; 1746 int64_t sum=0;
1807 1747
1808 for (j=0; j<filterSize; j++) 1748 for (j=0; j<filterSize; j++) {
1809 {
1810 sum+= filter[i*filterSize + j]; 1749 sum+= filter[i*filterSize + j];
1811 } 1750 }
1812 sum= (sum + one/2)/ one; 1751 sum= (sum + one/2)/ one;
1813 for (j=0; j<*outFilterSize; j++) 1752 for (j=0; j<*outFilterSize; j++) {
1814 {
1815 int64_t v= filter[i*filterSize + j] + error; 1753 int64_t v= filter[i*filterSize + j] + error;
1816 int intV= ROUNDED_DIV(v, sum); 1754 int intV= ROUNDED_DIV(v, sum);
1817 (*outFilter)[i*(*outFilterSize) + j]= intV; 1755 (*outFilter)[i*(*outFilterSize) + j]= intV;
1818 error= v - intV*sum; 1756 error= v - intV*sum;
1819 } 1757 }
1820 } 1758 }
1821 1759
1822 (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end 1760 (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end
1823 for (i=0; i<*outFilterSize; i++) 1761 for (i=0; i<*outFilterSize; i++) {
1824 {
1825 int j= dstW*(*outFilterSize); 1762 int j= dstW*(*outFilterSize);
1826 (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)]; 1763 (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)];
1827 } 1764 }
1828 1765
1829 ret=0; 1766 ret=0;
1931 ); 1868 );
1932 1869
1933 xpos= 0; //lumXInc/2 - 0x8000; // difference between pixel centers 1870 xpos= 0; //lumXInc/2 - 0x8000; // difference between pixel centers
1934 fragmentPos=0; 1871 fragmentPos=0;
1935 1872
1936 for (i=0; i<dstW/numSplits; i++) 1873 for (i=0; i<dstW/numSplits; i++) {
1937 {
1938 int xx=xpos>>16; 1874 int xx=xpos>>16;
1939 1875
1940 if ((i&3) == 0) 1876 if ((i&3) == 0) {
1941 {
1942 int a=0; 1877 int a=0;
1943 int b=((xpos+xInc)>>16) - xx; 1878 int b=((xpos+xInc)>>16) - xx;
1944 int c=((xpos+xInc*2)>>16) - xx; 1879 int c=((xpos+xInc*2)>>16) - xx;
1945 int d=((xpos+xInc*3)>>16) - xx; 1880 int d=((xpos+xInc*3)>>16) - xx;
1946 int inc = (d+1<4); 1881 int inc = (d+1<4);
1966 a | (b<<2) | (c<<4) | (d<<6); 1901 a | (b<<2) | (c<<4) | (d<<6);
1967 1902
1968 if (i+4-inc>=dstW) shift=maxShift; //avoid overread 1903 if (i+4-inc>=dstW) shift=maxShift; //avoid overread
1969 else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align 1904 else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align
1970 1905
1971 if (shift && i>=shift) 1906 if (shift && i>=shift) {
1972 {
1973 filterCode[fragmentPos + imm8OfPShufW1]+= 0x55*shift; 1907 filterCode[fragmentPos + imm8OfPShufW1]+= 0x55*shift;
1974 filterCode[fragmentPos + imm8OfPShufW2]+= 0x55*shift; 1908 filterCode[fragmentPos + imm8OfPShufW2]+= 0x55*shift;
1975 filterPos[i/2]-=shift; 1909 filterPos[i/2]-=shift;
1976 } 1910 }
1977 } 1911 }
1988 1922
1989 return fragmentPos + 1; 1923 return fragmentPos + 1;
1990 } 1924 }
1991 #endif /* COMPILE_MMX2 */ 1925 #endif /* COMPILE_MMX2 */
1992 1926
1993 static void globalInit(void){ 1927 static void globalInit(void)
1928 {
1994 // generating tables: 1929 // generating tables:
1995 int i; 1930 int i;
1996 for (i=0; i<768; i++){ 1931 for (i=0; i<768; i++) {
1997 int c= av_clip_uint8(i-256); 1932 int c= av_clip_uint8(i-256);
1998 clip_table[i]=c; 1933 clip_table[i]=c;
1999 } 1934 }
2000 } 1935 }
2001 1936
2052 #endif 1987 #endif
2053 #endif //!CONFIG_RUNTIME_CPUDETECT 1988 #endif //!CONFIG_RUNTIME_CPUDETECT
2054 } 1989 }
2055 1990
2056 static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 1991 static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2057 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 1992 int srcSliceH, uint8_t* dstParam[], int dstStride[])
1993 {
2058 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; 1994 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
2059 /* Copy Y plane */ 1995 /* Copy Y plane */
2060 if (dstStride[0]==srcStride[0] && srcStride[0] > 0) 1996 if (dstStride[0]==srcStride[0] && srcStride[0] > 0)
2061 memcpy(dst, src[0], srcSliceH*dstStride[0]); 1997 memcpy(dst, src[0], srcSliceH*dstStride[0]);
2062 else 1998 else {
2063 {
2064 int i; 1999 int i;
2065 const uint8_t *srcPtr= src[0]; 2000 const uint8_t *srcPtr= src[0];
2066 uint8_t *dstPtr= dst; 2001 uint8_t *dstPtr= dst;
2067 for (i=0; i<srcSliceH; i++) 2002 for (i=0; i<srcSliceH; i++) {
2068 {
2069 memcpy(dstPtr, srcPtr, c->srcW); 2003 memcpy(dstPtr, srcPtr, c->srcW);
2070 srcPtr+= srcStride[0]; 2004 srcPtr+= srcStride[0];
2071 dstPtr+= dstStride[0]; 2005 dstPtr+= dstStride[0];
2072 } 2006 }
2073 } 2007 }
2079 2013
2080 return srcSliceH; 2014 return srcSliceH;
2081 } 2015 }
2082 2016
2083 static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2017 static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2084 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2018 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2019 {
2085 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; 2020 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
2086 2021
2087 yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); 2022 yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]);
2088 2023
2089 return srcSliceH; 2024 return srcSliceH;
2090 } 2025 }
2091 2026
2092 static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2027 static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2093 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2028 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2029 {
2094 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; 2030 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
2095 2031
2096 yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); 2032 yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]);
2097 2033
2098 return srcSliceH; 2034 return srcSliceH;
2099 } 2035 }
2100 2036
2101 static int YUV422PToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2037 static int YUV422PToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2102 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2038 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2039 {
2103 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; 2040 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
2104 2041
2105 yuv422ptoyuy2(src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0]); 2042 yuv422ptoyuy2(src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0]);
2106 2043
2107 return srcSliceH; 2044 return srcSliceH;
2108 } 2045 }
2109 2046
2110 static int YUV422PToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2047 static int YUV422PToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2111 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2048 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2049 {
2112 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; 2050 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
2113 2051
2114 yuv422ptouyvy(src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0]); 2052 yuv422ptouyvy(src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0]);
2115 2053
2116 return srcSliceH; 2054 return srcSliceH;
2117 } 2055 }
2118 2056
2119 static int YUYV2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2057 static int YUYV2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2120 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2058 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2059 {
2121 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; 2060 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
2122 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY/2; 2061 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY/2;
2123 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY/2; 2062 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY/2;
2124 2063
2125 yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); 2064 yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]);
2129 2068
2130 return srcSliceH; 2069 return srcSliceH;
2131 } 2070 }
2132 2071
2133 static int YUYV2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2072 static int YUYV2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2134 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2073 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2074 {
2135 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; 2075 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
2136 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY; 2076 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY;
2137 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY; 2077 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY;
2138 2078
2139 yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); 2079 yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]);
2140 2080
2141 return srcSliceH; 2081 return srcSliceH;
2142 } 2082 }
2143 2083
2144 static int UYVY2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2084 static int UYVY2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2145 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2085 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2086 {
2146 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; 2087 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
2147 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY/2; 2088 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY/2;
2148 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY/2; 2089 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY/2;
2149 2090
2150 uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); 2091 uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]);
2154 2095
2155 return srcSliceH; 2096 return srcSliceH;
2156 } 2097 }
2157 2098
2158 static int UYVY2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2099 static int UYVY2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2159 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ 2100 int srcSliceH, uint8_t* dstParam[], int dstStride[])
2101 {
2160 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; 2102 uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY;
2161 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY; 2103 uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY;
2162 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY; 2104 uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY;
2163 2105
2164 uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); 2106 uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]);
2165 2107
2166 return srcSliceH; 2108 return srcSliceH;
2167 } 2109 }
2168 2110
2169 static int pal2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2111 static int pal2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2170 int srcSliceH, uint8_t* dst[], int dstStride[]){ 2112 int srcSliceH, uint8_t* dst[], int dstStride[])
2113 {
2171 const enum PixelFormat srcFormat= c->srcFormat; 2114 const enum PixelFormat srcFormat= c->srcFormat;
2172 const enum PixelFormat dstFormat= c->dstFormat; 2115 const enum PixelFormat dstFormat= c->dstFormat;
2173 void (*conv)(const uint8_t *src, uint8_t *dst, long num_pixels, 2116 void (*conv)(const uint8_t *src, uint8_t *dst, long num_pixels,
2174 const uint8_t *palette)=NULL; 2117 const uint8_t *palette)=NULL;
2175 int i; 2118 int i;
2178 2121
2179 if (!usePal(srcFormat)) 2122 if (!usePal(srcFormat))
2180 av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", 2123 av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
2181 sws_format_name(srcFormat), sws_format_name(dstFormat)); 2124 sws_format_name(srcFormat), sws_format_name(dstFormat));
2182 2125
2183 switch(dstFormat){ 2126 switch(dstFormat) {
2184 case PIX_FMT_RGB32 : conv = palette8topacked32; break; 2127 case PIX_FMT_RGB32 : conv = palette8topacked32; break;
2185 case PIX_FMT_BGR32 : conv = palette8topacked32; break; 2128 case PIX_FMT_BGR32 : conv = palette8topacked32; break;
2186 case PIX_FMT_BGR32_1: conv = palette8topacked32; break; 2129 case PIX_FMT_BGR32_1: conv = palette8topacked32; break;
2187 case PIX_FMT_RGB32_1: conv = palette8topacked32; break; 2130 case PIX_FMT_RGB32_1: conv = palette8topacked32; break;
2188 case PIX_FMT_RGB24 : conv = palette8topacked24; break; 2131 case PIX_FMT_RGB24 : conv = palette8topacked24; break;
2201 return srcSliceH; 2144 return srcSliceH;
2202 } 2145 }
2203 2146
2204 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */ 2147 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
2205 static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2148 static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2206 int srcSliceH, uint8_t* dst[], int dstStride[]){ 2149 int srcSliceH, uint8_t* dst[], int dstStride[])
2150 {
2207 const enum PixelFormat srcFormat= c->srcFormat; 2151 const enum PixelFormat srcFormat= c->srcFormat;
2208 const enum PixelFormat dstFormat= c->dstFormat; 2152 const enum PixelFormat dstFormat= c->dstFormat;
2209 const int srcBpp= (fmt_depth(srcFormat) + 7) >> 3; 2153 const int srcBpp= (fmt_depth(srcFormat) + 7) >> 3;
2210 const int dstBpp= (fmt_depth(dstFormat) + 7) >> 3; 2154 const int dstBpp= (fmt_depth(dstFormat) + 7) >> 3;
2211 const int srcId= fmt_depth(srcFormat) >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ 2155 const int srcId= fmt_depth(srcFormat) >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */
2212 const int dstId= fmt_depth(dstFormat) >> 2; 2156 const int dstId= fmt_depth(dstFormat) >> 2;
2213 void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; 2157 void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL;
2214 2158
2215 /* BGR -> BGR */ 2159 /* BGR -> BGR */
2216 if ( (isBGR(srcFormat) && isBGR(dstFormat)) 2160 if ( (isBGR(srcFormat) && isBGR(dstFormat))
2217 || (isRGB(srcFormat) && isRGB(dstFormat))){ 2161 || (isRGB(srcFormat) && isRGB(dstFormat))) {
2218 switch(srcId | (dstId<<4)){ 2162 switch(srcId | (dstId<<4)) {
2219 case 0x34: conv= rgb16to15; break; 2163 case 0x34: conv= rgb16to15; break;
2220 case 0x36: conv= rgb24to15; break; 2164 case 0x36: conv= rgb24to15; break;
2221 case 0x38: conv= rgb32to15; break; 2165 case 0x38: conv= rgb32to15; break;
2222 case 0x43: conv= rgb15to16; break; 2166 case 0x43: conv= rgb15to16; break;
2223 case 0x46: conv= rgb24to16; break; 2167 case 0x46: conv= rgb24to16; break;
2229 case 0x84: conv= rgb16to32; break; 2173 case 0x84: conv= rgb16to32; break;
2230 case 0x86: conv= rgb24to32; break; 2174 case 0x86: conv= rgb24to32; break;
2231 default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", 2175 default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
2232 sws_format_name(srcFormat), sws_format_name(dstFormat)); break; 2176 sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
2233 } 2177 }
2234 }else if ( (isBGR(srcFormat) && isRGB(dstFormat)) 2178 } else if ( (isBGR(srcFormat) && isRGB(dstFormat))
2235 || (isRGB(srcFormat) && isBGR(dstFormat))){ 2179 || (isRGB(srcFormat) && isBGR(dstFormat))) {
2236 switch(srcId | (dstId<<4)){ 2180 switch(srcId | (dstId<<4)) {
2237 case 0x33: conv= rgb15tobgr15; break; 2181 case 0x33: conv= rgb15tobgr15; break;
2238 case 0x34: conv= rgb16tobgr15; break; 2182 case 0x34: conv= rgb16tobgr15; break;
2239 case 0x36: conv= rgb24tobgr15; break; 2183 case 0x36: conv= rgb24tobgr15; break;
2240 case 0x38: conv= rgb32tobgr15; break; 2184 case 0x38: conv= rgb32tobgr15; break;
2241 case 0x43: conv= rgb15tobgr16; break; 2185 case 0x43: conv= rgb15tobgr16; break;
2251 case 0x86: conv= rgb24tobgr32; break; 2195 case 0x86: conv= rgb24tobgr32; break;
2252 case 0x88: conv= rgb32tobgr32; break; 2196 case 0x88: conv= rgb32tobgr32; break;
2253 default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", 2197 default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
2254 sws_format_name(srcFormat), sws_format_name(dstFormat)); break; 2198 sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
2255 } 2199 }
2256 }else{ 2200 } else {
2257 av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", 2201 av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
2258 sws_format_name(srcFormat), sws_format_name(dstFormat)); 2202 sws_format_name(srcFormat), sws_format_name(dstFormat));
2259 } 2203 }
2260 2204
2261 if(conv) 2205 if(conv) {
2262 {
2263 uint8_t *srcPtr= src[0]; 2206 uint8_t *srcPtr= src[0];
2264 if(srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) 2207 if(srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1)
2265 srcPtr += ALT32_CORR; 2208 srcPtr += ALT32_CORR;
2266 2209
2267 if (dstStride[0]*srcBpp == srcStride[0]*dstBpp && srcStride[0] > 0) 2210 if (dstStride[0]*srcBpp == srcStride[0]*dstBpp && srcStride[0] > 0)
2268 conv(srcPtr, dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); 2211 conv(srcPtr, dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]);
2269 else 2212 else {
2270 {
2271 int i; 2213 int i;
2272 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; 2214 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
2273 2215
2274 for (i=0; i<srcSliceH; i++) 2216 for (i=0; i<srcSliceH; i++) {
2275 {
2276 conv(srcPtr, dstPtr, c->srcW*srcBpp); 2217 conv(srcPtr, dstPtr, c->srcW*srcBpp);
2277 srcPtr+= srcStride[0]; 2218 srcPtr+= srcStride[0];
2278 dstPtr+= dstStride[0]; 2219 dstPtr+= dstStride[0];
2279 } 2220 }
2280 } 2221 }
2281 } 2222 }
2282 return srcSliceH; 2223 return srcSliceH;
2283 } 2224 }
2284 2225
2285 static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2226 static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2286 int srcSliceH, uint8_t* dst[], int dstStride[]){ 2227 int srcSliceH, uint8_t* dst[], int dstStride[])
2228 {
2287 2229
2288 rgb24toyv12( 2230 rgb24toyv12(
2289 src[0], 2231 src[0],
2290 dst[0]+ srcSliceY *dstStride[0], 2232 dst[0]+ srcSliceY *dstStride[0],
2291 dst[1]+(srcSliceY>>1)*dstStride[1], 2233 dst[1]+(srcSliceY>>1)*dstStride[1],
2296 fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); 2238 fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
2297 return srcSliceH; 2239 return srcSliceH;
2298 } 2240 }
2299 2241
2300 static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2242 static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2301 int srcSliceH, uint8_t* dst[], int dstStride[]){ 2243 int srcSliceH, uint8_t* dst[], int dstStride[])
2244 {
2302 int i; 2245 int i;
2303 2246
2304 /* copy Y */ 2247 /* copy Y */
2305 if (srcStride[0]==dstStride[0] && srcStride[0] > 0) 2248 if (srcStride[0]==dstStride[0] && srcStride[0] > 0)
2306 memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH); 2249 memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH);
2307 else{ 2250 else {
2308 uint8_t *srcPtr= src[0]; 2251 uint8_t *srcPtr= src[0];
2309 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; 2252 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
2310 2253
2311 for (i=0; i<srcSliceH; i++) 2254 for (i=0; i<srcSliceH; i++) {
2312 {
2313 memcpy(dstPtr, srcPtr, c->srcW); 2255 memcpy(dstPtr, srcPtr, c->srcW);
2314 srcPtr+= srcStride[0]; 2256 srcPtr+= srcStride[0];
2315 dstPtr+= dstStride[0]; 2257 dstPtr+= dstStride[0];
2316 } 2258 }
2317 } 2259 }
2318 2260
2319 if (c->dstFormat==PIX_FMT_YUV420P || c->dstFormat==PIX_FMT_YUVA420P){ 2261 if (c->dstFormat==PIX_FMT_YUV420P || c->dstFormat==PIX_FMT_YUVA420P) {
2320 planar2x(src[1], dst[1] + dstStride[1]*(srcSliceY >> 1), c->chrSrcW, 2262 planar2x(src[1], dst[1] + dstStride[1]*(srcSliceY >> 1), c->chrSrcW,
2321 srcSliceH >> 2, srcStride[1], dstStride[1]); 2263 srcSliceH >> 2, srcStride[1], dstStride[1]);
2322 planar2x(src[2], dst[2] + dstStride[2]*(srcSliceY >> 1), c->chrSrcW, 2264 planar2x(src[2], dst[2] + dstStride[2]*(srcSliceY >> 1), c->chrSrcW,
2323 srcSliceH >> 2, srcStride[2], dstStride[2]); 2265 srcSliceH >> 2, srcStride[2], dstStride[2]);
2324 }else{ 2266 } else {
2325 planar2x(src[1], dst[2] + dstStride[2]*(srcSliceY >> 1), c->chrSrcW, 2267 planar2x(src[1], dst[2] + dstStride[2]*(srcSliceY >> 1), c->chrSrcW,
2326 srcSliceH >> 2, srcStride[1], dstStride[2]); 2268 srcSliceH >> 2, srcStride[1], dstStride[2]);
2327 planar2x(src[2], dst[1] + dstStride[1]*(srcSliceY >> 1), c->chrSrcW, 2269 planar2x(src[2], dst[1] + dstStride[1]*(srcSliceY >> 1), c->chrSrcW,
2328 srcSliceH >> 2, srcStride[2], dstStride[1]); 2270 srcSliceH >> 2, srcStride[2], dstStride[1]);
2329 } 2271 }
2336 static int packedCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2278 static int packedCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2337 int srcSliceH, uint8_t* dst[], int dstStride[]) 2279 int srcSliceH, uint8_t* dst[], int dstStride[])
2338 { 2280 {
2339 if (dstStride[0]==srcStride[0] && srcStride[0] > 0) 2281 if (dstStride[0]==srcStride[0] && srcStride[0] > 0)
2340 memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]); 2282 memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]);
2341 else 2283 else {
2342 {
2343 int i; 2284 int i;
2344 uint8_t *srcPtr= src[0]; 2285 uint8_t *srcPtr= src[0];
2345 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; 2286 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
2346 int length=0; 2287 int length=0;
2347 2288
2348 /* universal length finder */ 2289 /* universal length finder */
2349 while(length+c->srcW <= FFABS(dstStride[0]) 2290 while(length+c->srcW <= FFABS(dstStride[0])
2350 && length+c->srcW <= FFABS(srcStride[0])) length+= c->srcW; 2291 && length+c->srcW <= FFABS(srcStride[0])) length+= c->srcW;
2351 assert(length!=0); 2292 assert(length!=0);
2352 2293
2353 for (i=0; i<srcSliceH; i++) 2294 for (i=0; i<srcSliceH; i++) {
2354 {
2355 memcpy(dstPtr, srcPtr, length); 2295 memcpy(dstPtr, srcPtr, length);
2356 srcPtr+= srcStride[0]; 2296 srcPtr+= srcStride[0];
2357 dstPtr+= dstStride[0]; 2297 dstPtr+= dstStride[0];
2358 } 2298 }
2359 } 2299 }
2362 2302
2363 static int planarCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 2303 static int planarCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
2364 int srcSliceH, uint8_t* dst[], int dstStride[]) 2304 int srcSliceH, uint8_t* dst[], int dstStride[])
2365 { 2305 {
2366 int plane, i, j; 2306 int plane, i, j;
2367 for (plane=0; plane<4; plane++) 2307 for (plane=0; plane<4; plane++) {
2368 {
2369 int length= (plane==0 || plane==3) ? c->srcW : -((-c->srcW )>>c->chrDstHSubSample); 2308 int length= (plane==0 || plane==3) ? c->srcW : -((-c->srcW )>>c->chrDstHSubSample);
2370 int y= (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample); 2309 int y= (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);
2371 int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample); 2310 int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);
2372 uint8_t *srcPtr= src[plane]; 2311 uint8_t *srcPtr= src[plane];
2373 uint8_t *dstPtr= dst[plane] + dstStride[plane]*y; 2312 uint8_t *dstPtr= dst[plane] + dstStride[plane]*y;
2374 2313
2375 if (!dst[plane]) continue; 2314 if (!dst[plane]) continue;
2376 // ignore palette for GRAY8 2315 // ignore palette for GRAY8
2377 if (plane == 1 && !dst[2]) continue; 2316 if (plane == 1 && !dst[2]) continue;
2378 if (!src[plane] || (plane == 1 && !src[2])){ 2317 if (!src[plane] || (plane == 1 && !src[2])) {
2379 if(is16BPS(c->dstFormat)) 2318 if(is16BPS(c->dstFormat))
2380 length*=2; 2319 length*=2;
2381 fillPlane(dst[plane], dstStride[plane], length, height, y, (plane==3) ? 255 : 128); 2320 fillPlane(dst[plane], dstStride[plane], length, height, y, (plane==3) ? 255 : 128);
2382 }else 2321 } else {
2383 { 2322 if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {
2384 if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)){
2385 if (!isBE(c->srcFormat)) srcPtr++; 2323 if (!isBE(c->srcFormat)) srcPtr++;
2386 for (i=0; i<height; i++){ 2324 for (i=0; i<height; i++) {
2387 for (j=0; j<length; j++) dstPtr[j] = srcPtr[j<<1]; 2325 for (j=0; j<length; j++) dstPtr[j] = srcPtr[j<<1];
2388 srcPtr+= srcStride[plane]; 2326 srcPtr+= srcStride[plane];
2389 dstPtr+= dstStride[plane]; 2327 dstPtr+= dstStride[plane];
2390 } 2328 }
2391 }else if(!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)){ 2329 } else if(!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) {
2392 for (i=0; i<height; i++){ 2330 for (i=0; i<height; i++) {
2393 for (j=0; j<length; j++){ 2331 for (j=0; j<length; j++) {
2394 dstPtr[ j<<1 ] = srcPtr[j]; 2332 dstPtr[ j<<1 ] = srcPtr[j];
2395 dstPtr[(j<<1)+1] = srcPtr[j]; 2333 dstPtr[(j<<1)+1] = srcPtr[j];
2396 } 2334 }
2397 srcPtr+= srcStride[plane]; 2335 srcPtr+= srcStride[plane];
2398 dstPtr+= dstStride[plane]; 2336 dstPtr+= dstStride[plane];
2399 } 2337 }
2400 }else if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat) 2338 } else if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat)
2401 && isBE(c->srcFormat) != isBE(c->dstFormat)){ 2339 && isBE(c->srcFormat) != isBE(c->dstFormat)) {
2402 2340
2403 for (i=0; i<height; i++){ 2341 for (i=0; i<height; i++) {
2404 for (j=0; j<length; j++) 2342 for (j=0; j<length; j++)
2405 ((uint16_t*)dstPtr)[j] = bswap_16(((uint16_t*)srcPtr)[j]); 2343 ((uint16_t*)dstPtr)[j] = bswap_16(((uint16_t*)srcPtr)[j]);
2406 srcPtr+= srcStride[plane]; 2344 srcPtr+= srcStride[plane];
2407 dstPtr+= dstStride[plane]; 2345 dstPtr+= dstStride[plane];
2408 } 2346 }
2409 } else if (dstStride[plane]==srcStride[plane] && srcStride[plane] > 0) 2347 } else if (dstStride[plane]==srcStride[plane] && srcStride[plane] > 0)
2410 memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]); 2348 memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]);
2411 else 2349 else {
2412 {
2413 if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) 2350 if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
2414 length*=2; 2351 length*=2;
2415 for (i=0; i<height; i++) 2352 for (i=0; i<height; i++) {
2416 {
2417 memcpy(dstPtr, srcPtr, length); 2353 memcpy(dstPtr, srcPtr, length);
2418 srcPtr+= srcStride[plane]; 2354 srcPtr+= srcStride[plane];
2419 dstPtr+= dstStride[plane]; 2355 dstPtr+= dstStride[plane];
2420 } 2356 }
2421 } 2357 }
2423 } 2359 }
2424 return srcSliceH; 2360 return srcSliceH;
2425 } 2361 }
2426 2362
2427 2363
2428 static void getSubSampleFactors(int *h, int *v, int format){ 2364 static void getSubSampleFactors(int *h, int *v, int format)
2429 switch(format){ 2365 {
2366 switch(format) {
2430 case PIX_FMT_UYVY422: 2367 case PIX_FMT_UYVY422:
2431 case PIX_FMT_YUYV422: 2368 case PIX_FMT_YUYV422:
2432 *h=1; 2369 *h=1;
2433 *v=0; 2370 *v=0;
2434 break; 2371 break;
2473 *v=0; 2410 *v=0;
2474 break; 2411 break;
2475 } 2412 }
2476 } 2413 }
2477 2414
2478 static uint16_t roundToInt16(int64_t f){ 2415 static uint16_t roundToInt16(int64_t f)
2416 {
2479 int r= (f + (1<<15))>>16; 2417 int r= (f + (1<<15))>>16;
2480 if (r<-0x7FFF) return 0x8000; 2418 if (r<-0x7FFF) return 0x8000;
2481 else if (r> 0x7FFF) return 0x7FFF; 2419 else if (r> 0x7FFF) return 0x7FFF;
2482 else return r; 2420 else return r;
2483 } 2421 }
2484 2422
2485 int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation){ 2423 int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
2424 {
2486 int64_t crv = inv_table[0]; 2425 int64_t crv = inv_table[0];
2487 int64_t cbu = inv_table[1]; 2426 int64_t cbu = inv_table[1];
2488 int64_t cgu = -inv_table[2]; 2427 int64_t cgu = -inv_table[2];
2489 int64_t cgv = -inv_table[3]; 2428 int64_t cgv = -inv_table[3];
2490 int64_t cy = 1<<16; 2429 int64_t cy = 1<<16;
2501 if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; 2440 if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
2502 2441
2503 c->uOffset= 0x0400040004000400LL; 2442 c->uOffset= 0x0400040004000400LL;
2504 c->vOffset= 0x0400040004000400LL; 2443 c->vOffset= 0x0400040004000400LL;
2505 2444
2506 if (!srcRange){ 2445 if (!srcRange) {
2507 cy= (cy*255) / 219; 2446 cy= (cy*255) / 219;
2508 oy= 16<<16; 2447 oy= 16<<16;
2509 }else{ 2448 } else {
2510 crv= (crv*224) / 255; 2449 crv= (crv*224) / 255;
2511 cbu= (cbu*224) / 255; 2450 cbu= (cbu*224) / 255;
2512 cgu= (cgu*224) / 255; 2451 cgu= (cgu*224) / 255;
2513 cgv= (cgv*224) / 255; 2452 cgv= (cgv*224) / 255;
2514 } 2453 }
2543 ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness, contrast, saturation); 2482 ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness, contrast, saturation);
2544 #endif 2483 #endif
2545 return 0; 2484 return 0;
2546 } 2485 }
2547 2486
2548 int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation){ 2487 int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
2488 {
2549 if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; 2489 if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
2550 2490
2551 *inv_table = c->srcColorspaceTable; 2491 *inv_table = c->srcColorspaceTable;
2552 *table = c->dstColorspaceTable; 2492 *table = c->dstColorspaceTable;
2553 *srcRange = c->srcRange; 2493 *srcRange = c->srcRange;
2617 && ((fmt_depth(dstFormat))<(fmt_depth(srcFormat)) || (!(isRGB(srcFormat) || isBGR(srcFormat)))); 2557 && ((fmt_depth(dstFormat))<(fmt_depth(srcFormat)) || (!(isRGB(srcFormat) || isBGR(srcFormat))));
2618 2558
2619 srcRange = handle_jpeg(&srcFormat); 2559 srcRange = handle_jpeg(&srcFormat);
2620 dstRange = handle_jpeg(&dstFormat); 2560 dstRange = handle_jpeg(&dstFormat);
2621 2561
2622 if (!isSupportedIn(srcFormat)) 2562 if (!isSupportedIn(srcFormat)) {
2623 {
2624 av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); 2563 av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat));
2625 return NULL; 2564 return NULL;
2626 } 2565 }
2627 if (!isSupportedOut(dstFormat)) 2566 if (!isSupportedOut(dstFormat)) {
2628 {
2629 av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); 2567 av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat));
2630 return NULL; 2568 return NULL;
2631 } 2569 }
2632 2570
2633 i= flags & ( SWS_POINT 2571 i= flags & ( SWS_POINT
2639 |SWS_GAUSS 2577 |SWS_GAUSS
2640 |SWS_LANCZOS 2578 |SWS_LANCZOS
2641 |SWS_SINC 2579 |SWS_SINC
2642 |SWS_SPLINE 2580 |SWS_SPLINE
2643 |SWS_BICUBLIN); 2581 |SWS_BICUBLIN);
2644 if(!i || (i & (i-1))) 2582 if(!i || (i & (i-1))) {
2645 {
2646 av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n"); 2583 av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n");
2647 return NULL; 2584 return NULL;
2648 } 2585 }
2649 2586
2650 /* sanity check */ 2587 /* sanity check */
2651 if (srcW<4 || srcH<1 || dstW<8 || dstH<1) //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code 2588 if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code
2652 {
2653 av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", 2589 av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n",
2654 srcW, srcH, dstW, dstH); 2590 srcW, srcH, dstW, dstH);
2655 return NULL; 2591 return NULL;
2656 } 2592 }
2657 if(srcW > VOFW || dstW > VOFW){ 2593 if(srcW > VOFW || dstW > VOFW) {
2658 av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n"); 2594 av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n");
2659 return NULL; 2595 return NULL;
2660 } 2596 }
2661 2597
2662 if (!dstFilter) dstFilter= &dummyFilter; 2598 if (!dstFilter) dstFilter= &dummyFilter;
2702 && srcFormat!=PIX_FMT_RGB4 && srcFormat!=PIX_FMT_BGR4 2638 && srcFormat!=PIX_FMT_RGB4 && srcFormat!=PIX_FMT_BGR4
2703 && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE 2639 && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE
2704 && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&(SWS_FAST_BILINEAR|SWS_POINT)))) 2640 && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&(SWS_FAST_BILINEAR|SWS_POINT))))
2705 c->chrSrcHSubSample=1; 2641 c->chrSrcHSubSample=1;
2706 2642
2707 if (param){ 2643 if (param) {
2708 c->param[0] = param[0]; 2644 c->param[0] = param[0];
2709 c->param[1] = param[1]; 2645 c->param[1] = param[1];
2710 }else{ 2646 } else {
2711 c->param[0] = 2647 c->param[0] =
2712 c->param[1] = SWS_PARAM_DEFAULT; 2648 c->param[1] = SWS_PARAM_DEFAULT;
2713 } 2649 }
2714 2650
2715 // Note the -((-x)>>y) is so that we always round toward +inf. 2651 // Note the -((-x)>>y) is so that we always round toward +inf.
2719 c->chrDstH= -((-dstH) >> c->chrDstVSubSample); 2655 c->chrDstH= -((-dstH) >> c->chrDstVSubSample);
2720 2656
2721 sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); 2657 sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16);
2722 2658
2723 /* unscaled special cases */ 2659 /* unscaled special cases */
2724 if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isBGR(dstFormat) || isRGB(dstFormat))) 2660 if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isBGR(dstFormat) || isRGB(dstFormat))) {
2725 {
2726 /* yv12_to_nv12 */ 2661 /* yv12_to_nv12 */
2727 if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) 2662 if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) {
2728 {
2729 c->swScale= PlanarToNV12Wrapper; 2663 c->swScale= PlanarToNV12Wrapper;
2730 } 2664 }
2731 /* yuv2bgr */ 2665 /* yuv2bgr */
2732 if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P || srcFormat==PIX_FMT_YUVA420P) && (isBGR(dstFormat) || isRGB(dstFormat)) 2666 if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P || srcFormat==PIX_FMT_YUVA420P) && (isBGR(dstFormat) || isRGB(dstFormat))
2733 && !(flags & SWS_ACCURATE_RND) && !(dstH&1)) 2667 && !(flags & SWS_ACCURATE_RND) && !(dstH&1)) {
2734 {
2735 c->swScale= ff_yuv2rgb_get_func_ptr(c); 2668 c->swScale= ff_yuv2rgb_get_func_ptr(c);
2736 } 2669 }
2737 2670
2738 if (srcFormat==PIX_FMT_YUV410P && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_BITEXACT)) 2671 if (srcFormat==PIX_FMT_YUV410P && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_BITEXACT)) {
2739 {
2740 c->swScale= yvu9toyv12Wrapper; 2672 c->swScale= yvu9toyv12Wrapper;
2741 } 2673 }
2742 2674
2743 /* bgr24toYV12 */ 2675 /* bgr24toYV12 */
2744 if (srcFormat==PIX_FMT_BGR24 && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_ACCURATE_RND)) 2676 if (srcFormat==PIX_FMT_BGR24 && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_ACCURATE_RND))
2769 dstFormat == PIX_FMT_BGR32 || 2701 dstFormat == PIX_FMT_BGR32 ||
2770 dstFormat == PIX_FMT_BGR32_1 || 2702 dstFormat == PIX_FMT_BGR32_1 ||
2771 dstFormat == PIX_FMT_BGR24))) 2703 dstFormat == PIX_FMT_BGR24)))
2772 c->swScale= pal2rgbWrapper; 2704 c->swScale= pal2rgbWrapper;
2773 2705
2774 if (srcFormat == PIX_FMT_YUV422P) 2706 if (srcFormat == PIX_FMT_YUV422P) {
2775 {
2776 if (dstFormat == PIX_FMT_YUYV422) 2707 if (dstFormat == PIX_FMT_YUYV422)
2777 c->swScale= YUV422PToYuy2Wrapper; 2708 c->swScale= YUV422PToYuy2Wrapper;
2778 else if (dstFormat == PIX_FMT_UYVY422) 2709 else if (dstFormat == PIX_FMT_UYVY422)
2779 c->swScale= YUV422PToUyvyWrapper; 2710 c->swScale= YUV422PToUyvyWrapper;
2780 } 2711 }
2781 2712
2782 /* LQ converters if -sws 0 or -sws 4*/ 2713 /* LQ converters if -sws 0 or -sws 4*/
2783 if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)){ 2714 if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
2784 /* yv12_to_yuy2 */ 2715 /* yv12_to_yuy2 */
2785 if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) 2716 if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) {
2786 {
2787 if (dstFormat == PIX_FMT_YUYV422) 2717 if (dstFormat == PIX_FMT_YUYV422)
2788 c->swScale= PlanarToYuy2Wrapper; 2718 c->swScale= PlanarToYuy2Wrapper;
2789 else if (dstFormat == PIX_FMT_UYVY422) 2719 else if (dstFormat == PIX_FMT_UYVY422)
2790 c->swScale= PlanarToUyvyWrapper; 2720 c->swScale= PlanarToUyvyWrapper;
2791 } 2721 }
2832 #if ARCH_BFIN 2762 #if ARCH_BFIN
2833 if (flags & SWS_CPU_CAPS_BFIN) 2763 if (flags & SWS_CPU_CAPS_BFIN)
2834 ff_bfin_get_unscaled_swscale (c); 2764 ff_bfin_get_unscaled_swscale (c);
2835 #endif 2765 #endif
2836 2766
2837 if (c->swScale){ 2767 if (c->swScale) {
2838 if (flags&SWS_PRINT_INFO) 2768 if (flags&SWS_PRINT_INFO)
2839 av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n", 2769 av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n",
2840 sws_format_name(srcFormat), sws_format_name(dstFormat)); 2770 sws_format_name(srcFormat), sws_format_name(dstFormat));
2841 return c; 2771 return c;
2842 } 2772 }
2843 } 2773 }
2844 2774
2845 if (flags & SWS_CPU_CAPS_MMX2) 2775 if (flags & SWS_CPU_CAPS_MMX2) {
2846 {
2847 c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; 2776 c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0;
2848 if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) 2777 if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) {
2849 {
2850 if (flags&SWS_PRINT_INFO) 2778 if (flags&SWS_PRINT_INFO)
2851 av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n"); 2779 av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n");
2852 } 2780 }
2853 if (usesHFilter) c->canMMX2BeUsed=0; 2781 if (usesHFilter) c->canMMX2BeUsed=0;
2854 } 2782 }
2862 // but only for the FAST_BILINEAR mode otherwise do correct scaling 2790 // but only for the FAST_BILINEAR mode otherwise do correct scaling
2863 // n-2 is the last chrominance sample available 2791 // n-2 is the last chrominance sample available
2864 // this is not perfect, but no one should notice the difference, the more correct variant 2792 // this is not perfect, but no one should notice the difference, the more correct variant
2865 // would be like the vertical one, but that would require some special code for the 2793 // would be like the vertical one, but that would require some special code for the
2866 // first and last pixel 2794 // first and last pixel
2867 if (flags&SWS_FAST_BILINEAR) 2795 if (flags&SWS_FAST_BILINEAR) {
2868 { 2796 if (c->canMMX2BeUsed) {
2869 if (c->canMMX2BeUsed)
2870 {
2871 c->lumXInc+= 20; 2797 c->lumXInc+= 20;
2872 c->chrXInc+= 20; 2798 c->chrXInc+= 20;
2873 } 2799 }
2874 //we don't use the x86 asm scaler if MMX is available 2800 //we don't use the x86 asm scaler if MMX is available
2875 else if (flags & SWS_CPU_CAPS_MMX) 2801 else if (flags & SWS_CPU_CAPS_MMX) {
2876 {
2877 c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; 2802 c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20;
2878 c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; 2803 c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20;
2879 } 2804 }
2880 } 2805 }
2881 2806
2895 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, 2820 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
2896 srcFilter->chrH, dstFilter->chrH, c->param); 2821 srcFilter->chrH, dstFilter->chrH, c->param);
2897 2822
2898 #if defined(COMPILE_MMX2) 2823 #if defined(COMPILE_MMX2)
2899 // can't downscale !!! 2824 // can't downscale !!!
2900 if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) 2825 if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) {
2901 {
2902 c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8); 2826 c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8);
2903 c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4); 2827 c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4);
2904 2828
2905 #ifdef MAP_ANONYMOUS 2829 #ifdef MAP_ANONYMOUS
2906 c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 2830 c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
2968 } 2892 }
2969 2893
2970 // calculate buffer sizes so that they won't run out while handling these damn slices 2894 // calculate buffer sizes so that they won't run out while handling these damn slices
2971 c->vLumBufSize= c->vLumFilterSize; 2895 c->vLumBufSize= c->vLumFilterSize;
2972 c->vChrBufSize= c->vChrFilterSize; 2896 c->vChrBufSize= c->vChrFilterSize;
2973 for (i=0; i<dstH; i++) 2897 for (i=0; i<dstH; i++) {
2974 {
2975 int chrI= i*c->chrDstH / dstH; 2898 int chrI= i*c->chrDstH / dstH;
2976 int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, 2899 int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1,
2977 ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample)); 2900 ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));
2978 2901
2979 nextSlice>>= c->chrSrcVSubSample; 2902 nextSlice>>= c->chrSrcVSubSample;
3004 2927
3005 assert(2*VOFW == VOF); 2928 assert(2*VOFW == VOF);
3006 2929
3007 assert(c->chrDstH <= dstH); 2930 assert(c->chrDstH <= dstH);
3008 2931
3009 if (flags&SWS_PRINT_INFO) 2932 if (flags&SWS_PRINT_INFO) {
3010 {
3011 #ifdef DITHER1XBPP 2933 #ifdef DITHER1XBPP
3012 const char *dither= " dithered"; 2934 const char *dither= " dithered";
3013 #else 2935 #else
3014 const char *dither= ""; 2936 const char *dither= "";
3015 #endif 2937 #endif
3055 av_log(c, AV_LOG_INFO, "using AltiVec\n"); 2977 av_log(c, AV_LOG_INFO, "using AltiVec\n");
3056 else 2978 else
3057 av_log(c, AV_LOG_INFO, "using C\n"); 2979 av_log(c, AV_LOG_INFO, "using C\n");
3058 } 2980 }
3059 2981
3060 if (flags & SWS_PRINT_INFO) 2982 if (flags & SWS_PRINT_INFO) {
3061 { 2983 if (flags & SWS_CPU_CAPS_MMX) {
3062 if (flags & SWS_CPU_CAPS_MMX)
3063 {
3064 if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) 2984 if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR))
3065 av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); 2985 av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");
3066 else 2986 else {
3067 {
3068 if (c->hLumFilterSize==4) 2987 if (c->hLumFilterSize==4)
3069 av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n"); 2988 av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n");
3070 else if (c->hLumFilterSize==8) 2989 else if (c->hLumFilterSize==8)
3071 av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n"); 2990 av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n");
3072 else 2991 else
3077 else if (c->hChrFilterSize==8) 2996 else if (c->hChrFilterSize==8)
3078 av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n"); 2997 av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n");
3079 else 2998 else
3080 av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n"); 2999 av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n");
3081 } 3000 }
3082 } 3001 } else {
3083 else
3084 {
3085 #if ARCH_X86 3002 #if ARCH_X86
3086 av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n"); 3003 av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n");
3087 #else 3004 #else
3088 if (flags & SWS_FAST_BILINEAR) 3005 if (flags & SWS_FAST_BILINEAR)
3089 av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n"); 3006 av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n");
3090 else 3007 else
3091 av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n"); 3008 av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n");
3092 #endif 3009 #endif
3093 } 3010 }
3094 if (isPlanarYUV(dstFormat)) 3011 if (isPlanarYUV(dstFormat)) {
3095 {
3096 if (c->vLumFilterSize==1) 3012 if (c->vLumFilterSize==1)
3097 av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); 3013 av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
3098 else 3014 else
3099 av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); 3015 av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
3100 } 3016 } else {
3101 else
3102 {
3103 if (c->vLumFilterSize==1 && c->vChrFilterSize==2) 3017 if (c->vLumFilterSize==1 && c->vChrFilterSize==2)
3104 av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" 3018 av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
3105 " 2-tap scaler for vertical chrominance scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); 3019 " 2-tap scaler for vertical chrominance scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
3106 else if (c->vLumFilterSize==2 && c->vChrFilterSize==2) 3020 else if (c->vLumFilterSize==2 && c->vChrFilterSize==2)
3107 av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); 3021 av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
3119 else if (dstFormat==PIX_FMT_BGR555) 3033 else if (dstFormat==PIX_FMT_BGR555)
3120 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); 3034 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
3121 3035
3122 av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); 3036 av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
3123 } 3037 }
3124 if (flags & SWS_PRINT_INFO) 3038 if (flags & SWS_PRINT_INFO) {
3125 {
3126 av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", 3039 av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
3127 c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); 3040 c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);
3128 av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", 3041 av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
3129 c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); 3042 c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc);
3130 } 3043 }
3131 3044
3132 c->swScale= getSwsFunc(c); 3045 c->swScale= getSwsFunc(c);
3133 return c; 3046 return c;
3134 } 3047 }
3135 3048
3136 static void reset_ptr(uint8_t* src[], int format){ 3049 static void reset_ptr(uint8_t* src[], int format)
3050 {
3137 if(!isALPHA(format)) 3051 if(!isALPHA(format))
3138 src[3]=NULL; 3052 src[3]=NULL;
3139 if(!isPlanarYUV(format)){ 3053 if(!isPlanarYUV(format)) {
3140 src[3]=src[2]=NULL; 3054 src[3]=src[2]=NULL;
3141 if( format != PIX_FMT_PAL8 3055 if( format != PIX_FMT_PAL8
3142 && format != PIX_FMT_RGB8 3056 && format != PIX_FMT_RGB8
3143 && format != PIX_FMT_BGR8 3057 && format != PIX_FMT_BGR8
3144 && format != PIX_FMT_RGB4_BYTE 3058 && format != PIX_FMT_RGB4_BYTE
3151 /** 3065 /**
3152 * swscale wrapper, so we don't need to export the SwsContext. 3066 * swscale wrapper, so we don't need to export the SwsContext.
3153 * Assumes planar YUV to be in YUV order instead of YVU. 3067 * Assumes planar YUV to be in YUV order instead of YVU.
3154 */ 3068 */
3155 int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 3069 int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
3156 int srcSliceH, uint8_t* dst[], int dstStride[]){ 3070 int srcSliceH, uint8_t* dst[], int dstStride[])
3071 {
3157 int i; 3072 int i;
3158 uint8_t* src2[4]= {src[0], src[1], src[2], src[3]}; 3073 uint8_t* src2[4]= {src[0], src[1], src[2], src[3]};
3159 uint8_t* dst2[4]= {dst[0], dst[1], dst[2], dst[3]}; 3074 uint8_t* dst2[4]= {dst[0], dst[1], dst[2], dst[3]};
3160 3075
3161 if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { 3076 if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
3164 } 3079 }
3165 if (c->sliceDir == 0) { 3080 if (c->sliceDir == 0) {
3166 if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; 3081 if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
3167 } 3082 }
3168 3083
3169 if (usePal(c->srcFormat)){ 3084 if (usePal(c->srcFormat)) {
3170 for (i=0; i<256; i++){ 3085 for (i=0; i<256; i++) {
3171 int p, r, g, b,y,u,v; 3086 int p, r, g, b,y,u,v;
3172 if(c->srcFormat == PIX_FMT_PAL8){ 3087 if(c->srcFormat == PIX_FMT_PAL8) {
3173 p=((uint32_t*)(src[1]))[i]; 3088 p=((uint32_t*)(src[1]))[i];
3174 r= (p>>16)&0xFF; 3089 r= (p>>16)&0xFF;
3175 g= (p>> 8)&0xFF; 3090 g= (p>> 8)&0xFF;
3176 b= p &0xFF; 3091 b= p &0xFF;
3177 }else if(c->srcFormat == PIX_FMT_RGB8){ 3092 } else if(c->srcFormat == PIX_FMT_RGB8) {
3178 r= (i>>5 )*36; 3093 r= (i>>5 )*36;
3179 g= ((i>>2)&7)*36; 3094 g= ((i>>2)&7)*36;
3180 b= (i&3 )*85; 3095 b= (i&3 )*85;
3181 }else if(c->srcFormat == PIX_FMT_BGR8){ 3096 } else if(c->srcFormat == PIX_FMT_BGR8) {
3182 b= (i>>6 )*85; 3097 b= (i>>6 )*85;
3183 g= ((i>>3)&7)*36; 3098 g= ((i>>3)&7)*36;
3184 r= (i&7 )*36; 3099 r= (i&7 )*36;
3185 }else if(c->srcFormat == PIX_FMT_RGB4_BYTE){ 3100 } else if(c->srcFormat == PIX_FMT_RGB4_BYTE) {
3186 r= (i>>3 )*255; 3101 r= (i>>3 )*255;
3187 g= ((i>>1)&3)*85; 3102 g= ((i>>1)&3)*85;
3188 b= (i&1 )*255; 3103 b= (i&1 )*255;
3189 }else { 3104 } else {
3190 assert(c->srcFormat == PIX_FMT_BGR4_BYTE); 3105 assert(c->srcFormat == PIX_FMT_BGR4_BYTE);
3191 b= (i>>3 )*255; 3106 b= (i>>3 )*255;
3192 g= ((i>>1)&3)*85; 3107 g= ((i>>1)&3)*85;
3193 r= (i&1 )*255; 3108 r= (i&1 )*255;
3194 } 3109 }
3259 } 3174 }
3260 } 3175 }
3261 3176
3262 #if LIBSWSCALE_VERSION_MAJOR < 1 3177 #if LIBSWSCALE_VERSION_MAJOR < 1
3263 int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 3178 int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
3264 int srcSliceH, uint8_t* dst[], int dstStride[]){ 3179 int srcSliceH, uint8_t* dst[], int dstStride[])
3180 {
3265 return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); 3181 return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
3266 } 3182 }
3267 #endif 3183 #endif
3268 3184
3269 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, 3185 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
3271 float chromaHShift, float chromaVShift, 3187 float chromaHShift, float chromaVShift,
3272 int verbose) 3188 int verbose)
3273 { 3189 {
3274 SwsFilter *filter= av_malloc(sizeof(SwsFilter)); 3190 SwsFilter *filter= av_malloc(sizeof(SwsFilter));
3275 3191
3276 if (lumaGBlur!=0.0){ 3192 if (lumaGBlur!=0.0) {
3277 filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); 3193 filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0);
3278 filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); 3194 filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0);
3279 }else{ 3195 } else {
3280 filter->lumH= sws_getIdentityVec(); 3196 filter->lumH= sws_getIdentityVec();
3281 filter->lumV= sws_getIdentityVec(); 3197 filter->lumV= sws_getIdentityVec();
3282 } 3198 }
3283 3199
3284 if (chromaGBlur!=0.0){ 3200 if (chromaGBlur!=0.0) {
3285 filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); 3201 filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0);
3286 filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); 3202 filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0);
3287 }else{ 3203 } else {
3288 filter->chrH= sws_getIdentityVec(); 3204 filter->chrH= sws_getIdentityVec();
3289 filter->chrV= sws_getIdentityVec(); 3205 filter->chrV= sws_getIdentityVec();
3290 } 3206 }
3291 3207
3292 if (chromaSharpen!=0.0){ 3208 if (chromaSharpen!=0.0) {
3293 SwsVector *id= sws_getIdentityVec(); 3209 SwsVector *id= sws_getIdentityVec();
3294 sws_scaleVec(filter->chrH, -chromaSharpen); 3210 sws_scaleVec(filter->chrH, -chromaSharpen);
3295 sws_scaleVec(filter->chrV, -chromaSharpen); 3211 sws_scaleVec(filter->chrV, -chromaSharpen);
3296 sws_addVec(filter->chrH, id); 3212 sws_addVec(filter->chrH, id);
3297 sws_addVec(filter->chrV, id); 3213 sws_addVec(filter->chrV, id);
3298 sws_freeVec(id); 3214 sws_freeVec(id);
3299 } 3215 }
3300 3216
3301 if (lumaSharpen!=0.0){ 3217 if (lumaSharpen!=0.0) {
3302 SwsVector *id= sws_getIdentityVec(); 3218 SwsVector *id= sws_getIdentityVec();
3303 sws_scaleVec(filter->lumH, -lumaSharpen); 3219 sws_scaleVec(filter->lumH, -lumaSharpen);
3304 sws_scaleVec(filter->lumV, -lumaSharpen); 3220 sws_scaleVec(filter->lumV, -lumaSharpen);
3305 sws_addVec(filter->lumH, id); 3221 sws_addVec(filter->lumH, id);
3306 sws_addVec(filter->lumV, id); 3222 sws_addVec(filter->lumV, id);
3322 if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG); 3238 if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
3323 3239
3324 return filter; 3240 return filter;
3325 } 3241 }
3326 3242
3327 SwsVector *sws_getGaussianVec(double variance, double quality){ 3243 SwsVector *sws_getGaussianVec(double variance, double quality)
3244 {
3328 const int length= (int)(variance*quality + 0.5) | 1; 3245 const int length= (int)(variance*quality + 0.5) | 1;
3329 int i; 3246 int i;
3330 double *coeff= av_malloc(length*sizeof(double)); 3247 double *coeff= av_malloc(length*sizeof(double));
3331 double middle= (length-1)*0.5; 3248 double middle= (length-1)*0.5;
3332 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3249 SwsVector *vec= av_malloc(sizeof(SwsVector));
3333 3250
3334 vec->coeff= coeff; 3251 vec->coeff= coeff;
3335 vec->length= length; 3252 vec->length= length;
3336 3253
3337 for (i=0; i<length; i++) 3254 for (i=0; i<length; i++) {
3338 {
3339 double dist= i-middle; 3255 double dist= i-middle;
3340 coeff[i]= exp(-dist*dist/(2*variance*variance)) / sqrt(2*variance*PI); 3256 coeff[i]= exp(-dist*dist/(2*variance*variance)) / sqrt(2*variance*PI);
3341 } 3257 }
3342 3258
3343 sws_normalizeVec(vec, 1.0); 3259 sws_normalizeVec(vec, 1.0);
3344 3260
3345 return vec; 3261 return vec;
3346 } 3262 }
3347 3263
3348 SwsVector *sws_getConstVec(double c, int length){ 3264 SwsVector *sws_getConstVec(double c, int length)
3265 {
3349 int i; 3266 int i;
3350 double *coeff= av_malloc(length*sizeof(double)); 3267 double *coeff= av_malloc(length*sizeof(double));
3351 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3268 SwsVector *vec= av_malloc(sizeof(SwsVector));
3352 3269
3353 vec->coeff= coeff; 3270 vec->coeff= coeff;
3358 3275
3359 return vec; 3276 return vec;
3360 } 3277 }
3361 3278
3362 3279
3363 SwsVector *sws_getIdentityVec(void){ 3280 SwsVector *sws_getIdentityVec(void)
3281 {
3364 return sws_getConstVec(1.0, 1); 3282 return sws_getConstVec(1.0, 1);
3365 } 3283 }
3366 3284
3367 double sws_dcVec(SwsVector *a){ 3285 double sws_dcVec(SwsVector *a)
3286 {
3368 int i; 3287 int i;
3369 double sum=0; 3288 double sum=0;
3370 3289
3371 for (i=0; i<a->length; i++) 3290 for (i=0; i<a->length; i++)
3372 sum+= a->coeff[i]; 3291 sum+= a->coeff[i];
3373 3292
3374 return sum; 3293 return sum;
3375 } 3294 }
3376 3295
3377 void sws_scaleVec(SwsVector *a, double scalar){ 3296 void sws_scaleVec(SwsVector *a, double scalar)
3297 {
3378 int i; 3298 int i;
3379 3299
3380 for (i=0; i<a->length; i++) 3300 for (i=0; i<a->length; i++)
3381 a->coeff[i]*= scalar; 3301 a->coeff[i]*= scalar;
3382 } 3302 }
3383 3303
3384 void sws_normalizeVec(SwsVector *a, double height){ 3304 void sws_normalizeVec(SwsVector *a, double height)
3305 {
3385 sws_scaleVec(a, height/sws_dcVec(a)); 3306 sws_scaleVec(a, height/sws_dcVec(a));
3386 } 3307 }
3387 3308
3388 static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){ 3309 static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b)
3310 {
3389 int length= a->length + b->length - 1; 3311 int length= a->length + b->length - 1;
3390 double *coeff= av_malloc(length*sizeof(double)); 3312 double *coeff= av_malloc(length*sizeof(double));
3391 int i, j; 3313 int i, j;
3392 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3314 SwsVector *vec= av_malloc(sizeof(SwsVector));
3393 3315
3394 vec->coeff= coeff; 3316 vec->coeff= coeff;
3395 vec->length= length; 3317 vec->length= length;
3396 3318
3397 for (i=0; i<length; i++) coeff[i]= 0.0; 3319 for (i=0; i<length; i++) coeff[i]= 0.0;
3398 3320
3399 for (i=0; i<a->length; i++) 3321 for (i=0; i<a->length; i++) {
3400 { 3322 for (j=0; j<b->length; j++) {
3401 for (j=0; j<b->length; j++)
3402 {
3403 coeff[i+j]+= a->coeff[i]*b->coeff[j]; 3323 coeff[i+j]+= a->coeff[i]*b->coeff[j];
3404 } 3324 }
3405 } 3325 }
3406 3326
3407 return vec; 3327 return vec;
3408 } 3328 }
3409 3329
3410 static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b){ 3330 static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b)
3331 {
3411 int length= FFMAX(a->length, b->length); 3332 int length= FFMAX(a->length, b->length);
3412 double *coeff= av_malloc(length*sizeof(double)); 3333 double *coeff= av_malloc(length*sizeof(double));
3413 int i; 3334 int i;
3414 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3335 SwsVector *vec= av_malloc(sizeof(SwsVector));
3415 3336
3422 for (i=0; i<b->length; i++) coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; 3343 for (i=0; i<b->length; i++) coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i];
3423 3344
3424 return vec; 3345 return vec;
3425 } 3346 }
3426 3347
3427 static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b){ 3348 static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b)
3349 {
3428 int length= FFMAX(a->length, b->length); 3350 int length= FFMAX(a->length, b->length);
3429 double *coeff= av_malloc(length*sizeof(double)); 3351 double *coeff= av_malloc(length*sizeof(double));
3430 int i; 3352 int i;
3431 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3353 SwsVector *vec= av_malloc(sizeof(SwsVector));
3432 3354
3440 3362
3441 return vec; 3363 return vec;
3442 } 3364 }
3443 3365
3444 /* shift left / or right if "shift" is negative */ 3366 /* shift left / or right if "shift" is negative */
3445 static SwsVector *sws_getShiftedVec(SwsVector *a, int shift){ 3367 static SwsVector *sws_getShiftedVec(SwsVector *a, int shift)
3368 {
3446 int length= a->length + FFABS(shift)*2; 3369 int length= a->length + FFABS(shift)*2;
3447 double *coeff= av_malloc(length*sizeof(double)); 3370 double *coeff= av_malloc(length*sizeof(double));
3448 int i; 3371 int i;
3449 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3372 SwsVector *vec= av_malloc(sizeof(SwsVector));
3450 3373
3451 vec->coeff= coeff; 3374 vec->coeff= coeff;
3452 vec->length= length; 3375 vec->length= length;
3453 3376
3454 for (i=0; i<length; i++) coeff[i]= 0.0; 3377 for (i=0; i<length; i++) coeff[i]= 0.0;
3455 3378
3456 for (i=0; i<a->length; i++) 3379 for (i=0; i<a->length; i++) {
3457 {
3458 coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; 3380 coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i];
3459 } 3381 }
3460 3382
3461 return vec; 3383 return vec;
3462 } 3384 }
3463 3385
3464 void sws_shiftVec(SwsVector *a, int shift){ 3386 void sws_shiftVec(SwsVector *a, int shift)
3387 {
3465 SwsVector *shifted= sws_getShiftedVec(a, shift); 3388 SwsVector *shifted= sws_getShiftedVec(a, shift);
3466 av_free(a->coeff); 3389 av_free(a->coeff);
3467 a->coeff= shifted->coeff; 3390 a->coeff= shifted->coeff;
3468 a->length= shifted->length; 3391 a->length= shifted->length;
3469 av_free(shifted); 3392 av_free(shifted);
3470 } 3393 }
3471 3394
3472 void sws_addVec(SwsVector *a, SwsVector *b){ 3395 void sws_addVec(SwsVector *a, SwsVector *b)
3396 {
3473 SwsVector *sum= sws_sumVec(a, b); 3397 SwsVector *sum= sws_sumVec(a, b);
3474 av_free(a->coeff); 3398 av_free(a->coeff);
3475 a->coeff= sum->coeff; 3399 a->coeff= sum->coeff;
3476 a->length= sum->length; 3400 a->length= sum->length;
3477 av_free(sum); 3401 av_free(sum);
3478 } 3402 }
3479 3403
3480 void sws_subVec(SwsVector *a, SwsVector *b){ 3404 void sws_subVec(SwsVector *a, SwsVector *b)
3405 {
3481 SwsVector *diff= sws_diffVec(a, b); 3406 SwsVector *diff= sws_diffVec(a, b);
3482 av_free(a->coeff); 3407 av_free(a->coeff);
3483 a->coeff= diff->coeff; 3408 a->coeff= diff->coeff;
3484 a->length= diff->length; 3409 a->length= diff->length;
3485 av_free(diff); 3410 av_free(diff);
3486 } 3411 }
3487 3412
3488 void sws_convVec(SwsVector *a, SwsVector *b){ 3413 void sws_convVec(SwsVector *a, SwsVector *b)
3414 {
3489 SwsVector *conv= sws_getConvVec(a, b); 3415 SwsVector *conv= sws_getConvVec(a, b);
3490 av_free(a->coeff); 3416 av_free(a->coeff);
3491 a->coeff= conv->coeff; 3417 a->coeff= conv->coeff;
3492 a->length= conv->length; 3418 a->length= conv->length;
3493 av_free(conv); 3419 av_free(conv);
3494 } 3420 }
3495 3421
3496 SwsVector *sws_cloneVec(SwsVector *a){ 3422 SwsVector *sws_cloneVec(SwsVector *a)
3423 {
3497 double *coeff= av_malloc(a->length*sizeof(double)); 3424 double *coeff= av_malloc(a->length*sizeof(double));
3498 int i; 3425 int i;
3499 SwsVector *vec= av_malloc(sizeof(SwsVector)); 3426 SwsVector *vec= av_malloc(sizeof(SwsVector));
3500 3427
3501 vec->coeff= coeff; 3428 vec->coeff= coeff;
3504 for (i=0; i<a->length; i++) coeff[i]= a->coeff[i]; 3431 for (i=0; i<a->length; i++) coeff[i]= a->coeff[i];
3505 3432
3506 return vec; 3433 return vec;
3507 } 3434 }
3508 3435
3509 void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level){ 3436 void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level)
3437 {
3510 int i; 3438 int i;
3511 double max=0; 3439 double max=0;
3512 double min=0; 3440 double min=0;
3513 double range; 3441 double range;
3514 3442
3518 for (i=0; i<a->length; i++) 3446 for (i=0; i<a->length; i++)
3519 if (a->coeff[i]<min) min= a->coeff[i]; 3447 if (a->coeff[i]<min) min= a->coeff[i];
3520 3448
3521 range= max - min; 3449 range= max - min;
3522 3450
3523 for (i=0; i<a->length; i++) 3451 for (i=0; i<a->length; i++) {
3524 {
3525 int x= (int)((a->coeff[i]-min)*60.0/range +0.5); 3452 int x= (int)((a->coeff[i]-min)*60.0/range +0.5);
3526 av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]); 3453 av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]);
3527 for (;x>0; x--) av_log(log_ctx, log_level, " "); 3454 for (;x>0; x--) av_log(log_ctx, log_level, " ");
3528 av_log(log_ctx, log_level, "|\n"); 3455 av_log(log_ctx, log_level, "|\n");
3529 } 3456 }
3530 } 3457 }
3531 3458
3532 #if LIBSWSCALE_VERSION_MAJOR < 1 3459 #if LIBSWSCALE_VERSION_MAJOR < 1
3533 void sws_printVec(SwsVector *a){ 3460 void sws_printVec(SwsVector *a)
3461 {
3534 sws_printVec2(a, NULL, AV_LOG_DEBUG); 3462 sws_printVec2(a, NULL, AV_LOG_DEBUG);
3535 } 3463 }
3536 #endif 3464 #endif
3537 3465
3538 void sws_freeVec(SwsVector *a){ 3466 void sws_freeVec(SwsVector *a)
3467 {
3539 if (!a) return; 3468 if (!a) return;
3540 av_freep(&a->coeff); 3469 av_freep(&a->coeff);
3541 a->length=0; 3470 a->length=0;
3542 av_free(a); 3471 av_free(a);
3543 } 3472 }
3544 3473
3545 void sws_freeFilter(SwsFilter *filter){ 3474 void sws_freeFilter(SwsFilter *filter)
3475 {
3546 if (!filter) return; 3476 if (!filter) return;
3547 3477
3548 if (filter->lumH) sws_freeVec(filter->lumH); 3478 if (filter->lumH) sws_freeVec(filter->lumH);
3549 if (filter->lumV) sws_freeVec(filter->lumV); 3479 if (filter->lumV) sws_freeVec(filter->lumV);
3550 if (filter->chrH) sws_freeVec(filter->chrH); 3480 if (filter->chrH) sws_freeVec(filter->chrH);
3551 if (filter->chrV) sws_freeVec(filter->chrV); 3481 if (filter->chrV) sws_freeVec(filter->chrV);
3552 av_free(filter); 3482 av_free(filter);
3553 } 3483 }
3554 3484
3555 3485
3556 void sws_freeContext(SwsContext *c){ 3486 void sws_freeContext(SwsContext *c)
3487 {
3557 int i; 3488 int i;
3558 if (!c) return; 3489 if (!c) return;
3559 3490
3560 if (c->lumPixBuf) 3491 if (c->lumPixBuf) {
3561 {
3562 for (i=0; i<c->vLumBufSize; i++) 3492 for (i=0; i<c->vLumBufSize; i++)
3563 av_freep(&c->lumPixBuf[i]); 3493 av_freep(&c->lumPixBuf[i]);
3564 av_freep(&c->lumPixBuf); 3494 av_freep(&c->lumPixBuf);
3565 } 3495 }
3566 3496
3567 if (c->chrPixBuf) 3497 if (c->chrPixBuf) {
3568 {
3569 for (i=0; i<c->vChrBufSize; i++) 3498 for (i=0; i<c->vChrBufSize; i++)
3570 av_freep(&c->chrPixBuf[i]); 3499 av_freep(&c->chrPixBuf[i]);
3571 av_freep(&c->chrPixBuf); 3500 av_freep(&c->chrPixBuf);
3572 } 3501 }
3573 3502
3574 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){ 3503 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
3575 for (i=0; i<c->vLumBufSize; i++) 3504 for (i=0; i<c->vLumBufSize; i++)
3576 av_freep(&c->alpPixBuf[i]); 3505 av_freep(&c->alpPixBuf[i]);
3577 av_freep(&c->alpPixBuf); 3506 av_freep(&c->alpPixBuf);
3578 } 3507 }
3579 3508