Mercurial > mplayer.hg
comparison postproc/swscale.c @ 13373:6bd869a18d2c
passing an array or double precission parameters for the scaling function, instead of missusing a few bits of the flags
fixing the naming of the scaling functions a little
author | michael |
---|---|
date | Sat, 18 Sep 2004 00:08:17 +0000 |
parents | 1d6892e87a2c |
children | 992960f68af0 |
comparison
equal
deleted
inserted
replaced
13372:c537796e79b7 | 13373:6bd869a18d2c |
---|---|
773 dist-1.0); | 773 dist-1.0); |
774 } | 774 } |
775 | 775 |
776 static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, | 776 static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, |
777 int srcW, int dstW, int filterAlign, int one, int flags, | 777 int srcW, int dstW, int filterAlign, int one, int flags, |
778 SwsVector *srcFilter, SwsVector *dstFilter) | 778 SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) |
779 { | 779 { |
780 int i; | 780 int i; |
781 int filterSize; | 781 int filterSize; |
782 int filter2Size; | 782 int filter2Size; |
783 int minFilterSize; | 783 int minFilterSize; |
853 else | 853 else |
854 { | 854 { |
855 double xDstInSrc; | 855 double xDstInSrc; |
856 double sizeFactor, filterSizeInSrc; | 856 double sizeFactor, filterSizeInSrc; |
857 const double xInc1= (double)xInc / (double)(1<<16); | 857 const double xInc1= (double)xInc / (double)(1<<16); |
858 int param= (flags&SWS_PARAM_MASK)>>SWS_PARAM_SHIFT; | |
859 | 858 |
860 if (flags&SWS_BICUBIC) sizeFactor= 4.0; | 859 if (flags&SWS_BICUBIC) sizeFactor= 4.0; |
861 else if(flags&SWS_X) sizeFactor= 8.0; | 860 else if(flags&SWS_X) sizeFactor= 8.0; |
862 else if(flags&SWS_AREA) sizeFactor= 1.0; //downscale only, for upscale it is bilinear | 861 else if(flags&SWS_AREA) sizeFactor= 1.0; //downscale only, for upscale it is bilinear |
863 else if(flags&SWS_GAUSS) sizeFactor= 8.0; // infinite ;) | 862 else if(flags&SWS_GAUSS) sizeFactor= 8.0; // infinite ;) |
864 else if(flags&SWS_LANCZOS) sizeFactor= param ? 2.0*param : 6.0; | 863 else if(flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? 2.0*param[0] : 6.0; |
865 else if(flags&SWS_SINC) sizeFactor= 20.0; // infinite ;) | 864 else if(flags&SWS_SINC) sizeFactor= 20.0; // infinite ;) |
866 else if(flags&SWS_SPLINE) sizeFactor= 20.0; // infinite ;) | 865 else if(flags&SWS_SPLINE) sizeFactor= 20.0; // infinite ;) |
867 else if(flags&SWS_BILINEAR) sizeFactor= 2.0; | 866 else if(flags&SWS_BILINEAR) sizeFactor= 2.0; |
868 else { | 867 else { |
869 sizeFactor= 0.0; //GCC warning killer | 868 sizeFactor= 0.0; //GCC warning killer |
888 { | 887 { |
889 double d= ABS(xx - xDstInSrc)/filterSizeInSrc*sizeFactor; | 888 double d= ABS(xx - xDstInSrc)/filterSizeInSrc*sizeFactor; |
890 double coeff; | 889 double coeff; |
891 if(flags & SWS_BICUBIC) | 890 if(flags & SWS_BICUBIC) |
892 { | 891 { |
893 double A= param ? -param*0.01 : -0.60; | 892 double B= param[0] != SWS_PARAM_DEFAULT ? param[0] : 0.0; |
894 | 893 double C= param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6; |
895 // Equation is from VirtualDub | 894 |
896 if(d<1.0) | 895 if(d<1.0) |
897 coeff = (1.0 - (A+3.0)*d*d + (A+2.0)*d*d*d); | 896 coeff = (12-9*B-6*C)*d*d*d + (-18+12*B+6*C)*d*d + 6-2*B; |
898 else if(d<2.0) | 897 else if(d<2.0) |
899 coeff = (-4.0*A + 8.0*A*d - 5.0*A*d*d + A*d*d*d); | 898 coeff = (-B-6*C)*d*d*d + (6*B+30*C)*d*d + (-12*B-48*C)*d +8*B+24*C; |
900 else | 899 else |
901 coeff=0.0; | 900 coeff=0.0; |
902 } | 901 } |
903 /* else if(flags & SWS_X) | 902 /* else if(flags & SWS_X) |
904 { | 903 { |
906 coeff = d ? sin(d*PI)/(d*PI) : 1.0; | 905 coeff = d ? sin(d*PI)/(d*PI) : 1.0; |
907 coeff*= pow(2.0, - p*d*d); | 906 coeff*= pow(2.0, - p*d*d); |
908 }*/ | 907 }*/ |
909 else if(flags & SWS_X) | 908 else if(flags & SWS_X) |
910 { | 909 { |
911 double A= param ? param*0.1 : 1.0; | 910 double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; |
912 | 911 |
913 if(d<1.0) | 912 if(d<1.0) |
914 coeff = cos(d*PI); | 913 coeff = cos(d*PI); |
915 else | 914 else |
916 coeff=-1.0; | 915 coeff=-1.0; |
925 else if(d - srcPixelSize/2 < 0.5) coeff= (0.5-d)/srcPixelSize + 0.5; | 924 else if(d - srcPixelSize/2 < 0.5) coeff= (0.5-d)/srcPixelSize + 0.5; |
926 else coeff=0.0; | 925 else coeff=0.0; |
927 } | 926 } |
928 else if(flags & SWS_GAUSS) | 927 else if(flags & SWS_GAUSS) |
929 { | 928 { |
930 double p= param ? param*0.1 : 3.0; | 929 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; |
931 coeff = pow(2.0, - p*d*d); | 930 coeff = pow(2.0, - p*d*d); |
932 } | 931 } |
933 else if(flags & SWS_SINC) | 932 else if(flags & SWS_SINC) |
934 { | 933 { |
935 coeff = d ? sin(d*PI)/(d*PI) : 1.0; | 934 coeff = d ? sin(d*PI)/(d*PI) : 1.0; |
936 } | 935 } |
937 else if(flags & SWS_LANCZOS) | 936 else if(flags & SWS_LANCZOS) |
938 { | 937 { |
939 double p= param ? param : 3.0; | 938 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; |
940 coeff = d ? sin(d*PI)*sin(d*PI/p)/(d*d*PI*PI/p) : 1.0; | 939 coeff = d ? sin(d*PI)*sin(d*PI/p)/(d*d*PI*PI/p) : 1.0; |
941 if(d>p) coeff=0; | 940 if(d>p) coeff=0; |
942 } | 941 } |
943 else if(flags & SWS_BILINEAR) | 942 else if(flags & SWS_BILINEAR) |
944 { | 943 { |
1746 | 1745 |
1747 return 0; | 1746 return 0; |
1748 } | 1747 } |
1749 | 1748 |
1750 SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int dstH, int origDstFormat, int flags, | 1749 SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int dstH, int origDstFormat, int flags, |
1751 SwsFilter *srcFilter, SwsFilter *dstFilter){ | 1750 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param){ |
1752 | 1751 |
1753 SwsContext *c; | 1752 SwsContext *c; |
1754 int i; | 1753 int i; |
1755 int usesVFilter, usesHFilter; | 1754 int usesVFilter, usesHFilter; |
1756 int unscaled, needsDither; | 1755 int unscaled, needsDither; |
1845 | 1844 |
1846 // drop every 2. pixel for chroma calculation unless user wants full chroma | 1845 // drop every 2. pixel for chroma calculation unless user wants full chroma |
1847 if((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP)) | 1846 if((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP)) |
1848 c->chrSrcHSubSample=1; | 1847 c->chrSrcHSubSample=1; |
1849 | 1848 |
1849 if(param){ | |
1850 c->param[0] = param[0]; | |
1851 c->param[1] = param[1]; | |
1852 }else{ | |
1853 c->param[0] = | |
1854 c->param[1] = SWS_PARAM_DEFAULT; | |
1855 } | |
1856 | |
1850 c->chrIntHSubSample= c->chrDstHSubSample; | 1857 c->chrIntHSubSample= c->chrDstHSubSample; |
1851 c->chrIntVSubSample= c->chrSrcVSubSample; | 1858 c->chrIntVSubSample= c->chrSrcVSubSample; |
1852 | 1859 |
1853 // note the -((-x)>>y) is so that we allways round toward +inf | 1860 // note the -((-x)>>y) is so that we allways round toward +inf |
1854 c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); | 1861 c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); |
1980 1; | 1987 1; |
1981 | 1988 |
1982 initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, | 1989 initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, |
1983 srcW , dstW, filterAlign, 1<<14, | 1990 srcW , dstW, filterAlign, 1<<14, |
1984 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, | 1991 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, |
1985 srcFilter->lumH, dstFilter->lumH); | 1992 srcFilter->lumH, dstFilter->lumH, c->param); |
1986 initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, | 1993 initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, |
1987 c->chrSrcW, c->chrDstW, filterAlign, 1<<14, | 1994 c->chrSrcW, c->chrDstW, filterAlign, 1<<14, |
1988 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, | 1995 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, |
1989 srcFilter->chrH, dstFilter->chrH); | 1996 srcFilter->chrH, dstFilter->chrH, c->param); |
1990 | 1997 |
1991 #ifdef ARCH_X86 | 1998 #ifdef ARCH_X86 |
1992 // can't downscale !!! | 1999 // can't downscale !!! |
1993 if(c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) | 2000 if(c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) |
1994 { | 2001 { |
2012 1; | 2019 1; |
2013 | 2020 |
2014 initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, | 2021 initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, |
2015 srcH , dstH, filterAlign, (1<<12)-4, | 2022 srcH , dstH, filterAlign, (1<<12)-4, |
2016 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, | 2023 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, |
2017 srcFilter->lumV, dstFilter->lumV); | 2024 srcFilter->lumV, dstFilter->lumV, c->param); |
2018 initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, | 2025 initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, |
2019 c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4, | 2026 c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4, |
2020 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, | 2027 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, |
2021 srcFilter->chrV, dstFilter->chrV); | 2028 srcFilter->chrV, dstFilter->chrV, c->param); |
2022 } | 2029 } |
2023 | 2030 |
2024 // Calculate Buffer Sizes so that they won't run out while handling these damn slices | 2031 // Calculate Buffer Sizes so that they won't run out while handling these damn slices |
2025 c->vLumBufSize= c->vLumFilterSize; | 2032 c->vLumBufSize= c->vLumFilterSize; |
2026 c->vChrBufSize= c->vChrFilterSize; | 2033 c->vChrBufSize= c->vChrFilterSize; |