Mercurial > mplayer.hg
annotate libmpcodecs/vf_smartblur.c @ 9975:3914afe5c0a7
removing sws - global verbose var dependancy
removing sws - cpudetect dependancy (note rgb2rgb still needs it)
moving mplayer specific stuff from swscale.c -> vf_scale.c
author | michael |
---|---|
date | Thu, 24 Apr 2003 17:04:20 +0000 |
parents | e9a2af584986 |
children | 35f52ad860a0 |
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 | |
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 #include <assert.h> | |
24 | |
25 #include "../config.h" | |
26 #include "../mp_msg.h" | |
27 | |
8263 | 28 #ifdef USE_SETLOCALE |
29 #include <locale.h> | |
30 #endif | |
31 | |
8106 | 32 #ifdef HAVE_MALLOC_H |
33 #include <malloc.h> | |
34 #endif | |
35 | |
36 #include "img_format.h" | |
37 #include "mp_image.h" | |
38 #include "vf.h" | |
39 #include "../libvo/fastmemcpy.h" | |
40 #include "../postproc/swscale.h" | |
41 | |
42 //===========================================================================// | |
43 | |
44 typedef struct FilterParam{ | |
45 float radius; | |
46 float strength; | |
47 int threshold; | |
48 float quality; | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
49 struct SwsContext *filterContext; |
8106 | 50 }FilterParam; |
51 | |
52 struct vf_priv_s { | |
53 FilterParam luma; | |
54 FilterParam chroma; | |
55 }; | |
56 | |
57 | |
58 /***************************************************************************/ | |
59 | |
60 //FIXME stupid code duplication | |
61 static void getSubSampleFactors(int *h, int *v, int format){ | |
62 switch(format){ | |
63 case IMGFMT_YV12: | |
64 case IMGFMT_I420: | |
65 *h=1; | |
66 *v=1; | |
67 break; | |
68 case IMGFMT_YVU9: | |
69 *h=2; | |
70 *v=2; | |
71 break; | |
72 case IMGFMT_444P: | |
73 *h=0; | |
74 *v=0; | |
75 break; | |
76 case IMGFMT_422P: | |
77 *h=1; | |
78 *v=0; | |
79 break; | |
80 case IMGFMT_411P: | |
81 *h=2; | |
82 *v=0; | |
83 break; | |
84 } | |
85 } | |
86 | |
87 static int allocStuff(FilterParam *f, int width, int height){ | |
88 SwsVector *vec; | |
89 SwsFilter swsF; | |
90 | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
91 vec = sws_getGaussianVec(f->radius, f->quality); |
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
92 sws_scaleVec(vec, f->strength); |
8106 | 93 vec->coeff[vec->length/2]+= 1.0 - f->strength; |
94 swsF.lumH= swsF.lumV= vec; | |
95 swsF.chrH= swsF.chrV= NULL; | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
96 f->filterContext= sws_getContext( |
9975 | 97 width, height, IMGFMT_Y8, width, height, IMGFMT_Y8, get_sws_cpuflags(), &swsF, NULL); |
8106 | 98 |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
99 sws_freeVec(vec); |
8106 | 100 |
101 return 0; | |
102 } | |
103 | |
104 static int config(struct vf_instance_s* vf, | |
105 int width, int height, int d_width, int d_height, | |
106 unsigned int flags, unsigned int outfmt){ | |
107 | |
108 int sw, sh; | |
109 | |
110 allocStuff(&vf->priv->luma, width, height); | |
111 | |
112 getSubSampleFactors(&sw, &sh, outfmt); | |
113 allocStuff(&vf->priv->chroma, width>>sw, height>>sh); | |
114 | |
115 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
116 } | |
117 | |
118 static void freeBuffers(FilterParam *f){ | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
119 if(f->filterContext) sws_freeContext(f->filterContext); |
8106 | 120 f->filterContext=NULL; |
121 } | |
122 | |
123 static void uninit(struct vf_instance_s* vf){ | |
124 if(!vf->priv) return; | |
125 | |
126 freeBuffers(&vf->priv->luma); | |
127 freeBuffers(&vf->priv->chroma); | |
128 | |
129 free(vf->priv); | |
130 vf->priv=NULL; | |
131 } | |
132 | |
133 static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){ | |
134 int x, y; | |
135 FilterParam f= *fp; | |
136 uint8_t *srcArray[3]= {src, NULL, NULL}; | |
137 uint8_t *dstArray[3]= {dst, NULL, NULL}; | |
138 int srcStrideArray[3]= {srcStride, 0, 0}; | |
139 int dstStrideArray[3]= {dstStride, 0, 0}; | |
140 | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
141 sws_scale(f.filterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray); |
8106 | 142 |
143 if(f.threshold > 0){ | |
144 for(y=0; y<h; y++){ | |
145 for(x=0; x<w; x++){ | |
146 const int orig= src[x + y*srcStride]; | |
147 const int filtered= dst[x + y*dstStride]; | |
148 const int diff= orig - filtered; | |
149 | |
150 if(diff > 0){ | |
151 if(diff > 2*f.threshold){ | |
152 dst[x + y*dstStride]= orig; | |
153 }else if(diff > f.threshold){ | |
154 dst[x + y*dstStride]= filtered + diff - f.threshold; | |
155 } | |
156 }else{ | |
157 if(-diff > 2*f.threshold){ | |
158 dst[x + y*dstStride]= orig; | |
159 }else if(-diff > f.threshold){ | |
160 dst[x + y*dstStride]= filtered + diff + f.threshold; | |
161 } | |
162 } | |
163 } | |
164 } | |
165 }else if(f.threshold < 0){ | |
166 for(y=0; y<h; y++){ | |
167 for(x=0; x<w; x++){ | |
168 const int orig= src[x + y*srcStride]; | |
169 const int filtered= dst[x + y*dstStride]; | |
170 const int diff= orig - filtered; | |
171 | |
172 if(diff > 0){ | |
173 if(diff > -2*f.threshold){ | |
174 }else if(diff > -f.threshold){ | |
175 dst[x + y*dstStride]= orig - diff - f.threshold; | |
176 }else | |
177 dst[x + y*dstStride]= orig; | |
178 }else{ | |
179 if(diff < 2*f.threshold){ | |
180 }else if(diff < f.threshold){ | |
181 dst[x + y*dstStride]= orig - diff + f.threshold; | |
182 }else | |
183 dst[x + y*dstStride]= orig; | |
184 } | |
185 } | |
186 } | |
187 } | |
188 } | |
189 | |
190 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
191 int cw= mpi->w >> mpi->chroma_x_shift; | |
192 int ch= mpi->h >> mpi->chroma_y_shift; | |
193 | |
194 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
195 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
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 | |
204 return vf_next_put_image(vf,dmpi); | |
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 | |
8263 | 237 #ifdef USE_SETLOCALE |
238 setlocale( LC_NUMERIC, "C" ); | |
239 #endif | |
8106 | 240 e=sscanf(args, "%f:%f:%d:%f:%f:%d", |
241 &vf->priv->luma.radius, | |
242 &vf->priv->luma.strength, | |
243 &vf->priv->luma.threshold, | |
244 &vf->priv->chroma.radius, | |
245 &vf->priv->chroma.strength, | |
246 &vf->priv->chroma.threshold | |
247 ); | |
8263 | 248 #ifdef USE_SETLOCALE |
249 setlocale( LC_NUMERIC, "" ); | |
250 #endif | |
8106 | 251 |
252 vf->priv->luma.quality = vf->priv->chroma.quality= 3.0; | |
253 | |
254 if(e==3){ | |
255 vf->priv->chroma.radius= vf->priv->luma.radius; | |
256 vf->priv->chroma.strength= vf->priv->luma.strength; | |
257 vf->priv->chroma.threshold = vf->priv->luma.threshold; | |
258 }else if(e!=6) | |
259 return 0; | |
260 | |
261 return 1; | |
262 } | |
263 | |
264 vf_info_t vf_info_smartblur = { | |
265 "smart blur", | |
266 "smartblur", | |
267 "Michael Niedermayer", | |
268 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9494
diff
changeset
|
269 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9494
diff
changeset
|
270 NULL |
8106 | 271 }; |
272 | |
273 //===========================================================================// |