Mercurial > mplayer.hg
annotate libmpcodecs/vf_geq.c @ 24020:918b0974e3a1
printf in mp_image.h was changed to fprintf in r17972.
author | cehoyos |
---|---|
date | Wed, 08 Aug 2007 23:28:29 +0000 |
parents | f8d4f8eff72b |
children | 90302c23df72 |
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 | |
30 // Needed to bring in lrintf. | |
31 #define HAVE_AV_CONFIG_H | |
32 | |
33 #include "libavcodec/avcodec.h" | |
34 #include "libavcodec/dsputil.h" | |
20455 | 35 #include "libavcodec/eval.h" |
20266 | 36 #include "libavutil/common.h" |
37 | |
24020
918b0974e3a1
printf in mp_image.h was changed to fprintf in r17972.
cehoyos
parents:
23373
diff
changeset
|
38 /* FIXME: common.h defines fprintf away when HAVE_AV_CONFIG |
918b0974e3a1
printf in mp_image.h was changed to fprintf in r17972.
cehoyos
parents:
23373
diff
changeset
|
39 * is defined, but mp_image.h needs fprintf. |
20266 | 40 */ |
24020
918b0974e3a1
printf in mp_image.h was changed to fprintf in r17972.
cehoyos
parents:
23373
diff
changeset
|
41 #undef fprintf |
20266 | 42 |
43 #ifdef HAVE_MALLOC_H | |
44 #include <malloc.h> | |
45 #endif | |
46 | |
47 #include "img_format.h" | |
48 #include "mp_image.h" | |
49 #include "vf.h" | |
50 | |
51 | |
52 struct vf_priv_s { | |
20456 | 53 AVEvalExpr * e[3]; |
54 int framenum; | |
55 mp_image_t *mpi; | |
20266 | 56 }; |
57 | |
58 static int config(struct vf_instance_s* vf, | |
59 int width, int height, int d_width, int d_height, | |
20456 | 60 unsigned int flags, unsigned int outfmt){ |
61 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
20266 | 62 } |
63 | |
64 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
65 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
66 // ok, we can do pp in-place (or pp disabled): | |
67 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
68 mpi->type, mpi->flags, mpi->w, mpi->h); | |
69 mpi->planes[0]=vf->dmpi->planes[0]; | |
70 mpi->stride[0]=vf->dmpi->stride[0]; | |
71 mpi->width=vf->dmpi->width; | |
72 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
73 mpi->planes[1]=vf->dmpi->planes[1]; | |
74 mpi->planes[2]=vf->dmpi->planes[2]; | |
20456 | 75 mpi->stride[1]=vf->dmpi->stride[1]; |
76 mpi->stride[2]=vf->dmpi->stride[2]; | |
20266 | 77 } |
78 mpi->flags|=MP_IMGFLAG_DIRECT; | |
79 } | |
80 | |
23219
cdf6ab5cf76d
Fix "inline keyword not at beginning of declaration" warning.
diego
parents:
20466
diff
changeset
|
81 static inline double getpix(struct vf_instance_s* vf, double x, double y, int plane){ |
20270 | 82 int xi, yi; |
83 mp_image_t *mpi= vf->priv->mpi; | |
84 int stride= mpi->stride[plane]; | |
85 uint8_t *src= mpi->planes[plane]; | |
86 xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1); | |
87 yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1); | |
88 | |
89 x-=xi; | |
90 y-=yi; | |
91 | |
92 return | |
93 (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride]) | |
94 + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]); | |
95 } | |
96 | |
97 //FIXME cubic interpolate | |
20266 | 98 //FIXME keep the last few frames |
99 static double lum(struct vf_instance_s* vf, double x, double y){ | |
20270 | 100 return getpix(vf, x, y, 0); |
20266 | 101 } |
102 | |
103 static double cb(struct vf_instance_s* vf, double x, double y){ | |
20270 | 104 return getpix(vf, x, y, 1); |
20266 | 105 } |
106 | |
107 static double cr(struct vf_instance_s* vf, double x, double y){ | |
20270 | 108 return getpix(vf, x, y, 2); |
20266 | 109 } |
110 | |
111 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ | |
20456 | 112 mp_image_t *dmpi; |
113 int x,y, plane; | |
20455 | 114 |
20456 | 115 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
116 // no DR, so get a new image! hope we'll get DR buffer: | |
117 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, | |
118 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
119 mpi->w,mpi->h); | |
120 } | |
20455 | 121 |
20456 | 122 dmpi= vf->dmpi; |
123 vf->priv->mpi= mpi; | |
20455 | 124 |
20456 | 125 vf_clone_mpi_attributes(dmpi, mpi); |
20455 | 126 |
20456 | 127 for(plane=0; plane<3; plane++){ |
128 int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0); | |
129 int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0); | |
130 uint8_t *dst = dmpi->planes[plane]; | |
131 int dst_stride= dmpi->stride[plane]; | |
132 double const_values[]={ | |
133 M_PI, | |
134 M_E, | |
135 0, | |
136 0, | |
137 w, | |
138 h, | |
139 vf->priv->framenum, | |
140 w/(double)mpi->w, | |
141 h/(double)mpi->h, | |
142 0 | |
143 }; | |
144 if (!vf->priv->e[plane]) continue; | |
145 for(y=0; y<h; y++){ | |
146 const_values[3]=y; | |
147 for(x=0; x<w; x++){ | |
148 const_values[2]=x; | |
149 dst[x+y* dst_stride]= ff_parse_eval(vf->priv->e[plane], const_values, vf); | |
20455 | 150 } |
151 } | |
20456 | 152 } |
20455 | 153 |
20456 | 154 vf->priv->framenum++; |
20455 | 155 |
20456 | 156 return vf_next_put_image(vf,dmpi, pts); |
20455 | 157 } |
158 | |
159 static void uninit(struct vf_instance_s* vf){ | |
20456 | 160 if(!vf->priv) return; |
20455 | 161 |
20456 | 162 av_free(vf->priv); |
163 vf->priv=NULL; | |
20455 | 164 } |
165 | |
166 //===========================================================================// | |
167 static int open(vf_instance_t *vf, char* args){ | |
168 char eq[3][2000] = { { 0 }, { 0 }, { 0 } }; | |
169 int plane; | |
170 | |
171 vf->config=config; | |
172 vf->put_image=put_image; | |
173 // vf->get_image=get_image; | |
174 vf->uninit=uninit; | |
175 vf->priv=av_malloc(sizeof(struct vf_priv_s)); | |
176 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
177 | |
20466 | 178 if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]); |
20455 | 179 |
180 if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1); | |
181 if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1); | |
182 | |
183 for(plane=0; plane<3; plane++){ | |
20266 | 184 static const char *const_names[]={ |
185 "PI", | |
186 "E", | |
187 "X", | |
188 "Y", | |
189 "W", | |
190 "H", | |
191 "N", | |
192 "SW", | |
193 "SH", | |
194 NULL | |
195 }; | |
196 static const char *func2_names[]={ | |
197 "lum", | |
198 "cb", | |
199 "cr", | |
200 "p", | |
201 NULL | |
202 }; | |
20455 | 203 double (*func2[])(void *, double, double)={ |
204 lum, | |
205 cb, | |
206 cr, | |
207 plane==0 ? lum : (plane==1 ? cb : cr), | |
208 NULL | |
209 }; | |
210 char * a; | |
211 vf->priv->e[plane] = ff_parse(eq[plane], const_names, NULL, NULL, func2, func2_names, &a); | |
20266 | 212 |
20455 | 213 if (!vf->priv->e[plane]) { |
214 mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s': %s\n", eq[plane], a); | |
20266 | 215 } |
20455 | 216 } |
20266 | 217 |
218 return 1; | |
219 } | |
220 | |
221 vf_info_t vf_info_geq = { | |
222 "generic equation filter", | |
223 "geq", | |
224 "Michael Niedermayer", | |
225 "", | |
226 open, | |
227 NULL | |
228 }; |