annotate libmpcodecs/vf_perspective.c @ 19318:a3ddd3320b47

removed udp socket creation code from rtp stack to a new dedicated udp helper file
author ben
date Fri, 04 Aug 2006 19:31:53 +0000
parents 20aca9baf5d8
children f8d4f8eff72b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
1 /*
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
2 Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
3
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
7 (at your option) any later version.
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
8
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
12 GNU General Public License for more details.
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
13
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
15 along with this program; if not, write to the Free Software
17367
401b440a6d76 Update licensing information: The FSF changed postal address.
diego
parents: 17012
diff changeset
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
17 */
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
18
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
19 #include <stdio.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
20 #include <stdlib.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
21 #include <string.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
22 #include <inttypes.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
23 #include <assert.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
24 #include <math.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
25
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
26 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
27 #include "mp_msg.h"
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
28
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
29 #ifdef HAVE_MALLOC_H
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
30 #include <malloc.h>
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
31 #endif
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
32
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
33 #include "img_format.h"
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
34 #include "mp_image.h"
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
35 #include "vf.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
36 #include "libvo/fastmemcpy.h"
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
37
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
38 #define SUB_PIXEL_BITS 8
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
39 #define SUB_PIXELS (1<<SUB_PIXEL_BITS)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
40 #define COEFF_BITS 11
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
41
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
42 //===========================================================================//
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
43
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
44 struct vf_priv_s {
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
45 double ref[4][2];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
46 int32_t coeff[1<<SUB_PIXEL_BITS][4];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
47 int32_t (*pv)[2];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
48 int pvStride;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
49 int cubic;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
50 };
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
51
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
52
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
53 /***************************************************************************/
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
54
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
55 static void initPv(struct vf_priv_s *priv, int W, int H){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
56 double a,b,c,d,e,f,g,h,D;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
57 double (*ref)[2]= priv->ref;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
58 int x,y;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
59
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
60 g= ( (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[2][1] - ref[3][1])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
61 - (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[2][0] - ref[3][0]))*H;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
62 h= ( (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[1][0] - ref[3][0])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
63 - (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[1][1] - ref[3][1]))*W;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
64 D= (ref[1][0] - ref[3][0])*(ref[2][1] - ref[3][1])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
65 - (ref[2][0] - ref[3][0])*(ref[1][1] - ref[3][1]);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
66
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
67 a= D*(ref[1][0] - ref[0][0])*H + g*ref[1][0];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
68 b= D*(ref[2][0] - ref[0][0])*W + h*ref[2][0];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
69 c= D*ref[0][0]*W*H;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
70 d= D*(ref[1][1] - ref[0][1])*H + g*ref[1][1];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
71 e= D*(ref[2][1] - ref[0][1])*W + h*ref[2][1];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
72 f= D*ref[0][1]*W*H;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
73
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
74 for(y=0; y<H; y++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
75 for(x=0; x<W; x++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
76 int u, v;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
77
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
78 u= (int)floor( SUB_PIXELS*(a*x + b*y + c)/(g*x + h*y + D*W*H) + 0.5);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
79 v= (int)floor( SUB_PIXELS*(d*x + e*y + f)/(g*x + h*y + D*W*H) + 0.5);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
80
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
81 priv->pv[x + y*W][0]= u;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
82 priv->pv[x + y*W][1]= v;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
83 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
84 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
85 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
86
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
87 static double getCoeff(double d){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
88 double A= -0.60;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
89 double coeff;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
90
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
91 d= fabs(d);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
92
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
93 // Equation is from VirtualDub
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
94 if(d<1.0)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
95 coeff = (1.0 - (A+3.0)*d*d + (A+2.0)*d*d*d);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
96 else if(d<2.0)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
97 coeff = (-4.0*A + 8.0*A*d - 5.0*A*d*d + A*d*d*d);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
98 else
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
99 coeff=0.0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
100
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
101 return coeff;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
102 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
103
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
104 static int config(struct vf_instance_s* vf,
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
105 int width, int height, int d_width, int d_height,
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
106 unsigned int flags, unsigned int outfmt){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
107 int i, j;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
108
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
109 vf->priv->pvStride= width;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
110 vf->priv->pv= (void*)memalign(8, width*height*2*sizeof(int32_t));
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
111 initPv(vf->priv, width, height);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
113 for(i=0; i<SUB_PIXELS; i++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
114 double d= i/(double)SUB_PIXELS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
115 double temp[4];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
116 double sum=0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
117
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
118 for(j=0; j<4; j++)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
119 temp[j]= getCoeff(j - d - 1);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
120
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
121 for(j=0; j<4; j++)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
122 sum+= temp[j];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
123
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
124 for(j=0; j<4; j++)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
125 vf->priv->coeff[i][j]= (int)floor((1<<COEFF_BITS)*temp[j]/sum + 0.5);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
126 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
127
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
128 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
129 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
130
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
131 static void uninit(struct vf_instance_s* vf){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
132 if(!vf->priv) return;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
133
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
134 if(vf->priv->pv) free(vf->priv->pv);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
135 vf->priv->pv= NULL;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
136
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
137 free(vf->priv);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
138 vf->priv=NULL;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
139 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
140
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
141 static inline void resampleCubic(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, struct vf_priv_s *privParam, int xShift, int yShift){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
142 int x, y;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
143 struct vf_priv_s priv= *privParam;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
144
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
145 for(y=0; y<h; y++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
146 for(x=0; x<w; x++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
147 int u, v, subU, subV, sum, sx, sy;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
148
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
149 sx= x << xShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
150 sy= y << yShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
151 u= priv.pv[sx + sy*priv.pvStride][0]>>xShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
152 v= priv.pv[sx + sy*priv.pvStride][1]>>yShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
153 subU= u & (SUB_PIXELS-1);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
154 subV= v & (SUB_PIXELS-1);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
155 u >>= SUB_PIXEL_BITS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
156 v >>= SUB_PIXEL_BITS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
157
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
158 if(u>0 && v>0 && u<w-2 && v<h-2){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
159 const int index= u + v*srcStride;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
160 const int a= priv.coeff[subU][0];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
161 const int b= priv.coeff[subU][1];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
162 const int c= priv.coeff[subU][2];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
163 const int d= priv.coeff[subU][3];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
164
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
165 sum=
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
166 priv.coeff[subV][0]*( a*src[index - 1 - srcStride] + b*src[index - 0 - srcStride]
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
167 + c*src[index + 1 - srcStride] + d*src[index + 2 - srcStride])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
168 +priv.coeff[subV][1]*( a*src[index - 1 ] + b*src[index - 0 ]
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
169 + c*src[index + 1 ] + d*src[index + 2 ])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
170 +priv.coeff[subV][2]*( a*src[index - 1 + srcStride] + b*src[index - 0 + srcStride]
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
171 + c*src[index + 1 + srcStride] + d*src[index + 2 + srcStride])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
172 +priv.coeff[subV][3]*( a*src[index - 1+2*srcStride] + b*src[index - 0+2*srcStride]
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
173 + c*src[index + 1+2*srcStride] + d*src[index + 2+2*srcStride]);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
174 }else{
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
175 int dx, dy;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
176 sum=0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
177
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
178 for(dy=0; dy<4; dy++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
179 int iy= v + dy - 1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
180 if (iy< 0) iy=0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
181 else if(iy>=h) iy=h-1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
182 for(dx=0; dx<4; dx++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
183 int ix= u + dx - 1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
184 if (ix< 0) ix=0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
185 else if(ix>=w) ix=w-1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
186
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
187 sum+= priv.coeff[subU][dx]*priv.coeff[subV][dy]
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
188 *src[ ix + iy*srcStride];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
189 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
190 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
191 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
192 sum= (sum + (1<<(COEFF_BITS*2-1)) ) >> (COEFF_BITS*2);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
193 if(sum&~255){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
194 if(sum<0) sum=0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
195 else sum=255;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
196 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
197 dst[ x + y*dstStride]= sum;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
198 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
199 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
200 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
201
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
202 static inline void resampleLinear(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride,
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
203 struct vf_priv_s *privParam, int xShift, int yShift){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
204 int x, y;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
205 struct vf_priv_s priv= *privParam;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
206
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
207 for(y=0; y<h; y++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
208 for(x=0; x<w; x++){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
209 int u, v, subU, subV, sum, sx, sy, index, subUI, subVI;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
210
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
211 sx= x << xShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
212 sy= y << yShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
213 u= priv.pv[sx + sy*priv.pvStride][0]>>xShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
214 v= priv.pv[sx + sy*priv.pvStride][1]>>yShift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
215 subU= u & (SUB_PIXELS-1);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
216 subV= v & (SUB_PIXELS-1);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
217 u >>= SUB_PIXEL_BITS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
218 v >>= SUB_PIXEL_BITS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
219 index= u + v*srcStride;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
220 subUI= SUB_PIXELS - subU;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
221 subVI= SUB_PIXELS - subV;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
222
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
223 if((unsigned)u < (unsigned)(w - 1)){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
224 if((unsigned)v < (unsigned)(h - 1)){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
225 sum= subVI*(subUI*src[index ] + subU*src[index +1])
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
226 +subV *(subUI*src[index+srcStride] + subU*src[index+srcStride+1]);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
227 sum= (sum + (1<<(SUB_PIXEL_BITS*2-1)) ) >> (SUB_PIXEL_BITS*2);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
228 }else{
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
229 if(v<0) v= 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
230 else v= h-1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
231 index= u + v*srcStride;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
232 sum= subUI*src[index] + subU*src[index+1];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
233 sum= (sum + (1<<(SUB_PIXEL_BITS-1)) ) >> SUB_PIXEL_BITS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
234 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
235 }else{
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
236 if((unsigned)v < (unsigned)(h - 1)){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
237 if(u<0) u= 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
238 else u= w-1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
239 index= u + v*srcStride;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
240 sum= subVI*src[index] + subV*src[index+srcStride];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
241 sum= (sum + (1<<(SUB_PIXEL_BITS-1)) ) >> SUB_PIXEL_BITS;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
242 }else{
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
243 if(u<0) u= 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
244 else u= w-1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
245 if(v<0) v= 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
246 else v= h-1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
247 index= u + v*srcStride;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
248 sum= src[index];
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
249 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
250 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
251 if(sum&~255){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
252 if(sum<0) sum=0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
253 else sum=255;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
254 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
255 dst[ x + y*dstStride]= sum;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
256 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
257 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
258 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
259
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17367
diff changeset
260 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
261 int cw= mpi->w >> mpi->chroma_x_shift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
262 int ch= mpi->h >> mpi->chroma_y_shift;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
263
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
264 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
265 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
266 mpi->w,mpi->h);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
267
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
268 assert(mpi->flags&MP_IMGFLAG_PLANAR);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
269
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
270 if(vf->priv->cubic){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
271 resampleCubic(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
272 vf->priv, 0, 0);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
273 resampleCubic(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
274 vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
275 resampleCubic(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
276 vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
277 }else{
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
278 resampleLinear(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
279 vf->priv, 0, 0);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
280 resampleLinear(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
281 vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
282 resampleLinear(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
283 vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
284 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
285
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17367
diff changeset
286 return vf_next_put_image(vf,dmpi, pts);
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
287 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
288
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
289 //===========================================================================//
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
290
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
291 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
292 switch(fmt)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
293 {
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
294 case IMGFMT_YV12:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
295 case IMGFMT_I420:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
296 case IMGFMT_IYUV:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
297 case IMGFMT_YVU9:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
298 case IMGFMT_444P:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
299 case IMGFMT_422P:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
300 case IMGFMT_411P:
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
301 return vf_next_query_format(vf, fmt);
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
302 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
303 return 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
304 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
305
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
306 static int open(vf_instance_t *vf, char* args){
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
307 int e;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
308
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
309 vf->config=config;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
310 vf->put_image=put_image;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
311 // vf->get_image=get_image;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
312 vf->query_format=query_format;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
313 vf->uninit=uninit;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
314 vf->priv=malloc(sizeof(struct vf_priv_s));
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
315 memset(vf->priv, 0, sizeof(struct vf_priv_s));
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
316
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
317 if(args==NULL) return 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
318
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
319 e=sscanf(args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf:%d",
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
320 &vf->priv->ref[0][0], &vf->priv->ref[0][1],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
321 &vf->priv->ref[1][0], &vf->priv->ref[1][1],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
322 &vf->priv->ref[2][0], &vf->priv->ref[2][1],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
323 &vf->priv->ref[3][0], &vf->priv->ref[3][1],
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
324 &vf->priv->cubic
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
325 );
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
326
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
327 if(e!=9)
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
328 return 0;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
329
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
330 return 1;
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
331 }
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
332
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
333 vf_info_t vf_info_perspective = {
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
334 "perspective correcture",
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
335 "perspective",
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
336 "Michael Niedermayer",
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
337 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 8112
diff changeset
338 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 8112
diff changeset
339 NULL
8112
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
340 };
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
341
6d97e935a071 perspective correcture filter
michael
parents:
diff changeset
342 //===========================================================================//