Core: Add back screenshots
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Feb 2016 15:29:02 -0800
6 files changed,
47 insertions(+),
2 deletions(-)
M
src/core/core.c
→
src/core/core.c
@@ -9,6 +9,8 @@ #include "core/log.h"
#include "util/vfs.h" #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 +#include "util/png-io.h" + bool mCoreLoadFile(struct mCore* core, const char* path) { struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM); if (!rom) {@@ -74,6 +76,32 @@ void mCoreDeleteState(struct mCore* core, int slot) {
char name[PATH_MAX]; snprintf(name, sizeof(name), "%s.ss%i", core->dirs.baseName, slot); core->dirs.state->deleteFile(core->dirs.state, name); +} + +void mCoreTakeScreenshot(struct mCore* core) { +#ifdef USE_PNG + size_t stride; + color_t* pixels = 0; + unsigned width, height; + core->desiredVideoDimensions(core, &width, &height); + struct VFile* vf = VDirFindNextAvailable(core->dirs.screenshot, core->dirs.baseName, "-", ".png", O_CREAT | O_TRUNC | O_WRONLY); + bool success = false; + if (vf) { + core->getVideoBuffer(core, &pixels, &stride); + png_structp png = PNGWriteOpen(vf); + png_infop info = PNGWriteHeader(png, width, height); + success = PNGWritePixels(png, width, height, stride, pixels); + PNGWriteClose(png, info); + vf->close(vf); + } + if (success) { + mLOG(STATUS, INFO, "Screenshot saved"); + return; + } +#else + UNUSED(core); +#endif + mLOG(STATUS, WARN, "Failed to take screenshot"); } #endif
M
src/core/core.h
→
src/core/core.h
@@ -51,6 +51,7 @@ void (*loadConfig)(struct mCore*);
void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height); void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride); + void (*getVideoBuffer)(struct mCore*, color_t** buffer, size_t* stride); struct blip_t* (*getAudioChannel)(struct mCore*, int ch);@@ -93,6 +94,8 @@ bool mCoreSaveState(struct mCore* core, int slot, int flags);
bool mCoreLoadState(struct mCore* core, int slot, int flags); struct VFile* mCoreGetState(struct mCore* core, int slot, bool write); void mCoreDeleteState(struct mCore* core, int slot); + +void mCoreTakeScreenshot(struct mCore* core); #endif void mCoreInitConfig(struct mCore* core, const char* port);
M
src/gb/core.c
→
src/gb/core.c
@@ -77,6 +77,12 @@ gbcore->renderer.outputBuffer = buffer;
gbcore->renderer.outputBufferStride = stride; } +static void _GBCoreGetVideoBuffer(struct mCore* core, color_t** buffer, size_t* stride) { + struct GBCore* gbcore = (struct GBCore*) core; + *buffer = gbcore->renderer.outputBuffer; + *stride = gbcore->renderer.outputBufferStride; +} + static struct blip_t* _GBCoreGetAudioChannel(struct mCore* core, int ch) { struct GB* gb = core->board; switch (ch) {@@ -200,6 +206,7 @@ core->setSync = _GBCoreSetSync;
core->loadConfig = _GBCoreLoadConfig; core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions; core->setVideoBuffer = _GBCoreSetVideoBuffer; + core->getVideoBuffer = _GBCoreGetVideoBuffer; core->getAudioChannel = _GBCoreGetAudioChannel; core->isROM = GBIsROM; core->loadROM = _GBCoreLoadROM;
M
src/gba/core.c
→
src/gba/core.c
@@ -104,6 +104,12 @@ gbacore->renderer.outputBuffer = buffer;
gbacore->renderer.outputBufferStride = stride; } +static void _GBACoreGetVideoBuffer(struct mCore* core, color_t** buffer, size_t* stride) { + struct GBACore* gbacore = (struct GBACore*) core; + *buffer = gbacore->renderer.outputBuffer; + *stride = gbacore->renderer.outputBufferStride; +} + static struct blip_t* _GBACoreGetAudioChannel(struct mCore* core, int ch) { struct GBA* gba = core->board; switch (ch) {@@ -243,6 +249,7 @@ core->setSync = _GBACoreSetSync;
core->loadConfig = _GBACoreLoadConfig; core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions; core->setVideoBuffer = _GBACoreSetVideoBuffer; + core->getVideoBuffer = _GBACoreGetVideoBuffer; core->getAudioChannel = _GBACoreGetAudioChannel; core->isROM = GBAIsROM; core->loadROM = _GBACoreLoadROM;
M
src/gba/gui/gui-runner.c
→
src/gba/gui/gui-runner.c
@@ -342,7 +342,7 @@ case RUNNER_LOAD_STATE:
mCoreLoadState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT); break; case RUNNER_SCREENSHOT: - // TODO: Put back screenshots + mCoreTakeScreenshot(runner->core); break; case RUNNER_CONFIG: mGUIShowConfig(runner, runner->configExtra, runner->nConfigExtra);
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -561,7 +561,7 @@ // TODO: Put back debugger
return; #ifdef USE_PNG case SDLK_F12: - // TODO: Put back screenshots + mCoreTakeScreenshot(context->core); return; #endif case SDLK_BACKSLASH: