Mercurial > mplayer.hg
annotate libmpcodecs/vf_geq.c @ 34745:56ae910c2d34
Add H264QPEL flags for FFmpeg compilation.
author | reimar |
---|---|
date | Sun, 25 Mar 2012 22:05:07 +0000 |
parents | d676ffcbc45f |
children | d206960484fe |
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 | |
24738 | 31 #include "img_format.h" |
32 #include "mp_image.h" | |
33 #include "vf.h" | |
34 | |
20266 | 35 #include "libavcodec/avcodec.h" |
31256 | 36 #include "libavutil/eval.h" |
20266 | 37 |
38 struct vf_priv_s { | |
30987
e1483ae3d93c
Fix build due to FFmpeg r22833 change (typedef rename).
iive
parents:
30642
diff
changeset
|
39 AVExpr * e[3]; |
20456 | 40 int framenum; |
41 mp_image_t *mpi; | |
20266 | 42 }; |
43 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
44 static int config(struct vf_instance *vf, |
20266 | 45 int width, int height, int d_width, int d_height, |
20456 | 46 unsigned int flags, unsigned int outfmt){ |
47 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
20266 | 48 } |
49 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
50 static inline double getpix(struct vf_instance *vf, double x, double y, int plane){ |
20270 | 51 int xi, yi; |
52 mp_image_t *mpi= vf->priv->mpi; | |
53 int stride= mpi->stride[plane]; | |
54 uint8_t *src= mpi->planes[plane]; | |
55 xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1); | |
56 yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1); | |
57 | |
58 x-=xi; | |
59 y-=yi; | |
60 | |
61 return | |
62 (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride]) | |
63 + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]); | |
64 } | |
65 | |
66 //FIXME cubic interpolate | |
20266 | 67 //FIXME keep the last few frames |
31543
59a6592b57b7
Fix function prototypes to match the required type.
reimar
parents:
31256
diff
changeset
|
68 static double lum(void *vf, double x, double y){ |
20270 | 69 return getpix(vf, x, y, 0); |
20266 | 70 } |
71 | |
31543
59a6592b57b7
Fix function prototypes to match the required type.
reimar
parents:
31256
diff
changeset
|
72 static double cb(void *vf, double x, double y){ |
20270 | 73 return getpix(vf, x, y, 1); |
20266 | 74 } |
75 | |
31543
59a6592b57b7
Fix function prototypes to match the required type.
reimar
parents:
31256
diff
changeset
|
76 static double cr(void *vf, double x, double y){ |
20270 | 77 return getpix(vf, x, y, 2); |
20266 | 78 } |
79 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
80 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
20456 | 81 mp_image_t *dmpi; |
82 int x,y, plane; | |
20455 | 83 |
20456 | 84 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
85 // no DR, so get a new image! hope we'll get DR buffer: | |
86 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, | |
87 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
88 mpi->w,mpi->h); | |
89 } | |
20455 | 90 |
20456 | 91 dmpi= vf->dmpi; |
92 vf->priv->mpi= mpi; | |
20455 | 93 |
20456 | 94 vf_clone_mpi_attributes(dmpi, mpi); |
20455 | 95 |
20456 | 96 for(plane=0; plane<3; plane++){ |
97 int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0); | |
98 int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0); | |
99 uint8_t *dst = dmpi->planes[plane]; | |
100 int dst_stride= dmpi->stride[plane]; | |
101 double const_values[]={ | |
102 M_PI, | |
103 M_E, | |
104 0, | |
105 0, | |
106 w, | |
107 h, | |
108 vf->priv->framenum, | |
109 w/(double)mpi->w, | |
110 h/(double)mpi->h, | |
111 0 | |
112 }; | |
113 if (!vf->priv->e[plane]) continue; | |
114 for(y=0; y<h; y++){ | |
115 const_values[3]=y; | |
116 for(x=0; x<w; x++){ | |
117 const_values[2]=x; | |
33183
d676ffcbc45f
vf_geq: Fix FFmpeg API usage; eliminates some deprecation warnings.
diego
parents:
33173
diff
changeset
|
118 dst[x + y * dst_stride] = av_expr_eval(vf->priv->e[plane], |
30989 | 119 const_values, vf); |
20455 | 120 } |
121 } | |
20456 | 122 } |
20455 | 123 |
20456 | 124 vf->priv->framenum++; |
20455 | 125 |
20456 | 126 return vf_next_put_image(vf,dmpi, pts); |
20455 | 127 } |
128 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
129 static void uninit(struct vf_instance *vf){ |
20456 | 130 av_free(vf->priv); |
131 vf->priv=NULL; | |
20455 | 132 } |
133 | |
134 //===========================================================================// | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
27694
diff
changeset
|
135 static int vf_open(vf_instance_t *vf, char *args){ |
20455 | 136 char eq[3][2000] = { { 0 }, { 0 }, { 0 } }; |
31233 | 137 int plane, res; |
20455 | 138 |
139 vf->config=config; | |
140 vf->put_image=put_image; | |
141 // vf->get_image=get_image; | |
142 vf->uninit=uninit; | |
143 vf->priv=av_malloc(sizeof(struct vf_priv_s)); | |
144 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
145 | |
20466 | 146 if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]); |
20455 | 147 |
148 if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1); | |
149 if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1); | |
150 | |
151 for(plane=0; plane<3; plane++){ | |
20266 | 152 static const char *const_names[]={ |
153 "PI", | |
154 "E", | |
155 "X", | |
156 "Y", | |
157 "W", | |
158 "H", | |
159 "N", | |
160 "SW", | |
161 "SH", | |
162 NULL | |
163 }; | |
164 static const char *func2_names[]={ | |
165 "lum", | |
166 "cb", | |
167 "cr", | |
168 "p", | |
169 NULL | |
170 }; | |
20455 | 171 double (*func2[])(void *, double, double)={ |
172 lum, | |
173 cb, | |
174 cr, | |
175 plane==0 ? lum : (plane==1 ? cb : cr), | |
176 NULL | |
177 }; | |
33183
d676ffcbc45f
vf_geq: Fix FFmpeg API usage; eliminates some deprecation warnings.
diego
parents:
33173
diff
changeset
|
178 res = av_expr_parse(&vf->priv->e[plane], eq[plane], const_names, NULL, NULL, func2_names, func2, 0, NULL); |
20266 | 179 |
31233 | 180 if (res < 0) { |
31130
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30991
diff
changeset
|
181 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
|
182 return 0; |
20266 | 183 } |
20455 | 184 } |
20266 | 185 |
186 return 1; | |
187 } | |
188 | |
25221 | 189 const vf_info_t vf_info_geq = { |
20266 | 190 "generic equation filter", |
191 "geq", | |
192 "Michael Niedermayer", | |
193 "", | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
27694
diff
changeset
|
194 vf_open, |
20266 | 195 NULL |
196 }; |