[MPlayer-dev-eng] [PATCH] aspect and round params for dsize

Oded Shimon ods15 at ods15.dyndns.org
Sat Jul 9 08:39:55 CEST 2005


If no-one objects, I'll commit tommorrow.
For full description of patch, see the patch for the man page. :)

- ods15
-------------- next part --------------
Index: libmpcodecs/vf_dsize.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_dsize.c,v
retrieving revision 1.1
diff -u -r1.1 vf_dsize.c
--- libmpcodecs/vf_dsize.c	27 Apr 2003 18:55:04 -0000	1.1
+++ libmpcodecs/vf_dsize.c	4 Jul 2005 09:01:25 -0000
@@ -12,6 +12,7 @@
 
 struct vf_priv_s {
 	int w, h;
+	int a, r;
 	float aspect;
 };
 
@@ -19,7 +20,27 @@
 	int width, int height, int d_width, int d_height,
 	unsigned int flags, unsigned int outfmt)
 {
-	if (vf->priv->w && vf->priv->h) {
+	if (vf->priv->aspect < 0.001) {
+		if (vf->priv->w == 0) vf->priv->w = d_width;
+		if (vf->priv->h == 0) vf->priv->h = d_height;
+		if (vf->priv->w == -1) vf->priv->w = width;
+		if (vf->priv->h == -1) vf->priv->h = height;
+		if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height;
+		if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height;
+		if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width;
+		if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width;
+		if (vf->priv->a > -1) { // 0 -> downscale, 1-> upscale.  +2 -> original aspect.
+			double aspect = (vf->priv->a & 2) ? ((double)d_height / d_width) : ((double)height / width);
+			if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->a & 1)) {
+				vf->priv->h = vf->priv->w * aspect;
+			} else {
+				vf->priv->w = vf->priv->h / aspect;
+			}
+		}
+		if (vf->priv->r > 1) {
+			vf->priv->w += (vf->priv->r - 1 - (vf->priv->w - 1) % vf->priv->r);
+			vf->priv->h += (vf->priv->r - 1 - (vf->priv->h - 1) % vf->priv->r);
+		}
 		d_width = vf->priv->w;
 		d_height = vf->priv->h;
 	} else {
@@ -34,13 +55,23 @@
 	return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
 }
 
+static void uninit(vf_instance_t *vf) {
+	free(vf->priv);
+	vf->priv = NULL;
+}
+
 static int open(vf_instance_t *vf, char* args)
 {
 	vf->config = config;
 	vf->draw_slice = vf_next_draw_slice;
+	vf->uninit = uninit;
 	//vf->default_caps = 0;
 	vf->priv = calloc(sizeof(struct vf_priv_s), 1);
-	vf->priv->aspect = 4.0/3.0;
+	vf->priv->aspect = 0.;
+	vf->priv->w = -1;
+	vf->priv->h = -1;
+	vf->priv->a = -1;
+	vf->priv->r = 1;
 	if (args) {
 		if (strchr(args, '/')) {
 			int w, h;
@@ -49,9 +80,17 @@
 		} else if (strchr(args, '.')) {
 			sscanf(args, "%f", &vf->priv->aspect);
 		} else {
-			sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h);
+			sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->a, &vf->priv->r);
 		}
 	}
+	if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) ||
+			((vf->priv->w < -1) && (vf->priv->h < -1)) ||
+			(vf->priv->a < -1) || (vf->priv->a > 3) || (vf->priv->r < 0)
+			) {
+		mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d keepaspect: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->a, vf->priv->r);
+		free(vf->priv); vf->priv = NULL;
+		return -1;
+	}
 	return 1;
 }
 
Index: DOCS/man/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v
retrieving revision 1.1022
diff -u -r1.1022 mplayer.1
--- DOCS/man/en/mplayer.1	20 Jun 2005 18:28:46 -0000	1.1022
+++ DOCS/man/en/mplayer.1	8 Jul 2005 10:04:24 -0000
@@ -4319,7 +4319,7 @@
 .RE
 .
 .TP
-.B dsize[=aspect|w:h]
+.B dsize[=aspect|w:h:aspect-method:r]
 Changes the intended display size/\:aspect at an arbitrary point in the
 filter chain.
 Aspect can be given as a fraction (4/\:3) or floating point number
@@ -4331,6 +4331,58 @@
 do any scaling itself; it just affects
 what later scalers (software or hardware) will do when auto-scaling to
 correct aspect.
+.RSs
+.IPs <w>,<h>
+New display width and height.
+Can also be these special values:
+.RSss
+ 0:   Original display width and height.
+.br
+-1:   Original video width and height (default).
+.br
+-2:   Calculate by using the other dimension and the original video
+aspect ratio.
+.br
+-3:   Calculate by using the other dimension and the original
+display aspect ratio.
+.REss
+.sp 1
+.I EXAMPLE:
+.PD 0
+.RSs
+.IP dsize=800:-2
+Specifies a dsize of 800x600 for a 4/3 aspect video, or 800x450
+for a 16/9 aspect video.
+.RE
+.IPs <aspect\-method>
+Modifies width and height according to original aspect ratios.
+.RSss
+-1: Ignore original aspect ratio (default).
+.br
+ 0: Keep display aspect ratio by using <w> and <h> as a maximum
+resolution.
+.br
+ 1: Keep display aspect ratio by using <w> and <h> as a minimum
+resolution.
+.br
+ 2: Keep video aspect ratio by using <w> and <h> as a maximum
+resolution.
+.br
+ 3: Keep video aspect ratio by using <w> and <h> as a minimum
+resolution.
+.REss
+.sp 1
+.I EXAMPLE:
+.PD 0
+.RSs
+.IP dsize=800:600:0
+Specifies a dsize of at most 800x600, or smaller, in order to
+keep aspect.
+.RE
+.PD 1
+.IPs <r>
+Rounds up to make both width and height divisible by <r> (default: 1).
+.RE
 .
 .TP
 .B yuy2\ \ \ 


More information about the MPlayer-dev-eng mailing list