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