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


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13374 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
michael 2004-09-18 00:08:17 +00:00
parent 5e71ad8c1e
commit 54df7e4a3e
9 changed files with 57 additions and 38 deletions

View File

@ -3291,7 +3291,7 @@ sincR
.IPs 9
lanczos
.IPs 10
bicubic spline
natural bicubic spline
.RE
.PD 1
.sp 1
@ -3549,7 +3549,7 @@ For parameters between 4\-7 rotation is only done if the movie's geometry is
portrait and not landscape.
.
.TP
.B scale[=w:h[:interlaced[:chr_drop[:param[:presize]]]]]
.B scale[=w:h[:interlaced[:chr_drop[:param[:param2[:presize]]]]]]
Scales the image with the software scaler (slow) and performs a YUV<\->RGB
colorspace conversion (also see \-sws).
.RSs
@ -3582,9 +3582,19 @@ chroma skipping
3: Use only every 8. input line for chroma.
.REss
.IPs param
scaling parameter (depends upon the scaling method used)
scaling parameters (depend upon the scaling method used)
.RSss
\-sws 2 (bicubic): sharpness (0 (soft) \- 100 (sharp))
\-sws 2 (bicubic): B (blurring) and C (ringing)
.br
(0.00, 0.60) default
.br
(0.00, 0.75) VirtualDubs "precise bicubic"
.br
(0.00, 0.50) Catmull-Rom spline
.br
(0.33, 0.33) Mitchell-Netravali spline
.br
(1.00, 0.00) cubic B-spline
.br
\-sws 7 (gaussian): sharpness (0 (soft) \- 100 (sharp))
.br

View File

@ -135,7 +135,7 @@ int decode_jpeg(void* data,int len,char* dbuffer,int dwidth,int dheight, int dst
jpeg_destroy_decompress(&cinfo);
swsContext= sws_getContext(width,height, in_fmt,
dwidth,dheight, IMGFMT_BGR|dbpp, SWS_BICUBIC, NULL, NULL);
dwidth,dheight, IMGFMT_BGR|dbpp, SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(swsContext,&img,&row_stride,0,height,&dbuffer, &dstride);

View File

@ -100,7 +100,7 @@ static int allocStuff(FilterParam *f, int width, int height){
swsF.lumH= swsF.lumV= vec;
swsF.chrH= swsF.chrV= NULL;
f->preFilterContext= sws_getContext(
width, height, IMGFMT_Y8, width, height, IMGFMT_Y8, get_sws_cpuflags(), &swsF, NULL);
width, height, IMGFMT_Y8, width, height, IMGFMT_Y8, get_sws_cpuflags(), &swsF, NULL, NULL);
sws_freeVec(vec);
vec = sws_getGaussianVec(f->strength, 5.0);

View File

@ -21,7 +21,7 @@
static struct vf_priv_s {
int w,h;
int v_chr_drop;
int param;
double param[2];
unsigned int fmt;
struct SwsContext *ctx;
struct SwsContext *ctx2; //for interlaced slices only
@ -31,7 +31,7 @@ static struct vf_priv_s {
} vf_priv_dflt = {
-1,-1,
0,
0,
{SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
0,
NULL,
NULL,
@ -186,18 +186,17 @@ static int config(struct vf_instance_s* vf,
// new swscaler:
sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
int_sws_flags|= vf->priv->param << SWS_PARAM_SHIFT;
vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
outfmt,
vf->priv->w, vf->priv->h >> vf->priv->interlaced,
best,
int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter);
int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
if(vf->priv->interlaced){
vf->priv->ctx2=sws_getContext(width, height >> 1,
outfmt,
vf->priv->w, vf->priv->h >> 1,
best,
int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter);
int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
}
if(!vf->priv->ctx){
// error...
@ -438,14 +437,16 @@ static int open(vf_instance_t *vf, char* args){
vf->priv->w=
vf->priv->h=-1;
vf->priv->v_chr_drop=0;
vf->priv->param=0;
vf->priv->param[0]=
vf->priv->param[1]=SWS_PARAM_DEFAULT;
vf->priv->palette=NULL;
} // if(!vf->priv)
if(args) sscanf(args, "%d:%d:%d:%d",
if(args) sscanf(args, "%d:%d:%d:%lf:%lf",
&vf->priv->w,
&vf->priv->h,
&vf->priv->v_chr_drop,
&vf->priv->param);
&vf->priv->param[0],
&vf->priv->param[1]);
mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
vf->priv->w,
vf->priv->h);
@ -524,7 +525,7 @@ struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat,
SwsFilter *dstFilterParam, *srcFilterParam;
sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
return sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam);
return sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
}
/// An example of presets usage
@ -572,7 +573,8 @@ static m_option_t vf_opts_fields[] = {
{"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-3 ,0, NULL},
{"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
{"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
{"param", ST_OFF(param), CONF_TYPE_INT, M_OPT_RANGE, 0, 100, NULL},
{"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
{"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
// Note that here the 2 field is NULL (ie 0)
// As we want this option to act on the option struct itself
{"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, &size_preset},

View File

@ -95,7 +95,7 @@ static int allocStuff(FilterParam *f, int width, int height){
swsF.lumH= swsF.lumV= vec;
swsF.chrH= swsF.chrV= NULL;
f->filterContext= sws_getContext(
width, height, IMGFMT_Y8, width, height, IMGFMT_Y8, get_sws_cpuflags(), &swsF, NULL);
width, height, IMGFMT_Y8, width, height, IMGFMT_Y8, get_sws_cpuflags(), &swsF, NULL, NULL);
sws_freeVec(vec);

View File

@ -775,7 +775,7 @@ static double getSplineCoeff(double a, double b, double c, double d, double dist
static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc,
int srcW, int dstW, int filterAlign, int one, int flags,
SwsVector *srcFilter, SwsVector *dstFilter)
SwsVector *srcFilter, SwsVector *dstFilter, double param[2])
{
int i;
int filterSize;
@ -855,13 +855,12 @@ static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *out
double xDstInSrc;
double sizeFactor, filterSizeInSrc;
const double xInc1= (double)xInc / (double)(1<<16);
int param= (flags&SWS_PARAM_MASK)>>SWS_PARAM_SHIFT;
if (flags&SWS_BICUBIC) sizeFactor= 4.0;
else if(flags&SWS_X) sizeFactor= 8.0;
else if(flags&SWS_AREA) sizeFactor= 1.0; //downscale only, for upscale it is bilinear
else if(flags&SWS_GAUSS) sizeFactor= 8.0; // infinite ;)
else if(flags&SWS_LANCZOS) sizeFactor= param ? 2.0*param : 6.0;
else if(flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? 2.0*param[0] : 6.0;
else if(flags&SWS_SINC) sizeFactor= 20.0; // infinite ;)
else if(flags&SWS_SPLINE) sizeFactor= 20.0; // infinite ;)
else if(flags&SWS_BILINEAR) sizeFactor= 2.0;
@ -890,13 +889,13 @@ static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *out
double coeff;
if(flags & SWS_BICUBIC)
{
double A= param ? -param*0.01 : -0.60;
// Equation is from VirtualDub
if(d<1.0)
coeff = (1.0 - (A+3.0)*d*d + (A+2.0)*d*d*d);
double B= param[0] != SWS_PARAM_DEFAULT ? param[0] : 0.0;
double C= param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6;
if(d<1.0)
coeff = (12-9*B-6*C)*d*d*d + (-18+12*B+6*C)*d*d + 6-2*B;
else if(d<2.0)
coeff = (-4.0*A + 8.0*A*d - 5.0*A*d*d + A*d*d*d);
coeff = (-B-6*C)*d*d*d + (6*B+30*C)*d*d + (-12*B-48*C)*d +8*B+24*C;
else
coeff=0.0;
}
@ -908,7 +907,7 @@ static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *out
}*/
else if(flags & SWS_X)
{
double A= param ? param*0.1 : 1.0;
double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;
if(d<1.0)
coeff = cos(d*PI);
@ -927,7 +926,7 @@ static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *out
}
else if(flags & SWS_GAUSS)
{
double p= param ? param*0.1 : 3.0;
double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
coeff = pow(2.0, - p*d*d);
}
else if(flags & SWS_SINC)
@ -936,7 +935,7 @@ static inline void initFilter(int16_t **outFilter, int16_t **filterPos, int *out
}
else if(flags & SWS_LANCZOS)
{
double p= param ? param : 3.0;
double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
coeff = d ? sin(d*PI)*sin(d*PI/p)/(d*d*PI*PI/p) : 1.0;
if(d>p) coeff=0;
}
@ -1748,7 +1747,7 @@ int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int
}
SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int dstH, int origDstFormat, int flags,
SwsFilter *srcFilter, SwsFilter *dstFilter){
SwsFilter *srcFilter, SwsFilter *dstFilter, double *param){
SwsContext *c;
int i;
@ -1847,6 +1846,14 @@ SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int
if((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP))
c->chrSrcHSubSample=1;
if(param){
c->param[0] = param[0];
c->param[1] = param[1];
}else{
c->param[0] =
c->param[1] = SWS_PARAM_DEFAULT;
}
c->chrIntHSubSample= c->chrDstHSubSample;
c->chrIntVSubSample= c->chrSrcVSubSample;
@ -1982,11 +1989,11 @@ SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int
initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc,
srcW , dstW, filterAlign, 1<<14,
(flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags,
srcFilter->lumH, dstFilter->lumH);
srcFilter->lumH, dstFilter->lumH, c->param);
initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc,
c->chrSrcW, c->chrDstW, filterAlign, 1<<14,
(flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
srcFilter->chrH, dstFilter->chrH);
srcFilter->chrH, dstFilter->chrH, c->param);
#ifdef ARCH_X86
// can't downscale !!!
@ -2014,11 +2021,11 @@ SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int
initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc,
srcH , dstH, filterAlign, (1<<12)-4,
(flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags,
srcFilter->lumV, dstFilter->lumV);
srcFilter->lumV, dstFilter->lumV, c->param);
initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc,
c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4,
(flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
srcFilter->chrV, dstFilter->chrV);
srcFilter->chrV, dstFilter->chrV, c->param);
}
// Calculate Buffer Sizes so that they won't run out while handling these damn slices

View File

@ -45,8 +45,7 @@ extern "C" {
#define SWS_SRC_V_CHR_DROP_MASK 0x30000
#define SWS_SRC_V_CHR_DROP_SHIFT 16
#define SWS_PARAM_MASK 0x3FC0000
#define SWS_PARAM_SHIFT 18
#define SWS_PARAM_DEFAULT 123456
#define SWS_PRINT_INFO 0x1000
@ -94,7 +93,7 @@ struct SwsContext;
void sws_freeContext(struct SwsContext *swsContext);
struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
SwsFilter *srcFilter, SwsFilter *dstFilter);
SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[]);
int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,

View File

@ -54,6 +54,7 @@ typedef struct SwsContext{
int chrIntHSubSample, chrIntVSubSample;
int chrDstHSubSample, chrDstVSubSample;
int vChrDrop;
double param[2];
int16_t **lumPixBuf;
int16_t **chrPixBuf;

View File

@ -752,7 +752,7 @@ void sws_spu_image(unsigned char *d1, unsigned char *d2, int dw, int dh, int ds,
oldvar = spu_gaussvar;
}
ctx=sws_getContext(sw, sh, IMGFMT_Y800, dw, dh, IMGFMT_Y800, SWS_GAUSS, &filter, NULL);
ctx=sws_getContext(sw, sh, IMGFMT_Y800, dw, dh, IMGFMT_Y800, SWS_GAUSS, &filter, NULL, NULL);
sws_scale(ctx,&s1,&ss,0,sh,&d1,&ds);
for (i=ss*sh-1; i>=0; i--) if (!s2[i]) s2[i] = 255; //else s2[i] = 1;
sws_scale(ctx,&s2,&ss,0,sh,&d2,&ds);