Mercurial > mplayer.hg
annotate libvo/aspect.c @ 28277:a062e840afca
Update copyright year, patch by Zhou Zongyi, zhouzongyi pset.suntec net.
author | diego |
---|---|
date | Thu, 15 Jan 2009 08:46:17 +0000 |
parents | afd170654f62 |
children | 7681eab10aea |
rev | line source |
---|---|
2053 | 1 /* Stuff for correct aspect scaling. */ |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
2 #include "aspect.h" |
11125 | 3 #include "geometry.h" |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
18105
diff
changeset
|
4 //#ifndef ASPECT_TEST |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
11125
diff
changeset
|
5 #include "mp_msg.h" |
20765 | 6 #include "help_mp.h" |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
18105
diff
changeset
|
7 //#endif |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
8 |
2250 | 9 //#define ASPECT_DEBUG |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
10 |
6087
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
11 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST) |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
12 #include <stdio.h> |
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
13 #endif |
2053 | 14 |
6307 | 15 int vo_panscan_x = 0; |
16 int vo_panscan_y = 0; | |
17 float vo_panscan_amount = 0; | |
16607 | 18 float vo_panscanrange = 1.0; |
6307 | 19 |
20 #include "video_out.h" | |
21 | |
23876
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
22 float force_monitor_aspect=0; |
23136 | 23 float monitor_aspect=0; |
24 float monitor_pixel_aspect=1; | |
10907 | 25 extern float movie_aspect; |
2053 | 26 |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
27 static struct { |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
28 int orgw; // real width |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
29 int orgh; // real height |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
30 int prew; // prescaled width |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
31 int preh; // prescaled height |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
32 int scrw; // horizontal resolution |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
33 int scrh; // vertical resolution |
6307 | 34 float asp; |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
35 } aspdat; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
36 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
37 void aspect_save_orig(int orgw, int orgh){ |
8936 | 38 #ifdef ASPECT_DEBUG |
39 printf("aspect_save_orig %dx%d \n",orgw,orgh); | |
40 #endif | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
41 aspdat.orgw = orgw; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
42 aspdat.orgh = orgh; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
43 } |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
44 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
45 void aspect_save_prescale(int prew, int preh){ |
8936 | 46 #ifdef ASPECT_DEBUG |
47 printf("aspect_save_prescale %dx%d \n",prew,preh); | |
48 #endif | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
49 aspdat.prew = prew; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
50 aspdat.preh = preh; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
51 } |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
52 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
53 void aspect_save_screenres(int scrw, int scrh){ |
8936 | 54 #ifdef ASPECT_DEBUG |
55 printf("aspect_save_screenres %dx%d \n",scrw,scrh); | |
56 #endif | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
57 aspdat.scrw = scrw; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
58 aspdat.scrh = scrh; |
23876
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
59 if (force_monitor_aspect) |
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
60 monitor_aspect = force_monitor_aspect; |
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
61 else |
18105
954eac69b532
new monitorpixelaspect option, esp. useful for xinerama setups with upcoming patch
reimar
parents:
16607
diff
changeset
|
62 monitor_aspect = monitor_pixel_aspect * scrw / scrh; |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
63 } |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
64 |
2053 | 65 /* aspect is called with the source resolution and the |
66 * resolution, that the scaled image should fit into | |
67 */ | |
68 | |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
69 void aspect_fit(int *srcw, int *srch, int fitw, int fith){ |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
70 int tmpw; |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
71 |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
72 #ifdef ASPECT_DEBUG |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
73 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh, |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
74 monitor_aspect); |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
75 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh); |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
76 #endif |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
77 *srcw = fitw; |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
78 *srch = (int)(((float)fitw / (float)aspdat.prew * (float)aspdat.preh) |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
79 * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect))); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
80 *srch+= *srch%2; // round |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
81 #ifdef ASPECT_DEBUG |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
82 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh); |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
83 #endif |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
84 if(*srch>aspdat.scrh || *srch<aspdat.orgh){ |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
85 tmpw = (int)(((float)fith / (float)aspdat.preh * (float)aspdat.prew) |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
86 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect)))); |
6087
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
87 tmpw+= tmpw%2; // round |
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
88 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){ |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
89 *srch = fith; |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
90 *srcw = tmpw; |
6087
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
91 }else{ |
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
92 #ifndef ASPECT_TEST |
20765 | 93 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound); |
6087
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
94 #else |
20765 | 95 mp_msg(MSGT_VO,MSGL_WARN,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes); |
6087
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
96 #endif |
2213 | 97 } |
2053 | 98 } |
6307 | 99 aspdat.asp=*srcw / (float)*srch; |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
100 #ifdef ASPECT_DEBUG |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
101 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh); |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
102 #endif |
2053 | 103 } |
104 | |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
105 void aspect(int *srcw, int *srch, int zoom){ |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
106 int fitw = zoom ? aspdat.scrw : aspdat.prew; |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
107 int fith = zoom ? aspdat.scrh : aspdat.preh; |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
108 if( !zoom && geometry_wh_changed ) { |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
109 #ifdef ASPECT_DEBUG |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
110 printf("aspect(0) no aspect forced!\n"); |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
111 #endif |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
112 return; // the user doesn't want to fix aspect |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
113 } |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
114 aspect_fit(srcw, srch, fitw, fith); |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
115 } |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
116 |
6307 | 117 void panscan_init( void ) |
118 { | |
119 vo_panscan_x=0; | |
120 vo_panscan_y=0; | |
121 vo_panscan_amount=0.0f; | |
122 } | |
123 | |
124 void panscan_calc( void ) | |
125 { | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
126 int fwidth,fheight; |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
127 int vo_panscan_area; |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
128 |
16607 | 129 if (vo_panscanrange > 0) { |
25781 | 130 aspect(&fwidth,&fheight,A_ZOOM); |
131 vo_panscan_area = (aspdat.scrh-fheight); | |
25782
aac51b420d89
-panscan should also work for right and left borders
reimar
parents:
25781
diff
changeset
|
132 if (!vo_panscan_area) |
aac51b420d89
-panscan should also work for right and left borders
reimar
parents:
25781
diff
changeset
|
133 vo_panscan_area = aspdat.scrw - fwidth; |
16607 | 134 vo_panscan_area *= vo_panscanrange; |
135 } else | |
136 vo_panscan_area = -vo_panscanrange * aspdat.scrh; | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
137 |
6307 | 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; | |
141 } | |
142 |