Mercurial > mplayer.hg
annotate libmpcodecs/vf_smartblur.c @ 14504:e394a9cfaf3f
Transition of suboption parser to subopt-helper parser.
Removal of stupid malloc_failed function.
author | ivo |
---|---|
date | Sat, 15 Jan 2005 20:06:49 +0000 |
parents | 6bd869a18d2c |
children | 4a6b79a1ad52 |
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" | |
10233
35f52ad860a0
vf_scale.h & related cleanup & some small warning fix by dominik
michael
parents:
9975
diff
changeset
|
41 #include "vf_scale.h" |
8106 | 42 |
43 //===========================================================================// | |
44 | |
45 typedef struct FilterParam{ | |
46 float radius; | |
47 float strength; | |
48 int threshold; | |
49 float quality; | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
50 struct SwsContext *filterContext; |
8106 | 51 }FilterParam; |
52 | |
53 struct vf_priv_s { | |
54 FilterParam luma; | |
55 FilterParam chroma; | |
56 }; | |
57 | |
58 | |
59 /***************************************************************************/ | |
60 | |
61 //FIXME stupid code duplication | |
62 static void getSubSampleFactors(int *h, int *v, int format){ | |
63 switch(format){ | |
64 case IMGFMT_YV12: | |
65 case IMGFMT_I420: | |
66 *h=1; | |
67 *v=1; | |
68 break; | |
69 case IMGFMT_YVU9: | |
70 *h=2; | |
71 *v=2; | |
72 break; | |
73 case IMGFMT_444P: | |
74 *h=0; | |
75 *v=0; | |
76 break; | |
77 case IMGFMT_422P: | |
78 *h=1; | |
79 *v=0; | |
80 break; | |
81 case IMGFMT_411P: | |
82 *h=2; | |
83 *v=0; | |
84 break; | |
85 } | |
86 } | |
87 | |
88 static int allocStuff(FilterParam *f, int width, int height){ | |
89 SwsVector *vec; | |
90 SwsFilter swsF; | |
91 | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
92 vec = sws_getGaussianVec(f->radius, f->quality); |
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
93 sws_scaleVec(vec, f->strength); |
8106 | 94 vec->coeff[vec->length/2]+= 1.0 - f->strength; |
95 swsF.lumH= swsF.lumV= vec; | |
96 swsF.chrH= swsF.chrV= NULL; | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
97 f->filterContext= sws_getContext( |
13373
6bd869a18d2c
passing an array or double precission parameters for the scaling function, instead of missusing a few bits of the flags
michael
parents:
10233
diff
changeset
|
98 width, height, IMGFMT_Y8, width, height, IMGFMT_Y8, get_sws_cpuflags(), &swsF, NULL, NULL); |
8106 | 99 |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
100 sws_freeVec(vec); |
8106 | 101 |
102 return 0; | |
103 } | |
104 | |
105 static int config(struct vf_instance_s* vf, | |
106 int width, int height, int d_width, int d_height, | |
107 unsigned int flags, unsigned int outfmt){ | |
108 | |
109 int sw, sh; | |
110 | |
111 allocStuff(&vf->priv->luma, width, height); | |
112 | |
113 getSubSampleFactors(&sw, &sh, outfmt); | |
114 allocStuff(&vf->priv->chroma, width>>sw, height>>sh); | |
115 | |
116 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
117 } | |
118 | |
119 static void freeBuffers(FilterParam *f){ | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
120 if(f->filterContext) sws_freeContext(f->filterContext); |
8106 | 121 f->filterContext=NULL; |
122 } | |
123 | |
124 static void uninit(struct vf_instance_s* vf){ | |
125 if(!vf->priv) return; | |
126 | |
127 freeBuffers(&vf->priv->luma); | |
128 freeBuffers(&vf->priv->chroma); | |
129 | |
130 free(vf->priv); | |
131 vf->priv=NULL; | |
132 } | |
133 | |
134 static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){ | |
135 int x, y; | |
136 FilterParam f= *fp; | |
137 uint8_t *srcArray[3]= {src, NULL, NULL}; | |
138 uint8_t *dstArray[3]= {dst, NULL, NULL}; | |
139 int srcStrideArray[3]= {srcStride, 0, 0}; | |
140 int dstStrideArray[3]= {dstStride, 0, 0}; | |
141 | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
8263
diff
changeset
|
142 sws_scale(f.filterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray); |
8106 | 143 |
144 if(f.threshold > 0){ | |
145 for(y=0; y<h; y++){ | |
146 for(x=0; x<w; x++){ | |
147 const int orig= src[x + y*srcStride]; | |
148 const int filtered= dst[x + y*dstStride]; | |
149 const int diff= orig - filtered; | |
150 | |
151 if(diff > 0){ | |
152 if(diff > 2*f.threshold){ | |
153 dst[x + y*dstStride]= orig; | |
154 }else if(diff > f.threshold){ | |
155 dst[x + y*dstStride]= filtered + diff - f.threshold; | |
156 } | |
157 }else{ | |
158 if(-diff > 2*f.threshold){ | |
159 dst[x + y*dstStride]= orig; | |
160 }else if(-diff > f.threshold){ | |
161 dst[x + y*dstStride]= filtered + diff + f.threshold; | |
162 } | |
163 } | |
164 } | |
165 } | |
166 }else if(f.threshold < 0){ | |
167 for(y=0; y<h; y++){ | |
168 for(x=0; x<w; x++){ | |
169 const int orig= src[x + y*srcStride]; | |
170 const int filtered= dst[x + y*dstStride]; | |
171 const int diff= orig - filtered; | |
172 | |
173 if(diff > 0){ | |
174 if(diff > -2*f.threshold){ | |
175 }else if(diff > -f.threshold){ | |
176 dst[x + y*dstStride]= orig - diff - f.threshold; | |
177 }else | |
178 dst[x + y*dstStride]= orig; | |
179 }else{ | |
180 if(diff < 2*f.threshold){ | |
181 }else if(diff < f.threshold){ | |
182 dst[x + y*dstStride]= orig - diff + f.threshold; | |
183 }else | |
184 dst[x + y*dstStride]= orig; | |
185 } | |
186 } | |
187 } | |
188 } | |
189 } | |
190 | |
191 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
192 int cw= mpi->w >> mpi->chroma_x_shift; | |
193 int ch= mpi->h >> mpi->chroma_y_shift; | |
194 | |
195 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
196 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
197 mpi->w,mpi->h); | |
198 | |
199 assert(mpi->flags&MP_IMGFLAG_PLANAR); | |
200 | |
201 blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma); | |
202 blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma); | |
203 blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma); | |
204 | |
205 return vf_next_put_image(vf,dmpi); | |
206 } | |
207 | |
208 //===========================================================================// | |
209 | |
210 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
211 switch(fmt) | |
212 { | |
213 case IMGFMT_YV12: | |
214 case IMGFMT_I420: | |
215 case IMGFMT_IYUV: | |
216 case IMGFMT_YVU9: | |
217 case IMGFMT_444P: | |
218 case IMGFMT_422P: | |
219 case IMGFMT_411P: | |
220 return vf_next_query_format(vf, fmt); | |
221 } | |
222 return 0; | |
223 } | |
224 | |
225 static int open(vf_instance_t *vf, char* args){ | |
226 int e; | |
227 | |
228 vf->config=config; | |
229 vf->put_image=put_image; | |
230 // vf->get_image=get_image; | |
231 vf->query_format=query_format; | |
232 vf->uninit=uninit; | |
233 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
234 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
235 | |
236 if(args==NULL) return 0; | |
237 | |
8263 | 238 #ifdef USE_SETLOCALE |
239 setlocale( LC_NUMERIC, "C" ); | |
240 #endif | |
8106 | 241 e=sscanf(args, "%f:%f:%d:%f:%f:%d", |
242 &vf->priv->luma.radius, | |
243 &vf->priv->luma.strength, | |
244 &vf->priv->luma.threshold, | |
245 &vf->priv->chroma.radius, | |
246 &vf->priv->chroma.strength, | |
247 &vf->priv->chroma.threshold | |
248 ); | |
8263 | 249 #ifdef USE_SETLOCALE |
250 setlocale( LC_NUMERIC, "" ); | |
251 #endif | |
8106 | 252 |
253 vf->priv->luma.quality = vf->priv->chroma.quality= 3.0; | |
254 | |
255 if(e==3){ | |
256 vf->priv->chroma.radius= vf->priv->luma.radius; | |
257 vf->priv->chroma.strength= vf->priv->luma.strength; | |
258 vf->priv->chroma.threshold = vf->priv->luma.threshold; | |
259 }else if(e!=6) | |
260 return 0; | |
261 | |
262 return 1; | |
263 } | |
264 | |
265 vf_info_t vf_info_smartblur = { | |
266 "smart blur", | |
267 "smartblur", | |
268 "Michael Niedermayer", | |
269 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9494
diff
changeset
|
270 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9494
diff
changeset
|
271 NULL |
8106 | 272 }; |
273 | |
274 //===========================================================================// |