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"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "vo.h"
|
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "core/options.h"
|
2001-10-03 14:41:53 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "vo.h"
|
2002-06-05 19:35:54 +00:00
|
|
|
|
2012-10-18 15:31:00 +00:00
|
|
|
void aspect_save_videores(struct vo *vo, int w, int h, int d_w, int d_h)
|
2008-05-01 08:02:26 +00:00
|
|
|
{
|
2012-10-18 15:31:00 +00:00
|
|
|
vo->aspdat.orgw = w;
|
|
|
|
vo->aspdat.orgh = h;
|
|
|
|
vo->aspdat.prew = d_w;
|
|
|
|
vo->aspdat.preh = d_h;
|
|
|
|
vo->aspdat.par = (double)d_w / d_h * h / w;
|
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);
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *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;
|
2013-03-04 21:41:27 +00:00
|
|
|
if (opts->force_monitor_aspect)
|
2013-03-14 15:21:37 +00:00
|
|
|
vo->aspdat.monitor_par = opts->force_monitor_aspect * scrh / scrw;
|
2008-05-01 08:14:29 +00:00
|
|
|
else
|
2013-03-14 15:21:37 +00:00
|
|
|
vo->aspdat.monitor_par = 1.0 / opts->monitor_pixel_aspect;
|
2001-10-18 02:42:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 15:21:37 +00:00
|
|
|
void aspect_calc_monitor(struct vo *vo, int *w, int *h)
|
|
|
|
{
|
|
|
|
float pixelaspect = vo->aspdat.monitor_par;
|
2001-10-03 14:41:53 +00:00
|
|
|
|
2013-03-14 15:21:37 +00:00
|
|
|
if (pixelaspect < 1) {
|
|
|
|
*h /= pixelaspect;
|
|
|
|
} else {
|
|
|
|
*w *= pixelaspect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspect_calc(struct vo *vo, int *srcw, int *srch)
|
2008-05-01 08:02:26 +00:00
|
|
|
{
|
|
|
|
struct aspect_data *aspdat = &vo->aspdat;
|
2013-03-14 15:21:37 +00:00
|
|
|
float pixelaspect = aspdat->monitor_par;
|
|
|
|
|
|
|
|
int fitw = vo->dwidth;
|
|
|
|
int fith = vo->dheight;
|
2001-10-18 02:42:20 +00:00
|
|
|
|
2012-10-18 15:31:00 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "aspect(0) fitin: %dx%d monitor_par: %.2f\n",
|
2013-03-14 15:21:37 +00:00
|
|
|
fitw, fith, aspdat->monitor_par);
|
2008-02-02 17:21:19 +00:00
|
|
|
*srcw = fitw;
|
2012-10-18 15:31:00 +00:00
|
|
|
*srch = (float)fitw / aspdat->prew * aspdat->preh / pixelaspect;
|
2011-07-04 21:26:14 +00:00
|
|
|
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) {
|
2012-10-18 15:31:00 +00:00
|
|
|
int tmpw = (float)fith / aspdat->preh * aspdat->prew * pixelaspect;
|
2011-07-04 21:26:14 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-14 15:21:37 +00:00
|
|
|
void aspect_calc_panscan(struct vo *vo, int *out_w, int *out_h)
|
2002-06-05 19:35:54 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-03-14 15:21:37 +00:00
|
|
|
int fwidth, fheight;
|
|
|
|
aspect_calc(vo, &fwidth, &fheight);
|
2002-06-10 18:40:19 +00:00
|
|
|
|
2013-03-14 15:21:37 +00:00
|
|
|
int vo_panscan_area;
|
2013-03-04 21:41:27 +00:00
|
|
|
if (opts->panscanrange > 0) {
|
2013-03-14 15:21:37 +00:00
|
|
|
vo_panscan_area = vo->dheight - fheight;
|
2008-05-01 08:02:26 +00:00
|
|
|
if (!vo_panscan_area)
|
2013-03-14 15:21:37 +00:00
|
|
|
vo_panscan_area = vo->dwidth - fwidth;
|
2013-03-04 21:41:27 +00:00
|
|
|
vo_panscan_area *= opts->panscanrange;
|
2008-05-01 08:02:26 +00:00
|
|
|
} else
|
2013-03-14 15:21:37 +00:00
|
|
|
vo_panscan_area = -opts->panscanrange * vo->dheight;
|
2002-06-05 19:35:54 +00:00
|
|
|
|
2013-03-17 21:12:16 +00:00
|
|
|
*out_w = fwidth + vo_panscan_area * opts->panscan * vo->aspdat.asp;
|
|
|
|
*out_h = fheight + vo_panscan_area * opts->panscan;
|
2009-08-27 18:36:51 +00:00
|
|
|
}
|