Fix wrong setting of samplesize (must be bytes per sample, not bits)
[mplayer/glamo.git] / libvo / aspect.c
blob44470e16e7277a399bb37ad271e325cdef1589ed
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 monitor_aspect=4.0/3.0;
23 float monitor_pixel_aspect=0;
24 extern float movie_aspect;
26 static struct {
27 int orgw; // real width
28 int orgh; // real height
29 int prew; // prescaled width
30 int preh; // prescaled height
31 int scrw; // horizontal resolution
32 int scrh; // vertical resolution
33 float asp;
34 } aspdat;
36 void aspect_save_orig(int orgw, int orgh){
37 #ifdef ASPECT_DEBUG
38 printf("aspect_save_orig %dx%d \n",orgw,orgh);
39 #endif
40 aspdat.orgw = orgw;
41 aspdat.orgh = orgh;
44 void aspect_save_prescale(int prew, int preh){
45 #ifdef ASPECT_DEBUG
46 printf("aspect_save_prescale %dx%d \n",prew,preh);
47 #endif
48 aspdat.prew = prew;
49 aspdat.preh = preh;
52 void aspect_save_screenres(int scrw, int scrh){
53 #ifdef ASPECT_DEBUG
54 printf("aspect_save_screenres %dx%d \n",scrw,scrh);
55 #endif
56 aspdat.scrw = scrw;
57 aspdat.scrh = scrh;
58 if (monitor_pixel_aspect)
59 monitor_aspect = monitor_pixel_aspect * scrw / scrh;
62 /* aspect is called with the source resolution and the
63 * resolution, that the scaled image should fit into
66 void aspect(int *srcw, int *srch, int zoom){
67 int tmpw;
69 if( !zoom && geometry_wh_changed ) {
70 #ifdef ASPECT_DEBUG
71 printf("aspect(0) no aspect forced!\n");
72 #endif
73 return; // the user doesn't want to fix aspect
76 #ifdef ASPECT_DEBUG
77 printf("aspect(0) fitin: %dx%d zoom: %d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh,
78 zoom,monitor_aspect);
79 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
80 #endif
81 if(zoom){
82 *srcw = aspdat.scrw;
83 *srch = (int)(((float)aspdat.scrw / (float)aspdat.prew * (float)aspdat.preh)
84 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
85 }else{
86 *srcw = aspdat.prew;
87 *srch = (int)((float)aspdat.preh
88 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
90 *srch+= *srch%2; // round
91 #ifdef ASPECT_DEBUG
92 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
93 #endif
94 if(*srch>aspdat.scrh || *srch<aspdat.orgh){
95 if(zoom)
96 tmpw = (int)(((float)aspdat.scrh / (float)aspdat.preh * (float)aspdat.prew)
97 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
98 else
99 tmpw = (int)((float)aspdat.prew
100 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
101 tmpw+= tmpw%2; // round
102 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){
103 *srch = zoom?aspdat.scrh:aspdat.preh;
104 *srcw = tmpw;
105 }else{
106 #ifndef ASPECT_TEST
107 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound);
108 #else
109 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes);
110 #endif
113 aspdat.asp=*srcw / (float)*srch;
114 #ifdef ASPECT_DEBUG
115 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
116 #endif
119 void panscan_init( void )
121 vo_panscan_x=0;
122 vo_panscan_y=0;
123 vo_panscan_amount=0.0f;
126 void panscan_calc( void )
128 int fwidth,fheight;
129 int vo_panscan_area;
131 if (vo_panscanrange > 0) {
132 aspect(&fwidth,&fheight,A_ZOOM);
133 vo_panscan_area = (aspdat.scrh-fheight);
134 vo_panscan_area *= vo_panscanrange;
135 } else
136 vo_panscan_area = -vo_panscanrange * aspdat.scrh;
138 vo_panscan_amount = vo_fs ? vo_panscan : 0;
139 vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp;
140 vo_panscan_y = vo_panscan_area * vo_panscan_amount;