mirror of https://github.com/stella-emu/stella.git
Minor reworking of the Snapshot class, making the savePNG method static.
There was really no need to have this as an object, since it's all static code anyway. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1145 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
12d9de32cc
commit
90723af108
|
@ -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: Snapshot.cxx,v 1.11 2006-11-09 03:06:42 stephena Exp $
|
||||
// $Id: Snapshot.cxx,v 1.12 2006-11-10 06:14:14 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifdef SNAPSHOT_SUPPORT
|
||||
|
@ -26,15 +26,7 @@
|
|||
#include "Snapshot.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Snapshot::Snapshot(FrameBuffer& framebuffer)
|
||||
: myFrameBuffer(framebuffer)
|
||||
{
|
||||
// Make sure we have a 'clean' image, with no onscreen messages
|
||||
myFrameBuffer.hideMessage();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string Snapshot::savePNG(string filename)
|
||||
void Snapshot::savePNG(FrameBuffer& framebuffer, const string& filename)
|
||||
{
|
||||
uInt8* buffer = (uInt8*) NULL;
|
||||
uInt8* compmem = (uInt8*) NULL;
|
||||
|
@ -42,10 +34,13 @@ string Snapshot::savePNG(string filename)
|
|||
|
||||
try
|
||||
{
|
||||
// Make sure we have a 'clean' image, with no onscreen messages
|
||||
framebuffer.hideMessage();
|
||||
|
||||
// Get actual image dimensions. which are not always the same
|
||||
// as the framebuffer dimensions
|
||||
int width = myFrameBuffer.imageWidth();
|
||||
int height = myFrameBuffer.imageHeight();
|
||||
int width = framebuffer.imageWidth();
|
||||
int height = framebuffer.imageHeight();
|
||||
|
||||
out.open(filename.c_str(), ios_base::binary);
|
||||
if(!out)
|
||||
|
@ -79,7 +74,7 @@ string Snapshot::savePNG(string filename)
|
|||
for(int row = 0; row < height; row++)
|
||||
{
|
||||
*buf_ptr++ = 0; // first byte of row is filter type
|
||||
myFrameBuffer.scanline(row, buf_ptr); // get another scanline
|
||||
framebuffer.scanline(row, buf_ptr); // get another scanline
|
||||
buf_ptr += rowbytes; // add pitch
|
||||
}
|
||||
|
||||
|
@ -101,21 +96,14 @@ string Snapshot::savePNG(string filename)
|
|||
if(compmem) delete[] compmem;
|
||||
out.close();
|
||||
|
||||
return "Snapshot saved";
|
||||
framebuffer.showMessage("Snapshot saved");
|
||||
}
|
||||
catch(const char *msg)
|
||||
{
|
||||
if(buffer) delete[] buffer;
|
||||
if(compmem) delete[] compmem;
|
||||
out.close();
|
||||
return msg;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
if(buffer) delete[] buffer;
|
||||
if(compmem) delete[] compmem;
|
||||
out.close();
|
||||
return "Couldn't create snapshot file";
|
||||
framebuffer.showMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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: Snapshot.hxx,v 1.6 2006-11-09 03:06:42 stephena Exp $
|
||||
// $Id: Snapshot.hxx,v 1.7 2006-11-10 06:14:14 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SNAPSHOT_HXX
|
||||
|
@ -29,27 +29,16 @@ class FrameBuffer;
|
|||
class Snapshot
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Create a new shapshot class for taking snapshots in PNG format.
|
||||
|
||||
@param framebuffer The SDL framebuffer containing the image data
|
||||
*/
|
||||
Snapshot(FrameBuffer& framebuffer);
|
||||
|
||||
/**
|
||||
Save the current frame buffer to a PNG file.
|
||||
|
||||
@param framebuffer The framebuffer containing the image data
|
||||
@param filename The filename of the PNG file
|
||||
@return The resulting string to print to the framebuffer
|
||||
*/
|
||||
string savePNG(string filename);
|
||||
static void savePNG(FrameBuffer& framebuffer, const string& filename);
|
||||
|
||||
private:
|
||||
static void writePNGChunk(ofstream& out, char* type, uInt8* data, int size);
|
||||
|
||||
private:
|
||||
// The Framebuffer for the system
|
||||
FrameBuffer& myFrameBuffer;
|
||||
};
|
||||
|
||||
#endif // SNAPSHOT_SUPPORT
|
||||
|
|
|
@ -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: EventHandler.cxx,v 1.168 2006-11-06 00:52:03 stephena Exp $
|
||||
// $Id: EventHandler.cxx,v 1.169 2006-11-10 06:14:14 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <sstream>
|
||||
|
@ -2159,10 +2159,8 @@ void EventHandler::takeSnapshot()
|
|||
else
|
||||
filename = sspath + ".png";
|
||||
|
||||
// Now create a Snapshot object and save the PNG
|
||||
Snapshot snapshot(myOSystem->frameBuffer());
|
||||
string result = snapshot.savePNG(filename);
|
||||
myOSystem->frameBuffer().showMessage(result);
|
||||
// Now create a PNG snapshot
|
||||
Snapshot::savePNG(myOSystem->frameBuffer(), filename);
|
||||
#else
|
||||
myOSystem->frameBuffer().showMessage("Snapshots unsupported");
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue