[MPlayer-dev-eng] [PATCH] dsize aspect and round params
Oded Shimon
ods15 at ods15.dyndns.org
Sat Jul 2 23:37:11 CEST 2005
IMHO a much better patch for dsize.
add a 'keepaspect' param:
-1 - do nothing
0 - downscale to keep d_w/d_h aspect
1 - same, upscale
2 - downscale to keep w/h aspect
3 - same, upscale
adds a 'round' param, rounds up to arbitrary value.
-1 for width or hieght gives original w, h
-2 gives d_w, d_h.
0 is a valid value for w and h, because it can be "upscaled" by aspect.
to get the same effect as 'scale=-2:600', you do 'dsize=0:600:1'. etc.
Works nice for me, now I can always have the picture at most 800x600...
I suck at documenting, what I wrote in the man page should probably be
fixed.
- 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 2 Jul 2005 21:31:12 -0000
@@ -12,6 +12,7 @@
struct vf_priv_s {
int w, h;
+ int a, r;
float aspect;
};
@@ -19,7 +20,23 @@
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 == -1) vf->priv->w = width;
+ if (vf->priv->h == -1) vf->priv->h = height;
+ if (vf->priv->w == -2) vf->priv->w = d_width;
+ if (vf->priv->h == -2) vf->priv->h = d_height;
+ 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 +51,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 +76,15 @@
} 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 < -2) || (vf->priv->h < -2) ||
+ (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 2 Jul 2005 21:31:20 -0000
@@ -4305,7 +4322,7 @@
.RE
.
.TP
-.B dsize[=aspect|w:h]
+.B dsize[=aspect|w:h:keepaspect:round]
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
@@ -4317,6 +4334,13 @@
do any scaling itself; it just affects
what later scalers (software or hardware) will do when auto-scaling to
correct aspect.
+For width and height params, -1 means original size, and -2 means
+prescaled size. (default: -1,-1)
+keepaspect can be 0 to mean downscale to keep original aspect, 1 to
+upscale, 2 to keep prescaled aspect by downscaling, and 3 to upscale.
+(default: -1, no aspect keeping)
+round rounds the size up to make width/hieght divisable by it.
+(default: 1)
.
.TP
.B yuy2\ \ \
More information about the MPlayer-dev-eng
mailing list