annotate libvo/aspect.c @ 8193:83d3125cb382

A bit more sane range.
author rguyom
date Thu, 14 Nov 2002 21:57:34 +0000
parents 86d5fc5b54e2
children 7c28736ebf2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2053
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
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"
6087
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
3 #ifndef ASPECT_TEST
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
4 #include "../mp_msg.h"
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
5 #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
6
2250
d7923c09dd46 Eeeh :) time to sleep!
atmos4
parents: 2249
diff changeset
7 //#define ASPECT_DEBUG
2071
7f27b212e07b Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents: 2058
diff changeset
8
6087
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
9 #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
10 #include <stdio.h>
7f27b212e07b Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents: 2058
diff changeset
11 #endif
2053
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
12
6307
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
13 int vo_panscan_x = 0;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
14 int vo_panscan_y = 0;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
15 float vo_panscan_amount = 0;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
16
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
17 #include "video_out.h"
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
18
2053
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
19 float monitor_aspect=4.0/3.0;
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
20
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
21 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
22 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
23 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
24 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
25 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
26 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
27 int scrh; // vertical resolution
6307
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
28 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
29 } 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
30
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 void aspect_save_orig(int orgw, int 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
32 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
33 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
34 }
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
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 void aspect_save_prescale(int prew, int 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
37 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
38 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
39 }
48f0ac1e9d13 Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents: 2213
diff changeset
40
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 void aspect_save_screenres(int scrw, int scrh){
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.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
43 aspdat.scrh = scrh;
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
2053
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
46 /* aspect is called with the source resolution and the
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
47 * resolution, that the scaled image should fit into
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
48 */
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
49
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
50 void aspect(int *srcw, int *srch, int zoom){
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 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
52
2071
7f27b212e07b Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents: 2058
diff changeset
53 #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
54 printf("aspect(0) fitin: %dx%d zoom: %d \n",aspdat.scrw,aspdat.scrh,zoom);
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 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
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 if(zoom){
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 *srcw = aspdat.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
59 *srch = (int)(((float)aspdat.scrw / (float)aspdat.prew * (float)aspdat.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
60 * ((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
61 }else{
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 *srcw = aspdat.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
63 *srch = (int)((float)aspdat.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
64 * ((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
65 }
48f0ac1e9d13 Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents: 2213
diff changeset
66 *srch+= *srch%2; // round
2071
7f27b212e07b Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents: 2058
diff changeset
67 #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
68 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
69 #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
70 if(*srch>aspdat.scrh || *srch<aspdat.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
71 if(zoom)
48f0ac1e9d13 Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents: 2213
diff changeset
72 tmpw = (int)(((float)aspdat.scrh / (float)aspdat.preh * (float)aspdat.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
73 * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/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
74 else
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 tmpw = (int)((float)aspdat.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
76 * ((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
77 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
78 if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){
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 *srch = zoom?aspdat.scrh:aspdat.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
80 *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
81 }else{
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
82 #ifndef ASPECT_TEST
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
83 mp_msg(MSGT_VO,MSGL_WARN,"aspect: Warning: no suitable new res found!\n");
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
84 #else
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
85 printf("error: no new size found that fits into res!\n");
8be92a9b30a4 Fix a bug in the aspect coden (roudning at wrong point) and allow donwscaling in second pass.
atmos4
parents: 2250
diff changeset
86 #endif
2213
a98d5300f5e9 Add downscaling as a last resort.
atmos4
parents: 2071
diff changeset
87 }
2053
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
88 }
6307
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
89 aspdat.asp=*srcw / (float)*srch;
2071
7f27b212e07b Add debug printfs to aspect(), add aspect() usage to vo_sdl.
atmos4
parents: 2058
diff changeset
90 #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
91 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
92 #endif
2053
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
93 }
720ca9249e4e Monitor aspect stuff.
atmos4
parents:
diff changeset
94
6307
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
95 void panscan_init( void )
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
96 {
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
97 vo_panscan_x=0;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
98 vo_panscan_y=0;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
99 vo_panscan_amount=0.0f;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
100 }
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
101
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
102 void panscan_calc( void )
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
103 {
6382
86d5fc5b54e2 fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents: 6335
diff changeset
104 int fwidth,fheight;
86d5fc5b54e2 fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents: 6335
diff changeset
105 int vo_panscan_area;
86d5fc5b54e2 fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents: 6335
diff changeset
106
86d5fc5b54e2 fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents: 6335
diff changeset
107 aspect(&fwidth,&fheight,A_ZOOM);
86d5fc5b54e2 fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents: 6335
diff changeset
108 vo_panscan_area = (aspdat.scrh-fheight);
86d5fc5b54e2 fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents: 6335
diff changeset
109
6307
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
110 vo_panscan_amount = vo_fs ? vo_panscan : 0;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
111 vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
112 vo_panscan_y = vo_panscan_area * vo_panscan_amount;
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
113 }
72c87b2ec779 added panscan support for xmga/xvidix
pontscho
parents: 6087
diff changeset
114