Mercurial > mplayer.hg
annotate libmpcodecs/vf_geq.c @ 25194:e816d546c4fe
ao_null: Make duration of "buffered" audio constant
Choose the "buffer size" for the amount of audio the driver accepts so
that it corresponds to about 0.2 seconds of playback based on the
number of channels, sample size and samplerate.
author | uau |
---|---|
date | Sat, 01 Dec 2007 01:39:39 +0000 |
parents | 72466750cdcd |
children | 00fff9a3b735 |
rev | line source |
---|---|
20266 | 1 /* |
2 Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at> | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <math.h> | |
23 #include <inttypes.h> | |
24 | |
25 #include "config.h" | |
26 | |
27 #include "mp_msg.h" | |
28 #include "cpudetect.h" | |
29 | |
24738 | 30 #include "img_format.h" |
31 #include "mp_image.h" | |
32 #include "vf.h" | |
33 | |
20266 | 34 #define HAVE_AV_CONFIG_H |
35 #include "libavcodec/avcodec.h" | |
20455 | 36 #include "libavcodec/eval.h" |
20266 | 37 |
38 struct vf_priv_s { | |
20456 | 39 AVEvalExpr * e[3]; |
40 int framenum; | |
41 mp_image_t *mpi; | |
20266 | 42 }; |
43 | |
44 static int config(struct vf_instance_s* vf, | |
45 int width, int height, int d_width, int d_height, | |
20456 | 46 unsigned int flags, unsigned int outfmt){ |
47 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
20266 | 48 } |
49 | |
23219
cdf6ab5cf76d
Fix "inline keyword not at beginning of declaration" warning.
diego
parents:
20466
diff
changeset
|
50 static inline double getpix(struct vf_instance_s* vf, double x, double y, int plane){ |
20270 | 51 int xi, yi; |
52 mp_image_t *mpi= vf->priv->mpi; | |
53 int stride= mpi->stride[plane]; | |
54 uint8_t *src= mpi->planes[plane]; | |
55 xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1); | |
56 yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1); | |
57 | |
58 x-=xi; | |
59 y-=yi; | |
60 | |
61 return | |
62 (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride]) | |
63 + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]); | |
64 } | |
65 | |
66 //FIXME cubic interpolate | |
20266 | 67 //FIXME keep the last few frames |
68 static double lum(struct vf_instance_s* vf, double x, double y){ | |
20270 | 69 return getpix(vf, x, y, 0); |
20266 | 70 } |
71 | |
72 static double cb(struct vf_instance_s* vf, double x, double y){ | |
20270 | 73 return getpix(vf, x, y, 1); |
20266 | 74 } |
75 | |
76 static double cr(struct vf_instance_s* vf, double x, double y){ | |
20270 | 77 return getpix(vf, x, y, 2); |
20266 | 78 } |
79 | |
80 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ | |
20456 | 81 mp_image_t *dmpi; |
82 int x,y, plane; | |
20455 | 83 |
20456 | 84 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
85 // no DR, so get a new image! hope we'll get DR buffer: | |
86 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, | |
87 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
88 mpi->w,mpi->h); | |
89 } | |
20455 | 90 |
20456 | 91 dmpi= vf->dmpi; |
92 vf->priv->mpi= mpi; | |
20455 | 93 |
20456 | 94 vf_clone_mpi_attributes(dmpi, mpi); |
20455 | 95 |
20456 | 96 for(plane=0; plane<3; plane++){ |
97 int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0); | |
98 int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0); | |
99 uint8_t *dst = dmpi->planes[plane]; | |
100 int dst_stride= dmpi->stride[plane]; | |
101 double const_values[]={ | |
102 M_PI, | |
103 M_E, | |
104 0, | |
105 0, | |
106 w, | |
107 h, | |
108 vf->priv->framenum, | |
109 w/(double)mpi->w, | |
110 h/(double)mpi->h, | |
111 0 | |
112 }; | |
113 if (!vf->priv->e[plane]) continue; | |
114 for(y=0; y<h; y++){ | |
115 const_values[3]=y; | |
116 for(x=0; x<w; x++){ | |
117 const_values[2]=x; | |
118 dst[x+y* dst_stride]= ff_parse_eval(vf->priv->e[plane], const_values, vf); | |
20455 | 119 } |
120 } | |
20456 | 121 } |
20455 | 122 |
20456 | 123 vf->priv->framenum++; |
20455 | 124 |
20456 | 125 return vf_next_put_image(vf,dmpi, pts); |
20455 | 126 } |
127 | |
128 static void uninit(struct vf_instance_s* vf){ | |
20456 | 129 if(!vf->priv) return; |
20455 | 130 |
20456 | 131 av_free(vf->priv); |
132 vf->priv=NULL; | |
20455 | 133 } |
134 | |
135 //===========================================================================// | |
136 static int open(vf_instance_t *vf, char* args){ | |
137 char eq[3][2000] = { { 0 }, { 0 }, { 0 } }; | |
138 int plane; | |
139 | |
140 vf->config=config; | |
141 vf->put_image=put_image; | |
142 // vf->get_image=get_image; | |
143 vf->uninit=uninit; | |
144 vf->priv=av_malloc(sizeof(struct vf_priv_s)); | |
145 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
146 | |
20466 | 147 if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]); |
20455 | 148 |
149 if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1); | |
150 if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1); | |
151 | |
152 for(plane=0; plane<3; plane++){ | |
20266 | 153 static const char *const_names[]={ |
154 "PI", | |
155 "E", | |
156 "X", | |
157 "Y", | |
158 "W", | |
159 "H", | |
160 "N", | |
161 "SW", | |
162 "SH", | |
163 NULL | |
164 }; | |
165 static const char *func2_names[]={ | |
166 "lum", | |
167 "cb", | |
168 "cr", | |
169 "p", | |
170 NULL | |
171 }; | |
20455 | 172 double (*func2[])(void *, double, double)={ |
173 lum, | |
174 cb, | |
175 cr, | |
176 plane==0 ? lum : (plane==1 ? cb : cr), | |
177 NULL | |
178 }; | |
179 char * a; | |
180 vf->priv->e[plane] = ff_parse(eq[plane], const_names, NULL, NULL, func2, func2_names, &a); | |
20266 | 181 |
20455 | 182 if (!vf->priv->e[plane]) { |
183 mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s': %s\n", eq[plane], a); | |
20266 | 184 } |
20455 | 185 } |
20266 | 186 |
187 return 1; | |
188 } | |
189 | |
190 vf_info_t vf_info_geq = { | |
191 "generic equation filter", | |
192 "geq", | |
193 "Michael Niedermayer", | |
194 "", | |
195 open, | |
196 NULL | |
197 }; |