Added '-sssingle' commandline argument to the X11 and SDL versions.

If specified, this will save single snapshots instead of generating multiple
snapshots saved as 'filename_x.png'.

Updated stellarc file to select 'sssingle' command.

Fixed some problems in the SDL snapshot code.

Fixed long-standing bug in the X11 version where closing the window did not
properly exit the emulator.  Now exits are done correctly.  No more
zombie stella-sound processes :)


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@43 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2002-02-23 16:05:52 +00:00
parent 5a8ca97c59
commit cc8ea20d1e
4 changed files with 99 additions and 43 deletions

View File

@ -26,3 +26,4 @@
;fullscreen = <0|1>
;ssdir = <pathname>
;ssname = <romname|md5sum>
;sssingle = <0|1>

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SnapSDL.cxx,v 1.1 2002-02-17 04:41:41 stephena Exp $
// $Id: SnapSDL.cxx,v 1.2 2002-02-23 16:05:52 stephena Exp $
//============================================================================
#include <SDL.h>
@ -36,7 +36,7 @@ int SnapshotSDL::savePNG(SDL_Surface *surface, const char *file)
{
SDL_RWops *out = SDL_RWFromFile(file, "wb");
if(!out)
return -1;
return 0;
int ret = IMG_SavePNG_RW(surface, out);
SDL_RWclose(out);
@ -96,7 +96,7 @@ int SnapshotSDL::IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *src)
if(png_ptr == NULL)
{
cerr << "SnapshotSDL: Couldn't allocate memory for PNG file\n";
return -1;
return 0;
}
/* Allocate/initialize the image information data. REQUIRED */
@ -117,7 +117,6 @@ int SnapshotSDL::IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *src)
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
*/
colortype = png_colortype_from_surface(surface);
png_set_IHDR(png_ptr, info_ptr, surface->w, surface->h, 8,
colortype, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainSDL.cxx,v 1.9 2002-02-17 04:41:41 stephena Exp $
// $Id: mainSDL.cxx,v 1.10 2002-02-23 16:05:52 stephena Exp $
//============================================================================
#include <assert.h>
@ -227,6 +227,10 @@ string theSnapShotDir = "";
// What the snapshot should be called (romname or md5sum)
string theSnapShotName = "";
// Indicates whether to generate multiple snapshots or keep
// overwriting the same file. Set to true by default.
bool theMultipleSnapShotFlag = true;
/**
This routine should be called once the console is created to setup
@ -400,8 +404,7 @@ bool createScreen(int w, int h)
g = format->palette->colors[i].g;
b = format->palette->colors[i].b;
palette[i] = SDL_MapRGB(format, r, g, b);
palette[i+1] = palette[i];
palette[i] = palette[i+1] = SDL_MapRGB(format, r, g, b);
}
return true;
@ -466,15 +469,15 @@ void resizeWindow(int mode)
*/
void centerWindow()
{
if(isFullscreen || isCentered)
return;
if(!x11Available)
{
cerr << "Window centering only available under X11.\n";
return;
}
if(isFullscreen || isCentered)
return;
int x, y, w, h;
info.info.x11.lock_func();
theX11Display = info.info.x11.display;
@ -1030,6 +1033,7 @@ void handleEvents()
the 'ssname' argument. If that name exists, they are named as "Name"_x.png,
where x starts with 1 and increases if the previous name already exists.
All spaces in filenames are converted to underscore '_'.
If theMultipleSnapShotFlag is false, then consecutive images are overwritten.
*/
void takeSnapshot()
{
@ -1038,12 +1042,7 @@ void takeSnapshot()
cerr << "Snapshot support disabled.\n";
return;
}
/* else if(isFullscreen)
{
cerr << "Snapshot support unavailable in fullscreen (for now).\n";
return;
}
*/
int width = screen->w;
int height = screen->h;
@ -1063,24 +1062,30 @@ void takeSnapshot()
// Replace all spaces in name with underscores
replace(filename.begin(), filename.end(), ' ', '_');
// Determine if the file already exists, checking each successive filename
// until one doesn't exist
string extFilename = filename + ".png";
if(access(extFilename.c_str(), F_OK) == 0 )
// Check whether we want multiple snapshots created
if(theMultipleSnapShotFlag)
{
uInt32 i;
char buffer[1024];
for(i = 1; ;++i)
// Determine if the file already exists, checking each successive filename
// until one doesn't exist
string extFilename = filename + ".png";
if(access(extFilename.c_str(), F_OK) == 0 )
{
snprintf(buffer, 1023, "%s_%d.png", filename.c_str(), i);
if(access(buffer, F_OK) == -1 )
break;
uInt32 i;
char buffer[1024];
for(i = 1; ;++i)
{
snprintf(buffer, 1023, "%s_%d.png", filename.c_str(), i);
if(access(buffer, F_OK) == -1 )
break;
}
filename = buffer;
}
filename = buffer;
else
filename = extFilename;
}
else
filename = extFilename;
filename = filename + ".png";
// Now save the snapshot file
snapshot->savePNG(screen, filename.c_str());
@ -1161,6 +1166,7 @@ void usage()
" -showinfo Shows some game info on exit",
" -ssdir <path> The directory to save snapshot files to",
" -ssname <name> How to name the snapshot (romname or md5sum)",
" -sssingle Generate single snapshot instead of many",
" -pro <props file> Use the given properties file instead of stella.pro",
"",
0
@ -1313,6 +1319,10 @@ void handleCommandLineArguments(int argc, char* argv[])
{
theSnapShotName = argv[++i];
}
else if(string(argv[i]) == "-sssingle")
{
theMultipleSnapShotFlag = false;
}
else if(string(argv[i]) == "-pro")
{
theAlternateProFile = argv[++i];
@ -1483,6 +1493,14 @@ void parseRCOptions(istream& in)
{
theSnapShotName = value;
}
else if(key == "sssingle")
{
uInt32 option = atoi(value.c_str());
if(option == 1)
theMultipleSnapShotFlag = false;
else if(option == 0)
theMultipleSnapShotFlag = true;
}
}
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainX11.cxx,v 1.9 2002-02-17 04:41:42 stephena Exp $
// $Id: mainX11.cxx,v 1.10 2002-02-23 16:05:52 stephena Exp $
//============================================================================
#include <assert.h>
@ -53,6 +53,10 @@
// What the snapshot should be called (romname or md5sum)
string theSnapShotName = "";
// Indicates whether to generate multiple snapshots or keep
// overwriting the same file. Set to true by default.
bool theMultipleSnapShotFlag = true;
#endif
#ifdef LINUX_JOYSTICK
@ -75,6 +79,7 @@ Colormap thePrivateColormap;
Cursor normalCursor;
Cursor blankCursor;
uInt32 eventMask;
Atom wm_delete_window;
// A graphic context for each of the 2600's colors
GC theGCTable[256];
@ -351,6 +356,10 @@ bool setupDisplay()
theGCTable[t + 1] = theGCTable[t];
}
// Set up the delete window stuff ...
wm_delete_window = XInternAtom(theDisplay, "WM_DELETE_WINDOW", False);
XSetWMProtocols(theDisplay, theWindow, &wm_delete_window, 1);
// If requested install a private colormap for the window
if(theUsePrivateColormapFlag)
{
@ -563,6 +572,16 @@ void handleEvents()
{
XEvent event;
// Handle the WM_DELETE_WINDOW message outside the event loop
if(XCheckTypedWindowEvent(theDisplay, theWindow, ClientMessage, &event))
{
if(event.xclient.data.l[0] == wm_delete_window)
{
doQuit();
return;
}
}
while(XCheckWindowEvent(theDisplay, theWindow, eventMask, &event))
{
char buffer[20];
@ -1041,24 +1060,30 @@ void takeSnapshot()
// Replace all spaces in name with underscores
replace(filename.begin(), filename.end(), ' ', '_');
// Determine if the file already exists, checking each successive filename
// until one doesn't exist
string extFilename = filename + ".png";
if(access(extFilename.c_str(), F_OK) == 0 )
// Check whether we want multiple snapshots created
if(theMultipleSnapShotFlag)
{
uInt32 i;
char buffer[1024];
for(i = 1; ;++i)
// Determine if the file already exists, checking each successive filename
// until one doesn't exist
string extFilename = filename + ".png";
if(access(extFilename.c_str(), F_OK) == 0 )
{
snprintf(buffer, 1023, "%s_%d.png", filename.c_str(), i);
if(access(buffer, F_OK) == -1 )
break;
uInt32 i;
char buffer[1024];
for(i = 1; ;++i)
{
snprintf(buffer, 1023, "%s_%d.png", filename.c_str(), i);
if(access(buffer, F_OK) == -1 )
break;
}
filename = buffer;
}
filename = buffer;
else
filename = extFilename;
}
else
filename = extFilename;
filename = filename + ".png";
// Now save the snapshot file
Imlib_save_image(imlibData, image, (char*)filename.c_str(), NULL);
@ -1134,6 +1159,7 @@ void usage()
#ifdef HAVE_IMLIB
" -ssdir <path> The directory to save snapshot files to",
" -ssname <name> How to name the snapshot (romname or md5sum)",
" -sssingle Generate single snapshot instead of many",
#endif
" -pro <props file> Use the given properties file instead of stella.pro",
"",
@ -1290,6 +1316,10 @@ void handleCommandLineArguments(int argc, char* argv[])
{
theSnapShotName = argv[++i];
}
else if(string(argv[i]) == "-sssingle")
{
theMultipleSnapShotFlag = false;
}
#endif
else if(string(argv[i]) == "-pro")
{
@ -1464,6 +1494,14 @@ void parseRCOptions(istream& in)
{
theSnapShotName = value;
}
else if(key == "sssingle")
{
uInt32 option = atoi(value.c_str());
if(option == 1)
theMultipleSnapShotFlag = false;
else if(option == 0)
theMultipleSnapShotFlag = true;
}
#endif
}
}