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"
|
2006-04-24 04:23:53 +00:00
|
|
|
//#ifndef ASPECT_TEST
|
2004-10-28 01:15:53 +00:00
|
|
|
#include "mp_msg.h"
|
2006-11-08 14:55:37 +00:00
|
|
|
#include "help_mp.h"
|
2008-05-01 08:14:29 +00:00
|
|
|
#include "options.h"
|
2006-04-24 04:23:53 +00:00
|
|
|
//#endif
|
2001-10-18 02:42:20 +00:00
|
|
|
|
2001-10-18 02:43:33 +00:00
|
|
|
//#define ASPECT_DEBUG
|
2001-10-04 11:42:21 +00:00
|
|
|
|
2002-05-14 00:22:03 +00:00
|
|
|
#if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
|
2001-10-04 11:42:21 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
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)
|
|
|
|
{
|
2003-01-13 01:50:20 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
|
|
|
printf("aspect_save_orig %dx%d \n",orgw,orgh);
|
|
|
|
#endif
|
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)
|
|
|
|
{
|
2003-01-13 01:50:20 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
|
|
|
printf("aspect_save_prescale %dx%d \n",prew,preh);
|
|
|
|
#endif
|
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)
|
|
|
|
{
|
2003-01-13 01:50:20 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
|
|
|
printf("aspect_save_screenres %dx%d \n",scrw,scrh);
|
|
|
|
#endif
|
2008-05-01 08:14:29 +00:00
|
|
|
struct MPOpts *opts = vo->opts;
|
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;
|
2001-10-18 02:42:20 +00:00
|
|
|
int tmpw;
|
|
|
|
|
2001-10-04 11:42:21 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
2008-05-01 08:02:26 +00:00
|
|
|
printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat->scrw,aspdat->scrh,
|
2008-02-02 17:21:19 +00:00
|
|
|
monitor_aspect);
|
2008-05-01 08:02:26 +00:00
|
|
|
printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
|
2001-10-04 11:42:21 +00:00
|
|
|
#endif
|
2008-02-02 17:21:19 +00:00
|
|
|
*srcw = fitw;
|
2008-05-01 08:02:26 +00:00
|
|
|
*srch = (int)(((float)fitw / (float)aspdat->prew * (float)aspdat->preh)
|
|
|
|
* ((float)aspdat->scrh / ((float)aspdat->scrw / vo->monitor_aspect)));
|
2001-10-18 02:42:20 +00:00
|
|
|
*srch+= *srch%2; // round
|
2001-10-04 11:42:21 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
2008-05-01 08:02:26 +00:00
|
|
|
printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
|
2001-10-04 11:42:21 +00:00
|
|
|
#endif
|
2009-09-04 16:49:35 +00:00
|
|
|
if(*srch>fith || *srch<aspdat->orgh){
|
2008-05-01 08:02:26 +00:00
|
|
|
tmpw = (int)(((float)fith / (float)aspdat->preh * (float)aspdat->prew)
|
|
|
|
* ((float)aspdat->scrw / ((float)aspdat->scrh / (1.0/vo->monitor_aspect))));
|
2002-05-14 00:22:03 +00:00
|
|
|
tmpw+= tmpw%2; // round
|
2009-09-04 16:49:35 +00:00
|
|
|
if(tmpw<=fitw /*&& tmpw>=aspdat->orgw*/){
|
2008-02-02 17:21:19 +00:00
|
|
|
*srch = fith;
|
2001-10-18 02:42:20 +00:00
|
|
|
*srcw = tmpw;
|
2002-05-14 00:22:03 +00:00
|
|
|
}else{
|
|
|
|
#ifndef ASPECT_TEST
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_VO,MSGL_WARN,"[ASPECT] Warning: No suitable new res found!\n");
|
2002-05-14 00:22:03 +00:00
|
|
|
#else
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_VO,MSGL_WARN,"[ASPECT] Error: No new size found that fits into res!\n");
|
2002-05-14 00:22:03 +00:00
|
|
|
#endif
|
2001-10-15 17:22:41 +00:00
|
|
|
}
|
2001-10-03 14:41:53 +00:00
|
|
|
}
|
2008-05-01 08:02:26 +00:00
|
|
|
aspdat->asp=*srcw / (float)*srch;
|
2001-10-04 11:42:21 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
2008-05-01 08:02:26 +00:00
|
|
|
printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
|
2001-10-04 11:42:21 +00:00
|
|
|
#endif
|
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;
|
|
|
|
*w = zoom ? aspdat->scrw : aspdat->prew;
|
|
|
|
*h = zoom ? aspdat->scrh : aspdat->preh;
|
2009-08-27 12:35:23 +00:00
|
|
|
if (zoom && WinID >= 0) zoom = A_WINZOOM;
|
|
|
|
if (zoom == A_WINZOOM) {
|
2009-09-04 16:49:35 +00:00
|
|
|
*w = vo->dwidth;
|
|
|
|
*h = vo->dheight;
|
2009-08-27 12:35:23 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2009-08-27 13:31:12 +00:00
|
|
|
int fitw;
|
|
|
|
int fith;
|
2009-09-04 16:49:35 +00:00
|
|
|
get_max_dims(vo, &fitw, &fith, zoom);
|
2008-02-02 17:21:19 +00:00
|
|
|
if( !zoom && geometry_wh_changed ) {
|
|
|
|
#ifdef ASPECT_DEBUG
|
|
|
|
printf("aspect(0) no aspect forced!\n");
|
|
|
|
#endif
|
|
|
|
return; // the user doesn't want to fix aspect
|
|
|
|
}
|
2008-05-01 08:02:26 +00:00
|
|
|
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
|
|
|
{
|
2002-06-10 18:40:19 +00:00
|
|
|
int fwidth,fheight;
|
|
|
|
int vo_panscan_area;
|
2009-08-27 13:31:12 +00:00
|
|
|
int max_w, max_h;
|
2009-09-04 16:49:35 +00:00
|
|
|
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-09-04 16:49:35 +00:00
|
|
|
void panscan_calc(struct vo *vo)
|
2009-08-27 18:36:51 +00:00
|
|
|
{
|
2009-09-04 16:49:35 +00:00
|
|
|
panscan_calc_internal(vo, A_ZOOM);
|
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
|
|
|
}
|