typo fixes
[mplayer/greg.git] / libvo / aspect.c
blobf69286d00f5889cd496f14170b13ad17d7d65e50
1 /* Stuff for correct aspect scaling. */
2 #include "aspect.h"
3 #include "geometry.h"
4 //#ifndef ASPECT_TEST
5 #include "mp_msg.h"
6 //#endif
8 //#define ASPECT_DEBUG
10 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
11 #include <stdio.h>
12 #endif
14 int vo_panscan_x = 0;
15 int vo_panscan_y = 0;
16 float vo_panscan_amount = 0;
17 float vo_panscanrange = 1.0;
19 #include "video_out.h"
21 float monitor_aspect=4.0/3.0;
22 float monitor_pixel_aspect=0;
23 extern float movie_aspect;
25 static struct {
26 int orgw; // real width
27 int orgh; // real height
28 int prew; // prescaled width
29 int preh; // prescaled height
30 int scrw; // horizontal resolution
31 int scrh; // vertical resolution
32 float asp;
33 } aspdat;
35 void aspect_save_orig(int orgw, int orgh){
36 #ifdef ASPECT_DEBUG
37 printf("aspect_save_orig %dx%d \n",orgw,orgh);
38 #endif
39 aspdat.orgw = orgw;
40 aspdat.orgh = orgh;
43 void aspect_save_prescale(int prew, int preh){
44 #ifdef ASPECT_DEBUG
45 printf("aspect_save_prescale %dx%d \n",prew,preh);
46 #endif
47 aspdat.prew = prew;
48 aspdat.preh = preh;
51 void aspect_save_screenres(int scrw, int scrh){
52 #ifdef ASPECT_DEBUG
53 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
54 #endif
55 aspdat.scrw = scrw;
56 aspdat.scrh = scrh;
57 if (monitor_pixel_aspect)
58 monitor_aspect = monitor_pixel_aspect * scrw / scrh;
61 /* aspect is called with the source resolution and the
62 * resolution, that the scaled image should fit into
65 void aspect(int *srcw, int *srch, int zoom){
66 int tmpw;
68 if( !zoom && geometry_wh_changed ) {
69 #ifdef ASPECT_DEBUG
70 printf("aspect(0) no aspect forced!\n");
71 #endif
72 return; // the user doesn't want to fix aspect
75 #ifdef ASPECT_DEBUG
76 printf("aspect(0) fitin: %dx%d zoom: %d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh,
77 zoom,monitor_aspect);
78 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
79 #endif
80 if(zoom){
81 *srcw = aspdat.scrw;
82 *srch = (int)(((float)aspdat.scrw / (float)aspdat.prew * (float)aspdat.preh)
83 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
84 }else{
85 *srcw = aspdat.prew;
86 *srch = (int)((float)aspdat.preh
87 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
89 *srch+= *srch%2; // round
90 #ifdef ASPECT_DEBUG
91 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
92 #endif
93 if(*srch>aspdat.scrh || *srch<aspdat.orgh){
94 if(zoom)
95 tmpw = (int)(((float)aspdat.scrh / (float)aspdat.preh * (float)aspdat.prew)
96 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
97 else
98 tmpw = (int)((float)aspdat.prew
99 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
100 tmpw+= tmpw%2; // round
101 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){
102 *srch = zoom?aspdat.scrh:aspdat.preh;
103 *srcw = tmpw;
104 }else{
105 #ifndef ASPECT_TEST
106 mp_msg(MSGT_VO,MSGL_WARN,"aspect: Warning: no suitable new res found!\n");
107 #else
108 mp_msg(MSGT_VO,MSGL_WARN,"error: no new size found that fits into res!\n");
109 #endif
112 aspdat.asp=*srcw / (float)*srch;
113 #ifdef ASPECT_DEBUG
114 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
115 #endif
118 void panscan_init( void )
120 vo_panscan_x=0;
121 vo_panscan_y=0;
122 vo_panscan_amount=0.0f;
125 void panscan_calc( void )
127 int fwidth,fheight;
128 int vo_panscan_area;
130 if (vo_panscanrange > 0) {
131 aspect(&fwidth,&fheight,A_ZOOM);
132 vo_panscan_area = (aspdat.scrh-fheight);
133 vo_panscan_area *= vo_panscanrange;
134 } else
135 vo_panscan_area = -vo_panscanrange * aspdat.scrh;
137 vo_panscan_amount = vo_fs ? vo_panscan : 0;
138 vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp;
139 vo_panscan_y = vo_panscan_area * vo_panscan_amount;