Mercurial > mplayer.hg
comparison libmpcodecs/vf_noise.c @ 6447:751a5775ac35
direct rendering (hopefully at least, TFM for the video filters is a bit nonexistent or iam just too stupid) ;)
uninit
author | michael |
---|---|
date | Sun, 16 Jun 2002 13:45:52 +0000 |
parents | 83032783f65d |
children | e10e3264c19c |
comparison
equal
deleted
inserted
replaced
6446:5238266d8b34 | 6447:751a5775ac35 |
---|---|
53 }FilterParam; | 53 }FilterParam; |
54 | 54 |
55 struct vf_priv_s { | 55 struct vf_priv_s { |
56 FilterParam lumaParam; | 56 FilterParam lumaParam; |
57 FilterParam chromaParam; | 57 FilterParam chromaParam; |
58 mp_image_t *dmpi; | |
59 unsigned int outfmt; | |
58 }; | 60 }; |
59 | 61 |
60 static int nonTempRandShift[MAX_RES]= {-1}; | 62 static int nonTempRandShift[MAX_RES]= {-1}; |
61 | 63 |
62 static int8_t *initNoise(FilterParam *fp){ | 64 static int8_t *initNoise(FilterParam *fp){ |
63 int strength= fp->strength; | 65 int strength= fp->strength; |
64 int uniform= fp->uniform; | 66 int uniform= fp->uniform; |
65 int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t)); //FIXME deallocate | 67 int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t)); |
66 int i; | 68 int i; |
67 | 69 |
68 srand(123457); | 70 srand(123457); |
69 | 71 |
70 for(i=0; i<MAX_NOISE; i++) | 72 for(i=0; i<MAX_NOISE; i++) |
176 int y; | 178 int y; |
177 int shift=0; | 179 int shift=0; |
178 | 180 |
179 if(!noise) | 181 if(!noise) |
180 { | 182 { |
183 if(src==dst) return; | |
184 | |
181 if(dstStride==srcStride) memcpy(dst, src, srcStride*height); | 185 if(dstStride==srcStride) memcpy(dst, src, srcStride*height); |
182 else | 186 else |
183 { | 187 { |
184 for(y=0; y<height; y++) | 188 for(y=0; y<height; y++) |
185 { | 189 { |
207 unsigned int flags, unsigned int outfmt){ | 211 unsigned int flags, unsigned int outfmt){ |
208 | 212 |
209 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | 213 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
210 } | 214 } |
211 | 215 |
216 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
217 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
218 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt) | |
219 return; // colorspace differ | |
220 // ok, we can do pp in-place (or pp disabled): | |
221 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
222 mpi->type, mpi->flags, mpi->w, mpi->h); | |
223 mpi->planes[0]=vf->priv->dmpi->planes[0]; | |
224 mpi->stride[0]=vf->priv->dmpi->stride[0]; | |
225 mpi->width=vf->priv->dmpi->width; | |
226 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
227 mpi->planes[1]=vf->priv->dmpi->planes[1]; | |
228 mpi->planes[2]=vf->priv->dmpi->planes[2]; | |
229 mpi->stride[1]=vf->priv->dmpi->stride[1]; | |
230 mpi->stride[2]=vf->priv->dmpi->stride[2]; | |
231 } | |
232 mpi->flags|=MP_IMGFLAG_DIRECT; | |
233 } | |
234 | |
212 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | 235 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
213 mp_image_t *dmpi; | 236 mp_image_t *dmpi; |
214 | 237 |
215 // hope we'll get DR buffer: | 238 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
216 dmpi=vf_get_image(vf->next,mpi->imgfmt, | 239 // no DR, so get a new image! hope we'll get DR buffer: |
240 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt, | |
217 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | 241 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, |
218 mpi->w, mpi->h); | 242 mpi->w,mpi->h); |
243 //printf("nodr\n"); | |
244 } | |
245 //else printf("dr\n"); | |
246 dmpi= vf->priv->dmpi; | |
219 | 247 |
220 noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam); | 248 noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam); |
221 noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); | 249 noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); |
222 noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); | 250 noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); |
223 | 251 |
232 #endif | 260 #endif |
233 | 261 |
234 vf_next_put_image(vf,dmpi); | 262 vf_next_put_image(vf,dmpi); |
235 } | 263 } |
236 | 264 |
265 static void uninit(struct vf_instance_s* vf){ | |
266 if(!vf->priv) return; | |
267 | |
268 if(vf->priv->chromaParam.noise) free(vf->priv->chromaParam.noise); | |
269 vf->priv->chromaParam.noise= NULL; | |
270 | |
271 if(vf->priv->lumaParam.noise) free(vf->priv->lumaParam.noise); | |
272 vf->priv->lumaParam.noise= NULL; | |
273 | |
274 free(vf->priv); | |
275 vf->priv=NULL; | |
276 } | |
277 | |
237 //===========================================================================// | 278 //===========================================================================// |
238 | 279 |
239 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | 280 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
240 switch(fmt) | 281 switch(fmt) |
241 { | 282 { |
242 case IMGFMT_YV12: | 283 case IMGFMT_YV12: |
243 case IMGFMT_I420: | 284 case IMGFMT_I420: |
244 case IMGFMT_IYUV: | 285 case IMGFMT_IYUV: |
245 return vf_next_query_format(vf,fmt); | 286 return vf_next_query_format(vf,vf->priv->outfmt); |
246 } | 287 } |
247 return 0; | 288 return 0; |
248 } | 289 } |
249 | 290 |
250 static void parse(FilterParam *fp, char* args){ | 291 static void parse(FilterParam *fp, char* args){ |
260 if(pos && pos<max) fp->temporal=1; | 301 if(pos && pos<max) fp->temporal=1; |
261 | 302 |
262 if(fp->strength) initNoise(fp); | 303 if(fp->strength) initNoise(fp); |
263 } | 304 } |
264 | 305 |
306 static unsigned int fmt_list[]={ | |
307 IMGFMT_YV12, | |
308 IMGFMT_I420, | |
309 IMGFMT_IYUV, | |
310 0 | |
311 }; | |
312 | |
265 static int open(vf_instance_t *vf, char* args){ | 313 static int open(vf_instance_t *vf, char* args){ |
266 vf->config=config; | 314 vf->config=config; |
267 vf->put_image=put_image; | 315 vf->put_image=put_image; |
316 vf->get_image=get_image; | |
268 vf->query_format=query_format; | 317 vf->query_format=query_format; |
318 vf->uninit=uninit; | |
269 vf->priv=malloc(sizeof(struct vf_priv_s)); | 319 vf->priv=malloc(sizeof(struct vf_priv_s)); |
270 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | 320 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
271 if(args) | 321 if(args) |
272 { | 322 { |
273 char *arg2= strchr(args,':'); | 323 char *arg2= strchr(args,':'); |
274 if(arg2) parse(&vf->priv->chromaParam, arg2+1); | 324 if(arg2) parse(&vf->priv->chromaParam, arg2+1); |
275 parse(&vf->priv->lumaParam, args); | 325 parse(&vf->priv->lumaParam, args); |
276 } | 326 } |
327 | |
328 // check csp: | |
329 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); | |
330 if(!vf->priv->outfmt) | |
331 { | |
332 uninit(vf); | |
333 return 0; // no csp match :( | |
334 } | |
335 | |
277 | 336 |
278 #ifdef HAVE_MMX | 337 #ifdef HAVE_MMX |
279 if(gCpuCaps.hasMMX) lineNoise= lineNoise_MMX; | 338 if(gCpuCaps.hasMMX) lineNoise= lineNoise_MMX; |
280 #endif | 339 #endif |
281 #ifdef HAVE_MMX2 | 340 #ifdef HAVE_MMX2 |