41 #define SUB_PIXEL_BITS 8
42 #define SUB_PIXELS (1<<SUB_PIXEL_BITS)
59 double a,
b,
c,d,e,f,
g,h,
D;
60 double (*ref)[2]= priv->
ref;
63 g= ( (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[2][1] - ref[3][1])
64 - (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[2][0] - ref[3][0]))*H;
65 h= ( (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[1][0] - ref[3][0])
66 - (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[1][1] - ref[3][1]))*W;
67 D= (ref[1][0] - ref[3][0])*(ref[2][1] - ref[3][1])
68 - (ref[2][0] - ref[3][0])*(ref[1][1] - ref[3][1]);
70 a= D*(ref[1][0] - ref[0][0])*H + g*ref[1][0];
71 b= D*(ref[2][0] - ref[0][0])*W + h*ref[2][0];
73 d= D*(ref[1][1] - ref[0][1])*H + g*ref[1][1];
74 e= D*(ref[2][1] - ref[0][1])*W + h*ref[2][1];
81 u= (int)floor(
SUB_PIXELS*(a*x + b*y + c)/(g*x + h*y + D*W*
H) + 0.5);
82 v= (int)floor(
SUB_PIXELS*(d*x + e*y + f)/(g*x + h*y + D*W*
H) + 0.5);
84 priv->
pv[x + y*
W][0]= u;
85 priv->
pv[x + y*
W][1]= v;
98 coeff = (1.0 - (A+3.0)*d*d + (A+2.0)*d*d*d);
100 coeff = (-4.0*A + 8.0*A*d - 5.0*A*d*d + A*d*d*d);
107 static int config(
struct vf_instance *vf,
109 unsigned int flags,
unsigned int outfmt){
112 vf->priv->pvStride=
width;
114 initPv(vf->priv, width, height);
117 double d= i/(double)SUB_PIXELS;
128 vf->priv->coeff[i][j]= (
int)floor((1<<
COEFF_BITS)*temp[j]/sum + 0.5);
134 static void uninit(
struct vf_instance *vf){
135 if(!vf->priv)
return;
150 int u, v, subU, subV,
sum, sx, sy;
161 if(u>0 && v>0 && u<w-2 && v<h-2){
162 const int index= u + v*srcStride;
163 const int a= priv.
coeff[subU][0];
164 const int b= priv.
coeff[subU][1];
165 const int c= priv.
coeff[subU][2];
166 const int d= priv.
coeff[subU][3];
169 priv.
coeff[subV][0]*( a*src[index - 1 - srcStride] + b*src[index - 0 - srcStride]
170 + c*src[index + 1 - srcStride] + d*src[index + 2 - srcStride])
171 +priv.
coeff[subV][1]*( a*src[index - 1 ] + b*src[index - 0 ]
172 + c*src[index + 1 ] + d*src[index + 2 ])
173 +priv.
coeff[subV][2]*( a*src[index - 1 + srcStride] + b*src[index - 0 + srcStride]
174 + c*src[index + 1 + srcStride] + d*src[index + 2 + srcStride])
175 +priv.
coeff[subV][3]*( a*src[index - 1+2*srcStride] + b*src[index - 0+2*srcStride]
176 + c*src[index + 1+2*srcStride] + d*src[index + 2+2*srcStride]);
181 for(dy=0; dy<4; dy++){
184 else if(iy>=h) iy=h-1;
185 for(dx=0; dx<4; dx++){
188 else if(ix>=w) ix=w-1;
190 sum+= priv.
coeff[subU][dx]*priv.
coeff[subV][dy]
191 *src[ ix + iy*srcStride];
200 dst[ x + y*dstStride]=
sum;
206 struct vf_priv_s *privParam,
int xShift,
int yShift){
212 int u, v, subU, subV,
sum, sx, sy,
index, subUI, subVI;
222 index= u + v*srcStride;
226 if((
unsigned)u < (unsigned)(w - 1)){
227 if((
unsigned)v < (unsigned)(h - 1)){
228 sum= subVI*(subUI*src[
index ] + subU*src[index +1])
229 +subV *(subUI*src[index+srcStride] + subU*src[index+srcStride+1]);
234 index= u + v*srcStride;
235 sum= subUI*src[
index] + subU*src[index+1];
239 if((
unsigned)v < (unsigned)(h - 1)){
242 index= u + v*srcStride;
243 sum= subVI*src[
index] + subV*src[index+srcStride];
250 index= u + v*srcStride;
258 dst[ x + y*dstStride]=
sum;
320 if(args==
NULL)
return 0;
322 e=sscanf(args,
"%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf:%d",
337 "perspective correcture",
339 "Michael Niedermayer",