2009-02-08 03:27:30 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2001-10-03 14:41:53 +00:00
|
|
|
/* Stuff for correct aspect scaling. */
|
2001-10-18 02:42:20 +00:00
|
|
|
#include "aspect.h"
|
2003-10-15 15:17:09 +00:00
|
|
|
#include "geometry.h"
|
2008-05-01 08:02:26 +00:00
|
|
|
#include "video_out.h"
|
2004-10-28 01:15:53 +00:00
|
|
|
#include "mp_msg.h"
|
2008-05-01 08:14:29 +00:00
|
|
|
#include "options.h"
|
2001-10-03 14:41:53 +00:00
|
|
|
|
2002-06-05 19:35:54 +00:00
|
|
|
#include "video_out.h"
|
|
|
|
|
2008-05-01 08:02:26 +00:00
|
|
|
void aspect_save_orig(struct vo *vo, int orgw, int orgh)
|
|
|
|
{
|
2011-07-04 21:26:14 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect_save_orig %dx%d\n", orgw, orgh);
|
2008-05-01 08:02:26 +00:00
|
|
|
vo->aspdat.orgw = orgw;
|
|
|
|
vo->aspdat.orgh = orgh;
|
2001-10-18 02:42:20 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 08:02:26 +00:00
|
|
|
void aspect_save_prescale(struct vo *vo, int prew, int preh)
|
|
|
|
{
|
2011-07-04 21:26:14 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect_save_prescale %dx%d\n", prew, preh);
|
2008-05-01 08:02:26 +00:00
|
|
|
vo->aspdat.prew = prew;
|
|
|
|
vo->aspdat.preh = preh;
|
2001-10-18 02:42:20 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 08:02:26 +00:00
|
|
|
void aspect_save_screenres(struct vo *vo, int scrw, int scrh)
|
|
|
|
{
|
2011-07-04 21:26:14 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect_save_screenres %dx%d\n", scrw, scrh);
|
2008-05-01 08:14:29 +00:00
|
|
|
struct MPOpts *opts = vo->opts;
|
2010-10-09 01:31:52 +00:00
|
|
|
if (scrw <= 0 && scrh <= 0)
|
|
|
|
scrw = 1024;
|
|
|
|
if (scrh <= 0)
|
|
|
|
scrh = (scrw * 3 + 3) / 4;
|
|
|
|
if (scrw <= 0)
|
|
|
|
scrw = (scrh * 4 + 2) / 3;
|
2008-05-01 08:02:26 +00:00
|
|
|
vo->aspdat.scrw = scrw;
|
|
|
|
vo->aspdat.scrh = scrh;
|
2008-05-01 08:14:29 +00:00
|
|
|
if (opts->force_monitor_aspect)
|
|
|
|
vo->monitor_aspect = opts->force_monitor_aspect;
|
|
|
|
else
|
|
|
|
vo->monitor_aspect = opts->monitor_pixel_aspect * scrw / scrh;
|
2001-10-18 02:42:20 +00:00
|
|
|
}
|
|
|
|
|
2001-10-03 14:41:53 +00:00
|
|
|
/* aspect is called with the source resolution and the
|
|
|
|
* resolution, that the scaled image should fit into
|
|
|
|
*/
|
|
|
|
|
2008-05-01 08:02:26 +00:00
|
|
|
void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith)
|
|
|
|
{
|
|
|
|
struct aspect_data *aspdat = &vo->aspdat;
|
2011-07-04 21:26:14 +00:00
|
|
|
float pixelaspect = vo->monitor_aspect * aspdat->scrh / aspdat->scrw;
|
2001-10-18 02:42:20 +00:00
|
|
|
|
2011-07-04 21:26:14 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect(0) fitin: %dx%d screenaspect: %.2f\n",
|
|
|
|
fitw, fith, vo->monitor_aspect);
|
2008-02-02 17:21:19 +00:00
|
|
|
*srcw = fitw;
|
2011-07-04 21:26:14 +00:00
|
|
|
*srch = (float)fitw / aspdat->prew * aspdat->preh * pixelaspect;
|
|
|
|
*srch += *srch % 2; // round
|
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect(1) wh: %dx%d (org: %dx%d)\n",
|
|
|
|
*srcw, *srch, aspdat->prew, aspdat->preh);
|
|
|
|
if (*srch > fith || *srch < aspdat->orgh) {
|
|
|
|
int tmpw = (float)fith / aspdat->preh * aspdat->prew / pixelaspect;
|
|
|
|
tmpw += tmpw % 2; // round
|
|
|
|
if (tmpw <= fitw) {
|
|
|
|
*srch = fith;
|
|
|
|
*srcw = tmpw;
|
2011-07-04 21:33:57 +00:00
|
|
|
} else if (*srch > fith) {
|
2011-07-04 21:26:14 +00:00
|
|
|
mp_tmsg(MSGT_VO, MSGL_WARN,
|
|
|
|
"[ASPECT] Warning: No suitable new res found!\n");
|
|
|
|
}
|
2001-10-15 17:22:41 +00:00
|
|
|
}
|
2011-07-04 21:26:14 +00:00
|
|
|
aspdat->asp = *srcw / (float)*srch;
|
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect(2) wh: %dx%d (org: %dx%d)\n",
|
|
|
|
*srcw, *srch, aspdat->prew, aspdat->preh);
|
2001-10-03 14:41:53 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:49:35 +00:00
|
|
|
static void get_max_dims(struct vo *vo, int *w, int *h, int zoom)
|
2009-08-27 13:31:12 +00:00
|
|
|
{
|
2009-09-04 16:49:35 +00:00
|
|
|
struct aspect_data *aspdat = &vo->aspdat;
|
2011-07-04 21:26:14 +00:00
|
|
|
*w = zoom ? aspdat->scrw : aspdat->prew;
|
|
|
|
*h = zoom ? aspdat->scrh : aspdat->preh;
|
|
|
|
if (zoom && WinID >= 0)
|
|
|
|
zoom = A_WINZOOM;
|
|
|
|
if (zoom == A_WINZOOM) {
|
|
|
|
*w = vo->dwidth;
|
|
|
|
*h = vo->dheight;
|
|
|
|
}
|
2009-08-27 13:31:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:49:35 +00:00
|
|
|
void aspect(struct vo *vo, int *srcw, int *srch, int zoom)
|
|
|
|
{
|
2011-07-04 21:26:14 +00:00
|
|
|
int fitw;
|
|
|
|
int fith;
|
|
|
|
get_max_dims(vo, &fitw, &fith, zoom);
|
|
|
|
if (!zoom && geometry_wh_changed) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect(0) no aspect forced!\n");
|
|
|
|
return; // the user doesn't want to fix aspect
|
|
|
|
}
|
|
|
|
aspect_fit(vo, srcw, srch, fitw, fith);
|
2008-02-02 17:21:19 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 08:02:26 +00:00
|
|
|
void panscan_init(struct vo *vo)
|
2002-06-05 19:35:54 +00:00
|
|
|
{
|
2008-05-01 08:02:26 +00:00
|
|
|
vo->panscan_x = 0;
|
|
|
|
vo->panscan_y = 0;
|
|
|
|
vo->panscan_amount = 0.0f;
|
2002-06-05 19:35:54 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:49:35 +00:00
|
|
|
static void panscan_calc_internal(struct vo *vo, int zoom)
|
2002-06-05 19:35:54 +00:00
|
|
|
{
|
2011-07-04 21:26:14 +00:00
|
|
|
int fwidth, fheight;
|
|
|
|
int vo_panscan_area;
|
|
|
|
int max_w, max_h;
|
|
|
|
get_max_dims(vo, &max_w, &max_h, zoom);
|
2008-05-01 08:14:29 +00:00
|
|
|
struct MPOpts *opts = vo->opts;
|
2002-06-10 18:40:19 +00:00
|
|
|
|
2008-05-01 08:14:29 +00:00
|
|
|
if (opts->vo_panscanrange > 0) {
|
2009-09-04 16:49:35 +00:00
|
|
|
aspect(vo, &fwidth, &fheight, zoom);
|
|
|
|
vo_panscan_area = max_h - fheight;
|
2008-05-01 08:02:26 +00:00
|
|
|
if (!vo_panscan_area)
|
2009-09-04 16:49:35 +00:00
|
|
|
vo_panscan_area = max_w - fwidth;
|
2008-05-01 08:14:29 +00:00
|
|
|
vo_panscan_area *= opts->vo_panscanrange;
|
2008-05-01 08:02:26 +00:00
|
|
|
} else
|
2009-09-04 16:49:35 +00:00
|
|
|
vo_panscan_area = -opts->vo_panscanrange * max_h;
|
2002-06-10 18:40:19 +00:00
|
|
|
|
2009-09-04 16:49:35 +00:00
|
|
|
vo->panscan_amount = vo_fs || zoom == A_WINZOOM ? vo_panscan : 0;
|
2008-05-01 08:02:26 +00:00
|
|
|
vo->panscan_x = vo_panscan_area * vo->panscan_amount * vo->aspdat.asp;
|
|
|
|
vo->panscan_y = vo_panscan_area * vo->panscan_amount;
|
2002-06-05 19:35:54 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 18:36:51 +00:00
|
|
|
/**
|
|
|
|
* vos that set vo_dwidth and v_dheight correctly should call this to update
|
|
|
|
* vo_panscan_x and vo_panscan_y
|
|
|
|
*/
|
2009-09-04 16:49:35 +00:00
|
|
|
void panscan_calc_windowed(struct vo *vo)
|
2009-08-27 18:36:51 +00:00
|
|
|
{
|
2009-09-04 16:49:35 +00:00
|
|
|
panscan_calc_internal(vo, A_WINZOOM);
|
2009-08-27 18:36:51 +00:00
|
|
|
}
|