sync with en/mplayer.1 r29805
[mplayer/glamo.git] / libvo / aspect.c
blob9ddc105aee3ef40f08a2cdee1faf26e1354ed2d1
1 /*
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. */
20 #include "aspect.h"
21 #include "geometry.h"
22 //#ifndef ASPECT_TEST
23 #include "mp_msg.h"
24 #include "help_mp.h"
25 //#endif
27 //#define ASPECT_DEBUG
29 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
30 #include <stdio.h>
31 #endif
33 int vo_panscan_x = 0;
34 int vo_panscan_y = 0;
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;
44 static struct {
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
51 float asp;
52 } aspdat;
54 void aspect_save_orig(int orgw, int orgh){
55 #ifdef ASPECT_DEBUG
56 printf("aspect_save_orig %dx%d \n",orgw,orgh);
57 #endif
58 aspdat.orgw = orgw;
59 aspdat.orgh = orgh;
62 void aspect_save_prescale(int prew, int preh){
63 #ifdef ASPECT_DEBUG
64 printf("aspect_save_prescale %dx%d \n",prew,preh);
65 #endif
66 aspdat.prew = prew;
67 aspdat.preh = preh;
70 void aspect_save_screenres(int scrw, int scrh){
71 #ifdef ASPECT_DEBUG
72 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
73 #endif
74 aspdat.scrw = scrw;
75 aspdat.scrh = scrh;
76 if (force_monitor_aspect)
77 monitor_aspect = force_monitor_aspect;
78 else
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){
87 int tmpw;
89 #ifdef ASPECT_DEBUG
90 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh,
91 monitor_aspect);
92 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
93 #endif
94 *srcw = fitw;
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
98 #ifdef ASPECT_DEBUG
99 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
100 #endif
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*/){
106 *srch = fith;
107 *srcw = tmpw;
108 }else{
109 #ifndef ASPECT_TEST
110 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound);
111 #else
112 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes);
113 #endif
116 aspdat.asp=*srcw / (float)*srch;
117 #ifdef ASPECT_DEBUG
118 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
119 #endif
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) {
128 *w = vo_dwidth;
129 *h = vo_dheight;
133 void aspect(int *srcw, int *srch, int zoom){
134 int fitw;
135 int fith;
136 get_max_dims(&fitw, &fith, zoom);
137 if( !zoom && geometry_wh_changed ) {
138 #ifdef ASPECT_DEBUG
139 printf("aspect(0) no aspect forced!\n");
140 #endif
141 return; // the user doesn't want to fix aspect
143 aspect_fit(srcw, srch, fitw, fith);
146 void panscan_init( void )
148 vo_panscan_x=0;
149 vo_panscan_y=0;
150 vo_panscan_amount=0.0f;
153 static void panscan_calc_internal(int zoom)
155 int fwidth,fheight;
156 int vo_panscan_area;
157 int max_w, max_h;
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;
166 } else
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);