1
mirror of https://github.com/mpv-player/mpv synced 2025-01-16 22:37:28 +01:00

moving getFilter stuff back (vf_scale.c -> swscale.c)

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9986 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
michael 2003-04-25 11:26:34 +00:00
parent b80199e5dc
commit 6c662cfb25
3 changed files with 90 additions and 59 deletions

View File

@ -40,6 +40,9 @@ extern int opt_screen_size_y;
//===========================================================================//
void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam);
struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat);
static unsigned int outfmt_list[]={
// RGB:
IMGFMT_BGR32,
@ -384,7 +387,7 @@ static int open(vf_instance_t *vf, char* args){
int sws_flags=2;
//global srcFilter
SwsFilter src_filter= {NULL, NULL, NULL, NULL};
static SwsFilter *src_filter= NULL;
float sws_lum_gblur= 0.0;
float sws_chr_gblur= 0.0;
@ -442,63 +445,13 @@ void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, Sw
}
else if(verbose>1) *flags= SWS_PRINT_INFO;
if(src_filter.lumH) sws_freeVec(src_filter.lumH);
if(src_filter.lumV) sws_freeVec(src_filter.lumV);
if(src_filter.chrH) sws_freeVec(src_filter.chrH);
if(src_filter.chrV) sws_freeVec(src_filter.chrV);
if(sws_lum_gblur!=0.0){
src_filter.lumH= sws_getGaussianVec(sws_lum_gblur, 3.0);
src_filter.lumV= sws_getGaussianVec(sws_lum_gblur, 3.0);
}else{
src_filter.lumH= sws_getIdentityVec();
src_filter.lumV= sws_getIdentityVec();
}
if(sws_chr_gblur!=0.0){
src_filter.chrH= sws_getGaussianVec(sws_chr_gblur, 3.0);
src_filter.chrV= sws_getGaussianVec(sws_chr_gblur, 3.0);
}else{
src_filter.chrH= sws_getIdentityVec();
src_filter.chrV= sws_getIdentityVec();
}
if(sws_chr_sharpen!=0.0){
SwsVector *g= sws_getConstVec(-1.0, 3);
SwsVector *id= sws_getConstVec(10.0/sws_chr_sharpen, 1);
g->coeff[1]=2.0;
sws_addVec(id, g);
sws_convVec(src_filter.chrH, id);
sws_convVec(src_filter.chrV, id);
sws_freeVec(g);
sws_freeVec(id);
}
if(sws_lum_sharpen!=0.0){
SwsVector *g= sws_getConstVec(-1.0, 3);
SwsVector *id= sws_getConstVec(10.0/sws_lum_sharpen, 1);
g->coeff[1]=2.0;
sws_addVec(id, g);
sws_convVec(src_filter.lumH, id);
sws_convVec(src_filter.lumV, id);
sws_freeVec(g);
sws_freeVec(id);
}
if(sws_chr_hshift)
sws_shiftVec(src_filter.chrH, sws_chr_hshift);
if(sws_chr_vshift)
sws_shiftVec(src_filter.chrV, sws_chr_vshift);
sws_normalizeVec(src_filter.chrH, 1.0);
sws_normalizeVec(src_filter.chrV, 1.0);
sws_normalizeVec(src_filter.lumH, 1.0);
sws_normalizeVec(src_filter.lumV, 1.0);
if(verbose > 1) sws_printVec(src_filter.chrH);
if(verbose > 1) sws_printVec(src_filter.lumH);
if(src_filter) sws_freeFilter(src_filter);
src_filter= sws_getDefaultFilter(
sws_lum_gblur, sws_chr_gblur,
sws_lum_sharpen, sws_chr_sharpen,
sws_chr_vshift, sws_chr_hshift, verbose>1);
switch(sws_flags)
{
case 0: *flags|= SWS_FAST_BILINEAR; break;
@ -515,7 +468,7 @@ void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, Sw
default:*flags|= SWS_BILINEAR; break;
}
*srcFilterParam= &src_filter;
*srcFilterParam= src_filter;
*dstFilterParam= NULL;
}

View File

@ -2110,11 +2110,72 @@ int sws_scale(SwsContext *c, uint8_t* srcParam[], int srcStrideParam[], int srcS
return c->swScale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
}
SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
float lumaSharpen, float chromaSharpen,
float chromaHShift, float chromaVShift,
int verbose)
{
SwsFilter *filter= malloc(sizeof(SwsFilter));
if(lumaGBlur!=0.0){
filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0);
filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0);
}else{
filter->lumH= sws_getIdentityVec();
filter->lumV= sws_getIdentityVec();
}
if(chromaGBlur!=0.0){
filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0);
filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0);
}else{
filter->chrH= sws_getIdentityVec();
filter->chrV= sws_getIdentityVec();
}
if(chromaSharpen!=0.0){
SwsVector *g= sws_getConstVec(-1.0, 3);
SwsVector *id= sws_getConstVec(10.0/chromaSharpen, 1);
g->coeff[1]=2.0;
sws_addVec(id, g);
sws_convVec(filter->chrH, id);
sws_convVec(filter->chrV, id);
sws_freeVec(g);
sws_freeVec(id);
}
if(lumaSharpen!=0.0){
SwsVector *g= sws_getConstVec(-1.0, 3);
SwsVector *id= sws_getConstVec(10.0/lumaSharpen, 1);
g->coeff[1]=2.0;
sws_addVec(id, g);
sws_convVec(filter->lumH, id);
sws_convVec(filter->lumV, id);
sws_freeVec(g);
sws_freeVec(id);
}
if(chromaHShift != 0.0)
sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5));
if(chromaVShift != 0.0)
sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5));
sws_normalizeVec(filter->chrH, 1.0);
sws_normalizeVec(filter->chrV, 1.0);
sws_normalizeVec(filter->lumH, 1.0);
sws_normalizeVec(filter->lumV, 1.0);
if(verbose) sws_printVec(filter->chrH);
if(verbose) sws_printVec(filter->lumH);
return filter;
}
/**
* returns a normalized gaussian curve used to filter stuff
* quality=3 is high quality, lowwer is lowwer quality
*/
SwsVector *sws_getGaussianVec(double variance, double quality){
const int length= (int)(variance*quality + 0.5) | 1;
int i;
@ -2335,6 +2396,17 @@ void sws_freeVec(SwsVector *a){
free(a);
}
void sws_freeFilter(SwsFilter *filter){
if(!filter) return;
if(filter->lumH) sws_freeVec(filter->lumH);
if(filter->lumV) sws_freeVec(filter->lumV);
if(filter->chrH) sws_freeVec(filter->chrH);
if(filter->chrV) sws_freeVec(filter->chrV);
free(filter);
}
void sws_freeContext(SwsContext *c){
int i;
if(!c) return;

View File

@ -116,6 +116,12 @@ SwsVector *sws_cloneVec(SwsVector *a);
void sws_printVec(SwsVector *a);
void sws_freeVec(SwsVector *a);
SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
float lumaSarpen, float chromaSharpen,
float chromaHShift, float chromaVShift,
int verbose);
void sws_freeFilter(SwsFilter *filter);
#ifdef __cplusplus
}
#endif