Added writing of text tags to PNG snapshots. For now, it only saves

the version of Stella used, as well as some ROM info (name, md5, etc).


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1155 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-11-26 16:58:21 +00:00
parent d536cb06ea
commit 563ba6b24b
3 changed files with 36 additions and 6 deletions

View File

@ -13,20 +13,25 @@
// 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.12 2006-11-10 06:14:14 stephena Exp $
// $Id: Snapshot.cxx,v 1.13 2006-11-26 16:58:21 stephena Exp $
//============================================================================
#ifdef SNAPSHOT_SUPPORT
#include <zlib.h>
#include <fstream>
#include <cstring>
#include <sstream>
#include "bspf.hxx"
#include "FrameBuffer.hxx"
#include "Props.hxx"
#include "Version.hxx"
#include "Snapshot.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Snapshot::savePNG(FrameBuffer& framebuffer, const string& filename)
void Snapshot::savePNG(FrameBuffer& framebuffer, const Properties& props,
const string& filename)
{
uInt8* buffer = (uInt8*) NULL;
uInt8* compmem = (uInt8*) NULL;
@ -88,6 +93,12 @@ void Snapshot::savePNG(FrameBuffer& framebuffer, const string& filename)
// Write the compressed framebuffer data
writePNGChunk(out, "IDAT", compmem, compmemsize);
// Add some info about this snapshot
writePNGText(out, "Software", string("Stella ") + STELLA_VERSION);
writePNGText(out, "ROM Name", props.get(Cartridge_Name));
writePNGText(out, "ROM MD5", props.get(Cartridge_MD5));
writePNGText(out, "Display Format", props.get(Display_Format));
// Finish up
writePNGChunk(out, "IEND", 0, 0);
@ -140,4 +151,18 @@ void Snapshot::writePNGChunk(ofstream& out, char* type, uInt8* data, int size)
out.write((const char*)temp, 4);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Snapshot::writePNGText(ofstream& out, const string& key, const string& text)
{
int length = key.length() + 1 + text.length() + 1;
uInt8* data = new uInt8[length];
strcpy((char*)data, key.c_str());
strcpy((char*)data + key.length() + 1, text.c_str());
writePNGChunk(out, "tEXt", data, length-1);
delete[] data;
}
#endif // SNAPSHOT_SUPPORT

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: Snapshot.hxx,v 1.7 2006-11-10 06:14:14 stephena Exp $
// $Id: Snapshot.hxx,v 1.8 2006-11-26 16:58:21 stephena Exp $
//============================================================================
#ifndef SNAPSHOT_HXX
@ -21,6 +21,7 @@
#ifdef SNAPSHOT_SUPPORT
class Properties;
class FrameBuffer;
#include <fstream>
@ -33,12 +34,15 @@ class Snapshot
Save the current frame buffer to a PNG file.
@param framebuffer The framebuffer containing the image data
@param props The properties object containing info about the ROM
@param filename The filename of the PNG file
*/
static void savePNG(FrameBuffer& framebuffer, const string& filename);
static void savePNG(FrameBuffer& framebuffer, const Properties& props,
const string& filename);
private:
static void writePNGChunk(ofstream& out, char* type, uInt8* data, int size);
static void writePNGText(ofstream& out, const string& key, const string& text);
};
#endif // SNAPSHOT_SUPPORT

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: EventHandler.cxx,v 1.171 2006-11-19 00:48:55 stephena Exp $
// $Id: EventHandler.cxx,v 1.172 2006-11-26 16:58:21 stephena Exp $
//============================================================================
#include <sstream>
@ -2159,7 +2159,8 @@ void EventHandler::takeSnapshot()
filename = sspath + ".png";
// Now create a PNG snapshot
Snapshot::savePNG(myOSystem->frameBuffer(), filename);
Snapshot::savePNG(myOSystem->frameBuffer(),
myOSystem->console().properties(), filename);
#else
myOSystem->frameBuffer().showMessage("Snapshots unsupported");
#endif