2006-02-01, 19:13
i have been using and testing this version of choosebestresolution for a while now and it works ok for me. this version doesn't use the 'autoswitch widescreen' option but chooses the best resolution according to the video aspect ratio and the bios settings (read this topic). i think the 'upsample to gui res' should also be removed (just remove the test at the begining of the function).
i hope this can be of some use.
comments ? suggestions ?
i hope this can be of some use.
comments ? suggestions ?
Quote:void cxboxrenderer::choosebestresolution(float fps)
{
// this function implements the following rules :
//
// bios settings ||display resolution
// ws|480p|720p/1080i||4:3 videos |16:6 videos
// ------------------||------------------------------
// - | x | x || 480p 4:3 | 720p
// - | x | - || 480p 4:3 | 480p 4:3
// - | - | x || 720p | 720p
// - | - | - || ntsc/pal 4:3 |ntsc/pal 4:3
// x | x | x || 720p | 720p
// x | x | - || 480p 4:3 | 480p 16:9
// x | - | x || 720p | 720p
// x | - | - || ntsc/pal 4:3 |ntsc/pal 16:9
bool busingpal = g_videoconfig.haspal(); // current video standard:pal or ntsc
bool bcandowidescreen = g_videoconfig.haswidescreen(); // can widescreen be enabled?
bool bwidescreenmode = false;
// if we use gui resolution then do nothing (should be removed ?)
if (g_guisettings.getbool("videoplayer.useguiresolution"))
{
m_iresolution = g_graphicscontext.getvideoresolution();
return;
}
// work out if the framerate suits pal50 or pal60
bool bpal60 = false;
if (busingpal && g_guisettings.getint("myvideos.framerateconversions") == frame_rate_use_pal60 && g_videoconfig.haspal60())
{
// yes we're in pal
// yes pal60 is allowed
// yes dashboard pal60 settings is enabled
// calculate the framerate difference from a divisor of 120fps and 100fps
// (twice 60fps and 50fps to allow for 2:3 ivtc pulldown)
float fframedifference60 = abs(120.0f / fps - floor(120.0f / fps + 0.5f));
float fframedifference50 = abs(100.0f / fps - floor(100.0f / fps + 0.5f));
// make a decision based on the framerate difference
if (fframedifference60 < fframedifference50)
bpal60 = true;
}
// work out if framesize suits 4:3 or 16:9
// uses the frame aspect ratio of 8/(3*sqrt(3)) (=1.53960) which is the optimal point
// where the percentage of black bars to screen area in 4:3 and 16:9 is equal
if (bcandowidescreen && m_fsourceframeratio > 8.0f / (3.0f*sqrt(3.0f)))
bwidescreenmode = true;
// we are allowed to switch video resolutions, so we must
// now decide which is the best resolution for the video we have
if (busingpal) // pal resolutions
{
// currently does not allow hdtv solutions, as it is my belief
// that the xbox hardware only allows hdtv resolutions for ntsc systems.
// this may need revising as more knowledge is obtained.
if (bpal60)
{
if (bwidescreenmode)
m_iresolution = pal60_16x9;
else
m_iresolution = pal60_4x3;
}
else // pal50
{
if (bwidescreenmode)
m_iresolution = pal_16x9;
else
m_iresolution = pal_4x3;
}
}
else // ntsc resolutions
{
if (bcandowidescreen)
{ // the tv set has a wide screen (16:9)
// so we always choose the best hd widescreen resolution no matter what
// the video aspect ratio is
// if the tv has no hd support widescreen mode is chossen according to video ar
if (g_videoconfig.has1080i()) // widescreen tv with 1080i res
m_iresolution = hdtv_1080i;
else if (g_videoconfig.has720p()) // widescreen tv with 720p res
m_iresolution = hdtv_720p;
else if (g_videoconfig.has480p()) // widescreen tv with 480p
{
if (bwidescreenmode) // choose widescreen mode according to video ar
m_iresolution = hdtv_480p_16x9;
else
m_iresolution = hdtv_480p_4x3;
}
else if (bwidescreenmode) // standard 16:9 tv set with no hd
m_iresolution = ntsc_16x9;
else
m_iresolution = ntsc_4x3;
}
else
{ // the tv set has a 4:3 aspect ratio
// so 4:3 video sources will best fit the screen with 4:3 resolution
// we choose 16:9 resolution only for 16:9 video sources
if (m_fsourceframeratio >= 16.0f / 9.0f)
{
// the video fits best into widescreen modes so they are
// the first choices
if (g_videoconfig.has1080i())
m_iresolution = hdtv_1080i;
else if (g_videoconfig.has720p())
m_iresolution = hdtv_720p;
else if (g_videoconfig.has480p())
m_iresolution = hdtv_480p_4x3;
else
m_iresolution = ntsc_4x3;
}
else
{
// the video fits best into 4:3 modes so 480p
// is the first choice
if (g_videoconfig.has480p())
m_iresolution = hdtv_480p_4x3;
else if (g_videoconfig.has1080i())
m_iresolution = hdtv_1080i;
else if (g_videoconfig.has720p())
m_iresolution = hdtv_720p;
else
m_iresolution = ntsc_4x3;
}
}
}