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. */
27 //#define ASPECT_DEBUG
29 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
35 float vo_panscan_amount
= 0;
36 float vo_panscanrange
= 1.0;
38 #include "video_out.h"
40 float force_monitor_aspect
=0;
41 float monitor_aspect
=0;
42 float monitor_pixel_aspect
=1;
45 int orgw
; // real width
46 int orgh
; // real height
47 int prew
; // prescaled width
48 int preh
; // prescaled height
49 int scrw
; // horizontal resolution
50 int scrh
; // vertical resolution
54 void aspect_save_orig(int orgw
, int orgh
){
56 printf("aspect_save_orig %dx%d \n",orgw
,orgh
);
62 void aspect_save_prescale(int prew
, int preh
){
64 printf("aspect_save_prescale %dx%d \n",prew
,preh
);
70 void aspect_save_screenres(int scrw
, int scrh
){
72 printf("aspect_save_screenres %dx%d \n",scrw
,scrh
);
76 if (force_monitor_aspect
)
77 monitor_aspect
= force_monitor_aspect
;
79 monitor_aspect
= monitor_pixel_aspect
* scrw
/ scrh
;
82 /* aspect is called with the source resolution and the
83 * resolution, that the scaled image should fit into
86 void aspect_fit(int *srcw
, int *srch
, int fitw
, int fith
){
90 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat
.scrw
,aspdat
.scrh
,
92 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
.prew
,aspdat
.preh
);
95 *srch
= (int)(((float)fitw
/ (float)aspdat
.prew
* (float)aspdat
.preh
)
96 * ((float)aspdat
.scrh
/ ((float)aspdat
.scrw
/ monitor_aspect
)));
97 *srch
+= *srch
%2; // round
99 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
.prew
,aspdat
.preh
);
101 if(*srch
>fith
|| *srch
<aspdat
.orgh
){
102 tmpw
= (int)(((float)fith
/ (float)aspdat
.preh
* (float)aspdat
.prew
)
103 * ((float)aspdat
.scrw
/ ((float)aspdat
.scrh
/ (1.0/monitor_aspect
))));
104 tmpw
+= tmpw
%2; // round
105 if(tmpw
<=fitw
/*&& tmpw>=aspdat.orgw*/){
110 mp_msg(MSGT_VO
,MSGL_WARN
,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound
);
112 mp_msg(MSGT_VO
,MSGL_WARN
,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes
);
116 aspdat
.asp
=*srcw
/ (float)*srch
;
118 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
.prew
,aspdat
.preh
);
122 static void get_max_dims(int *w
, int *h
, int zoom
)
124 *w
= zoom
? aspdat
.scrw
: aspdat
.prew
;
125 *h
= zoom
? aspdat
.scrh
: aspdat
.preh
;
126 if (zoom
&& WinID
>= 0) zoom
= A_WINZOOM
;
127 if (zoom
== A_WINZOOM
) {
133 void aspect(int *srcw
, int *srch
, int zoom
){
136 get_max_dims(&fitw
, &fith
, zoom
);
137 if( !zoom
&& geometry_wh_changed
) {
139 printf("aspect(0) no aspect forced!\n");
141 return; // the user doesn't want to fix aspect
143 aspect_fit(srcw
, srch
, fitw
, fith
);
146 void panscan_init( void )
150 vo_panscan_amount
=0.0f
;
153 static void panscan_calc_internal(int zoom
)
158 get_max_dims(&max_w
, &max_h
, zoom
);
160 if (vo_panscanrange
> 0) {
161 aspect(&fwidth
,&fheight
,zoom
);
162 vo_panscan_area
= max_h
- fheight
;
163 if (!vo_panscan_area
)
164 vo_panscan_area
= max_w
- fwidth
;
165 vo_panscan_area
*= vo_panscanrange
;
167 vo_panscan_area
= -vo_panscanrange
* max_h
;
169 vo_panscan_amount
= vo_fs
|| zoom
== A_WINZOOM
? vo_panscan
: 0;
170 vo_panscan_x
= vo_panscan_area
* vo_panscan_amount
* aspdat
.asp
;
171 vo_panscan_y
= vo_panscan_area
* vo_panscan_amount
;
174 void panscan_calc(void)
176 panscan_calc_internal(A_ZOOM
);
180 * vos that set vo_dwidth and v_dheight correctly should call this to update
181 * vo_panscan_x and vo_panscan_y
183 void panscan_calc_windowed(void)
185 panscan_calc_internal(A_WINZOOM
);