Mercurial > mplayer.hg
annotate libmpcodecs/vf_smartblur.c @ 20132:a8aa764559fa
added a simple timer to hide the mouse when in fullscreen mode.
author | vayne |
---|---|
date | Mon, 09 Oct 2006 18:22:57 +0000 |
parents | 1e5cf11e8b1f |
children | bf1fbe97cc40 |
rev | line source |
---|---|
8106 | 1 /* |
2 Copyright (C) 2002 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 | |
17367
401b440a6d76
Update licensing information: The FSF changed postal address.
diego
parents:
17012
diff
changeset
|
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
8106 | 17 */ |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 #include <assert.h> | |
24 | |
17012 | 25 #include "config.h" |
26 #include "mp_msg.h" | |
8106 | 27 |
28 #ifdef HAVE_MALLOC_H | |
29 #include <malloc.h> | |
30 #endif | |
31 | |
19870
1e5cf11e8b1f
Use PIX_FMT_* instead of IMGFMT_* when calling sws_getContext()
lucabe
parents:
18861
diff
changeset
|
32 #include "avutil.h" |
8106 | 33 #include "img_format.h" |
34 #include "mp_image.h" | |
35 #include "vf.h" | |
17012 | 36 #include "libvo/fastmemcpy.h" |
18861 | 37 #include "libswscale/swscale.h" |
10233
35f52ad860a0
vf_scale.h & related cleanup & some small warning fix by dominik
michael
parents:
9975
diff
changeset
|
38 #include "vf_scale.h" |
8106 | 39 |
40 //===========================================================================// | |
41 | |
42 typedef struct FilterParam{ | |
43 float radius; | |
44 float strength; | |
45 int threshold; | |
46 float quality; | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
47 struct SwsContext *filterContext; |
8106 | 48 }FilterParam; |
49 | |
50 struct vf_priv_s { | |
51 FilterParam luma; | |
52 FilterParam chroma; | |
53 }; | |
54 | |
55 | |
56 /***************************************************************************/ | |
57 | |
58 //FIXME stupid code duplication | |
59 static void getSubSampleFactors(int *h, int *v, int format){ | |
60 switch(format){ | |
61 case IMGFMT_YV12: | |
62 case IMGFMT_I420: | |
63 *h=1; | |
64 *v=1; | |
65 break; | |
66 case IMGFMT_YVU9: | |
67 *h=2; | |
68 *v=2; | |
69 break; | |
70 case IMGFMT_444P: | |
71 *h=0; | |
72 *v=0; | |
73 break; | |
74 case IMGFMT_422P: | |
75 *h=1; | |
76 *v=0; | |
77 break; | |
78 case IMGFMT_411P: | |
79 *h=2; | |
80 *v=0; | |
81 break; | |
82 } | |
83 } | |
84 | |
85 static int allocStuff(FilterParam *f, int width, int height){ | |
86 SwsVector *vec; | |
87 SwsFilter swsF; | |
88 | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
89 vec = sws_getGaussianVec(f->radius, f->quality); |
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
90 sws_scaleVec(vec, f->strength); |
8106 | 91 vec->coeff[vec->length/2]+= 1.0 - f->strength; |
92 swsF.lumH= swsF.lumV= vec; | |
93 swsF.chrH= swsF.chrV= NULL; | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
94 f->filterContext= sws_getContext( |
19870
1e5cf11e8b1f
Use PIX_FMT_* instead of IMGFMT_* when calling sws_getContext()
lucabe
parents:
18861
diff
changeset
|
95 width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, get_sws_cpuflags(), &swsF, NULL, NULL); |
8106 | 96 |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
97 sws_freeVec(vec); |
8106 | 98 |
99 return 0; | |
100 } | |
101 | |
102 static int config(struct vf_instance_s* vf, | |
103 int width, int height, int d_width, int d_height, | |
104 unsigned int flags, unsigned int outfmt){ | |
105 | |
106 int sw, sh; | |
107 | |
108 allocStuff(&vf->priv->luma, width, height); | |
109 | |
110 getSubSampleFactors(&sw, &sh, outfmt); | |
111 allocStuff(&vf->priv->chroma, width>>sw, height>>sh); | |
112 | |
113 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
114 } | |
115 | |
116 static void freeBuffers(FilterParam *f){ | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
117 if(f->filterContext) sws_freeContext(f->filterContext); |
8106 | 118 f->filterContext=NULL; |
119 } | |
120 | |
121 static void uninit(struct vf_instance_s* vf){ | |
122 if(!vf->priv) return; | |
123 | |
124 freeBuffers(&vf->priv->luma); | |
125 freeBuffers(&vf->priv->chroma); | |
126 | |
127 free(vf->priv); | |
128 vf->priv=NULL; | |
129 } | |
130 | |
131 static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){ | |
132 int x, y; | |
133 FilterParam f= *fp; | |
134 uint8_t *srcArray[3]= {src, NULL, NULL}; | |
135 uint8_t *dstArray[3]= {dst, NULL, NULL}; | |
136 int srcStrideArray[3]= {srcStride, 0, 0}; | |
137 int dstStrideArray[3]= {dstStride, 0, 0}; | |
138 | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
139 sws_scale(f.filterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray); |
8106 | 140 |
141 if(f.threshold > 0){ | |
142 for(y=0; y<h; y++){ | |
143 for(x=0; x<w; x++){ | |
144 const int orig= src[x + y*srcStride]; | |
145 const int filtered= dst[x + y*dstStride]; | |
146 const int diff= orig - filtered; | |
147 | |
148 if(diff > 0){ | |
149 if(diff > 2*f.threshold){ | |
150 dst[x + y*dstStride]= orig; | |
151 }else if(diff > f.threshold){ | |
152 dst[x + y*dstStride]= filtered + diff - f.threshold; | |
153 } | |
154 }else{ | |
155 if(-diff > 2*f.threshold){ | |
156 dst[x + y*dstStride]= orig; | |
157 }else if(-diff > f.threshold){ | |
158 dst[x + y*dstStride]= filtered + diff + f.threshold; | |
159 } | |
160 } | |
161 } | |
162 } | |
163 }else if(f.threshold < 0){ | |
164 for(y=0; y<h; y++){ | |
165 for(x=0; x<w; x++){ | |
166 const int orig= src[x + y*srcStride]; | |
167 const int filtered= dst[x + y*dstStride]; | |
168 const int diff= orig - filtered; | |
169 | |
170 if(diff > 0){ | |
171 if(diff > -2*f.threshold){ | |
172 }else if(diff > -f.threshold){ | |
173 dst[x + y*dstStride]= orig - diff - f.threshold; | |
174 }else | |
175 dst[x + y*dstStride]= orig; | |
176 }else{ | |
177 if(diff < 2*f.threshold){ | |
178 }else if(diff < f.threshold){ | |
179 dst[x + y*dstStride]= orig - diff + f.threshold; | |
180 }else | |
181 dst[x + y*dstStride]= orig; | |
182 } | |
183 } | |
184 } | |
185 } | |
186 } | |
187 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17367
diff
changeset
|
188 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8106 | 189 int cw= mpi->w >> mpi->chroma_x_shift; |
190 int ch= mpi->h >> mpi->chroma_y_shift; | |
16154
abe49bc12544
when threshold != 0 the dest image must be readable
reimar
parents:
14542
diff
changeset
|
191 FilterParam *f= &vf->priv; |
8106 | 192 |
193 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
16154
abe49bc12544
when threshold != 0 the dest image must be readable
reimar
parents:
14542
diff
changeset
|
194 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE| |
abe49bc12544
when threshold != 0 the dest image must be readable
reimar
parents:
14542
diff
changeset
|
195 (f->threshold) ? MP_IMGFLAG_READABLE : 0, |
8106 | 196 mpi->w,mpi->h); |
197 | |
198 assert(mpi->flags&MP_IMGFLAG_PLANAR); | |
199 | |
200 blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma); | |
201 blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma); | |
202 blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma); | |
203 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17367
diff
changeset
|
204 return vf_next_put_image(vf,dmpi, pts); |
8106 | 205 } |
206 | |
207 //===========================================================================// | |
208 | |
209 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
210 switch(fmt) | |
211 { | |
212 case IMGFMT_YV12: | |
213 case IMGFMT_I420: | |
214 case IMGFMT_IYUV: | |
215 case IMGFMT_YVU9: | |
216 case IMGFMT_444P: | |
217 case IMGFMT_422P: | |
218 case IMGFMT_411P: | |
219 return vf_next_query_format(vf, fmt); | |
220 } | |
221 return 0; | |
222 } | |
223 | |
224 static int open(vf_instance_t *vf, char* args){ | |
225 int e; | |
226 | |
227 vf->config=config; | |
228 vf->put_image=put_image; | |
229 // vf->get_image=get_image; | |
230 vf->query_format=query_format; | |
231 vf->uninit=uninit; | |
232 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
233 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
234 | |
235 if(args==NULL) return 0; | |
236 | |
237 e=sscanf(args, "%f:%f:%d:%f:%f:%d", | |
238 &vf->priv->luma.radius, | |
239 &vf->priv->luma.strength, | |
240 &vf->priv->luma.threshold, | |
241 &vf->priv->chroma.radius, | |
242 &vf->priv->chroma.strength, | |
243 &vf->priv->chroma.threshold | |
244 ); | |
245 | |
246 vf->priv->luma.quality = vf->priv->chroma.quality= 3.0; | |
247 | |
248 if(e==3){ | |
249 vf->priv->chroma.radius= vf->priv->luma.radius; | |
250 vf->priv->chroma.strength= vf->priv->luma.strength; | |
251 vf->priv->chroma.threshold = vf->priv->luma.threshold; | |
252 }else if(e!=6) | |
253 return 0; | |
254 | |
255 return 1; | |
256 } | |
257 | |
258 vf_info_t vf_info_smartblur = { | |
259 "smart blur", | |
260 "smartblur", | |
261 "Michael Niedermayer", | |
262 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9494
diff
changeset
|
263 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9494
diff
changeset
|
264 NULL |
8106 | 265 }; |
266 | |
267 //===========================================================================// |