Add -maxaspect option for fullscreen, which stretches / autocrops, but ignores 8:7 aspect.

This commit is contained in:
Greg Kennedy 2016-01-02 22:32:31 -06:00
parent 65a3701be3
commit f1f71f92e8
1 changed files with 41 additions and 23 deletions

View File

@ -276,6 +276,9 @@ struct GUIData
int scale_w; int scale_w;
int scale_h; int scale_h;
bool8 maxaspect;
int imageHeight;
int xv_format; int xv_format;
int xv_bpp; int xv_bpp;
unsigned char y_table[1 << 15]; unsigned char y_table[1 << 15];
@ -345,6 +348,7 @@ void S9xExtraDisplayUsage (void)
S9xMessage(S9X_INFO, S9X_USAGE, "-fullscreen Switch to full-screen on start"); S9xMessage(S9X_INFO, S9X_USAGE, "-fullscreen Switch to full-screen on start");
#ifdef USE_XVIDEO #ifdef USE_XVIDEO
S9xMessage(S9X_INFO, S9X_USAGE, "-xvideo Hardware accelerated scaling"); S9xMessage(S9X_INFO, S9X_USAGE, "-xvideo Hardware accelerated scaling");
S9xMessage(S9X_INFO, S9X_USAGE, "-maxaspect Try to fill the display, in fullscreen");
#endif #endif
S9xMessage(S9X_INFO, S9X_USAGE, ""); S9xMessage(S9X_INFO, S9X_USAGE, "");
S9xMessage(S9X_INFO, S9X_USAGE, "-v1 Video mode: Blocky (default)"); S9xMessage(S9X_INFO, S9X_USAGE, "-v1 Video mode: Blocky (default)");
@ -370,6 +374,9 @@ void S9xParseDisplayArg (char **argv, int &i, int argc)
if (!strcasecmp(argv[i], "-xvideo")) if (!strcasecmp(argv[i], "-xvideo"))
GUI.use_xvideo = TRUE; GUI.use_xvideo = TRUE;
else else
if (!strcasecmp(argv[i], "-maxaspect")
GUI.maxaspect = TRUE;
else
#endif #endif
if (!strncasecmp(argv[i], "-v", 2)) if (!strncasecmp(argv[i], "-v", 2))
{ {
@ -532,6 +539,7 @@ const char * S9xParseDisplayConfig (ConfigFile &conf, int pass)
GUI.fullscreen = conf.GetBool("Unix/X11::Fullscreen", FALSE); GUI.fullscreen = conf.GetBool("Unix/X11::Fullscreen", FALSE);
#ifdef USE_XVIDEO #ifdef USE_XVIDEO
GUI.use_xvideo = conf.GetBool("Unix/X11::Xvideo", FALSE); GUI.use_xvideo = conf.GetBool("Unix/X11::Xvideo", FALSE);
GUI.use_xvideo = conf.GetBool("Unix/X11::MaxAspect", FALSE);
#endif #endif
if (conf.Exists("Unix/X11::VideoMode")) if (conf.Exists("Unix/X11::VideoMode"))
@ -845,33 +853,39 @@ void S9xInitDisplay (int argc, char **argv)
#ifdef USE_XVIDEO #ifdef USE_XVIDEO
if (GUI.use_xvideo) if (GUI.use_xvideo)
{ {
// Compute the maximum screen size for scaling xvideo window.
double screenAspect = (double)WidthOfScreen(GUI.screen) / HeightOfScreen(GUI.screen);
double snesAspect = (double)SNES_WIDTH / SNES_HEIGHT_EXTENDED;
double ratio = screenAspect / snesAspect;
printf("\tScreen (%dx%d) aspect %f vs SNES (%dx%d) aspect %f (ratio: %f)\n",
WidthOfScreen(GUI.screen),HeightOfScreen(GUI.screen),screenAspect,
SNES_WIDTH,SNES_HEIGHT_EXTENDED,snesAspect,
ratio);
// Set some defaults // Set some defaults
GUI.scale_w = WidthOfScreen(GUI.screen); GUI.scale_w = WidthOfScreen(GUI.screen);
GUI.scale_h = HeightOfScreen(GUI.screen); GUI.scale_h = HeightOfScreen(GUI.screen);
// Correct aspect ratio GUI.imageHeight = SNES_HEIGHT_EXTENDED * 2;
if (screenAspect > snesAspect)
if (! GUI.maxaspect)
{ {
// widescreen monitor, 4:3 snes // Compute the maximum screen size for scaling xvideo window.
// match height, scale width double screenAspect = (double)WidthOfScreen(GUI.screen) / HeightOfScreen(GUI.screen);
GUI.scale_w /= ratio; double snesAspect = (double)SNES_WIDTH / SNES_HEIGHT_EXTENDED;
GUI.x_offset = (WidthOfScreen(GUI.screen) - GUI.scale_w) / 2; double ratio = screenAspect / snesAspect;
} else {
// narrow monitor, 4:3 snes printf("\tScreen (%dx%d) aspect %f vs SNES (%dx%d) aspect %f (ratio: %f)\n",
// match width, scale height WidthOfScreen(GUI.screen),HeightOfScreen(GUI.screen),screenAspect,
GUI.scale_h *= ratio; SNES_WIDTH,SNES_HEIGHT_EXTENDED,snesAspect,
GUI.y_offset = (HeightOfScreen(GUI.screen) - GUI.scale_h) / 2; ratio);
// Correct aspect ratio
if (screenAspect > snesAspect)
{
// widescreen monitor, 4:3 snes
// match height, scale width
GUI.scale_w /= ratio;
GUI.x_offset = (WidthOfScreen(GUI.screen) - GUI.scale_w) / 2;
} else {
// narrow monitor, 4:3 snes
// match width, scale height
GUI.scale_h *= ratio;
GUI.y_offset = (HeightOfScreen(GUI.screen) - GUI.scale_h) / 2;
}
} }
printf("\tUsing size %dx%d with offset (%d,%d)\n",GUI.scale_w,GUI.scale_h,GUI.x_offset,GUI.y_offset); printf("\tUsing size %dx%d with offset (%d,%d)\n",GUI.scale_w,GUI.scale_h,GUI.x_offset,GUI.y_offset);
} }
else else
@ -1401,6 +1415,10 @@ void S9xPutImage (int width, int height)
} }
} }
// Change the image height if we are in maxaspect mode
if (GUI.maxaspect && GUI.fullscreen)
GUI.imageHeight = height * 2;
#ifdef USE_XVIDEO #ifdef USE_XVIDEO
if (GUI.use_xvideo && (GUI.xv_format == FOURCC_YUY2)) if (GUI.use_xvideo && (GUI.xv_format == FOURCC_YUY2))
{ {
@ -1559,13 +1577,13 @@ static void Repaint (bool8 isFrameBoundry)
if (GUI.use_shared_memory) if (GUI.use_shared_memory)
{ {
XvShmPutImage(GUI.display, GUI.xv_port, GUI.window, GUI.gc, GUI.image->xvimage, XvShmPutImage(GUI.display, GUI.xv_port, GUI.window, GUI.gc, GUI.image->xvimage,
0, 0, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, 0, 0, SNES_WIDTH * 2, GUI.imageHeight,
GUI.x_offset, GUI.y_offset, GUI.scale_w, GUI.scale_h, False); GUI.x_offset, GUI.y_offset, GUI.scale_w, GUI.scale_h, False);
} }
else else
#endif #endif
XvPutImage(GUI.display, GUI.xv_port, GUI.window, GUI.gc, GUI.image->xvimage, XvPutImage(GUI.display, GUI.xv_port, GUI.window, GUI.gc, GUI.image->xvimage,
0, 0, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, 0, 0, SNES_WIDTH * 2, GUI.imageHeight,
GUI.x_offset, GUI.y_offset, GUI.scale_w, GUI.scale_h); GUI.x_offset, GUI.y_offset, GUI.scale_w, GUI.scale_h);
} }
else else