Add const where appropriate, also gets rid of a compiler warning.
[mplayer/glamo.git] / libvo / aspect.c
blobe54e8deb439666eec9e56551ed0a443dc78562c8
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;
43 extern float movie_aspect;
45 static struct {
46 int orgw; // real width
47 int orgh; // real height
48 int prew; // prescaled width
49 int preh; // prescaled height
50 int scrw; // horizontal resolution
51 int scrh; // vertical resolution
52 float asp;
53 } aspdat;
55 void aspect_save_orig(int orgw, int orgh){
56 #ifdef ASPECT_DEBUG
57 printf("aspect_save_orig %dx%d \n",orgw,orgh);
58 #endif
59 aspdat.orgw = orgw;
60 aspdat.orgh = orgh;
63 void aspect_save_prescale(int prew, int preh){
64 #ifdef ASPECT_DEBUG
65 printf("aspect_save_prescale %dx%d \n",prew,preh);
66 #endif
67 aspdat.prew = prew;
68 aspdat.preh = preh;
71 void aspect_save_screenres(int scrw, int scrh){
72 #ifdef ASPECT_DEBUG
73 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
74 #endif
75 aspdat.scrw = scrw;
76 aspdat.scrh = scrh;
77 if (force_monitor_aspect)
78 monitor_aspect = force_monitor_aspect;
79 else
80 monitor_aspect = monitor_pixel_aspect * scrw / scrh;
83 /* aspect is called with the source resolution and the
84 * resolution, that the scaled image should fit into
87 void aspect_fit(int *srcw, int *srch, int fitw, int fith){
88 int tmpw;
90 #ifdef ASPECT_DEBUG
91 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh,
92 monitor_aspect);
93 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
94 #endif
95 *srcw = fitw;
96 *srch = (int)(((float)fitw / (float)aspdat.prew * (float)aspdat.preh)
97 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
98 *srch+= *srch%2; // round
99 #ifdef ASPECT_DEBUG
100 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
101 #endif
102 if(*srch>aspdat.scrh || *srch<aspdat.orgh){
103 tmpw = (int)(((float)fith / (float)aspdat.preh * (float)aspdat.prew)
104 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
105 tmpw+= tmpw%2; // round
106 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){
107 *srch = fith;
108 *srcw = tmpw;
109 }else{
110 #ifndef ASPECT_TEST
111 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound);
112 #else
113 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes);
114 #endif
117 aspdat.asp=*srcw / (float)*srch;
118 #ifdef ASPECT_DEBUG
119 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
120 #endif
123 void aspect(int *srcw, int *srch, int zoom){
124 int fitw = zoom ? aspdat.scrw : aspdat.prew;
125 int fith = zoom ? aspdat.scrh : aspdat.preh;
126 if( !zoom && geometry_wh_changed ) {
127 #ifdef ASPECT_DEBUG
128 printf("aspect(0) no aspect forced!\n");
129 #endif
130 return; // the user doesn't want to fix aspect
132 aspect_fit(srcw, srch, fitw, fith);
135 void panscan_init( void )
137 vo_panscan_x=0;
138 vo_panscan_y=0;
139 vo_panscan_amount=0.0f;
142 void panscan_calc( void )
144 int fwidth,fheight;
145 int vo_panscan_area;
147 if (vo_panscanrange > 0) {
148 aspect(&fwidth,&fheight,A_ZOOM);
149 vo_panscan_area = (aspdat.scrh-fheight);
150 if (!vo_panscan_area)
151 vo_panscan_area = aspdat.scrw - fwidth;
152 vo_panscan_area *= vo_panscanrange;
153 } else
154 vo_panscan_area = -vo_panscanrange * aspdat.scrh;
156 vo_panscan_amount = vo_fs ? vo_panscan : 0;
157 vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp;
158 vo_panscan_y = vo_panscan_area * vo_panscan_amount;