1 /* Stuff for correct aspect scaling. */
11 //#define ASPECT_DEBUG
13 #if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
17 #include "video_out.h"
19 void aspect_save_orig(struct vo
*vo
, int orgw
, int orgh
)
22 printf("aspect_save_orig %dx%d \n",orgw
,orgh
);
24 vo
->aspdat
.orgw
= orgw
;
25 vo
->aspdat
.orgh
= orgh
;
28 void aspect_save_prescale(struct vo
*vo
, int prew
, int preh
)
31 printf("aspect_save_prescale %dx%d \n",prew
,preh
);
33 vo
->aspdat
.prew
= prew
;
34 vo
->aspdat
.preh
= preh
;
37 void aspect_save_screenres(struct vo
*vo
, int scrw
, int scrh
)
40 printf("aspect_save_screenres %dx%d \n",scrw
,scrh
);
42 struct MPOpts
*opts
= vo
->opts
;
43 vo
->aspdat
.scrw
= scrw
;
44 vo
->aspdat
.scrh
= scrh
;
45 if (opts
->force_monitor_aspect
)
46 vo
->monitor_aspect
= opts
->force_monitor_aspect
;
48 vo
->monitor_aspect
= opts
->monitor_pixel_aspect
* scrw
/ scrh
;
51 /* aspect is called with the source resolution and the
52 * resolution, that the scaled image should fit into
55 void aspect_fit(struct vo
*vo
, int *srcw
, int *srch
, int fitw
, int fith
)
57 struct aspect_data
*aspdat
= &vo
->aspdat
;
61 printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat
->scrw
,aspdat
->scrh
,
63 printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
->prew
,aspdat
->preh
);
66 *srch
= (int)(((float)fitw
/ (float)aspdat
->prew
* (float)aspdat
->preh
)
67 * ((float)aspdat
->scrh
/ ((float)aspdat
->scrw
/ vo
->monitor_aspect
)));
68 *srch
+= *srch
%2; // round
70 printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
->prew
,aspdat
->preh
);
72 if(*srch
>aspdat
->scrh
|| *srch
<aspdat
->orgh
){
73 tmpw
= (int)(((float)fith
/ (float)aspdat
->preh
* (float)aspdat
->prew
)
74 * ((float)aspdat
->scrw
/ ((float)aspdat
->scrh
/ (1.0/vo
->monitor_aspect
))));
75 tmpw
+= tmpw
%2; // round
76 if(tmpw
<=aspdat
->scrw
/*&& tmpw>=aspdat->orgw*/){
81 mp_msg(MSGT_VO
,MSGL_WARN
,MSGTR_LIBVO_ASPECT_NoSuitableNewResFound
);
83 mp_msg(MSGT_VO
,MSGL_WARN
,MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes
);
87 aspdat
->asp
=*srcw
/ (float)*srch
;
89 printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw
,*srch
,aspdat
->prew
,aspdat
->preh
);
93 void aspect(struct vo
*vo
, int *srcw
, int *srch
, int zoom
){
94 int fitw
= zoom
? vo
->aspdat
.scrw
: vo
->aspdat
.prew
;
95 int fith
= zoom
? vo
->aspdat
.scrh
: vo
->aspdat
.preh
;
96 if( !zoom
&& geometry_wh_changed
) {
98 printf("aspect(0) no aspect forced!\n");
100 return; // the user doesn't want to fix aspect
102 aspect_fit(vo
, srcw
, srch
, fitw
, fith
);
105 void panscan_init(struct vo
*vo
)
109 vo
->panscan_amount
= 0.0f
;
112 void panscan_calc(struct vo
*vo
)
116 struct MPOpts
*opts
= vo
->opts
;
118 if (opts
->vo_panscanrange
> 0) {
119 aspect(vo
, &fwidth
, &fheight
, A_ZOOM
);
120 vo_panscan_area
= (vo
->aspdat
.scrh
- fheight
);
121 if (!vo_panscan_area
)
122 vo_panscan_area
= vo
->aspdat
.scrw
- fwidth
;
123 vo_panscan_area
*= opts
->vo_panscanrange
;
125 vo_panscan_area
= -opts
->vo_panscanrange
* vo
->aspdat
.scrh
;
127 vo
->panscan_amount
= vo_fs
? vo_panscan
: 0;
128 vo
->panscan_x
= vo_panscan_area
* vo
->panscan_amount
* vo
->aspdat
.asp
;
129 vo
->panscan_y
= vo_panscan_area
* vo
->panscan_amount
;