1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-29 18:42:09 +00:00
mpv/libvo/aspect.c

184 lines
5.2 KiB
C
Raw Normal View History

/*
* 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.
*/
/* Stuff for correct aspect scaling. */
#include "aspect.h"
#include "geometry.h"
#include "video_out.h"
//#ifndef ASPECT_TEST
#include "mp_msg.h"
2008-05-01 08:14:29 +00:00
#include "options.h"
//#endif
//#define ASPECT_DEBUG
#if defined(ASPECT_DEBUG) || defined(ASPECT_TEST)
#include <stdio.h>
#endif
#include "video_out.h"
void aspect_save_orig(struct vo *vo, int orgw, int orgh)
{
#ifdef ASPECT_DEBUG
printf("aspect_save_orig %dx%d \n",orgw,orgh);
#endif
vo->aspdat.orgw = orgw;
vo->aspdat.orgh = orgh;
}
void aspect_save_prescale(struct vo *vo, int prew, int preh)
{
#ifdef ASPECT_DEBUG
printf("aspect_save_prescale %dx%d \n",prew,preh);
#endif
vo->aspdat.prew = prew;
vo->aspdat.preh = preh;
}
void aspect_save_screenres(struct vo *vo, int scrw, int scrh)
{
#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;
if (scrw <= 0 && scrh <= 0)
scrw = 1024;
if (scrh <= 0)
scrh = (scrw * 3 + 3) / 4;
if (scrw <= 0)
scrw = (scrh * 4 + 2) / 3;
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;
}
/* aspect is called with the source resolution and the
* resolution, that the scaled image should fit into
*/
void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith)
{
struct aspect_data *aspdat = &vo->aspdat;
int tmpw;
#ifdef ASPECT_DEBUG
printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat->scrw,aspdat->scrh,
monitor_aspect);
printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
#endif
*srcw = fitw;
*srch = (int)(((float)fitw / (float)aspdat->prew * (float)aspdat->preh)
* ((float)aspdat->scrh / ((float)aspdat->scrw / vo->monitor_aspect)));
*srch+= *srch%2; // round
#ifdef ASPECT_DEBUG
printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
#endif
2009-09-04 16:49:35 +00:00
if(*srch>fith || *srch<aspdat->orgh){
tmpw = (int)(((float)fith / (float)aspdat->preh * (float)aspdat->prew)
* ((float)aspdat->scrw / ((float)aspdat->scrh / (1.0/vo->monitor_aspect))));
tmpw+= tmpw%2; // round
2009-09-04 16:49:35 +00:00
if(tmpw<=fitw /*&& tmpw>=aspdat->orgw*/){
*srch = fith;
*srcw = tmpw;
}else{
#ifndef ASPECT_TEST
mp_tmsg(MSGT_VO,MSGL_WARN,"[ASPECT] Warning: No suitable new res found!\n");
#else
mp_tmsg(MSGT_VO,MSGL_WARN,"[ASPECT] Error: No new size found that fits into res!\n");
#endif
}
}
aspdat->asp=*srcw / (float)*srch;
#ifdef ASPECT_DEBUG
printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
#endif
}
2009-09-04 16:49:35 +00:00
static void get_max_dims(struct vo *vo, int *w, int *h, int zoom)
{
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;
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-09-04 16:49:35 +00:00
void aspect(struct vo *vo, int *srcw, int *srch, int zoom)
{
int fitw;
int fith;
2009-09-04 16:49:35 +00:00
get_max_dims(vo, &fitw, &fith, zoom);
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
}
aspect_fit(vo, srcw, srch, fitw, fith);
}
void panscan_init(struct vo *vo)
{
vo->panscan_x = 0;
vo->panscan_y = 0;
vo->panscan_amount = 0.0f;
}
2009-09-04 16:49:35 +00:00
static void panscan_calc_internal(struct vo *vo, int zoom)
{
int fwidth,fheight;
int vo_panscan_area;
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;
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;
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;
} else
2009-09-04 16:49:35 +00:00
vo_panscan_area = -opts->vo_panscanrange * max_h;
2009-09-04 16:49:35 +00:00
vo->panscan_amount = vo_fs || zoom == A_WINZOOM ? vo_panscan : 0;
vo->panscan_x = vo_panscan_area * vo->panscan_amount * vo->aspdat.asp;
vo->panscan_y = vo_panscan_area * vo->panscan_amount;
}
2009-09-04 16:49:35 +00:00
void panscan_calc(struct vo *vo)
{
2009-09-04 16:49:35 +00:00
panscan_calc_internal(vo, A_ZOOM);
}
/**
* 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-09-04 16:49:35 +00:00
panscan_calc_internal(vo, A_WINZOOM);
}