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
)
42 if (vf
->priv
->aspect
< 0.001) { // did the user input aspect or w,h params
43 if (vf
->priv
->w
== 0) vf
->priv
->w
= d_width
;
44 if (vf
->priv
->h
== 0) vf
->priv
->h
= d_height
;
45 if (vf
->priv
->w
== -1) vf
->priv
->w
= width
;
46 if (vf
->priv
->h
== -1) vf
->priv
->h
= height
;
47 if (vf
->priv
->w
== -2) vf
->priv
->w
= vf
->priv
->h
* (double)d_width
/ d_height
;
48 if (vf
->priv
->w
== -3) vf
->priv
->w
= vf
->priv
->h
* (double)width
/ height
;
49 if (vf
->priv
->h
== -2) vf
->priv
->h
= vf
->priv
->w
* (double)d_height
/ d_width
;
50 if (vf
->priv
->h
== -3) vf
->priv
->h
= vf
->priv
->w
* (double)height
/ width
;
51 if (vf
->priv
->method
> -1) {
52 double aspect
= (vf
->priv
->method
& 2) ? ((double)height
/ width
) : ((double)d_height
/ d_width
);
53 if ((vf
->priv
->h
> vf
->priv
->w
* aspect
) ^ (vf
->priv
->method
& 1)) {
54 vf
->priv
->h
= vf
->priv
->w
* aspect
;
56 vf
->priv
->w
= vf
->priv
->h
/ aspect
;
59 if (vf
->priv
->round
> 1) { // round up
60 vf
->priv
->w
+= (vf
->priv
->round
- 1 - (vf
->priv
->w
- 1) % vf
->priv
->round
);
61 vf
->priv
->h
+= (vf
->priv
->round
- 1 - (vf
->priv
->h
- 1) % vf
->priv
->round
);
63 d_width
= vf
->priv
->w
;
64 d_height
= vf
->priv
->h
;
66 if (vf
->priv
->aspect
* height
> width
) {
67 d_width
= height
* vf
->priv
->aspect
+ .5;
70 d_height
= width
/ vf
->priv
->aspect
+ .5;
74 return vf_next_config(vf
, width
, height
, d_width
, d_height
, flags
, outfmt
);
77 static void uninit(vf_instance_t
*vf
) {
82 static int vf_open(vf_instance_t
*vf
, char *args
)
85 vf
->draw_slice
= vf_next_draw_slice
;
87 //vf->default_caps = 0;
88 vf
->priv
= calloc(sizeof(struct vf_priv_s
), 1);
89 vf
->priv
->aspect
= 0.;
92 vf
->priv
->method
= -1;
95 if (strchr(args
, '/')) {
97 sscanf(args
, "%d/%d", &w
, &h
);
98 vf
->priv
->aspect
= (float)w
/h
;
99 } else if (strchr(args
, '.')) {
100 sscanf(args
, "%f", &vf
->priv
->aspect
);
102 sscanf(args
, "%d:%d:%d:%d", &vf
->priv
->w
, &vf
->priv
->h
, &vf
->priv
->method
, &vf
->priv
->round
);
105 if ((vf
->priv
->aspect
< 0.) || (vf
->priv
->w
< -3) || (vf
->priv
->h
< -3) ||
106 ((vf
->priv
->w
< -1) && (vf
->priv
->h
< -1)) ||
107 (vf
->priv
->method
< -1) || (vf
->priv
->method
> 3) ||
108 (vf
->priv
->round
< 0)) {
109 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
);
110 free(vf
->priv
); vf
->priv
= NULL
;
116 const vf_info_t vf_info_dsize
= {
117 "reset displaysize/aspect",