Mercurial > mplayer.hg
annotate libmpcodecs/vf_geq.c @ 24930:17fe71259132
add some updates
author | compn |
---|---|
date | Sat, 03 Nov 2007 19:14:16 +0000 |
parents | 14e4e1ca7988 |
children | 72466750cdcd |
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 // Needed to bring in lrintf. |
35 #define HAVE_AV_CONFIG_H | |
36 | |
37 #include "libavcodec/avcodec.h" | |
38 #include "libavcodec/dsputil.h" | |
20455 | 39 #include "libavcodec/eval.h" |
20266 | 40 #include "libavutil/common.h" |
41 | |
42 struct vf_priv_s { | |
20456 | 43 AVEvalExpr * e[3]; |
44 int framenum; | |
45 mp_image_t *mpi; | |
20266 | 46 }; |
47 | |
48 static int config(struct vf_instance_s* vf, | |
49 int width, int height, int d_width, int d_height, | |
20456 | 50 unsigned int flags, unsigned int outfmt){ |
51 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
20266 | 52 } |
53 | |
23219
cdf6ab5cf76d
Fix "inline keyword not at beginning of declaration" warning.
diego
parents:
20466
diff
changeset
|
54 static inline double getpix(struct vf_instance_s* vf, double x, double y, int plane){ |
20270 | 55 int xi, yi; |
56 mp_image_t *mpi= vf->priv->mpi; | |
57 int stride= mpi->stride[plane]; | |
58 uint8_t *src= mpi->planes[plane]; | |
59 xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1); | |
60 yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1); | |
61 | |
62 x-=xi; | |
63 y-=yi; | |
64 | |
65 return | |
66 (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride]) | |
67 + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]); | |
68 } | |
69 | |
70 //FIXME cubic interpolate | |
20266 | 71 //FIXME keep the last few frames |
72 static double lum(struct vf_instance_s* vf, double x, double y){ | |
20270 | 73 return getpix(vf, x, y, 0); |
20266 | 74 } |
75 | |
76 static double cb(struct vf_instance_s* vf, double x, double y){ | |
20270 | 77 return getpix(vf, x, y, 1); |
20266 | 78 } |
79 | |
80 static double cr(struct vf_instance_s* vf, double x, double y){ | |
20270 | 81 return getpix(vf, x, y, 2); |
20266 | 82 } |
83 | |
84 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ | |
20456 | 85 mp_image_t *dmpi; |
86 int x,y, plane; | |
20455 | 87 |
20456 | 88 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
89 // no DR, so get a new image! hope we'll get DR buffer: | |
90 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, | |
91 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
92 mpi->w,mpi->h); | |
93 } | |
20455 | 94 |
20456 | 95 dmpi= vf->dmpi; |
96 vf->priv->mpi= mpi; | |
20455 | 97 |
20456 | 98 vf_clone_mpi_attributes(dmpi, mpi); |
20455 | 99 |
20456 | 100 for(plane=0; plane<3; plane++){ |
101 int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0); | |
102 int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0); | |
103 uint8_t *dst = dmpi->planes[plane]; | |
104 int dst_stride= dmpi->stride[plane]; | |
105 double const_values[]={ | |
106 M_PI, | |
107 M_E, | |
108 0, | |
109 0, | |
110 w, | |
111 h, | |
112 vf->priv->framenum, | |
113 w/(double)mpi->w, | |
114 h/(double)mpi->h, | |
115 0 | |
116 }; | |
117 if (!vf->priv->e[plane]) continue; | |
118 for(y=0; y<h; y++){ | |
119 const_values[3]=y; | |
120 for(x=0; x<w; x++){ | |
121 const_values[2]=x; | |
122 dst[x+y* dst_stride]= ff_parse_eval(vf->priv->e[plane], const_values, vf); | |
20455 | 123 } |
124 } | |
20456 | 125 } |
20455 | 126 |
20456 | 127 vf->priv->framenum++; |
20455 | 128 |
20456 | 129 return vf_next_put_image(vf,dmpi, pts); |
20455 | 130 } |
131 | |
132 static void uninit(struct vf_instance_s* vf){ | |
20456 | 133 if(!vf->priv) return; |
20455 | 134 |
20456 | 135 av_free(vf->priv); |
136 vf->priv=NULL; | |
20455 | 137 } |
138 | |
139 //===========================================================================// | |
140 static int open(vf_instance_t *vf, char* args){ | |
141 char eq[3][2000] = { { 0 }, { 0 }, { 0 } }; | |
142 int plane; | |
143 | |
144 vf->config=config; | |
145 vf->put_image=put_image; | |
146 // vf->get_image=get_image; | |
147 vf->uninit=uninit; | |
148 vf->priv=av_malloc(sizeof(struct vf_priv_s)); | |
149 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
150 | |
20466 | 151 if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]); |
20455 | 152 |
153 if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1); | |
154 if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1); | |
155 | |
156 for(plane=0; plane<3; plane++){ | |
20266 | 157 static const char *const_names[]={ |
158 "PI", | |
159 "E", | |
160 "X", | |
161 "Y", | |
162 "W", | |
163 "H", | |
164 "N", | |
165 "SW", | |
166 "SH", | |
167 NULL | |
168 }; | |
169 static const char *func2_names[]={ | |
170 "lum", | |
171 "cb", | |
172 "cr", | |
173 "p", | |
174 NULL | |
175 }; | |
20455 | 176 double (*func2[])(void *, double, double)={ |
177 lum, | |
178 cb, | |
179 cr, | |
180 plane==0 ? lum : (plane==1 ? cb : cr), | |
181 NULL | |
182 }; | |
183 char * a; | |
184 vf->priv->e[plane] = ff_parse(eq[plane], const_names, NULL, NULL, func2, func2_names, &a); | |
20266 | 185 |
20455 | 186 if (!vf->priv->e[plane]) { |
187 mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s': %s\n", eq[plane], a); | |
20266 | 188 } |
20455 | 189 } |
20266 | 190 |
191 return 1; | |
192 } | |
193 | |
194 vf_info_t vf_info_geq = { | |
195 "generic equation filter", | |
196 "geq", | |
197 "Michael Niedermayer", | |
198 "", | |
199 open, | |
200 NULL | |
201 }; |