Mercurial > mplayer.hg
changeset 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 | 5238266d8b34 |
children | e10e3264c19c |
files | libmpcodecs/vf_noise.c |
diffstat | 1 files changed, 64 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpcodecs/vf_noise.c Sun Jun 16 11:24:49 2002 +0000 +++ b/libmpcodecs/vf_noise.c Sun Jun 16 13:45:52 2002 +0000 @@ -55,6 +55,8 @@ struct vf_priv_s { FilterParam lumaParam; FilterParam chromaParam; + mp_image_t *dmpi; + unsigned int outfmt; }; static int nonTempRandShift[MAX_RES]= {-1}; @@ -62,7 +64,7 @@ static int8_t *initNoise(FilterParam *fp){ int strength= fp->strength; int uniform= fp->uniform; - int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t)); //FIXME deallocate + int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t)); int i; srand(123457); @@ -178,6 +180,8 @@ if(!noise) { + if(src==dst) return; + if(dstStride==srcStride) memcpy(dst, src, srcStride*height); else { @@ -209,13 +213,37 @@ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); } +static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ + if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change + if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt) + return; // colorspace differ + // ok, we can do pp in-place (or pp disabled): + vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt, + mpi->type, mpi->flags, mpi->w, mpi->h); + mpi->planes[0]=vf->priv->dmpi->planes[0]; + mpi->stride[0]=vf->priv->dmpi->stride[0]; + mpi->width=vf->priv->dmpi->width; + if(mpi->flags&MP_IMGFLAG_PLANAR){ + mpi->planes[1]=vf->priv->dmpi->planes[1]; + mpi->planes[2]=vf->priv->dmpi->planes[2]; + mpi->stride[1]=vf->priv->dmpi->stride[1]; + mpi->stride[2]=vf->priv->dmpi->stride[2]; + } + mpi->flags|=MP_IMGFLAG_DIRECT; +} + static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ mp_image_t *dmpi; - // hope we'll get DR buffer: - dmpi=vf_get_image(vf->next,mpi->imgfmt, + if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ + // no DR, so get a new image! hope we'll get DR buffer: + vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, - mpi->w, mpi->h); + mpi->w,mpi->h); +//printf("nodr\n"); + } +//else printf("dr\n"); + dmpi= vf->priv->dmpi; noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam); noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); @@ -234,6 +262,19 @@ vf_next_put_image(vf,dmpi); } +static void uninit(struct vf_instance_s* vf){ + if(!vf->priv) return; + + if(vf->priv->chromaParam.noise) free(vf->priv->chromaParam.noise); + vf->priv->chromaParam.noise= NULL; + + if(vf->priv->lumaParam.noise) free(vf->priv->lumaParam.noise); + vf->priv->lumaParam.noise= NULL; + + free(vf->priv); + vf->priv=NULL; +} + //===========================================================================// static int query_format(struct vf_instance_s* vf, unsigned int fmt){ @@ -242,7 +283,7 @@ case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_IYUV: - return vf_next_query_format(vf,fmt); + return vf_next_query_format(vf,vf->priv->outfmt); } return 0; } @@ -262,10 +303,19 @@ if(fp->strength) initNoise(fp); } +static unsigned int fmt_list[]={ + IMGFMT_YV12, + IMGFMT_I420, + IMGFMT_IYUV, + 0 +}; + static int open(vf_instance_t *vf, char* args){ vf->config=config; vf->put_image=put_image; + vf->get_image=get_image; vf->query_format=query_format; + vf->uninit=uninit; vf->priv=malloc(sizeof(struct vf_priv_s)); memset(vf->priv, 0, sizeof(struct vf_priv_s)); if(args) @@ -274,6 +324,15 @@ if(arg2) parse(&vf->priv->chromaParam, arg2+1); parse(&vf->priv->lumaParam, args); } + + // check csp: + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + if(!vf->priv->outfmt) + { + uninit(vf); + return 0; // no csp match :( + } + #ifdef HAVE_MMX if(gCpuCaps.hasMMX) lineNoise= lineNoise_MMX;