0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

Adds rounding parameter for width and height values returned.

Based on idea from <rcooley (at) spamcop (dot) net>.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13206 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2004-08-30 20:39:32 +00:00
parent 7d0af8ba27
commit 264676faef
2 changed files with 41 additions and 6 deletions

View File

@ -3317,12 +3317,24 @@ Position of the cropped picture, defaults to center.
.PD 1 .PD 1
. .
.TP .TP
.B cropdetect[=0\-255] .B cropdetect[=limit:round]
Calculates necessary cropping parameters and prints the recommended parameters Calculates necessary cropping parameters and prints the recommended parameters
to stdout. to stdout.
The threshold can be optionally specified from nothing (0) to everything .PD 0
.RSs
.IPs limit
threshold, which can be optionally specified from nothing (0) to everything
(255). (255).
(default: 24) (default: 24)
.br
.IPs round
value which the width/height should be divisible by.
The offset is automatically adjusted to center the video.
Use \'2\' to get only even dimentions (needed for 4:2:2 video).
\'16\' is best when encoding to most video codecs.
(default: 16)
.RE
.PD 1
. .
.TP .TP
.B rectangle[=w:h:x:y] .B rectangle[=w:h:x:y]

View File

@ -16,6 +16,7 @@
struct vf_priv_s { struct vf_priv_s {
int x1,y1,x2,y2; int x1,y1,x2,y2;
int limit; int limit;
int round;
int fno; int fno;
}; };
@ -57,7 +58,7 @@ static int config(struct vf_instance_s* vf,
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
mp_image_t *dmpi; mp_image_t *dmpi;
int bpp=mpi->bpp/8; int bpp=mpi->bpp/8;
int x,y; int w,h,x,y,shrink_by;
// hope we'll get DR buffer: // hope we'll get DR buffer:
dmpi=vf_get_image(vf->next,mpi->imgfmt, dmpi=vf_get_image(vf->next,mpi->imgfmt,
@ -103,14 +104,34 @@ if(++vf->priv->fno>2){ // ignore first 2 frames - they may be empty
} }
} }
// round x and y (up), important for yuv colorspaces
// make sure they stay rounded!
x=(vf->priv->x1+1)&(~1); x=(vf->priv->x1+1)&(~1);
y=(vf->priv->y1+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", printf("crop area: X: %d..%d Y: %d..%d (-vf crop=%d:%d:%d:%d)\n",
vf->priv->x1,vf->priv->x2, vf->priv->x1,vf->priv->x2,
vf->priv->y1,vf->priv->y2, 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 @@ static int open(vf_instance_t *vf, char* args){
vf->put_image=put_image; vf->put_image=put_image;
vf->priv=malloc(sizeof(struct vf_priv_s)); vf->priv=malloc(sizeof(struct vf_priv_s));
vf->priv->limit=24; // should be option 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; return 1;
} }