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.
19 /* Stuff for correct aspect scaling. */
22 #include "video_out.h"
28 //#define ASPECT_DEBUG
30 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
34 #include "video_out.h"
36 void aspect_save_orig(struct vo
*vo
, int orgw
, int orgh
)
39 printf("aspect_save_orig %dx%d \n",orgw
,orgh
);
41 vo
->aspdat
.orgw
= orgw
;
42 vo
->aspdat
.orgh
= orgh
;
45 void aspect_save_prescale(struct vo
*vo
, int prew
, int preh
)
48 printf("aspect_save_prescale %dx%d \n",prew
,preh
);
50 vo
->aspdat
.prew
= prew
;
51 vo
->aspdat
.preh
= preh
;
54 void aspect_save_screenres(struct vo
*vo
, int scrw
, int scrh
)
57 printf("aspect_save_screenres %dx%d \n",scrw
,scrh
);
59 struct MPOpts
*opts
= vo
->opts
;
60 vo
->aspdat
.scrw
= scrw
;
61 vo
->aspdat
.scrh
= scrh
;
62 if (opts
->force_monitor_aspect
)
63 vo
->monitor_aspect
= opts
->force_monitor_aspect
;
65 vo
->monitor_aspect
= opts
->monitor_pixel_aspect
* scrw
/ scrh
;
68 /* aspect is called with the source resolution and the
69 * resolution, that the scaled image should fit into
72 void aspect_fit(struct vo
*vo
, int *srcw
, int *srch
, int fitw
, int fith
)
74 struct aspect_data
*aspdat
= &vo
->aspdat
;
78 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat
->scrw
,aspdat
->scrh
,
80 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
->prew
,aspdat
->preh
);
83 *srch
= (int)(((float)fitw
/ (float)aspdat
->prew
* (float)aspdat
->preh
)
84 * ((float)aspdat
->scrh
/ ((float)aspdat
->scrw
/ vo
->monitor_aspect
)));
85 *srch
+= *srch
%2; // round
87 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
->prew
,aspdat
->preh
);
89 if(*srch
>fith
|| *srch
<aspdat
->orgh
){
90 tmpw
= (int)(((float)fith
/ (float)aspdat
->preh
* (float)aspdat
->prew
)
91 * ((float)aspdat
->scrw
/ ((float)aspdat
->scrh
/ (1.0/vo
->monitor_aspect
))));
92 tmpw
+= tmpw
%2; // round
93 if(tmpw
<=fitw
/*&& tmpw>=aspdat->orgw*/){
98 mp_tmsg(MSGT_VO
,MSGL_WARN
,"[ASPECT] Warning: No suitable new res found!\n");
100 mp_tmsg(MSGT_VO
,MSGL_WARN
,"[ASPECT] Error: No new size found that fits into res!\n");
104 aspdat
->asp
=*srcw
/ (float)*srch
;
106 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
->prew
,aspdat
->preh
);
110 static void get_max_dims(struct vo
*vo
, int *w
, int *h
, int zoom
)
112 struct aspect_data
*aspdat
= &vo
->aspdat
;
113 *w
= zoom
? aspdat
->scrw
: aspdat
->prew
;
114 *h
= zoom
? aspdat
->scrh
: aspdat
->preh
;
115 if (zoom
&& WinID
>= 0) zoom
= A_WINZOOM
;
116 if (zoom
== A_WINZOOM
) {
122 void aspect(struct vo
*vo
, int *srcw
, int *srch
, int zoom
)
126 get_max_dims(vo
, &fitw
, &fith
, zoom
);
127 if( !zoom
&& geometry_wh_changed
) {
129 printf("aspect(0) no aspect forced!\n");
131 return; // the user doesn't want to fix aspect
133 aspect_fit(vo
, srcw
, srch
, fitw
, fith
);
136 void panscan_init(struct vo
*vo
)
140 vo
->panscan_amount
= 0.0f
;
143 static void panscan_calc_internal(struct vo
*vo
, int zoom
)
148 get_max_dims(vo
, &max_w
, &max_h
, zoom
);
149 struct MPOpts
*opts
= vo
->opts
;
151 if (opts
->vo_panscanrange
> 0) {
152 aspect(vo
, &fwidth
, &fheight
, zoom
);
153 vo_panscan_area
= max_h
- fheight
;
154 if (!vo_panscan_area
)
155 vo_panscan_area
= max_w
- fwidth
;
156 vo_panscan_area
*= opts
->vo_panscanrange
;
158 vo_panscan_area
= -opts
->vo_panscanrange
* max_h
;
160 vo
->panscan_amount
= vo_fs
|| zoom
== A_WINZOOM
? vo_panscan
: 0;
161 vo
->panscan_x
= vo_panscan_area
* vo
->panscan_amount
* vo
->aspdat
.asp
;
162 vo
->panscan_y
= vo_panscan_area
* vo
->panscan_amount
;
165 void panscan_calc(struct vo
*vo
)
167 panscan_calc_internal(vo
, A_ZOOM
);
171 * vos that set vo_dwidth and v_dheight correctly should call this to update
172 * vo_panscan_x and vo_panscan_y
174 void panscan_calc_windowed(struct vo
*vo
)
176 panscan_calc_internal(vo
, A_WINZOOM
);