annotate libmpcodecs/vf_geq.c @ 36021:bc1d68f48ca5

Make gtkSetDefaultToCList() static. It only has file scope. Additionally, rename it gtkSelectInCList().
author ib
date Sun, 31 Mar 2013 17:38:13 +0000
parents d206960484fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
1 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
2 * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
3 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
4 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
7 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
9 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
10 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
14 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
15 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
16 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
19 */
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
20
5f216140e72b generic equation filter
michael
parents:
diff changeset
21 #include <stdio.h>
5f216140e72b generic equation filter
michael
parents:
diff changeset
22 #include <stdlib.h>
5f216140e72b generic equation filter
michael
parents:
diff changeset
23 #include <string.h>
5f216140e72b generic equation filter
michael
parents:
diff changeset
24 #include <math.h>
5f216140e72b generic equation filter
michael
parents:
diff changeset
25 #include <inttypes.h>
5f216140e72b generic equation filter
michael
parents:
diff changeset
26
5f216140e72b generic equation filter
michael
parents:
diff changeset
27 #include "config.h"
5f216140e72b generic equation filter
michael
parents:
diff changeset
28
5f216140e72b generic equation filter
michael
parents:
diff changeset
29 #include "mp_msg.h"
5f216140e72b generic equation filter
michael
parents:
diff changeset
30
24738
45189040161d Reorder #includes to get rid of the FIXME
zuxy
parents: 24737
diff changeset
31 #include "img_format.h"
45189040161d Reorder #includes to get rid of the FIXME
zuxy
parents: 24737
diff changeset
32 #include "mp_image.h"
45189040161d Reorder #includes to get rid of the FIXME
zuxy
parents: 24737
diff changeset
33 #include "vf.h"
45189040161d Reorder #includes to get rid of the FIXME
zuxy
parents: 24737
diff changeset
34
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
35 #include "libavcodec/avcodec.h"
35712
d206960484fe Add a number of missing libavutil header #includes.
diego
parents: 33183
diff changeset
36 #include "libavutil/common.h"
31256
0d03e9c53d26 Fix compilation after FFmpeg r23485.
cehoyos
parents: 31233
diff changeset
37 #include "libavutil/eval.h"
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
38
5f216140e72b generic equation filter
michael
parents:
diff changeset
39 struct vf_priv_s {
30987
e1483ae3d93c Fix build due to FFmpeg r22833 change (typedef rename).
iive
parents: 30642
diff changeset
40 AVExpr * e[3];
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
41 int framenum;
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
42 mp_image_t *mpi;
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
43 };
5f216140e72b generic equation filter
michael
parents:
diff changeset
44
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
45 static int config(struct vf_instance *vf,
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
46 int width, int height, int d_width, int d_height,
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
47 unsigned int flags, unsigned int outfmt){
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
48 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
49 }
5f216140e72b generic equation filter
michael
parents:
diff changeset
50
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
51 static inline double getpix(struct vf_instance *vf, double x, double y, int plane){
20270
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
52 int xi, yi;
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
53 mp_image_t *mpi= vf->priv->mpi;
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
54 int stride= mpi->stride[plane];
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
55 uint8_t *src= mpi->planes[plane];
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
56 xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1);
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
57 yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1);
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
58
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
59 x-=xi;
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
60 y-=yi;
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
61
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
62 return
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
63 (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride])
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
64 + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]);
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
65 }
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
66
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
67 //FIXME cubic interpolate
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
68 //FIXME keep the last few frames
31543
59a6592b57b7 Fix function prototypes to match the required type.
reimar
parents: 31256
diff changeset
69 static double lum(void *vf, double x, double y){
20270
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
70 return getpix(vf, x, y, 0);
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
71 }
5f216140e72b generic equation filter
michael
parents:
diff changeset
72
31543
59a6592b57b7 Fix function prototypes to match the required type.
reimar
parents: 31256
diff changeset
73 static double cb(void *vf, double x, double y){
20270
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
74 return getpix(vf, x, y, 1);
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
75 }
5f216140e72b generic equation filter
michael
parents:
diff changeset
76
31543
59a6592b57b7 Fix function prototypes to match the required type.
reimar
parents: 31256
diff changeset
77 static double cr(void *vf, double x, double y){
20270
eaddc65c500a bilinear interpolation
michael
parents: 20268
diff changeset
78 return getpix(vf, x, y, 2);
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
79 }
5f216140e72b generic equation filter
michael
parents:
diff changeset
80
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
81 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
82 mp_image_t *dmpi;
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
83 int x,y, plane;
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
84
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
85 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
86 // no DR, so get a new image! hope we'll get DR buffer:
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
87 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
88 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
89 mpi->w,mpi->h);
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
90 }
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
91
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
92 dmpi= vf->dmpi;
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
93 vf->priv->mpi= mpi;
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
94
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
95 vf_clone_mpi_attributes(dmpi, mpi);
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
96
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
97 for(plane=0; plane<3; plane++){
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
98 int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0);
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
99 int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0);
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
100 uint8_t *dst = dmpi->planes[plane];
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
101 int dst_stride= dmpi->stride[plane];
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
102 double const_values[]={
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
103 M_PI,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
104 M_E,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
105 0,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
106 0,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
107 w,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
108 h,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
109 vf->priv->framenum,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
110 w/(double)mpi->w,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
111 h/(double)mpi->h,
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
112 0
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
113 };
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
114 if (!vf->priv->e[plane]) continue;
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
115 for(y=0; y<h; y++){
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
116 const_values[3]=y;
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
117 for(x=0; x<w; x++){
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
118 const_values[2]=x;
33183
d676ffcbc45f vf_geq: Fix FFmpeg API usage; eliminates some deprecation warnings.
diego
parents: 33173
diff changeset
119 dst[x + y * dst_stride] = av_expr_eval(vf->priv->e[plane],
30989
686241d65b86 Fix build after FFmpeg symbol rename:
diego
parents: 30987
diff changeset
120 const_values, vf);
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
121 }
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
122 }
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
123 }
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
124
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
125 vf->priv->framenum++;
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
126
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
127 return vf_next_put_image(vf,dmpi, pts);
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
128 }
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
129
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
130 static void uninit(struct vf_instance *vf){
20456
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
131 av_free(vf->priv);
52b0d09d347a cosmetic, reindentation, tab removal
ods15
parents: 20455
diff changeset
132 vf->priv=NULL;
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
133 }
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
134
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
135 //===========================================================================//
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 27694
diff changeset
136 static int vf_open(vf_instance_t *vf, char *args){
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
137 char eq[3][2000] = { { 0 }, { 0 }, { 0 } };
31233
01fdbb0aaa5c Fix compilation after FFmpeg r23402.
cehoyos
parents: 31130
diff changeset
138 int plane, res;
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
139
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
140 vf->config=config;
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
141 vf->put_image=put_image;
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
142 // vf->get_image=get_image;
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
143 vf->uninit=uninit;
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
144 vf->priv=av_malloc(sizeof(struct vf_priv_s));
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
145 memset(vf->priv, 0, sizeof(struct vf_priv_s));
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
146
20466
a5d299e877b2 make vf_geq read whitespace in equation param
ods15
parents: 20457
diff changeset
147 if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]);
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
148
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
149 if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1);
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
150 if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1);
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
151
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
152 for(plane=0; plane<3; plane++){
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
153 static const char *const_names[]={
5f216140e72b generic equation filter
michael
parents:
diff changeset
154 "PI",
5f216140e72b generic equation filter
michael
parents:
diff changeset
155 "E",
5f216140e72b generic equation filter
michael
parents:
diff changeset
156 "X",
5f216140e72b generic equation filter
michael
parents:
diff changeset
157 "Y",
5f216140e72b generic equation filter
michael
parents:
diff changeset
158 "W",
5f216140e72b generic equation filter
michael
parents:
diff changeset
159 "H",
5f216140e72b generic equation filter
michael
parents:
diff changeset
160 "N",
5f216140e72b generic equation filter
michael
parents:
diff changeset
161 "SW",
5f216140e72b generic equation filter
michael
parents:
diff changeset
162 "SH",
5f216140e72b generic equation filter
michael
parents:
diff changeset
163 NULL
5f216140e72b generic equation filter
michael
parents:
diff changeset
164 };
5f216140e72b generic equation filter
michael
parents:
diff changeset
165 static const char *func2_names[]={
5f216140e72b generic equation filter
michael
parents:
diff changeset
166 "lum",
5f216140e72b generic equation filter
michael
parents:
diff changeset
167 "cb",
5f216140e72b generic equation filter
michael
parents:
diff changeset
168 "cr",
5f216140e72b generic equation filter
michael
parents:
diff changeset
169 "p",
5f216140e72b generic equation filter
michael
parents:
diff changeset
170 NULL
5f216140e72b generic equation filter
michael
parents:
diff changeset
171 };
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
172 double (*func2[])(void *, double, double)={
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
173 lum,
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
174 cb,
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
175 cr,
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
176 plane==0 ? lum : (plane==1 ? cb : cr),
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
177 NULL
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
178 };
33183
d676ffcbc45f vf_geq: Fix FFmpeg API usage; eliminates some deprecation warnings.
diego
parents: 33173
diff changeset
179 res = av_expr_parse(&vf->priv->e[plane], eq[plane], const_names, NULL, NULL, func2_names, func2, 0, NULL);
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
180
31233
01fdbb0aaa5c Fix compilation after FFmpeg r23402.
cehoyos
parents: 31130
diff changeset
181 if (res < 0) {
31130
d1f5069bef25 Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents: 30991
diff changeset
182 mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s'\n", eq[plane]);
d1f5069bef25 Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents: 30991
diff changeset
183 return 0;
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
184 }
20455
e36737b5ec2f update vf_geq to new ff_eval API
ods15
parents: 20270
diff changeset
185 }
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
186
5f216140e72b generic equation filter
michael
parents:
diff changeset
187 return 1;
5f216140e72b generic equation filter
michael
parents:
diff changeset
188 }
5f216140e72b generic equation filter
michael
parents:
diff changeset
189
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24975
diff changeset
190 const vf_info_t vf_info_geq = {
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
191 "generic equation filter",
5f216140e72b generic equation filter
michael
parents:
diff changeset
192 "geq",
5f216140e72b generic equation filter
michael
parents:
diff changeset
193 "Michael Niedermayer",
5f216140e72b generic equation filter
michael
parents:
diff changeset
194 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 27694
diff changeset
195 vf_open,
20266
5f216140e72b generic equation filter
michael
parents:
diff changeset
196 NULL
5f216140e72b generic equation filter
michael
parents:
diff changeset
197 };