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