Merge svn changes up to r30216
[mplayer/glamo.git] / libvo / aspect.c
blob1b1e5857f3c75345b09d9676d223b76c335b746e
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 #include "video_out.h"
23 //#ifndef ASPECT_TEST
24 #include "mp_msg.h"
25 #include "help_mp.h"
26 #include "options.h"
27 //#endif
29 //#define ASPECT_DEBUG
31 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
32 #include <stdio.h>
33 #endif
35 #include "video_out.h"
37 void aspect_save_orig(struct vo *vo, int orgw, int orgh)
39 #ifdef ASPECT_DEBUG
40 printf("aspect_save_orig %dx%d \n",orgw,orgh);
41 #endif
42 vo->aspdat.orgw = orgw;
43 vo->aspdat.orgh = orgh;
46 void aspect_save_prescale(struct vo *vo, int prew, int preh)
48 #ifdef ASPECT_DEBUG
49 printf("aspect_save_prescale %dx%d \n",prew,preh);
50 #endif
51 vo->aspdat.prew = prew;
52 vo->aspdat.preh = preh;
55 void aspect_save_screenres(struct vo *vo, int scrw, int scrh)
57 #ifdef ASPECT_DEBUG
58 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
59 #endif
60 struct MPOpts *opts = vo->opts;
61 vo->aspdat.scrw = scrw;
62 vo->aspdat.scrh = scrh;
63 if (opts->force_monitor_aspect)
64 vo->monitor_aspect = opts->force_monitor_aspect;
65 else
66 vo->monitor_aspect = opts->monitor_pixel_aspect * scrw / scrh;
69 /* aspect is called with the source resolution and the
70 * resolution, that the scaled image should fit into
73 void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith)
75 struct aspect_data *aspdat = &vo->aspdat;
76 int tmpw;
78 #ifdef ASPECT_DEBUG
79 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat->scrw,aspdat->scrh,
80 monitor_aspect);
81 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
82 #endif
83 *srcw = fitw;
84 *srch = (int)(((float)fitw / (float)aspdat->prew * (float)aspdat->preh)
85 * ((float)aspdat->scrh / ((float)aspdat->scrw / vo->monitor_aspect)));
86 *srch+= *srch%2; // round
87 #ifdef ASPECT_DEBUG
88 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
89 #endif
90 if(*srch>fith || *srch<aspdat->orgh){
91 tmpw = (int)(((float)fith / (float)aspdat->preh * (float)aspdat->prew)
92 * ((float)aspdat->scrw / ((float)aspdat->scrh / (1.0/vo->monitor_aspect))));
93 tmpw+= tmpw%2; // round
94 if(tmpw<=fitw /*&& tmpw>=aspdat->orgw*/){
95 *srch = fith;
96 *srcw = tmpw;
97 }else{
98 #ifndef ASPECT_TEST
99 mp_tmsg(MSGT_VO,MSGL_WARN,"[ASPECT] Warning: No suitable new res found!\n");
100 #else
101 mp_tmsg(MSGT_VO,MSGL_WARN,"[ASPECT] Error: No new size found that fits into res!\n");
102 #endif
105 aspdat->asp=*srcw / (float)*srch;
106 #ifdef ASPECT_DEBUG
107 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
108 #endif
111 static void get_max_dims(struct vo *vo, int *w, int *h, int zoom)
113 struct aspect_data *aspdat = &vo->aspdat;
114 *w = zoom ? aspdat->scrw : aspdat->prew;
115 *h = zoom ? aspdat->scrh : aspdat->preh;
116 if (zoom && WinID >= 0) zoom = A_WINZOOM;
117 if (zoom == A_WINZOOM) {
118 *w = vo->dwidth;
119 *h = vo->dheight;
123 void aspect(struct vo *vo, int *srcw, int *srch, int zoom)
125 int fitw;
126 int fith;
127 get_max_dims(vo, &fitw, &fith, zoom);
128 if( !zoom && geometry_wh_changed ) {
129 #ifdef ASPECT_DEBUG
130 printf("aspect(0) no aspect forced!\n");
131 #endif
132 return; // the user doesn't want to fix aspect
134 aspect_fit(vo, srcw, srch, fitw, fith);
137 void panscan_init(struct vo *vo)
139 vo->panscan_x = 0;
140 vo->panscan_y = 0;
141 vo->panscan_amount = 0.0f;
144 static void panscan_calc_internal(struct vo *vo, int zoom)
146 int fwidth,fheight;
147 int vo_panscan_area;
148 int max_w, max_h;
149 get_max_dims(vo, &max_w, &max_h, zoom);
150 struct MPOpts *opts = vo->opts;
152 if (opts->vo_panscanrange > 0) {
153 aspect(vo, &fwidth, &fheight, zoom);
154 vo_panscan_area = max_h - fheight;
155 if (!vo_panscan_area)
156 vo_panscan_area = max_w - fwidth;
157 vo_panscan_area *= opts->vo_panscanrange;
158 } else
159 vo_panscan_area = -opts->vo_panscanrange * max_h;
161 vo->panscan_amount = vo_fs || zoom == A_WINZOOM ? vo_panscan : 0;
162 vo->panscan_x = vo_panscan_area * vo->panscan_amount * vo->aspdat.asp;
163 vo->panscan_y = vo_panscan_area * vo->panscan_amount;
166 void panscan_calc(struct vo *vo)
168 panscan_calc_internal(vo, A_ZOOM);
172 * vos that set vo_dwidth and v_dheight correctly should call this to update
173 * vo_panscan_x and vo_panscan_y
175 void panscan_calc_windowed(struct vo *vo)
177 panscan_calc_internal(vo, A_WINZOOM);