[MPlayer-dev-eng] [PATCH] dsize negative scale values
Oded Shimon
ods15 at ods15.dyndns.org
Mon Jul 4 11:02:48 CEST 2005
On Mon, Jul 04, 2005 at 12:22:57AM -0700, Trent Piepho wrote:
> On Sun, 3 Jul 2005, RC wrote:
> >
> > How about a compromise between these two? Why not just add two
> > (optional) parameters to my version of the dsize patch... A max width/
> > height value, so eg. "dsize=800:-2:800:600" (or
> > dsize=800:-2::600, or dsize=-2:600:800) would work for you, and still be
> > very simple and easy for everyone to understand?
>
> How about....
>
> dsize=x:y:aspect_method
>
> x or y = 0, as if you had specified the original size
> aspect_method = 0 Preserve aspect, treat x:y as a minimum size (default)
.. as in, upscale
> aspect_method = 1 Preserve aspect, treat x:y as a maximum size
as in, downscale...
> apsect_method = 2 Ignore the aspect ratio, just use x:y
If you haven't noticed, what you just described is (almost) EXACTLY the
same as what I've done!! Only described differently and using different
numbers...
mine does it so -1 means ignore aspect, 0 means downscale, and 1 means
upscale! the same!
also in my patch, -1 means original size, not 0. Seriously, what you
described is exactly what I did, so I don't see how you can claim mine is
more complicated..
> If you want to:
> Upscale to the correct aspect, dsize=0:0:0
> Downscale to the correct aspect, dsize=0:0:1
> Fit in 800x600 with the correct aspect, dsize=800:600:1
> Just horizontally scale to get the correct aspect, dsize=9999:0:1
> Just use 640x480 no matter what, dsize=640:480:2
>
> Is there any reasonable thing that a person would want to do that you can't
> easily do this way?
You forgot only one thing - there are TWO different kinds of aspects.
original aspect and display aspect. This is the only "complexity" added,
and it is very necessary. Again, like the example I gave, a SVCD NTSC
video, is 480x480 resolution, so it's "aspect" is 1:1. But its display
aspect is ofcourse 4:3. Depending on the occassion, you might want either.
So the only difference between what you just described and my patch, is
that mine offers to use either aspect, depending on which you choose...
On Mon, Jul 04, 2005 at 01:06:25AM -0700, RC wrote:
> On Mon, 4 Jul 2005 10:12:58 +0300
> Oded Shimon <ods15 at ods15.dyndns.org> wrote:
>
> > TBH that sounds even MORE complicated,
>
> I don't see how anyone could think that is more complex...
I honestly don't see how you could think my original patch was complex :/ I
guess complexity is to taste.
What I didn't like about your suggestion, it's limited. Say, I want a
bounding box which will be the minimum size, not possible with your
compromise. Maybe if you add yet another param... and then you're back to
complexity. Also, everything possible with your patch is still possible
with my patch.
ANYWAY... Here's my new patch, the one I suggested as a compromise, how's
this for a man page description, tell me if it sounds complicated.
<w>,<h>
New display width and height.
Can also be these special values:
0: Original display width, height.
-1: Original video width and height (default)
-2: Calculate by using the other dimention and the original video aspect ratio
-3: Calculate by using the other dimention and the original display aspect ratio
<aspect method>
Modifies width and height according to original aspect ratios.
-1: Ignore original aspect ratio (default)
0: Keep display aspect ratio by using <w> and <h> as a maximum size
1: Keep display aspect ratio by using <w> and <h> as a minimum size
2: Keep video aspect ratio by using <w> and <h> as a maximum size
3: Keep video aspect ratio by using <w> and <h> as a minimum size
<r>
Round width and hieght up to be divisable by <r>. (default: 1)
Ok.. It's long.. But it's not complicated. Is it?
- 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;
}
More information about the MPlayer-dev-eng
mailing list