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