Mercurial > mplayer.hg
annotate libvo/aspect.c @ 28854:96c6451478af
rtjpegn.c is only needed by the NuppelVideo encoder, change Makefile accordingly
author | reimar |
---|---|
date | Sun, 08 Mar 2009 13:56:35 +0000 |
parents | 7681eab10aea |
children | d3700065005f |
rev | line source |
---|---|
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
1 /* |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
2 * This file is part of MPlayer. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
3 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
7 * (at your option) any later version. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
8 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
12 * GNU General Public License for more details. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
13 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
17 */ |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
25917
diff
changeset
|
18 |
2053 | 19 /* 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
|
20 #include "aspect.h" |
11125 | 21 #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
|
22 //#ifndef ASPECT_TEST |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
11125
diff
changeset
|
23 #include "mp_msg.h" |
20765 | 24 #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
|
25 //#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
|
26 |
2250 | 27 //#define ASPECT_DEBUG |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
28 |
6087
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
29 #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
|
30 #include <stdio.h> |
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
31 #endif |
2053 | 32 |
6307 | 33 int vo_panscan_x = 0; |
34 int vo_panscan_y = 0; | |
35 float vo_panscan_amount = 0; | |
16607 | 36 float vo_panscanrange = 1.0; |
6307 | 37 |
38 #include "video_out.h" | |
39 | |
23876
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
40 float force_monitor_aspect=0; |
23136 | 41 float monitor_aspect=0; |
42 float monitor_pixel_aspect=1; | |
10907 | 43 extern float movie_aspect; |
2053 | 44 |
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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 int scrh; // vertical resolution |
6307 | 52 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
|
53 } 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
|
54 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
55 void aspect_save_orig(int orgw, int orgh){ |
8936 | 56 #ifdef ASPECT_DEBUG |
57 printf("aspect_save_orig %dx%d \n",orgw,orgh); | |
58 #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
|
59 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
|
60 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
|
61 } |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2213
diff
changeset
|
62 |
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 void aspect_save_prescale(int prew, int preh){ |
8936 | 64 #ifdef ASPECT_DEBUG |
65 printf("aspect_save_prescale %dx%d \n",prew,preh); | |
66 #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
|
67 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
|
68 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
|
69 } |
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 |
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 void aspect_save_screenres(int scrw, int scrh){ |
8936 | 72 #ifdef ASPECT_DEBUG |
73 printf("aspect_save_screenres %dx%d \n",scrw,scrh); | |
74 #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
|
75 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
|
76 aspdat.scrh = scrh; |
23876
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
77 if (force_monitor_aspect) |
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
78 monitor_aspect = force_monitor_aspect; |
b38974c30ed6
Use a new variable for user-supplied monitor-aspect so we can overwrite
reimar
parents:
23136
diff
changeset
|
79 else |
18105
954eac69b532
new monitorpixelaspect option, esp. useful for xinerama setups with upcoming patch
reimar
parents:
16607
diff
changeset
|
80 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
|
81 } |
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 |
2053 | 83 /* aspect is called with the source resolution and the |
84 * resolution, that the scaled image should fit into | |
85 */ | |
86 | |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
87 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
|
88 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
|
89 |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
90 #ifdef ASPECT_DEBUG |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 #endif |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
95 *srcw = fitw; |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
96 *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
|
97 * ((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
|
98 *srch+= *srch%2; // round |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
99 #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
|
100 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
|
101 #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
|
102 if(*srch>aspdat.scrh || *srch<aspdat.orgh){ |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
103 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
|
104 * ((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
|
105 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
|
106 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){ |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
107 *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
|
108 *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
|
109 }else{ |
8be92a9b30a4
Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents:
2250
diff
changeset
|
110 #ifndef ASPECT_TEST |
20765 | 111 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
|
112 #else |
20765 | 113 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
|
114 #endif |
2213 | 115 } |
2053 | 116 } |
6307 | 117 aspdat.asp=*srcw / (float)*srch; |
2071
7f27b212e07b
Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents:
2058
diff
changeset
|
118 #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
|
119 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
|
120 #endif |
2053 | 121 } |
122 | |
25917
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
123 void aspect(int *srcw, int *srch, int zoom){ |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
124 int fitw = zoom ? aspdat.scrw : aspdat.prew; |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
125 int fith = zoom ? aspdat.scrh : aspdat.preh; |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
126 if( !zoom && geometry_wh_changed ) { |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
127 #ifdef ASPECT_DEBUG |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
128 printf("aspect(0) no aspect forced!\n"); |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
129 #endif |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
130 return; // the user doesn't want to fix aspect |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
131 } |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
132 aspect_fit(srcw, srch, fitw, fith); |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
133 } |
afd170654f62
Make aspect adjustment calculation simpler and more flexible.
reimar
parents:
25782
diff
changeset
|
134 |
6307 | 135 void panscan_init( void ) |
136 { | |
137 vo_panscan_x=0; | |
138 vo_panscan_y=0; | |
139 vo_panscan_amount=0.0f; | |
140 } | |
141 | |
142 void panscan_calc( void ) | |
143 { | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
144 int fwidth,fheight; |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
145 int vo_panscan_area; |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
146 |
16607 | 147 if (vo_panscanrange > 0) { |
25781 | 148 aspect(&fwidth,&fheight,A_ZOOM); |
149 vo_panscan_area = (aspdat.scrh-fheight); | |
25782
aac51b420d89
-panscan should also work for right and left borders
reimar
parents:
25781
diff
changeset
|
150 if (!vo_panscan_area) |
aac51b420d89
-panscan should also work for right and left borders
reimar
parents:
25781
diff
changeset
|
151 vo_panscan_area = aspdat.scrw - fwidth; |
16607 | 152 vo_panscan_area *= vo_panscanrange; |
153 } else | |
154 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
|
155 |
6307 | 156 vo_panscan_amount = vo_fs ? vo_panscan : 0; |
157 vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp; | |
158 vo_panscan_y = vo_panscan_area * vo_panscan_amount; | |
159 } | |
160 |