stream.h: Add 2 prototypes instead of declaring them in cache2.c
[mplayer.git] / libvo / aspect.c
blob5a2091baba16a097017cc18e183697d2814452e7
1 /* Stuff for correct aspect scaling. */
2 #include "aspect.h"
3 #include "geometry.h"
4 #include "video_out.h"
5 //#ifndef ASPECT_TEST
6 #include "mp_msg.h"
7 #include "help_mp.h"
8 #include "options.h"
9 //#endif
11 //#define ASPECT_DEBUG
13 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
14 #include <stdio.h>
15 #endif
17 #include "video_out.h"
19 void aspect_save_orig(struct vo *vo, int orgw, int orgh)
21 #ifdef ASPECT_DEBUG
22 printf("aspect_save_orig %dx%d \n",orgw,orgh);
23 #endif
24 vo->aspdat.orgw = orgw;
25 vo->aspdat.orgh = orgh;
28 void aspect_save_prescale(struct vo *vo, int prew, int preh)
30 #ifdef ASPECT_DEBUG
31 printf("aspect_save_prescale %dx%d \n",prew,preh);
32 #endif
33 vo->aspdat.prew = prew;
34 vo->aspdat.preh = preh;
37 void aspect_save_screenres(struct vo *vo, int scrw, int scrh)
39 #ifdef ASPECT_DEBUG
40 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
41 #endif
42 struct MPOpts *opts = vo->opts;
43 vo->aspdat.scrw = scrw;
44 vo->aspdat.scrh = scrh;
45 if (opts->force_monitor_aspect)
46 vo->monitor_aspect = opts->force_monitor_aspect;
47 else
48 vo->monitor_aspect = opts->monitor_pixel_aspect * scrw / scrh;
51 /* aspect is called with the source resolution and the
52 * resolution, that the scaled image should fit into
55 void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith)
57 struct aspect_data *aspdat = &vo->aspdat;
58 int tmpw;
60 #ifdef ASPECT_DEBUG
61 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat->scrw,aspdat->scrh,
62 monitor_aspect);
63 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
64 #endif
65 *srcw = fitw;
66 *srch = (int)(((float)fitw / (float)aspdat->prew * (float)aspdat->preh)
67 * ((float)aspdat->scrh / ((float)aspdat->scrw / vo->monitor_aspect)));
68 *srch+= *srch%2; // round
69 #ifdef ASPECT_DEBUG
70 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
71 #endif
72 if(*srch>aspdat->scrh || *srch<aspdat->orgh){
73 tmpw = (int)(((float)fith / (float)aspdat->preh * (float)aspdat->prew)
74 * ((float)aspdat->scrw / ((float)aspdat->scrh / (1.0/vo->monitor_aspect))));
75 tmpw+= tmpw%2; // round
76 if(tmpw<=aspdat->scrw /*&& tmpw>=aspdat->orgw*/){
77 *srch = fith;
78 *srcw = tmpw;
79 }else{
80 #ifndef ASPECT_TEST
81 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound);
82 #else
83 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes);
84 #endif
87 aspdat->asp=*srcw / (float)*srch;
88 #ifdef ASPECT_DEBUG
89 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
90 #endif
93 void aspect(struct vo *vo, int *srcw, int *srch, int zoom){
94 int fitw = zoom ? vo->aspdat.scrw : vo->aspdat.prew;
95 int fith = zoom ? vo->aspdat.scrh : vo->aspdat.preh;
96 if( !zoom && geometry_wh_changed ) {
97 #ifdef ASPECT_DEBUG
98 printf("aspect(0) no aspect forced!\n");
99 #endif
100 return; // the user doesn't want to fix aspect
102 aspect_fit(vo, srcw, srch, fitw, fith);
105 void panscan_init(struct vo *vo)
107 vo->panscan_x = 0;
108 vo->panscan_y = 0;
109 vo->panscan_amount = 0.0f;
112 void panscan_calc(struct vo *vo)
114 int fwidth,fheight;
115 int vo_panscan_area;
116 struct MPOpts *opts = vo->opts;
118 if (opts->vo_panscanrange > 0) {
119 aspect(vo, &fwidth, &fheight, A_ZOOM);
120 vo_panscan_area = (vo->aspdat.scrh - fheight);
121 if (!vo_panscan_area)
122 vo_panscan_area = vo->aspdat.scrw - fwidth;
123 vo_panscan_area *= opts->vo_panscanrange;
124 } else
125 vo_panscan_area = -opts->vo_panscanrange * vo->aspdat.scrh;
127 vo->panscan_amount = vo_fs ? vo_panscan : 0;
128 vo->panscan_x = vo_panscan_area * vo->panscan_amount * vo->aspdat.asp;
129 vo->panscan_y = vo_panscan_area * vo->panscan_amount;