2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "img_format.h"
33 int method
; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect.
38 static int config(struct vf_instance
*vf
,
39 int width
, int height
, int d_width
, int d_height
,
40 unsigned int flags
, unsigned int outfmt
)
44 if (vf
->priv
->aspect
< 0.001) { // did the user input aspect or w,h params
45 if (w
== 0) w
= d_width
;
46 if (h
== 0) h
= d_height
;
47 if (w
== -1) w
= width
;
48 if (h
== -1) h
= height
;
49 if (w
== -2) w
= h
* (double)d_width
/ d_height
;
50 if (w
== -3) w
= h
* (double)width
/ height
;
51 if (h
== -2) h
= w
* (double)d_height
/ d_width
;
52 if (h
== -3) h
= w
* (double)height
/ width
;
53 if (vf
->priv
->method
> -1) {
54 double aspect
= (vf
->priv
->method
& 2) ? ((double)height
/ width
) : ((double)d_height
/ d_width
);
55 if ((h
> w
* aspect
) ^ (vf
->priv
->method
& 1)) {
61 if (vf
->priv
->round
> 1) { // round up
62 w
+= (vf
->priv
->round
- 1 - (w
- 1) % vf
->priv
->round
);
63 h
+= (vf
->priv
->round
- 1 - (h
- 1) % vf
->priv
->round
);
68 if (vf
->priv
->aspect
* height
> width
) {
69 d_width
= height
* vf
->priv
->aspect
+ .5;
72 d_height
= width
/ vf
->priv
->aspect
+ .5;
76 return vf_next_config(vf
, width
, height
, d_width
, d_height
, flags
, outfmt
);
79 static void uninit(vf_instance_t
*vf
) {
84 static int vf_open(vf_instance_t
*vf
, char *args
)
87 vf
->draw_slice
= vf_next_draw_slice
;
89 //vf->default_caps = 0;
90 vf
->priv
= calloc(sizeof(struct vf_priv_s
), 1);
91 vf
->priv
->aspect
= 0.;
94 vf
->priv
->method
= -1;
97 if (strchr(args
, '/')) {
99 sscanf(args
, "%d/%d", &w
, &h
);
100 vf
->priv
->aspect
= (float)w
/h
;
101 } else if (strchr(args
, '.')) {
102 sscanf(args
, "%f", &vf
->priv
->aspect
);
104 sscanf(args
, "%d:%d:%d:%d", &vf
->priv
->w
, &vf
->priv
->h
, &vf
->priv
->method
, &vf
->priv
->round
);
107 if ((vf
->priv
->aspect
< 0.) || (vf
->priv
->w
< -3) || (vf
->priv
->h
< -3) ||
108 ((vf
->priv
->w
< -1) && (vf
->priv
->h
< -1)) ||
109 (vf
->priv
->method
< -1) || (vf
->priv
->method
> 3) ||
110 (vf
->priv
->round
< 0)) {
111 mp_msg(MSGT_VFILTER
, MSGL_ERR
, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf
->priv
->aspect
, vf
->priv
->w
, vf
->priv
->h
, vf
->priv
->method
, vf
->priv
->round
);
112 free(vf
->priv
); vf
->priv
= NULL
;
118 const vf_info_t vf_info_dsize
= {
119 "reset displaysize/aspect",