1000l, play_tree_parser_stop_keeping broke 0-termination of buffer
[mplayer/glamo.git] / libvo / aspect.c
blobdfed30d97689e9b306bef3df32125a66380504c4
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_fit(int *srcw, int *srch, int fitw, int fith){
70 int tmpw;
72 #ifdef ASPECT_DEBUG
73 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh,
74 monitor_aspect);
75 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
76 #endif
77 *srcw = fitw;
78 *srch = (int)(((float)fitw / (float)aspdat.prew * (float)aspdat.preh)
79 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
80 *srch+= *srch%2; // round
81 #ifdef ASPECT_DEBUG
82 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
83 #endif
84 if(*srch>aspdat.scrh || *srch<aspdat.orgh){
85 tmpw = (int)(((float)fith / (float)aspdat.preh * (float)aspdat.prew)
86 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
87 tmpw+= tmpw%2; // round
88 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){
89 *srch = fith;
90 *srcw = tmpw;
91 }else{
92 #ifndef ASPECT_TEST
93 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound);
94 #else
95 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes);
96 #endif
99 aspdat.asp=*srcw / (float)*srch;
100 #ifdef ASPECT_DEBUG
101 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
102 #endif
105 void aspect(int *srcw, int *srch, int zoom){
106 int fitw = zoom ? aspdat.scrw : aspdat.prew;
107 int fith = zoom ? aspdat.scrh : aspdat.preh;
108 if( !zoom && geometry_wh_changed ) {
109 #ifdef ASPECT_DEBUG
110 printf("aspect(0) no aspect forced!\n");
111 #endif
112 return; // the user doesn't want to fix aspect
114 aspect_fit(srcw, srch, fitw, fith);
117 void panscan_init( void )
119 vo_panscan_x=0;
120 vo_panscan_y=0;
121 vo_panscan_amount=0.0f;
124 void panscan_calc( void )
126 int fwidth,fheight;
127 int vo_panscan_area;
129 if (vo_panscanrange > 0) {
130 aspect(&fwidth,&fheight,A_ZOOM);
131 vo_panscan_area = (aspdat.scrh-fheight);
132 if (!vo_panscan_area)
133 vo_panscan_area = aspdat.scrw - fwidth;
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;