Comment out the correct #endif directive.
[mplayer/greg.git] / libvo / aspect.c
blobb7f9b4bc84ff63b09a5da5883c2c3b19dd994921
1 /* Stuff for correct aspect scaling. */
2 #include "aspect.h"
3 #include "geometry.h"
4 //#ifndef ASPECT_TEST
5 #include "mp_msg.h"
6 #include "help_mp.h"
7 //#endif
9 //#define ASPECT_DEBUG
11 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
12 #include <stdio.h>
13 #endif
15 int vo_panscan_x = 0;
16 int vo_panscan_y = 0;
17 float vo_panscan_amount = 0;
18 float vo_panscanrange = 1.0;
20 #include "video_out.h"
22 float force_monitor_aspect=0;
23 float monitor_aspect=0;
24 float monitor_pixel_aspect=1;
25 extern float movie_aspect;
27 static struct {
28 int orgw; // real width
29 int orgh; // real height
30 int prew; // prescaled width
31 int preh; // prescaled height
32 int scrw; // horizontal resolution
33 int scrh; // vertical resolution
34 float asp;
35 } aspdat;
37 void aspect_save_orig(int orgw, int orgh){
38 #ifdef ASPECT_DEBUG
39 printf("aspect_save_orig %dx%d \n",orgw,orgh);
40 #endif
41 aspdat.orgw = orgw;
42 aspdat.orgh = orgh;
45 void aspect_save_prescale(int prew, int preh){
46 #ifdef ASPECT_DEBUG
47 printf("aspect_save_prescale %dx%d \n",prew,preh);
48 #endif
49 aspdat.prew = prew;
50 aspdat.preh = preh;
53 void aspect_save_screenres(int scrw, int scrh){
54 #ifdef ASPECT_DEBUG
55 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
56 #endif
57 aspdat.scrw = scrw;
58 aspdat.scrh = scrh;
59 if (force_monitor_aspect)
60 monitor_aspect = force_monitor_aspect;
61 else
62 monitor_aspect = monitor_pixel_aspect * scrw / scrh;
65 /* aspect is called with the source resolution and the
66 * resolution, that the scaled image should fit into
69 void aspect(int *srcw, int *srch, int zoom){
70 int tmpw;
72 if( !zoom && geometry_wh_changed ) {
73 #ifdef ASPECT_DEBUG
74 printf("aspect(0) no aspect forced!\n");
75 #endif
76 return; // the user doesn't want to fix aspect
79 #ifdef ASPECT_DEBUG
80 printf("aspect(0) fitin: %dx%d zoom: %d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh,
81 zoom,monitor_aspect);
82 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
83 #endif
84 if(zoom){
85 *srcw = aspdat.scrw;
86 *srch = (int)(((float)aspdat.scrw / (float)aspdat.prew * (float)aspdat.preh)
87 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
88 }else{
89 *srcw = aspdat.prew;
90 *srch = (int)((float)aspdat.preh
91 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
93 *srch+= *srch%2; // round
94 #ifdef ASPECT_DEBUG
95 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
96 #endif
97 if(*srch>aspdat.scrh || *srch<aspdat.orgh){
98 if(zoom)
99 tmpw = (int)(((float)aspdat.scrh / (float)aspdat.preh * (float)aspdat.prew)
100 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
101 else
102 tmpw = (int)((float)aspdat.prew
103 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
104 tmpw+= tmpw%2; // round
105 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){
106 *srch = zoom?aspdat.scrh:aspdat.preh;
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 void panscan_init( void )
124 vo_panscan_x=0;
125 vo_panscan_y=0;
126 vo_panscan_amount=0.0f;
129 void panscan_calc( void )
131 int fwidth,fheight;
132 int vo_panscan_area;
134 if (vo_panscanrange > 0) {
135 aspect(&fwidth,&fheight,A_ZOOM);
136 vo_panscan_area = (aspdat.scrh-fheight);
137 vo_panscan_area *= vo_panscanrange;
138 } else
139 vo_panscan_area = -vo_panscanrange * aspdat.scrh;
141 vo_panscan_amount = vo_fs ? vo_panscan : 0;
142 vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp;
143 vo_panscan_y = vo_panscan_area * vo_panscan_amount;