[Mplayer-cvslog] CVS: main/libmpcodecs vf_cropdetect.c,1.8,1.9

Reimar Döffinger CVS syncmail at mplayerhq.hu
Mon Aug 30 22:39:34 CEST 2004


CVS change done by Reimar Döffinger CVS

Update of /cvsroot/mplayer/main/libmpcodecs
In directory mail:/var2/tmp/cvs-serv26993/libmpcodecs

Modified Files:
	vf_cropdetect.c 
Log Message:
Adds rounding parameter for width and height values returned.
Based on idea from <rcooley (at) spamcop (dot) net>.


Index: vf_cropdetect.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_cropdetect.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- vf_cropdetect.c	25 Oct 2003 18:37:34 -0000	1.8
+++ vf_cropdetect.c	30 Aug 2004 20:39:32 -0000	1.9
@@ -16,6 +16,7 @@
 struct vf_priv_s {
     int x1,y1,x2,y2;
     int limit;
+    int round;
     int fno;
 };
 
@@ -57,7 +58,7 @@
 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
     mp_image_t *dmpi;
     int bpp=mpi->bpp/8;
-    int x,y;
+    int w,h,x,y,shrink_by;
 
     // hope we'll get DR buffer:
     dmpi=vf_get_image(vf->next,mpi->imgfmt,
@@ -103,14 +104,34 @@
 	}
     }
 
+    // round x and y (up), important for yuv colorspaces
+    // make sure they stay rounded!
     x=(vf->priv->x1+1)&(~1);
     y=(vf->priv->y1+1)&(~1);
     
+    w = vf->priv->x2 - x;
+    h = vf->priv->y2 - y;
+
+    // w and h must be divisible by 2 as well because of yuv
+    // colorspace problems.
+    if (vf->priv->round <= 1)
+      vf->priv->round = 16;
+    if (vf->priv->round % 2)
+      vf->priv->round *= 2;
+
+    shrink_by = w % vf->priv->round;
+    w -= shrink_by;
+    x += (shrink_by / 2 + 1) & ~1;
+
+    shrink_by = h % vf->priv->round;
+    h -= shrink_by;
+    y += (shrink_by / 2 + 1) & ~1;
+
     printf("crop area: X: %d..%d  Y: %d..%d  (-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
-	  );
+	w,h,x,y);
+
 
 }
 
@@ -124,7 +145,9 @@
     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);
+    if(args) sscanf(args, "%d:%d",
+    &vf->priv->limit,
+    &vf->priv->round);
     return 1;
 }
 




More information about the MPlayer-cvslog mailing list