Index: vf_cropdetect.c =================================================================== RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_cropdetect.c,v retrieving revision 1.8 diff -u -b -B -r1.8 vf_cropdetect.c --- vf_cropdetect.c 25 Oct 2003 18:37:34 -0000 1.8 +++ vf_cropdetect.c 2 Mar 2004 19:32:21 -0000 @@ -17,6 +17,7 @@ int x1,y1,x2,y2; int limit; int fno; + int roundsize, roundpos; }; static int checkline(unsigned char* src,int stride,int len,int bpp){ @@ -103,14 +104,29 @@ } } - x=(vf->priv->x1+1)&(~1); - y=(vf->priv->y1+1)&(~1); + { + int cw, ch, x1, y1; - printf("crop area: X: %d..%d Y: %d..%d (-vf crop=%d:%d:%d:%d)\n", + /* round top left to align chroma */ + vf->priv->x1 = (vf->priv->x1 + vf->priv->roundpos - 1) / vf->priv->roundpos * vf->priv->roundpos; + vf->priv->y1 = (vf->priv->y1 + vf->priv->roundpos - 1) / vf->priv->roundpos * vf->priv->roundpos; + + /* round the size */ + cw = (vf->priv->x2 + 1 - vf->priv->x1) / vf->priv->roundsize * vf->priv->roundsize; + ch = (vf->priv->y2 + 1 - vf->priv->y1) / vf->priv->roundsize * vf->priv->roundsize; + + /* center the section, round to the nearest lower chroma-aligned */ + x1 = vf->priv->x1 + ((vf->priv->x2 + 1 - vf->priv->x1) - cw) / 2 / vf->priv->roundpos * vf->priv->roundpos; + y1 = vf->priv->y1 + ((vf->priv->y2 + 1 - vf->priv->y1) - ch) / 2 / vf->priv->roundpos * vf->priv->roundpos; + + printf("crop area: X: %d..%d Y: %d..%d, rnd: size %d px, pos %d px (-vf crop=%d:%d:%d:%d)\n", vf->priv->x1,vf->priv->x2, vf->priv->y1,vf->priv->y2, - (vf->priv->x2+1-x)&(~1),(vf->priv->y2+1-y)&(~1),x,y + vf->priv->roundsize, + vf->priv->roundpos, + cw,ch,x1,y1 ); + } } @@ -120,11 +136,17 @@ //===========================================================================// static int open(vf_instance_t *vf, char* args){ + int res; + vf->config=config; vf->put_image=put_image; vf->priv=malloc(sizeof(struct vf_priv_s)); - vf->priv->limit=24; // should be option - if(args) vf->priv->limit=atoi(args); + vf->priv->limit=24; + vf->priv->roundsize=16; + vf->priv->roundpos=2; + if (args) res = sscanf(args, "%d:%d:%d", &vf->priv->limit, &vf->priv->roundsize, &vf->priv->roundpos); + if (vf->priv->roundsize < 1 || vf->priv->roundsize > 64) vf->priv->roundsize = 16; + if (vf->priv->roundpos < 1 || vf->priv->roundpos > 64) vf->priv->roundpos = 2; return 1; }